ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/HiggsAnalysis/EarlyDataStudy/scripts/heds.sh
Revision: 1.6
Committed: Sat May 8 18:45:28 2010 UTC (14 years, 11 months ago) by mangano
Content type: application/x-sh
Branch: MAIN
Changes since 1.5: +139 -46 lines
Log Message:
use local root.file for producing html tables

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