ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/HiggsAnalysis/EarlyDataStudy/scripts/heds.sh
Revision: 1.9
Committed: Wed May 12 12:58:26 2010 UTC (14 years, 11 months ago) by mangano
Content type: application/x-sh
Branch: MAIN
CVS Tags: V00-01-00
Changes since 1.8: +85 -25 lines
Log Message:
too many fixes to list them

File Contents

# User Rev Content
1 mangano 1.1 #!/bin/bash
2    
3     ######################################################
4     # heds 0 (create new directories)
5     # heds 1 (query runregistry)
6     # heds 2 (create crab task)
7     # heds 3 (get and publish jobs)
8     # heds 4 (create all the html tables and store logs)
9     # heds 5* (event display stuff)
10     ######################################################
11    
12     choice=$1
13    
14     dailySkim=$HEDS_NAMEPREFIX$HEDS_LABEL-v$HEDS_TASKATTEMPT
15    
16    
17    
18     case $choice in
19 mangano 1.5 ######### "public functions" which are meant to be called by the users ################
20     up) ### bootstrap for heds job submission. It creates the intial configuration file
21     cat > ./heds.cfg <<EOF
22 mangano 1.7 ### insert a day of data-taking in the format DD.MM.YYYY
23 mangano 1.5 HEDS_LABEL=18.04.2010
24 mangano 1.7
25     ### name of the local folder containing the configuration and output of your heds task
26     HEDS_LOCALSTORE=""
27    
28     ### input sample
29     #HEDS_INPUTDATASET=/MinimumBias/Commissioning10-Apr20ReReco-v1/RECO #up to run 133532
30     HEDS_INPUTDATASET=/MinimumBias/Commissioning10-PromptReco-v9/RECO #starting from run 133532
31    
32    
33     HEDS_SKIMVERSION=7
34 mangano 1.5 HEDS_TASKATTEMPT=1
35    
36     HEDS_USERID=mangano
37     HEDS_T2SITE=T2_US_UCSD
38    
39    
40     ### TO BE FIXED. THESE VARIABLE COULD BE RETRIEVED FROM A QUERY TO PHEDEX ###
41     HEDS_STORAGEPATH=/srm/v2/server?SFN=/hadoop/cms
42     HEDS_STORAGEPORT=8443
43     EOF
44     echo -e "+++ Bootstrap of \"heds\" scripts peformed"
45     echo -e "+++ The configuration file \"heds.cfg\" has been created in the current folder:"
46     echo -e " "$PWD "\n"
47     echo "+++ Edit the heds.cfg according to your needs and then execute: "
48     echo -e " ""heds.sh create heds.cfg"
49     ;;
50    
51     create) ### create local heds taskFolder
52     configFile=$2
53     if [ -z "$configFile" ]; then
54     echo "+++ ERROR: you have to specify the configuration file as in:"
55     echo " heds.sh create <heds.cfg>"
56     exit 1
57     fi
58    
59     if [ -z "$CMSSW_BASE" ]; then
60     echo "+++ ERROR: you have to setup CMSSW environment first. Run cmsenv";
61     (exit 1;)
62     fi
63    
64     if [ ! -d $CMSSW_BASE/src/HiggsAnalysis/EarlyDataStudy/scripts ]; then
65     echo "+++ ERROR: you have to checkout and compile \"HiggsAnalysis/EarlyDataStudy\" first.";
66     (exit 1;)
67     fi
68    
69    
70    
71     # get rid of lines with comments
72     grep -v '^#' $configFile > tmpFile
73     mv tmpFile ${configFile}
74    
75     # add export lines
76     grep -v '^$' ${configFile}| awk '{print "export "$0}' > tmpFile
77     mv tmpFile ${configFile}
78    
79     # define default taskFolder if it is not defined in the cfg file
80     autoString=heds_taskFolder_`date '+%d_%m_%Y_%H_%M'`
81     source ${configFile}
82     if [ -z "$HEDS_LOCALSTORE" ]; then
83     sed "s#HEDS_LOCALSTORE=\"\"#HEDS_LOCALSTORE=$autoString#" ${configFile} > tmpFile
84     mv tmpFile ${configFile}
85     fi
86    
87     # make taskFolder path absolute
88     tmpString="HEDS_LOCALSTORE=`pwd`/"
89     sed "s#HEDS_LOCALSTORE=#$tmpString#" ${configFile} > tmpFile
90     mv tmpFile ${configFile}
91    
92     source ${configFile}
93    
94     cat >> ${configFile} <<EOF
95 mangano 1.6 ###### this part was not set by the user. It was automatically generated ########
96 mangano 1.5 export HEDS_NAMEPREFIX=HiggsSimpleSkimV${HEDS_SKIMVERSION}\_
97     export HEDS_CASTORFOLDER=/castor/cern.ch/user/${HEDS_USERID:0:1}/$HEDS_USERID/HEDS
98     export HEDS_WWWAREA_TMP=${HEDS_LOCALSTORE}/wwwPagesInPreliminaryShape
99     export HEDS_WWWAREA=/afs/cern.ch/cms/Physics/Higgs/HiggsDQM/HiggsEDS
100 mangano 1.6 export HEDSPATH=$CMSSW_BASE/src/HiggsAnalysis/EarlyDataStudy
101 mangano 1.5 EOF
102    
103    
104    
105     if [ -d $HEDS_LOCALSTORE ]; then
106     echo "ERROR: the folder" $HEDS_LOCALSTORE "already exists." \
107     "Plese specify a different one in your .cfg file"
108     exit 1
109     else
110     mkdir $HEDS_LOCALSTORE
111     mv ./${configFile} $HEDS_LOCALSTORE/configuration
112     fi
113    
114 mangano 1.6 cat > $HEDS_LOCALSTORE/status <<EOF
115     create
116     EOF
117    
118 mangano 1.5
119     ;;
120    
121     submit) ### start doing something serious using the settings stored in the hedsTaskFolder
122     hedsTaskFolder=$2
123     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
124     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
125     echo " heds.sh submit <hedsTaskFolder>"
126     exit 1
127     fi
128    
129     echo -e "+++ Your heds task is going to use the following settings: \n"
130    
131     source ./$hedsTaskFolder/configuration
132     env |grep -i heds
133     echo -e "\n"
134    
135     echo -e "+++ Are you Ok with such settings? [y/n] "
136    
137    
138     read -p "$prompt" answer
139     case "$answer" in
140     [yY1] )
141     echo "you said you are happy"
142     ;;
143     [nN0] )
144     echo "you said you are not happy"
145     exit
146     ;;
147     *)
148     echo -e "Incorrect answer. Run \"heds submit\" again and type [y/n]"
149     exit
150     ;;
151     esac
152    
153     initialFolder=`pwd`
154     cd $HEDS_LOCALSTORE
155     heds.sh 0 #create setup
156     heds.sh 1 #query runregistry, create crab cfg
157     heds.sh 2 #submit crab jobs
158 mangano 1.7
159 mangano 1.5 cd $initialFolder
160     ;;
161    
162    
163     status) ### check status
164     hedsTaskFolder=$2
165     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
166     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
167     echo " heds.sh status <hedsTaskFolder>"
168     exit 1
169     fi
170     source ./$hedsTaskFolder/configuration
171 mangano 1.6
172     initialFolder=`pwd`
173     cd $HEDS_LOCALSTORE
174     status=`tail -n1 status`
175    
176     case $status in
177     create)
178     echo "+++ Last step successfully execute was: "
179     echo -e " heds create <taskFolder>\n"
180     echo "+++ Next step to run is: "
181     echo -e " heds submit <taskFolder>"
182     ;;
183     submit)
184     echo "+++ Last step execute was: "
185     echo -e " heds submit <taskFolder>\n"
186    
187     dailySkim=$HEDS_NAMEPREFIX$HEDS_LABEL-v$HEDS_TASKATTEMPT
188 mangano 1.9 crab -status -c $HEDS_LOCALSTORE/$dailySkim >& crab.status.log
189     jobsOK=`grep "Wrapper Exit Code : 0" crab.status.log| awk '{print $2}'`
190     jobsDone=`grep ">>>>>>>>>" crab.status.log |grep "Jobs Done"| awk '{print $2}'`
191     jobsRunning=`grep ">>>>>>>>>" crab.status.log |grep "Jobs Running"| awk '{print $2}'`
192     jobsAborted=`grep ">>>>>>>>>" crab.status.log |grep "Jobs Aborted"| awk '{print $2}'`
193     jobsTotal=`grep "crab:" crab.status.log |grep "Total Jobs"| awk '{print $2}'`
194    
195     if [ -n "$jobsTotal" ]; then echo "# jobs Total: " $jobsTotal; else jobsTotal=0; fi
196     if [ -n "$jobsDone" ]; then echo "# jobs Done: " $jobsDone; else jobsDone=0; fi
197     if [ -n "$jobsRunning" ]; then echo "# jobs Running: " $jobsRunning; else jobsRunning=0; fi
198     if [ -n "$jobsAborted" ]; then echo "# jobs Aborted: " $jobsAborted; else jobsAborted=0; fi
199     if [ -n "$jobsOK" ]; then echo "# jobs Retrieved OK: " $jobsOK; else jobsOK=0; fi
200    
201     if(($jobsDone)); then
202     echo "There are jobs in DONE status. Retrieving them"
203     crab -get -c $HEDS_LOCALSTORE/$dailySkim > /dev/null
204    
205     echo "+++ Run the following command again: "
206     echo " heds status <taskFolder>"
207 mangano 1.6 fi
208 mangano 1.9 rm crab.status.log
209    
210     if [ "$jobsTotal" == "$jobsOK" ];
211     then
212     echo "+++ all the crab jobs has been correctly retrieved."
213 mangano 1.6 echo "+++ You can now run:"
214     echo " heds get <taskFolder>"
215     cat >> $HEDS_LOCALSTORE/status <<EOF
216     crab_done
217     EOF
218     else
219 mangano 1.9 if(($jobsAborted)); then
220     echo "+++ Some crab jobs aborted. You need to resubmit them directly using:"
221     echo " crab -resubmit <job-interval> -c $HEDS_LOCALSTORE/$dailySkim"
222    
223     else
224     echo "+++ There are still crab jobs running. Try again later."
225     echo "+++ You can directly handle your crab jobs with:"
226     echo " crab -<command> -c $HEDS_LOCALSTORE/$dailySkim"
227     fi
228 mangano 1.6 fi
229     ;;
230    
231 mangano 1.7 submit_empty)
232     echo "+++ Last step execute was: "
233     echo -e " heds submit <taskFolder>\n"
234    
235     echo "+++ No good runs were found, so no crab jobs were submitted."
236     echo " You can directly go to the step:"
237     echo " heds tables <taskFolder>"
238     ;;
239    
240 mangano 1.6 crab_done)
241     echo "+++ All you crab jobs are DONE."
242     echo " You can now run:"
243     echo " heds get <taskFolder>"
244     ;;
245    
246     get)
247     echo "+++ Last step successfully execute was: "
248     echo -e " heds get <taskFolder>\n"
249     echo "+++ Next step to run is: "
250 mangano 1.9 echo -e " heds merge <taskFolder>"
251     ;;
252    
253     merge)
254     echo "+++ Last step successfully execute was: "
255     echo -e " heds merge <taskFolder>\n"
256     echo "+++ Next step to run is: "
257 mangano 1.6 echo -e " heds tables <taskFolder>"
258     ;;
259    
260     tables)
261     echo "+++ Last step successfully execute was: "
262     echo -e " heds tables <taskFolder>\n"
263     echo "+++ Next step to run is: "
264     echo -e " heds preview <taskFolder>"
265     ;;
266 mangano 1.9
267     preview)
268     echo "+++ Last step successfully execute was: "
269     echo -e " heds preview <taskFolder>\n"
270     echo "+++ Next step to run is: "
271     echo -e " heds add2Web <taskFolder>"
272     ;;
273    
274     add2Web)
275     echo "+++ Last step successfully execute was: "
276     echo -e " heds add2Web <taskFolder>\n"
277     echo "+++ You are done "
278     ;;
279 mangano 1.6
280     *)
281     echo "+++ ERROR: undefined heds status."
282     echo "+++ Restart from scratch running:"
283     echo " heds up"
284     echo " heds create heds.cfg"
285     ;;
286     esac
287     cd $initialFolder
288 mangano 1.5 ;;
289    
290    
291     get) ### get output from crab
292     hedsTaskFolder=$2
293     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
294     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
295     echo " heds.sh status <hedsTaskFolder>"
296     exit 1
297     fi
298    
299 mangano 1.6 source ./$hedsTaskFolder/configuration
300 mangano 1.5 cd $HEDS_LOCALSTORE
301 mangano 1.6 status=`tail -n1 status`
302     if [ ! "$status" == "crab_done" ];then
303     echo "+++ ERROR: crab jobs are not done yet. Try:"
304     echo " heds status <taskFolder>"
305     exit 1
306     fi
307 mangano 1.9
308     echo "Crab jobs are going to be published in DBS. This is going to take a long while"
309     dailySkim=$HEDS_NAMEPREFIX$HEDS_LABEL-v$HEDS_TASKATTEMPT
310     crab -publish -c $HEDS_LOCALSTORE/$dailySkim
311 mangano 1.8 heds.sh 4c #copy file from the SE
312     #heds.sh 4c_temp #copy file from the SE manually using scp
313 mangano 1.9
314     if ((! $?));
315     then
316     cat >> status <<EOF
317 mangano 1.6 get
318     EOF
319 mangano 1.9 fi
320 mangano 1.5 cd $initialFolder
321     ;;
322    
323    
324     tables) ### produce html tables
325     hedsTaskFolder=$2
326     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
327     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
328     echo " heds.sh tables <hedsTaskFolder>"
329     exit 1
330     fi
331 mangano 1.6 source ./$hedsTaskFolder/configuration
332 mangano 1.5 cd $HEDS_LOCALSTORE
333 mangano 1.6 status=`tail -n1 status`
334 mangano 1.9 echo "status: " $status
335     if [[ !("$status" == "merge") && !("$status" == "submit_empty") ]];then
336     echo "+++ ERROR: you may have to retrieve crab jobs first. Try:"
337 mangano 1.6 echo " heds status <taskFolder>"
338     exit 1
339     fi
340    
341 mangano 1.7
342     if [ -d $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION ]; then
343     echo "Warning: " logs.SkimV$HEDS_SKIMVERSION " already exist in final WWW_AREA."
344     echo "Copying base html tables from there."
345    
346     ##TO BE FIXED. Check that files exist before copy
347     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php \
348     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
349     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableHeader.shtm \
350     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
351     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableBody.shtm \
352     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
353     fi
354    
355    
356 mangano 1.9 if [ "$status" == "merge" ]; then
357 mangano 1.7 heds.sh 4a #copy all logs file
358 mangano 1.9 heds.sh store . #copy zipped edm file and crab logs
359 mangano 1.7 heds.sh 4b #making skim report
360     heds.sh 4f #list of skimmed events
361     heds.sh 4g #copy logs about run selection
362     heds.sh 4h #preparing event dumps
363     heds.sh 4i #preparing final html tables
364     fi
365    
366     if [ "$status" == "submit_empty" ]; then
367     heds.sh 4g #copy logs about run selection
368     heds.sh 4i2 #preparing final html tables
369     fi
370    
371 mangano 1.6 cat >> status <<EOF
372     tables
373     EOF
374 mangano 1.5 cd $initialFolder
375     ;;
376    
377 mangano 1.7 merge) ### merge files before copying them to castor area
378     hedsTaskFolder=$2
379     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
380     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
381     echo " heds.sh tables <hedsTaskFolder>"
382     exit 1
383     fi
384     source ./$hedsTaskFolder/configuration
385     cd $HEDS_LOCALSTORE
386     status=`grep "crab_done" status`
387     if [ -z "$status" ];then
388     echo "+++ ERROR: crab jobs are not done yet. Try:"
389     echo " heds status <taskFolder>"
390     exit 1
391     fi
392    
393     heds.sh 4d #merging edm files
394    
395 mangano 1.9 cat >> status <<EOF
396     merge
397     EOF
398 mangano 1.7 cd $initialFolder
399     ;;
400    
401    
402 mangano 1.5
403     store) ### produce html tables
404     hedsTaskFolder=$2
405     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
406     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
407     echo " heds.sh tables <hedsTaskFolder>"
408     exit 1
409     fi
410 mangano 1.6 source ./$hedsTaskFolder/configuration
411 mangano 1.5 cd $HEDS_LOCALSTORE
412 mangano 1.6 status=`grep "crab_done" status`
413     if [ -z "$status" ];then
414     echo "+++ ERROR: crab jobs are not done yet. Try:"
415     echo " heds status <taskFolder>"
416     exit 1
417     fi
418    
419     ### create CASTOR folder
420     nsls -d $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION >& tmp
421     check=`cat tmp |grep "No such" |wc -w`
422     rm tmp
423     if [ $check == 0 ]
424     then echo "directory " $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION "already exists"
425     else
426     echo "making " $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION " directory"
427     rfmkdir -p $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION
428     fi
429    
430 mangano 1.5 heds.sh 6 #copy merged log files in CASTOR
431     heds.sh 4e #copy merged edm files in CASTOR
432 mangano 1.9 # cat >> status <<EOF
433     #store
434     #EOF
435 mangano 1.5 cd $initialFolder
436     ;;
437    
438     preview) ### produce html tables
439     hedsTaskFolder=$2
440     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
441     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
442     echo " heds.sh tables <hedsTaskFolder>"
443     exit 1
444     fi
445 mangano 1.7 source ./$hedsTaskFolder/configuration
446    
447     initialFolder=`pwd`
448 mangano 1.5 cd $HEDS_LOCALSTORE
449     heds.sh 4j #
450 mangano 1.9 php $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php > FirstPage.html
451     mv FirstPage.html $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
452     cp $HEDS_WWWAREA/fromGiovanni.css $HEDS_WWWAREA_TMP
453     cat >> status <<EOF
454     preview
455     EOF
456 mangano 1.5 cd $initialFolder
457     ;;
458 mangano 1.7
459     add2Web) ### produce html tables
460     hedsTaskFolder=$2
461     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
462     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
463     echo " heds.sh tables <hedsTaskFolder>"
464     exit 1
465     fi
466     source ./$hedsTaskFolder/configuration
467    
468     initialFolder=`pwd`
469     cd $HEDS_LOCALSTORE
470     heds.sh final #
471 mangano 1.9 cat >> status <<EOF
472     add2Web
473     EOF
474 mangano 1.7 cd $initialFolder
475     ;;
476 mangano 1.5
477    
478    
479    
480     ########## internal "functions" which are not meant to be used by users ###############
481 mangano 1.1 0)
482 mangano 1.5 echo "=== Setting up directories and one-time things ==="
483 mangano 1.1 echo ""
484    
485 mangano 1.3 ### create WWW folders
486 mangano 1.2 if [ -d $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION ]
487 mangano 1.3 then echo "directory " $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION \
488     " already exists. Then skipping \"mkdir\" "
489    
490     if [ ! -d $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents ]; then
491     echo "making " $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
492     mkdir -p $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
493     fi
494    
495 mangano 1.1 else
496 mangano 1.2 echo "making " $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION " directory"
497 mangano 1.3 mkdir -p $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
498    
499     if [ -d $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION ]; then
500     echo "Warning: " logs.SkimV$HEDS_SKIMVERSION " already exist in final WWW_AREA."
501     echo "Copying base html tables from there."
502 mangano 1.4
503     ##TO BE FIXED. Check that files exist before copy
504 mangano 1.3 cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php \
505     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
506     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableHeader.shtm \
507     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
508     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableBody.shtm \
509     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
510     fi
511    
512     if [ ! -d $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents ]; then
513     echo "making " $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
514     mkdir -p $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
515     fi
516 mangano 1.1 fi
517     ;;
518    
519     1)
520     echo "=== you selected option 1. Querying RunRegistry, select good runs and submit crab jobs ==="
521     echo ""
522    
523     dateForDbsSearch=`echo $HEDS_LABEL|awk -F\. '{print $3"-"$2"-"$1}'`
524     echo "dateForDbsSearch: " $dateForDbsSearch
525     dbs search --query="find run where dataset=$HEDS_INPUTDATASET and run.createdate=$dateForDbsSearch" \
526     > tmpRunList.txt
527     lastRun=`cat tmpRunList.txt |grep [0-9][0-9][0-9][0-9][0-9][0-9] |head -n1`
528     firstRun=`cat tmpRunList.txt|tail -n1`
529     rm tmpRunList.txt
530     #TO BE FIXED: add a protection for when there are no runs
531     echo "first,last runs: " $firstRun $lastRun
532    
533    
534     runselection="runselection="
535     cat $HEDSPATH/scripts/runreg.cfg | sed s/SET_RUNMIN/$firstRun/ | \
536     sed s/SET_RUNMAX/$lastRun/ > runreg.cfg
537     python $HEDSPATH/scripts/runregparse.py > tmp.log
538     rm runreg.cfg
539     echo "here we have the good run list"
540    
541     IFS=$'\n'
542     found=0
543     lastGoodRun=0
544     for line in $(cat tmp.log);
545     do
546     if [ $found == 0 ]
547     then
548     found=`echo $line |grep lumisToProcess|wc |awk '{print $1}'`
549     continue;
550     fi
551     if [ $line == ")" ]
552     then
553     break;
554     fi
555     thisRun=`echo $line | sed s/\'//g | sed s/,//g |awk -F: '{print $1}'`
556     if [ $thisRun != $lastGoodRun ]
557     then
558     runselection=$runselection$thisRun\,
559     fi
560     lastGoodRun=$thisRun
561     done
562     #echo "========= THE FOLLOWING LINE TO YOUR crab.cfg FILE ========="
563     echo $runselection
564     #echo "================================================================"
565     echo $runselection > $HEDS_LABEL.runselection
566     echo $firstRun-$lastRun > $HEDS_LABEL.runinterval
567     rm tmp.log
568    
569     check=`echo $runselection | sed s/runselection=// |wc -w`
570    
571     if [ $check == 0 ]
572     then
573     echo "No good runs have been selected. No CRAB cfg will be created."
574 mangano 1.7 cat >> status <<EOF
575     runselection_empty
576     EOF
577 mangano 1.1 else
578     echo "Some good runs have been selected. CRAB cfg will be created."
579 mangano 1.7 cat >> status <<EOF
580     runselection_done
581     EOF
582 mangano 1.1 cat $HEDSPATH/scripts/crab.template.cfg |sed "s#SET_DATASET#$HEDS_INPUTDATASET#" | \
583 mangano 1.3 # sed "s#SET_REMOTEDIR#$HEDS_USERID/HEDS/#" | \
584     sed "s#SET_REMOTEDIR#$HEDS_USERID/#" | \
585 mangano 1.1 sed "s#SET_T2#$HEDS_T2SITE#" | \
586     sed "s/SET_RUNSELECTION/$runselection/" > tmp.cfg
587     pset=$HEDSPATH/python/earlyDataInterestingEvents_cfg.py
588     echo "pset: " $pset
589     cat tmp.cfg |sed s#SET_PSET#$pset# | sed "s#SET_TASK_NAME#$dailySkim#" > tmp2.cfg; rm tmp.cfg
590     mv tmp2.cfg $HEDS_LABEL.crab.cfg
591     fi
592     ;;
593     2)
594 mangano 1.7 status=`tail -n1 status`
595     if [ ! "$status" == "runselection_done" ];then
596     #no crab jobs to be submitted
597     cat >> status <<EOF
598     submit_empty
599     EOF
600     exit 0
601     fi
602    
603 mangano 1.1 echo "creating and submitting CRAB jobs for " $dailySkim
604     if [ -e $HEDS_LABEL.crab.cfg ]
605     then
606     crab -create -submit -cfg $HEDS_LABEL.crab.cfg
607     if ((! $?)); then rm $HEDS_LABEL.crab.cfg; fi
608 mangano 1.7 cat >> status <<EOF
609     submit
610     EOF
611 mangano 1.1 else
612     echo "ERROR: " $HEDS_LABEL.crab.cfg " doesn't exist"
613     fi
614     ;;
615     3)
616     echo "getting output and publishing crab jobs"
617 mangano 1.6 crab -status -c $dailySkim &> /dev/null
618 mangano 1.1 crab -get -c $dailySkim
619 mangano 1.6 crab -status -c $dailySkim &> /dev/null
620 mangano 1.1 crab -publish -c $dailySkim
621     ;;
622    
623    
624     4)
625     echo "option 4 "
626     if [ -d $dailySkim ] #the crab job was run on at least 1 run
627     then
628     heds 4a
629     heds 4b
630     heds 4c
631     heds 4d
632     heds 4e
633     heds 4f
634     heds 4g
635     heds 4h
636     heds 4i
637     else
638     echo "copying only the log files about runs and selected-runs"
639     heds 4g
640 mangano 1.7 heds 4i2
641 mangano 1.1 fi
642     ;;
643    
644     4a)
645 mangano 1.3 #### echo "...copying log files"
646 mangano 1.1 if [ ! -d $HEDS_LOCALSTORE/$dailySkim/logs ]; then
647     mkdir -p $HEDS_LOCALSTORE/$dailySkim/logs
648     fi
649     cp $dailySkim/res/*.std* $HEDS_LOCALSTORE/$dailySkim/logs
650     if (($?)); then
651     echo "ERROR: failed to copy log files in " $HEDS_LOCALSTORE/$dailySkim/logs;
652     else
653     echo "copied all logs file in " $HEDS_LOCALSTORE/$dailySkim/logs
654     fi
655    
656 mangano 1.5 ###
657 mangano 1.1 tarName=$HEDS_LABEL.log.tgz
658     cd $HEDS_LOCALSTORE/$dailySkim/logs/
659     if (($?));then
660     echo "ERROR: failed to go to " $HEDS_LOCALSTORE/$dailySkim/logs/
661     else
662 mangano 1.3 echo "compriming log files... "
663     tar czvf $tarName *.std* >& /dev/null
664     echo -e "done \n"
665 mangano 1.1 cd -
666     fi
667     ;;
668    
669     4b)
670     ###
671 mangano 1.3 echo -e "creating skimReport..."
672 mangano 1.1 logName=$HEDS_LABEL.log
673     $HEDSPATH/scripts/skimreport $HEDS_LOCALSTORE/$dailySkim/logs/*.stdout > $logName
674 mangano 1.7 cp $logName $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents/
675 mangano 1.3 echo -e "done \n"
676 mangano 1.1 ;;
677    
678     4c)
679     ###
680     echo "...coping files from the T2's SE"
681     echo "dataset to retreive: " $dailySkim
682     dbs search --url=https://cmsdbsprod.cern.ch:8443/cms_dbs_ph_analysis_02_writer/servlet/DBSServlet \
683     --query="find file,site where dataset=*$dailySkim*" |grep .root >listFiles
684    
685     IFS=$'\n'
686     for j in $(cat listFiles)
687     do
688     echo "going to copy file: $j"
689     fileName=`echo $j |awk '{print$1}'| awk -F$dailySkim/ '{print $2}' | awk -F/ '{print $2}'`
690    
691     storage_elem=`echo $j |awk '{print $2}'`
692     remote_path=`echo $j|awk '{print $1}'`
693     lcg-cp -b -D srmv2 srm://$storage_elem:$HEDS_STORAGEPORT$HEDS_STORAGEPATH$remote_path file://$HEDS_LOCALSTORE/$dailySkim/$fileName
694     done
695     rm listFiles
696 mangano 1.6 #nFiles=`ls $HEDS_LOCALSTORE/$dailySkim/*.root|wc -l`
697     #nJobs=`ls $HEDS_LOCALSTORE/$dailySkim/logs/CMSSW_*.stdout |wc -l`
698 mangano 1.7 ;;
699 mangano 1.1
700 mangano 1.7 4c_temp)
701     echo "copying manually files from SE.. "
702     scp bmangano@uaf-6.t2.ucsd.edu:/hadoop/cms/store/user/mangano/MinimumBias/$dailySkim/*/*.root $HEDS_LOCALSTORE/$dailySkim/
703 mangano 1.1 ;;
704    
705 mangano 1.7
706 mangano 1.1 4d)
707     ###
708 mangano 1.3 echo -e "Merging files edm files..."
709 mangano 1.1 cp $HEDSPATH/scripts/prepareMerging.sh $HEDS_LOCALSTORE/$dailySkim
710     cp $HEDSPATH/scripts/merge.py $HEDS_LOCALSTORE/$dailySkim
711     cd $HEDS_LOCALSTORE/$dailySkim
712    
713 mangano 1.6 mergedName=$HEDS_LABEL.root
714     mergedName=merged_$mergedName
715    
716 mangano 1.1 ./prepareMerging.sh
717     numberFilesToMerge=`ls *.root|wc -l`
718     echo "numberFilesToMerge: " $numberFilesToMerge
719     cmsRun merge.py >& merging.log
720 mangano 1.6 mv merged.root $HEDS_LOCALSTORE/$mergedName
721 mangano 1.3 echo -e "done \n"
722 mangano 1.1 cd -
723     ;;
724    
725     4e)
726     ###
727 mangano 1.3 echo -e "Storing merged edm file in CASTOR..."
728 mangano 1.1 mergedName=$HEDS_LABEL.root
729     mergedName=merged_$mergedName
730     echo "mergedName: " $mergedName
731     cd $HEDS_LOCALSTORE/$dailySkim
732     if ((! $?)); then
733     echo "going to copy the merged file into: " $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION
734 mangano 1.6 rfcp $HEDS_LOCALSTORE/$mergedName $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION/
735 mangano 1.1 cd -
736     fi
737 mangano 1.3 echo -e "done \n"
738 mangano 1.1 ;;
739    
740     4f)
741     ###
742 mangano 1.3 echo "Preparing detailed list of skimmed events..."
743 mangano 1.1 cp $HEDSPATH/scripts/listSkimmedEvent.C $HEDS_LOCALSTORE
744     cd $HEDS_LOCALSTORE
745 mangano 1.7 forRootExecution="listSkimmedEvent.C++(\"${HEDS_LABEL}\")"
746    
747     root.exe -b -q $forRootExecution >& /dev/null
748 mangano 1.2 listSkimmedEventsPath=$HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
749 mangano 1.1 if [ ! -d $listSkimmedEventsPath ]
750     then
751     mkdir $listSkimmedEventsPath
752     fi
753 mangano 1.7 listDetailedLogs=`ls ${HEDS_LABEL}_Skim_*`
754 mangano 1.1 for j in $listDetailedLogs
755     do
756     echo "preparing log " $j
757     # sort entries by date
758     cat $j |sort -k7 > tmp
759     mv tmp $j
760     mv $j $listSkimmedEventsPath
761     done
762 mangano 1.3 echo -e "done \n"
763 mangano 1.1 cd -
764     ;;
765    
766     4g)
767     ###
768 mangano 1.3 echo "Copying logs about run selection..."
769 mangano 1.7 cp $HEDS_LABEL.runselection $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
770     cp $HEDS_LABEL.runinterval $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
771 mangano 1.3 echo -e "done \n"
772 mangano 1.1 ;;
773    
774     4h)
775     ###
776 mangano 1.3 echo "Preparing event dumps..."
777 mangano 1.1 input=$HEDS_LOCALSTORE/merged_$HEDS_LABEL.root
778     echo "input: " $input
779     sed s#INPUT#$input# $HEDSPATH/scripts/dumpEvent.py > dumpEvent.py
780     cmsRun dumpEvent.py >& $HEDS_LABEL.dumperLog
781 mangano 1.7
782 mangano 1.1 $HEDSPATH/scripts/parseDumperOutput.sh 1 >& $HEDS_LABEL.dump
783     $HEDSPATH/scripts/parseDumperOutput.sh 2
784     rm dumpEvent.py
785     rm $HEDS_LABEL.dumperLog
786     rm $HEDS_LABEL.dump
787 mangano 1.3 echo -e "done \n"
788 mangano 1.1 ;;
789     4i)
790     ###
791 mangano 1.3 echo "Preparing html tables..."
792 mangano 1.2 if [ ! -e $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php ];then
793 mangano 1.1 echo "create first version of FirstTable.sh"
794     $HEDSPATH/scripts/editFirstTable.sh create
795 mangano 1.3 $HEDSPATH/scripts/createTableSkimDetails.sh add ; echo "level-3 tables produced"
796     $HEDSPATH/scripts/createTableSkimSummary.sh ; echo "level-2 tables produced"
797     $HEDSPATH/scripts/editFirstTable.sh add below ; echo "level-1 table modified"
798     else
799     $HEDSPATH/scripts/createTableSkimDetails.sh clean; echo "clean up old html tables"
800     $HEDSPATH/scripts/createTableSkimDetails.sh add ; echo "level-3 tables produced"
801     $HEDSPATH/scripts/createTableSkimSummary.sh ; echo "level-2 tables produced"
802     $HEDSPATH/scripts/editFirstTable.sh add below ; echo "level-1 table modified"
803     fi
804     echo -e "done \n"
805     ;;
806    
807 mangano 1.7 4i2)
808     ###
809     echo "Preparing html tables..."
810     if [ ! -e $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php ];then
811     echo "create first version of FirstTable.sh"
812     $HEDSPATH/scripts/editFirstTable.sh create
813     #$HEDSPATH/scripts/createTableSkimDetails.sh add ; echo "level-3 tables produced"
814     #$HEDSPATH/scripts/createTableSkimSummary.sh ; echo "level-2 tables produced"
815     $HEDSPATH/scripts/editFirstTable.sh addSpecial below ; echo "level-1 table modified"
816     else
817     #$HEDSPATH/scripts/createTableSkimDetails.sh clean; echo "clean up old html tables"
818     #$HEDSPATH/scripts/createTableSkimDetails.sh add ; echo "level-3 tables produced"
819     #$HEDSPATH/scripts/createTableSkimSummary.sh ; echo "level-2 tables produced"
820     $HEDSPATH/scripts/editFirstTable.sh addSpecial below ; echo "level-1 table modified"
821     fi
822     echo -e "done \n"
823     ;;
824    
825    
826 mangano 1.3 4j) ###
827     echo -e "Your preliminary table is available at the following URL: "
828 mangano 1.6 url="file://"
829 mangano 1.9 url=$url$HEDS_WWWAREA_TMP"/logs.SkimV$HEDS_SKIMVERSION/FirstPage.html"
830 mangano 1.3 echo -e $url "\n"
831     echo -e "After you verified that all the tables have been correctly produced, " \
832 mangano 1.9 "they can be moved to the final repository using:"
833     echo " heds add2Web <taskFolder>"
834 mangano 1.3
835 mangano 1.1 ;;
836 mangano 1.3
837 mangano 1.5
838     6) ### copying stuff to castor
839     tarName=$HEDS_LABEL.log.tgz
840     cd $HEDS_LOCALSTORE/$dailySkim/logs/
841     if (($?));then
842     echo "ERROR: failed to go to " $HEDS_LOCALSTORE/$dailySkim/logs/
843     else
844     echo "copying " $tarName " file to CASTOR area.."
845     rfcp $tarName $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION
846     echo -e "done \n"
847     cd -
848     fi
849     ;;
850    
851 mangano 1.1 5a)
852     echo ".... preparing event display server"
853     mkdir $HEDS_LABEL.shots
854     port=3005
855     $HEDSPATH/scripts/eventDisplayServer.sh $port &
856     ;;
857     5b)
858     echo "getting snapshots"
859     port=3005
860     file=$HEDS_LOCALSTORE/merged_$HEDS_LABEL.root
861     echo "$file" | nc -w 10 localhost $port
862     ;;
863     5c)
864     echo "moving snapshots"
865 mangano 1.2 mv $HEDS_LABEL.shots $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
866 mangano 1.1 cp $HEDSPATH/scripts/indexFileForDetailedSnapShots.php \
867 mangano 1.2 $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.shots/index.php
868 mangano 1.1 ;;
869    
870    
871 mangano 1.3 final)
872     #TO BE FIXED. this call could written in a much more compact way
873     echo "WWW pages are going to be moved from the temporary repository"
874     echo -e "("$HEDS_WWWAREA_TMP")\n"
875     echo "to the permanent one"
876     echo -e "("$HEDS_WWWAREA")\n"
877    
878     if [ ! -d $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION ]; then
879     mkdir $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION
880     fi
881    
882     if [ -e $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php ]; then
883     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php \
884     $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php.BAK
885     fi
886     if [ -e $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableBody.shtm ]; then
887     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableBody.shtm \
888     $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableBody.shtm.BAK
889     fi
890     if [ -e $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableHeader.php ]; then
891     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableHeader.shtm \
892     $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableHeader.shtm.BAK
893     fi
894    
895 mangano 1.7 cp $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/*.php \
896 mangano 1.3 $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/
897 mangano 1.7 cp $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/*.shtm \
898 mangano 1.3 $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/
899    
900 mangano 1.7 if [ -e $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents ]; then
901     if [ -e $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents ]; then
902     echo "WARNING: replacing folder in AFS area."
903     rm -r -i $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
904     fi
905     cp -r $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents \
906     $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
907     fi
908 mangano 1.3
909    
910 mangano 1.7 url="https://cms-project-higgsdqm.web.cern.ch/cms-project-higgsdqm/HiggsEDS"
911 mangano 1.3 url=$url"/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php"
912    
913     echo "The new tables created by you are accessible through the following URL: "
914     echo $url
915     ;;
916    
917 mangano 1.1 ##################### after the crab part is done ###################
918 mangano 1.2 99) echo "Doing bakcup of $HEDS_WWWAREA_TMP"
919 mangano 1.1 date=`date +%k\.%M\.%S_%e\.%m\.%Y`
920     fileName="HiggsIES.BAK."$date".tgz"
921     echo "file name: " $fileName
922 mangano 1.2 tar -czvf $fileName $HEDS_WWWAREA_TMP
923     mv $fileName $HEDS_WWWAREA_TMP/..
924 mangano 1.1 ;;
925    
926    
927     *)
928     echo "option not defined"
929     ;;
930     esac