ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/HiggsAnalysis/EarlyDataStudy/scripts/heds.sh
Revision: 1.10
Committed: Wed May 12 16:48:40 2010 UTC (14 years, 11 months ago) by mangano
Content type: application/x-sh
Branch: MAIN
CVS Tags: V00-01-01
Changes since 1.9: +106 -15 lines
Log Message:
add more verbosity. add protection when there are no input runs

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 mangano 1.10 echo -e "\n"
142     ;;
143     [nN0] )
144     exit
145     ;;
146     *)
147     echo -e "Incorrect answer. Run \"heds submit\" again and type [y/n]"
148     exit
149     ;;
150     esac
151    
152     echo -e "+++ Have you also checked HEDS_STORAGEPATH and HEDS_STORAGEPORT values ? "
153     echo -e "+++ This values have still to be set by hand. Please consult the settings of your T2's SE"
154     echo -e " as described here:"
155     echo " https://twiki.cern.ch/twiki/bin/view/CMS/AnalysisOpsPriorityuser#Tier_2_Sites_Responsibility"
156     echo "Please insert the final confirmation [y/n]"
157     read -p "$prompt" answer
158     case "$answer" in
159     [yY1] )
160 mangano 1.5 echo "you said you are happy"
161     ;;
162     [nN0] )
163     exit
164     ;;
165     *)
166     echo -e "Incorrect answer. Run \"heds submit\" again and type [y/n]"
167     exit
168     ;;
169     esac
170    
171 mangano 1.10
172    
173 mangano 1.5 initialFolder=`pwd`
174     cd $HEDS_LOCALSTORE
175     heds.sh 0 #create setup
176     heds.sh 1 #query runregistry, create crab cfg
177     heds.sh 2 #submit crab jobs
178 mangano 1.7
179 mangano 1.5 cd $initialFolder
180     ;;
181    
182    
183     status) ### check status
184     hedsTaskFolder=$2
185     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
186     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
187     echo " heds.sh status <hedsTaskFolder>"
188     exit 1
189     fi
190     source ./$hedsTaskFolder/configuration
191 mangano 1.6
192     initialFolder=`pwd`
193     cd $HEDS_LOCALSTORE
194     status=`tail -n1 status`
195    
196     case $status in
197     create)
198     echo "+++ Last step successfully execute was: "
199     echo -e " heds create <taskFolder>\n"
200     echo "+++ Next step to run is: "
201     echo -e " heds submit <taskFolder>"
202     ;;
203     submit)
204     echo "+++ Last step execute was: "
205     echo -e " heds submit <taskFolder>\n"
206    
207     dailySkim=$HEDS_NAMEPREFIX$HEDS_LABEL-v$HEDS_TASKATTEMPT
208 mangano 1.9 crab -status -c $HEDS_LOCALSTORE/$dailySkim >& crab.status.log
209     jobsOK=`grep "Wrapper Exit Code : 0" crab.status.log| awk '{print $2}'`
210     jobsDone=`grep ">>>>>>>>>" crab.status.log |grep "Jobs Done"| awk '{print $2}'`
211     jobsRunning=`grep ">>>>>>>>>" crab.status.log |grep "Jobs Running"| awk '{print $2}'`
212     jobsAborted=`grep ">>>>>>>>>" crab.status.log |grep "Jobs Aborted"| awk '{print $2}'`
213     jobsTotal=`grep "crab:" crab.status.log |grep "Total Jobs"| awk '{print $2}'`
214    
215     if [ -n "$jobsTotal" ]; then echo "# jobs Total: " $jobsTotal; else jobsTotal=0; fi
216     if [ -n "$jobsDone" ]; then echo "# jobs Done: " $jobsDone; else jobsDone=0; fi
217     if [ -n "$jobsRunning" ]; then echo "# jobs Running: " $jobsRunning; else jobsRunning=0; fi
218     if [ -n "$jobsAborted" ]; then echo "# jobs Aborted: " $jobsAborted; else jobsAborted=0; fi
219     if [ -n "$jobsOK" ]; then echo "# jobs Retrieved OK: " $jobsOK; else jobsOK=0; fi
220    
221     if(($jobsDone)); then
222     echo "There are jobs in DONE status. Retrieving them"
223     crab -get -c $HEDS_LOCALSTORE/$dailySkim > /dev/null
224    
225     echo "+++ Run the following command again: "
226     echo " heds status <taskFolder>"
227 mangano 1.10 exit 0
228 mangano 1.6 fi
229 mangano 1.9
230     if [ "$jobsTotal" == "$jobsOK" ];
231     then
232     echo "+++ all the crab jobs has been correctly retrieved."
233 mangano 1.6 echo "+++ You can now run:"
234     echo " heds get <taskFolder>"
235     cat >> $HEDS_LOCALSTORE/status <<EOF
236     crab_done
237     EOF
238     else
239 mangano 1.9 if(($jobsAborted)); then
240     echo "+++ Some crab jobs aborted. You need to resubmit them directly using:"
241     echo " crab -resubmit <job-interval> -c $HEDS_LOCALSTORE/$dailySkim"
242    
243     else
244     echo "+++ There are still crab jobs running. Try again later."
245     echo "+++ You can directly handle your crab jobs with:"
246     echo " crab -<command> -c $HEDS_LOCALSTORE/$dailySkim"
247     fi
248 mangano 1.6 fi
249     ;;
250    
251 mangano 1.7 submit_empty)
252     echo "+++ Last step execute was: "
253     echo -e " heds submit <taskFolder>\n"
254    
255     echo "+++ No good runs were found, so no crab jobs were submitted."
256     echo " You can directly go to the step:"
257     echo " heds tables <taskFolder>"
258     ;;
259    
260 mangano 1.6 crab_done)
261     echo "+++ All you crab jobs are DONE."
262     echo " You can now run:"
263     echo " heds get <taskFolder>"
264     ;;
265    
266     get)
267     echo "+++ Last step successfully execute was: "
268     echo -e " heds get <taskFolder>\n"
269     echo "+++ Next step to run is: "
270 mangano 1.9 echo -e " heds merge <taskFolder>"
271     ;;
272    
273     merge)
274     echo "+++ Last step successfully execute was: "
275     echo -e " heds merge <taskFolder>\n"
276     echo "+++ Next step to run is: "
277 mangano 1.6 echo -e " heds tables <taskFolder>"
278     ;;
279    
280     tables)
281     echo "+++ Last step successfully execute was: "
282     echo -e " heds tables <taskFolder>\n"
283     echo "+++ Next step to run is: "
284     echo -e " heds preview <taskFolder>"
285     ;;
286 mangano 1.9
287     preview)
288     echo "+++ Last step successfully execute was: "
289     echo -e " heds preview <taskFolder>\n"
290     echo "+++ Next step to run is: "
291     echo -e " heds add2Web <taskFolder>"
292     ;;
293    
294     add2Web)
295     echo "+++ Last step successfully execute was: "
296     echo -e " heds add2Web <taskFolder>\n"
297     echo "+++ You are done "
298     ;;
299 mangano 1.6
300     *)
301     echo "+++ ERROR: undefined heds status."
302     echo "+++ Restart from scratch running:"
303     echo " heds up"
304     echo " heds create heds.cfg"
305     ;;
306     esac
307     cd $initialFolder
308 mangano 1.5 ;;
309    
310    
311     get) ### get output from crab
312     hedsTaskFolder=$2
313     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
314     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
315     echo " heds.sh status <hedsTaskFolder>"
316     exit 1
317     fi
318    
319 mangano 1.6 source ./$hedsTaskFolder/configuration
320 mangano 1.5 cd $HEDS_LOCALSTORE
321 mangano 1.6 status=`tail -n1 status`
322     if [ ! "$status" == "crab_done" ];then
323     echo "+++ ERROR: crab jobs are not done yet. Try:"
324     echo " heds status <taskFolder>"
325     exit 1
326     fi
327 mangano 1.9
328 mangano 1.10 echo "Crab job's output is going to be published in DBS. This step is going to take a long while (up to 1hr)."
329     echo "Do you have time for that? [y/n]"
330    
331     read -p "$prompt" answer
332     case "$answer" in
333     [yY1] )
334     echo "Ok. Proceding with crab -publish step"
335     ;;
336     [nN0] )
337     echo "Exiting heds.."
338     exit 0
339     ;;
340     *)
341     echo -e "Incorrect answer. Run your heds get command again and then answer [y/n]"
342     exit
343     ;;
344     esac
345    
346    
347 mangano 1.9 dailySkim=$HEDS_NAMEPREFIX$HEDS_LABEL-v$HEDS_TASKATTEMPT
348     crab -publish -c $HEDS_LOCALSTORE/$dailySkim
349 mangano 1.10 if((! $?)); then
350     heds.sh 4c #copy file from the SE
351     else
352     exit 1
353     fi
354 mangano 1.8 #heds.sh 4c_temp #copy file from the SE manually using scp
355 mangano 1.9
356     if ((! $?));
357     then
358     cat >> status <<EOF
359 mangano 1.6 get
360     EOF
361 mangano 1.9 fi
362 mangano 1.5 cd $initialFolder
363     ;;
364    
365    
366     tables) ### produce html tables
367     hedsTaskFolder=$2
368 mangano 1.10 rawLocation=$3
369 mangano 1.5 if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
370     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
371     echo " heds.sh tables <hedsTaskFolder>"
372     exit 1
373     fi
374 mangano 1.6 source ./$hedsTaskFolder/configuration
375 mangano 1.5 cd $HEDS_LOCALSTORE
376 mangano 1.6 status=`tail -n1 status`
377 mangano 1.9 echo "status: " $status
378     if [[ !("$status" == "merge") && !("$status" == "submit_empty") ]];then
379     echo "+++ ERROR: you may have to retrieve crab jobs first. Try:"
380 mangano 1.6 echo " heds status <taskFolder>"
381     exit 1
382     fi
383    
384 mangano 1.7
385     if [ -d $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION ]; then
386     echo "Warning: " logs.SkimV$HEDS_SKIMVERSION " already exist in final WWW_AREA."
387     echo "Copying base html tables from there."
388    
389     ##TO BE FIXED. Check that files exist before copy
390     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php \
391     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
392     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableHeader.shtm \
393     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
394     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableBody.shtm \
395     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
396     fi
397    
398 mangano 1.10 if [ -z "$rawLocation" ];then
399     rawLocation=below
400     fi
401 mangano 1.7
402 mangano 1.9 if [ "$status" == "merge" ]; then
403 mangano 1.7 heds.sh 4a #copy all logs file
404 mangano 1.9 heds.sh store . #copy zipped edm file and crab logs
405 mangano 1.7 heds.sh 4b #making skim report
406     heds.sh 4f #list of skimmed events
407     heds.sh 4g #copy logs about run selection
408     heds.sh 4h #preparing event dumps
409 mangano 1.10 heds.sh 4i $rawLocation #preparing final html tables
410 mangano 1.7 fi
411    
412     if [ "$status" == "submit_empty" ]; then
413     heds.sh 4g #copy logs about run selection
414 mangano 1.10 heds.sh 4i2 $rawLocation #preparing final html tables
415 mangano 1.7 fi
416    
417 mangano 1.6 cat >> status <<EOF
418     tables
419     EOF
420 mangano 1.5 cd $initialFolder
421     ;;
422    
423 mangano 1.7 merge) ### merge files before copying them to castor area
424     hedsTaskFolder=$2
425     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
426     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
427     echo " heds.sh tables <hedsTaskFolder>"
428     exit 1
429     fi
430     source ./$hedsTaskFolder/configuration
431     cd $HEDS_LOCALSTORE
432     status=`grep "crab_done" status`
433     if [ -z "$status" ];then
434     echo "+++ ERROR: crab jobs are not done yet. Try:"
435     echo " heds status <taskFolder>"
436     exit 1
437     fi
438    
439     heds.sh 4d #merging edm files
440    
441 mangano 1.9 cat >> status <<EOF
442     merge
443     EOF
444 mangano 1.7 cd $initialFolder
445     ;;
446    
447    
448 mangano 1.5
449     store) ### produce html tables
450     hedsTaskFolder=$2
451     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
452     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
453     echo " heds.sh tables <hedsTaskFolder>"
454     exit 1
455     fi
456 mangano 1.6 source ./$hedsTaskFolder/configuration
457 mangano 1.5 cd $HEDS_LOCALSTORE
458 mangano 1.6 status=`grep "crab_done" status`
459     if [ -z "$status" ];then
460     echo "+++ ERROR: crab jobs are not done yet. Try:"
461     echo " heds status <taskFolder>"
462     exit 1
463     fi
464    
465     ### create CASTOR folder
466     nsls -d $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION >& tmp
467     check=`cat tmp |grep "No such" |wc -w`
468     rm tmp
469     if [ $check == 0 ]
470     then echo "directory " $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION "already exists"
471     else
472     echo "making " $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION " directory"
473     rfmkdir -p $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION
474     fi
475    
476 mangano 1.5 heds.sh 6 #copy merged log files in CASTOR
477     heds.sh 4e #copy merged edm files in CASTOR
478 mangano 1.9 # cat >> status <<EOF
479     #store
480     #EOF
481 mangano 1.5 cd $initialFolder
482     ;;
483    
484     preview) ### produce html tables
485     hedsTaskFolder=$2
486     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
487     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
488     echo " heds.sh tables <hedsTaskFolder>"
489     exit 1
490     fi
491 mangano 1.7 source ./$hedsTaskFolder/configuration
492    
493     initialFolder=`pwd`
494 mangano 1.5 cd $HEDS_LOCALSTORE
495     heds.sh 4j #
496 mangano 1.9 php $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php > FirstPage.html
497     mv FirstPage.html $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
498     cp $HEDS_WWWAREA/fromGiovanni.css $HEDS_WWWAREA_TMP
499     cat >> status <<EOF
500     preview
501     EOF
502 mangano 1.5 cd $initialFolder
503     ;;
504 mangano 1.7
505     add2Web) ### produce html tables
506     hedsTaskFolder=$2
507     if [ -z "$hedsTaskFolder" -o ! -d ./$hedsTaskFolder ]; then
508     echo -e "+++ ERROR: you have to specify a \"hedsTaskFolder\" as in: "
509     echo " heds.sh tables <hedsTaskFolder>"
510     exit 1
511     fi
512     source ./$hedsTaskFolder/configuration
513    
514     initialFolder=`pwd`
515     cd $HEDS_LOCALSTORE
516     heds.sh final #
517 mangano 1.9 cat >> status <<EOF
518     add2Web
519     EOF
520 mangano 1.7 cd $initialFolder
521     ;;
522 mangano 1.5
523    
524    
525    
526     ########## internal "functions" which are not meant to be used by users ###############
527 mangano 1.1 0)
528 mangano 1.5 echo "=== Setting up directories and one-time things ==="
529 mangano 1.1 echo ""
530    
531 mangano 1.3 ### create WWW folders
532 mangano 1.2 if [ -d $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION ]
533 mangano 1.3 then echo "directory " $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION \
534     " already exists. Then skipping \"mkdir\" "
535    
536     if [ ! -d $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents ]; then
537     echo "making " $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
538     mkdir -p $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
539     fi
540    
541 mangano 1.1 else
542 mangano 1.2 echo "making " $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION " directory"
543 mangano 1.3 mkdir -p $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
544    
545     if [ -d $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION ]; then
546     echo "Warning: " logs.SkimV$HEDS_SKIMVERSION " already exist in final WWW_AREA."
547     echo "Copying base html tables from there."
548 mangano 1.4
549     ##TO BE FIXED. Check that files exist before copy
550 mangano 1.3 cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php \
551     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
552     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableHeader.shtm \
553     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
554     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableBody.shtm \
555     $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
556     fi
557    
558     if [ ! -d $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents ]; then
559     echo "making " $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
560     mkdir -p $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
561     fi
562 mangano 1.1 fi
563     ;;
564    
565     1)
566     echo "=== you selected option 1. Querying RunRegistry, select good runs and submit crab jobs ==="
567     echo ""
568    
569     dateForDbsSearch=`echo $HEDS_LABEL|awk -F\. '{print $3"-"$2"-"$1}'`
570 mangano 1.10 #echo "dateForDbsSearch: " $dateForDbsSearch
571 mangano 1.1 dbs search --query="find run where dataset=$HEDS_INPUTDATASET and run.createdate=$dateForDbsSearch" \
572     > tmpRunList.txt
573     lastRun=`cat tmpRunList.txt |grep [0-9][0-9][0-9][0-9][0-9][0-9] |head -n1`
574 mangano 1.10 firstRun=`cat tmpRunList.txt|grep [0-9][0-9][0-9][0-9][0-9][0-9] |tail -n1`
575    
576    
577     if((!${#lastRun}));then
578     rm tmpRunList.txt
579     echo "no runs" > $HEDS_LABEL.runinterval
580    
581     echo "No input runs for"
582     echo "HEDS_LABEL=" $HEDS_LABEL
583     echo "and"
584     echo "HEDS_INPUTDATASET=" $HEDS_INPUTDATASET
585     echo ""
586    
587     echo "No CRAB cfg will be created."
588     cat >> status <<EOF
589     runselection_empty
590     EOF
591     exit 0
592     fi
593    
594 mangano 1.1 rm tmpRunList.txt
595     echo "first,last runs: " $firstRun $lastRun
596    
597    
598     runselection="runselection="
599     cat $HEDSPATH/scripts/runreg.cfg | sed s/SET_RUNMIN/$firstRun/ | \
600     sed s/SET_RUNMAX/$lastRun/ > runreg.cfg
601     python $HEDSPATH/scripts/runregparse.py > tmp.log
602     rm runreg.cfg
603     echo "here we have the good run list"
604    
605     IFS=$'\n'
606     found=0
607     lastGoodRun=0
608     for line in $(cat tmp.log);
609     do
610     if [ $found == 0 ]
611     then
612     found=`echo $line |grep lumisToProcess|wc |awk '{print $1}'`
613     continue;
614     fi
615     if [ $line == ")" ]
616     then
617     break;
618     fi
619     thisRun=`echo $line | sed s/\'//g | sed s/,//g |awk -F: '{print $1}'`
620     if [ $thisRun != $lastGoodRun ]
621     then
622     runselection=$runselection$thisRun\,
623     fi
624     lastGoodRun=$thisRun
625     done
626     #echo "========= THE FOLLOWING LINE TO YOUR crab.cfg FILE ========="
627     echo $runselection
628     #echo "================================================================"
629     echo $runselection > $HEDS_LABEL.runselection
630     echo $firstRun-$lastRun > $HEDS_LABEL.runinterval
631     rm tmp.log
632    
633     check=`echo $runselection | sed s/runselection=// |wc -w`
634    
635     if [ $check == 0 ]
636     then
637     echo "No good runs have been selected. No CRAB cfg will be created."
638 mangano 1.7 cat >> status <<EOF
639     runselection_empty
640     EOF
641 mangano 1.1 else
642     echo "Some good runs have been selected. CRAB cfg will be created."
643 mangano 1.7 cat >> status <<EOF
644     runselection_done
645     EOF
646 mangano 1.1 cat $HEDSPATH/scripts/crab.template.cfg |sed "s#SET_DATASET#$HEDS_INPUTDATASET#" | \
647 mangano 1.3 # sed "s#SET_REMOTEDIR#$HEDS_USERID/HEDS/#" | \
648     sed "s#SET_REMOTEDIR#$HEDS_USERID/#" | \
649 mangano 1.1 sed "s#SET_T2#$HEDS_T2SITE#" | \
650     sed "s/SET_RUNSELECTION/$runselection/" > tmp.cfg
651     pset=$HEDSPATH/python/earlyDataInterestingEvents_cfg.py
652     echo "pset: " $pset
653     cat tmp.cfg |sed s#SET_PSET#$pset# | sed "s#SET_TASK_NAME#$dailySkim#" > tmp2.cfg; rm tmp.cfg
654     mv tmp2.cfg $HEDS_LABEL.crab.cfg
655     fi
656     ;;
657     2)
658 mangano 1.7 status=`tail -n1 status`
659     if [ ! "$status" == "runselection_done" ];then
660     #no crab jobs to be submitted
661     cat >> status <<EOF
662     submit_empty
663     EOF
664     exit 0
665     fi
666    
667 mangano 1.1 echo "creating and submitting CRAB jobs for " $dailySkim
668     if [ -e $HEDS_LABEL.crab.cfg ]
669     then
670     crab -create -submit -cfg $HEDS_LABEL.crab.cfg
671     if ((! $?)); then rm $HEDS_LABEL.crab.cfg; fi
672 mangano 1.7 cat >> status <<EOF
673     submit
674     EOF
675 mangano 1.1 else
676     echo "ERROR: " $HEDS_LABEL.crab.cfg " doesn't exist"
677     fi
678     ;;
679     3)
680     echo "getting output and publishing crab jobs"
681 mangano 1.6 crab -status -c $dailySkim &> /dev/null
682 mangano 1.1 crab -get -c $dailySkim
683 mangano 1.6 crab -status -c $dailySkim &> /dev/null
684 mangano 1.1 crab -publish -c $dailySkim
685     ;;
686    
687    
688     4)
689     echo "option 4 "
690     if [ -d $dailySkim ] #the crab job was run on at least 1 run
691     then
692     heds 4a
693     heds 4b
694     heds 4c
695     heds 4d
696     heds 4e
697     heds 4f
698     heds 4g
699     heds 4h
700     heds 4i
701     else
702     echo "copying only the log files about runs and selected-runs"
703     heds 4g
704 mangano 1.7 heds 4i2
705 mangano 1.1 fi
706     ;;
707    
708     4a)
709 mangano 1.3 #### echo "...copying log files"
710 mangano 1.1 if [ ! -d $HEDS_LOCALSTORE/$dailySkim/logs ]; then
711     mkdir -p $HEDS_LOCALSTORE/$dailySkim/logs
712     fi
713     cp $dailySkim/res/*.std* $HEDS_LOCALSTORE/$dailySkim/logs
714     if (($?)); then
715     echo "ERROR: failed to copy log files in " $HEDS_LOCALSTORE/$dailySkim/logs;
716     else
717     echo "copied all logs file in " $HEDS_LOCALSTORE/$dailySkim/logs
718     fi
719    
720 mangano 1.5 ###
721 mangano 1.1 tarName=$HEDS_LABEL.log.tgz
722     cd $HEDS_LOCALSTORE/$dailySkim/logs/
723     if (($?));then
724     echo "ERROR: failed to go to " $HEDS_LOCALSTORE/$dailySkim/logs/
725     else
726 mangano 1.3 echo "compriming log files... "
727     tar czvf $tarName *.std* >& /dev/null
728     echo -e "done \n"
729 mangano 1.1 cd -
730     fi
731     ;;
732    
733     4b)
734     ###
735 mangano 1.3 echo -e "creating skimReport..."
736 mangano 1.1 logName=$HEDS_LABEL.log
737     $HEDSPATH/scripts/skimreport $HEDS_LOCALSTORE/$dailySkim/logs/*.stdout > $logName
738 mangano 1.7 cp $logName $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents/
739 mangano 1.3 echo -e "done \n"
740 mangano 1.1 ;;
741    
742     4c)
743     ###
744     echo "...coping files from the T2's SE"
745     echo "dataset to retreive: " $dailySkim
746     dbs search --url=https://cmsdbsprod.cern.ch:8443/cms_dbs_ph_analysis_02_writer/servlet/DBSServlet \
747     --query="find file,site where dataset=*$dailySkim*" |grep .root >listFiles
748    
749     IFS=$'\n'
750     for j in $(cat listFiles)
751     do
752     echo "going to copy file: $j"
753     fileName=`echo $j |awk '{print$1}'| awk -F$dailySkim/ '{print $2}' | awk -F/ '{print $2}'`
754    
755     storage_elem=`echo $j |awk '{print $2}'`
756     remote_path=`echo $j|awk '{print $1}'`
757     lcg-cp -b -D srmv2 srm://$storage_elem:$HEDS_STORAGEPORT$HEDS_STORAGEPATH$remote_path file://$HEDS_LOCALSTORE/$dailySkim/$fileName
758     done
759     rm listFiles
760 mangano 1.6 #nFiles=`ls $HEDS_LOCALSTORE/$dailySkim/*.root|wc -l`
761     #nJobs=`ls $HEDS_LOCALSTORE/$dailySkim/logs/CMSSW_*.stdout |wc -l`
762 mangano 1.7 ;;
763 mangano 1.1
764 mangano 1.7 4c_temp)
765     echo "copying manually files from SE.. "
766     scp bmangano@uaf-6.t2.ucsd.edu:/hadoop/cms/store/user/mangano/MinimumBias/$dailySkim/*/*.root $HEDS_LOCALSTORE/$dailySkim/
767 mangano 1.1 ;;
768    
769 mangano 1.7
770 mangano 1.1 4d)
771     ###
772 mangano 1.3 echo -e "Merging files edm files..."
773 mangano 1.1 cp $HEDSPATH/scripts/prepareMerging.sh $HEDS_LOCALSTORE/$dailySkim
774     cp $HEDSPATH/scripts/merge.py $HEDS_LOCALSTORE/$dailySkim
775     cd $HEDS_LOCALSTORE/$dailySkim
776    
777 mangano 1.6 mergedName=$HEDS_LABEL.root
778     mergedName=merged_$mergedName
779    
780 mangano 1.1 ./prepareMerging.sh
781     numberFilesToMerge=`ls *.root|wc -l`
782     echo "numberFilesToMerge: " $numberFilesToMerge
783     cmsRun merge.py >& merging.log
784 mangano 1.6 mv merged.root $HEDS_LOCALSTORE/$mergedName
785 mangano 1.3 echo -e "done \n"
786 mangano 1.1 cd -
787     ;;
788    
789     4e)
790     ###
791 mangano 1.3 echo -e "Storing merged edm file in CASTOR..."
792 mangano 1.1 mergedName=$HEDS_LABEL.root
793     mergedName=merged_$mergedName
794     echo "mergedName: " $mergedName
795     cd $HEDS_LOCALSTORE/$dailySkim
796     if ((! $?)); then
797     echo "going to copy the merged file into: " $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION
798 mangano 1.6 rfcp $HEDS_LOCALSTORE/$mergedName $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION/
799 mangano 1.1 cd -
800     fi
801 mangano 1.3 echo -e "done \n"
802 mangano 1.1 ;;
803    
804     4f)
805     ###
806 mangano 1.3 echo "Preparing detailed list of skimmed events..."
807 mangano 1.1 cp $HEDSPATH/scripts/listSkimmedEvent.C $HEDS_LOCALSTORE
808     cd $HEDS_LOCALSTORE
809 mangano 1.7 forRootExecution="listSkimmedEvent.C++(\"${HEDS_LABEL}\")"
810    
811     root.exe -b -q $forRootExecution >& /dev/null
812 mangano 1.2 listSkimmedEventsPath=$HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
813 mangano 1.1 if [ ! -d $listSkimmedEventsPath ]
814     then
815     mkdir $listSkimmedEventsPath
816     fi
817 mangano 1.7 listDetailedLogs=`ls ${HEDS_LABEL}_Skim_*`
818 mangano 1.1 for j in $listDetailedLogs
819     do
820     echo "preparing log " $j
821     # sort entries by date
822     cat $j |sort -k7 > tmp
823     mv tmp $j
824     mv $j $listSkimmedEventsPath
825     done
826 mangano 1.3 echo -e "done \n"
827 mangano 1.1 cd -
828     ;;
829    
830     4g)
831     ###
832 mangano 1.3 echo "Copying logs about run selection..."
833 mangano 1.7 cp $HEDS_LABEL.runselection $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
834     cp $HEDS_LABEL.runinterval $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
835 mangano 1.3 echo -e "done \n"
836 mangano 1.1 ;;
837    
838     4h)
839     ###
840 mangano 1.3 echo "Preparing event dumps..."
841 mangano 1.1 input=$HEDS_LOCALSTORE/merged_$HEDS_LABEL.root
842     echo "input: " $input
843     sed s#INPUT#$input# $HEDSPATH/scripts/dumpEvent.py > dumpEvent.py
844     cmsRun dumpEvent.py >& $HEDS_LABEL.dumperLog
845 mangano 1.7
846 mangano 1.1 $HEDSPATH/scripts/parseDumperOutput.sh 1 >& $HEDS_LABEL.dump
847     $HEDSPATH/scripts/parseDumperOutput.sh 2
848     rm dumpEvent.py
849     rm $HEDS_LABEL.dumperLog
850     rm $HEDS_LABEL.dump
851 mangano 1.3 echo -e "done \n"
852 mangano 1.1 ;;
853     4i)
854     ###
855 mangano 1.10 rawLocation=$2
856 mangano 1.3 echo "Preparing html tables..."
857 mangano 1.2 if [ ! -e $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php ];then
858 mangano 1.1 echo "create first version of FirstTable.sh"
859     $HEDSPATH/scripts/editFirstTable.sh create
860 mangano 1.3 $HEDSPATH/scripts/createTableSkimDetails.sh add ; echo "level-3 tables produced"
861     $HEDSPATH/scripts/createTableSkimSummary.sh ; echo "level-2 tables produced"
862 mangano 1.10 $HEDSPATH/scripts/editFirstTable.sh add $rawLocation ; echo "level-1 table modified"
863 mangano 1.3 else
864     $HEDSPATH/scripts/createTableSkimDetails.sh clean; echo "clean up old html tables"
865     $HEDSPATH/scripts/createTableSkimDetails.sh add ; echo "level-3 tables produced"
866     $HEDSPATH/scripts/createTableSkimSummary.sh ; echo "level-2 tables produced"
867 mangano 1.10 $HEDSPATH/scripts/editFirstTable.sh add $rawLocation ; echo "level-1 table modified"
868 mangano 1.3 fi
869     echo -e "done \n"
870     ;;
871    
872 mangano 1.7 4i2)
873     ###
874 mangano 1.10 rawLocation=$2
875 mangano 1.7 echo "Preparing html tables..."
876     if [ ! -e $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php ];then
877     echo "create first version of FirstTable.sh"
878     $HEDSPATH/scripts/editFirstTable.sh create
879     #$HEDSPATH/scripts/createTableSkimDetails.sh add ; echo "level-3 tables produced"
880     #$HEDSPATH/scripts/createTableSkimSummary.sh ; echo "level-2 tables produced"
881 mangano 1.10 $HEDSPATH/scripts/editFirstTable.sh addSpecial $rawLocation ; echo "level-1 table modified"
882 mangano 1.7 else
883     #$HEDSPATH/scripts/createTableSkimDetails.sh clean; echo "clean up old html tables"
884     #$HEDSPATH/scripts/createTableSkimDetails.sh add ; echo "level-3 tables produced"
885     #$HEDSPATH/scripts/createTableSkimSummary.sh ; echo "level-2 tables produced"
886 mangano 1.10 $HEDSPATH/scripts/editFirstTable.sh addSpecial $rawLocation ; echo "level-1 table modified"
887 mangano 1.7 fi
888     echo -e "done \n"
889     ;;
890    
891    
892 mangano 1.3 4j) ###
893     echo -e "Your preliminary table is available at the following URL: "
894 mangano 1.6 url="file://"
895 mangano 1.9 url=$url$HEDS_WWWAREA_TMP"/logs.SkimV$HEDS_SKIMVERSION/FirstPage.html"
896 mangano 1.3 echo -e $url "\n"
897 mangano 1.10
898 mangano 1.3 echo -e "After you verified that all the tables have been correctly produced, " \
899 mangano 1.9 "they can be moved to the final repository using:"
900 mangano 1.10 echo -e " heds add2Web <taskFolder> \n"
901    
902    
903     echo "WARNING: if some php pages are not opened corretly, it may be because apache server is not"
904     echo " running on the machine hosting your HEDS_WWWAREA_TMP area."
905     echo "In such a case, copy the whole HEDS_WWWAREA_TMP where "
906     echo "php can be interpreted correctly: e.g. your personal webSite hosted at CERN "
907     echo ""
908     echo "To remind you, currently your HEDS_WWWAREA_TMP folder is: "
909     echo $HEDS_WWWAREA_TMP
910 mangano 1.3
911 mangano 1.1 ;;
912 mangano 1.3
913 mangano 1.5
914     6) ### copying stuff to castor
915     tarName=$HEDS_LABEL.log.tgz
916     cd $HEDS_LOCALSTORE/$dailySkim/logs/
917     if (($?));then
918     echo "ERROR: failed to go to " $HEDS_LOCALSTORE/$dailySkim/logs/
919     else
920     echo "copying " $tarName " file to CASTOR area.."
921     rfcp $tarName $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION
922     echo -e "done \n"
923     cd -
924     fi
925     ;;
926    
927 mangano 1.1 5a)
928     echo ".... preparing event display server"
929     mkdir $HEDS_LABEL.shots
930     port=3005
931     $HEDSPATH/scripts/eventDisplayServer.sh $port &
932     ;;
933     5b)
934     echo "getting snapshots"
935     port=3005
936     file=$HEDS_LOCALSTORE/merged_$HEDS_LABEL.root
937     echo "$file" | nc -w 10 localhost $port
938     ;;
939     5c)
940     echo "moving snapshots"
941 mangano 1.2 mv $HEDS_LABEL.shots $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/
942 mangano 1.1 cp $HEDSPATH/scripts/indexFileForDetailedSnapShots.php \
943 mangano 1.2 $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.shots/index.php
944 mangano 1.1 ;;
945    
946    
947 mangano 1.3 final)
948     #TO BE FIXED. this call could written in a much more compact way
949     echo "WWW pages are going to be moved from the temporary repository"
950     echo -e "("$HEDS_WWWAREA_TMP")\n"
951     echo "to the permanent one"
952     echo -e "("$HEDS_WWWAREA")\n"
953    
954     if [ ! -d $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION ]; then
955     mkdir $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION
956     fi
957    
958     if [ -e $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php ]; then
959     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php \
960     $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php.BAK
961     fi
962     if [ -e $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableBody.shtm ]; then
963     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableBody.shtm \
964     $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableBody.shtm.BAK
965     fi
966     if [ -e $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableHeader.php ]; then
967     cp $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableHeader.shtm \
968     $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/tableHeader.shtm.BAK
969     fi
970    
971 mangano 1.7 cp $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/*.php \
972 mangano 1.3 $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/
973 mangano 1.7 cp $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/*.shtm \
974 mangano 1.3 $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/
975    
976 mangano 1.7 if [ -e $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents ]; then
977     if [ -e $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents ]; then
978 mangano 1.10 echo "WARNING: replacing folder in the official AFS area of the HiggsDQM."
979    
980     echo "Do you know what you are doing? And is this what you really want to do? [y/n]"
981     read -p "$prompt" answer
982     case "$answer" in
983     [yY1] )
984     echo "proceeding with the update of the table.."
985     ;;
986     [nN0] )
987     exit 0
988     ;;
989     *)
990     echo -e "Incorrect answer. Assuming you meant to type \"No\" "
991     exit
992     ;;
993     esac
994 mangano 1.7 rm -r -i $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
995     fi
996     cp -r $HEDS_WWWAREA_TMP/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents \
997     $HEDS_WWWAREA/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
998     fi
999 mangano 1.3
1000    
1001 mangano 1.7 url="https://cms-project-higgsdqm.web.cern.ch/cms-project-higgsdqm/HiggsEDS"
1002 mangano 1.3 url=$url"/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php"
1003    
1004     echo "The new tables created by you are accessible through the following URL: "
1005     echo $url
1006     ;;
1007    
1008 mangano 1.1 ##################### after the crab part is done ###################
1009 mangano 1.2 99) echo "Doing bakcup of $HEDS_WWWAREA_TMP"
1010 mangano 1.1 date=`date +%k\.%M\.%S_%e\.%m\.%Y`
1011     fileName="HiggsIES.BAK."$date".tgz"
1012     echo "file name: " $fileName
1013 mangano 1.2 tar -czvf $fileName $HEDS_WWWAREA_TMP
1014     mv $fileName $HEDS_WWWAREA_TMP/..
1015 mangano 1.1 ;;
1016    
1017    
1018     *)
1019     echo "option not defined"
1020     ;;
1021     esac