]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/benchmark/benchmark.sh
setting of downscaling factors in the filetered trees creation
[u/mrichter/AliRoot.git] / PWGPP / benchmark / benchmark.sh
1 #!/bin/bash
2 # this script runs the CPass0/CPass1 train
3 # produced OCDB updates are local
4
5 main()
6 {
7   #run in proper mode depending on the selection
8   runMode=$1
9   if [[ $# -gt 0 ]]; then
10     echo "# $0 $*"
11   fi
12   umask 0002
13   shift
14   case $runMode in
15     "CPass0") goCPass0 "$@";;
16     "CPass1") goCPass1 "$@";;
17     "ConfOCDB") goConfigureOCDBforCPass1 "$@";;
18     "MergeCPass0") goMergeCPass0 "$@";;
19     "MergeCPass1") goMergeCPass1 "$@";;
20     "CreateQAplots") goCreateQAplots "$@";;
21     "WaitForOutput") goWaitForOutput "$@";;
22     "makeSummary") goMakeSummary "$@";;
23     "submit") goSubmit "$@";;
24     "submitQA") goSubmitQA "$@";;
25     "test") goTest "$@";;
26     "generateMakeflow") goGenerateMakeflow "$@";;
27     "makeflow") goMakeflow "$@";;
28     #and the default: unless sourced print some info
29     *) if [[ ! "$0" =~ "bash" ]]; then
30          echo " batch:    $0 \"submit\" inputList productionID [configFile=benchmark.config] [runNumber]"
31          echo " makeflow: $0 \"makeflow\" inputList productionID [configFile=benchmark.config] [runNumber]"
32        fi
33     ;;
34   esac
35 }
36
37 goCPass0()
38 {
39   umask 0002
40   
41   configFile=$5
42   source $configFile
43   [[ -f ${setupAliROOTenvInCurrentShell} && -z ${alirootEnv} ]] && source $setupAliROOTenvInCurrentShell
44
45   targetDirectory=$1
46   inputList=$2
47   nEvents=$3
48   ocdbPath=$4
49   configFile=$5
50   runNumber=$6
51   jobindex=$7
52
53   #use the jobindex only if set and non-negative
54   if [[ -z $jobindex || $jobindex -lt 0 ]]; then
55     [[ -n "$LSB_JOBINDEX" ]] && jobindex=$LSB_JOBINDEX
56     [[ -n "$SGE_TASK_ID" ]] && jobindex=$SGE_TASK_ID
57   fi
58
59   [[ ! -f ${inputList} && -z ${pretend} ]] && echo "input file $inputList not found, exiting..." && exit 1
60   if [[ "${inputList}" =~ \.root$ ]]; then
61     infile=$inputList
62   else
63     infile=`sed -ne "${jobindex}p" $inputList`
64   fi
65   
66   chunkName=${infile##*/}
67   outputDir=${targetDirectory}/${jobindex}
68   mkdir -p $outputDir
69   [[ ! -d $outputDir ]] && echo "cannot make $outputDir" && exit 1
70   
71   runpath=${PWD}/rundir_cpass0_${runNumber}_${jobindex}
72   [[ -z $commonOutputPath ]] && commonOutputPath=$PWD
73   [[ $reconstructInTemporaryDir -eq 1 && -n $TMPDIR ]] && runpath=$TMPDIR
74   [[ $reconstructInTemporaryDir -eq 1 && -z $TMPDIR ]] && runpath=$(mktemp -d)
75
76   mkdir -p $runpath
77   [[ ! -d ${runpath} ]] && echo "cannot make runpath ${runpath}" && exit 1
78   cd $runpath
79
80   logOutputDir=$runpath
81   [[ -n $logToFinalDestination ]] && logOutputDir=$outputDir
82   [[ -z $dontRedirectStdOutToLog ]] && exec 1> $logOutputDir/stdout
83   [[ -z $dontRedirectStdOutToLog ]] && exec 2> $logOutputDir/stderr
84   echo "$0 $*"
85
86   calibDoneFile="$commonOutputPath/cpass0.job${jobindex}.run${runNumber}.done"
87
88   echo "#####################"
89   echo CPass0:
90   echo JOB setup
91   echo nEvents            $nEvents
92   echo runNumber          $runNumber
93   echo ocdbPath           $ocdbPath
94   echo infile             $infile
95   echo chunkName          $chunkName
96   echo jobindex           $jobindex
97   echo recoTriggerOptions $recoTriggerOptions
98   echo targetDirectory    $targetDirectory
99   echo commonOutputPath         $commonOutputPath
100   echo calibDoneFile      $calibDoneFile
101   echo runpath            $runpath  
102   echo outputDir          $outputDir
103   echo ALICE_ROOT         $ALICE_ROOT
104   echo PWD                $PWD
105   echo "########## ###########"
106
107   alirootInfo > ALICE_ROOT_svn.log
108
109   filesCPass0=( 
110                "$commonOutputPath/runCPass0.sh"
111                "$commonOutputPath/recCPass0.C"
112                "$commonOutputPath/runCalibTrain.C"
113                "$commonOutputPath/localOCDBaccessConfig.C"
114                "$commonOutputPath/OCDB.root"
115                "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/runCPass0.sh"
116                "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/recCPass0.C" 
117                "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/runCalibTrain.C"
118   )
119
120   for file in ${filesCPass0[*]}; do
121     [[ ! -f ${file##*/} && -f ${file} ]] && echo "copying ${file}" && cp -f ${file} .
122   done
123
124   ln -s $infile $runpath/$chunkName
125
126   echo "this directory ($PWD) contents:"
127   ls -lh
128   echo
129   chmod u+x runCPass0.sh
130
131   if [[ -n $postSetUpActionCPass0 ]]; then
132     echo "running $postSetUpActionCPass0"
133     eval $postSetUpActionCPass0
134   fi
135
136   #run CPass0
137   echo "$runpath/runCPass0.sh $infile $nEvents $runNumber $ocdbPath $recoTriggerOptions"
138   if [[ -n $pretend ]]; then
139     touch AliESDfriends_v1.root
140     touch rec.log
141     touch calib.log
142   else
143     ./runCPass0.sh "$infile" "$nEvents" "$runNumber" "$ocdbPath" "$recoTriggerOptions"
144   fi
145   
146   #move stuff to final destination
147   echo "this directory ($PWD) contents:"
148   ls -lh
149   echo
150
151   echo rm -f ./$chunkName
152   rm -f ./$chunkName
153   echo "cp --recursive $runpath/* ${outputDir}"
154   cp --recursive $runpath/* $outputDir
155   echo
156   
157   #validate CPass0
158   cd ${outputDir}
159   touch ${calibDoneFile}
160   [[ -f AliESDfriends_v1.root ]] && echo "calibfile ${outputDir}/AliESDfriends_v1.root" > ${calibDoneFile}
161   summarizeLogs >> ${calibDoneFile}
162
163   rm -rf ${runpath}
164 }
165
166 goCPass1()
167 {
168   umask 0002
169   
170   configFile=$5
171   source $configFile
172   [[ -f ${setupAliROOTenvInCurrentShell} && -z ${alirootEnv} ]] && source $setupAliROOTenvInCurrentShell
173
174   targetDirectory=$1
175   inputList=$2
176   nEvents=$3
177   ocdbPath=$4
178   configFile=$5
179   runNumber=$6
180   jobindex=$7
181
182   #use the jobindex only if set and non-negative
183   if [[ -z $jobindex || $jobindex -lt 0 ]]; then
184     [[ -n "$LSB_JOBINDEX" ]] && jobindex=$LSB_JOBINDEX
185     [[ -n "$SGE_TASK_ID" ]] && jobindex=$SGE_TASK_ID
186   fi
187
188   [[ ! -f ${inputList} && -z ${pretend} ]] && echo "input file $inputList not found, exiting..." && exit 1
189   if [[ "${inputList}" =~ \.root$ ]]; then
190     infile=$inputList
191   else
192     infile=`sed -ne "${jobindex}p" $inputList`
193   fi
194   
195   chunkName=${infile##*/}
196   outputDir=${targetDirectory}/${jobindex}
197   mkdir -p $outputDir
198   [[ ! -d $outputDir ]] && echo "cannot make $outputDir" && exit 1
199   
200   runpath=${PWD}/rundir_cpass1_${runNumber}_${jobindex}
201   [[ -z $commonOutputPath ]] && commonOutputPath=$PWD
202   [[ $reconstructInTemporaryDir -eq 1 && -n $TMPDIR ]] && runpath=$TMPDIR
203   [[ $reconstructInTemporaryDir -eq 1 && -z $TMPDIR ]] && runpath=$(mktemp -d)
204
205   #init the running path
206   mkdir -p $runpath
207   [[ ! -d ${runpath} ]] && echo "cannot make runpath ${runpath}" && exit 1
208   cd $runpath
209
210
211   calibDoneFile="${commonOutputPath}/cpass1.job${jobindex}.run${runNumber}.done"
212
213   logOutputDir=$runpath
214   [[ -n $logToFinalDestination ]] && logOutputDir=$outputDir
215   [[ -z $dontRedirectStdOutToLog ]] && exec 1> $logOutputDir/stdout
216   [[ -z $dontRedirectStdOutToLog ]] && exec 2> $logOutputDir/stderr
217   echo "$0 $*"
218
219   echo "#####################"
220   echo CPass1:
221   echo JOB setup
222   echo nEvents            $nEvents
223   echo runNumber          $runNumber
224   echo ocdbPath           $ocdbPath
225   echo infile             $infile
226   echo chunkName          $chunkName
227   echo jobindex           $jobindex
228   echo recoTriggerOptions $recoTriggerOptions
229   echo targetDirectory    $targetDirectory
230   echo commonOutputPath         $commonOutputPath
231   echo calibDoneFile      $calibDoneFile
232   echo runpath            $runpath  
233   echo outputDir          $outputDir
234   echo ALICE_ROOT         $ALICE_ROOT
235   echo PWD                $PWD
236   echo "########## ###########"
237
238   alirootInfo > ALICE_ROOT_svn.log
239
240   filesCPass1=( 
241                "$commonOutputPath/runCPass1.sh"
242                "$commonOutputPath/recCPass1.C"
243                "$commonOutputPath/recCPass1_OuterDet.C"
244                "$commonOutputPath/runCalibTrain.C"
245                "$commonOutputPath/QAtrain_duo.C"
246                "$commonOutputPath/localOCDBaccessConfig.C"
247                "$commonOutputPath/cpass0.localOCDB.${runNumber}.tgz"
248                "$commonOutputPath/OCDB.root"
249                "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/runCPass1.sh"
250                "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/recCPass1.C" 
251                "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/recCPass1_OuterDet.C" 
252                "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/runCalibTrain.C"
253                "$ALICE_ROOT/ANALYSIS/macros/QAtrain_duo.C"
254   )
255
256   for file in ${filesCPass1[*]}; do
257     [[ ! -f ${file##*/} && -f ${file} ]] && echo "copying ${file}" && cp -f ${file} .
258   done
259
260   ln -s $infile $runpath/$chunkName
261
262   echo "this directory ($PWD) contents:"
263   ls -lh
264   echo
265
266   if [[ -n $postSetUpActionCPass1 ]]; then
267     echo "running $postSetUpActionCPass1"
268     eval $postSetUpActionCPass1
269     echo
270   fi
271
272   #configure local OCDB storage from CPass0 (creates the localOCDBaccessConfig.C script)
273   if [[ -f cpass0.localOCDB.${runNumber}.tgz ]]; then
274    echo goConfigureOCDBforCPass1 "cpass0.localOCDB.${runNumber}.tgz"
275    goConfigureOCDBforCPass1 "cpass0.localOCDB.${runNumber}.tgz"
276  else
277    echo "WARNING: file cpass0.localOCDB.${runNumber}.tgz not found!"
278  fi
279
280   #run CPass1
281   chmod u+x runCPass1.sh
282   echo "$runpath/runCPass1.sh $infile $nEvents $runNumber $ocdbPath $recoTriggerOptions"
283   if [[ -n $pretend ]]; then
284     touch AliESDfriends_v1.root
285     touch QAresults_Barrel.root
286     touch QAresults_Outer.root
287     touch rec.log
288     touch calib.log
289     touch qa.log
290   else
291     ./runCPass1.sh "$infile" "$nEvents" "$runNumber" "$ocdbPath" "$recoTriggerOptions"
292   fi
293   
294   #move stuff to final destination
295   echo "this directory ($PWD) contents:"
296   ls
297   echo
298
299   echo rm -f ./$chunkName
300   rm -f ./$chunkName
301   echo "cp --recursive ${runpath}/* ${outputDir}"
302   cp --recursive ${runpath}/* ${outputDir}
303   echo
304
305   #validate CPass1
306   cd ${outputDir}
307   touch ${calibDoneFile}
308   [[ -f AliESDfriends_v1.root ]] && echo "calibfile ${outputDir}/AliESDfriends_v1.root" > ${calibDoneFile}
309   [[ -f QAresults_Barrel.root ]] && echo "qafile ${outputDir}/QAresults_Barrel.root" >> ${calibDoneFile}
310   [[ -f QAresults_Outer.root ]] && echo "qafile ${outputDir}/QAresults_Outer.root" >> ${calibDoneFile}
311   summarizeLogs >> ${calibDoneFile}
312   
313   rm -rf ${runpath}
314 }
315
316
317 goMergeCPass0()
318 {
319   umask 0002
320   #
321   # find the output files and merge them
322   #
323
324   outputDir=$1
325   defaultOCDB=$2
326   configFile=$3
327   runNumber=$4
328   calibrationFilesToMergeExternal=$5
329
330   source $configFile
331   [[ -f ${setupAliROOTenvInCurrentShell} && -z ${alirootEnv} ]] && source $setupAliROOTenvInCurrentShell
332
333   runpath=${PWD}/rundir_cpass0_Merge_${runNumber}
334   [[ -z $commonOutputPath ]] && commonOutputPath=$PWD
335   [[ $reconstructInTemporaryDir -eq 1 && -n $TMPDIR ]] && runpath=$TMPDIR
336   [[ $reconstructInTemporaryDir -eq 1 && -z $TMPDIR ]] && runpath=$(mktemp -d)
337
338   mkdir -p $runpath
339   [[ ! -d $runpath ]] && echo "not able to make the runpath $runpath" && exit 1
340   cd $runpath
341
342   logOutputDir=$runpath
343   [[ -n $logToFinalDestination ]] && logOutputDir=$outputDir
344   [[ -z $dontRedirectStdOutToLog ]] && exec 2>&1 > $logOutputDir/mergeMakeOCDB.log
345   echo "$0 $*"
346
347   calibrationFilesToMerge=$calibrationFilesToMergeExternal
348   [[ -z $calibrationFilesToMerge ]] && calibrationFilesToMerge="calibrationFilesToMerge.list"
349   calibrationOutputFileName="AliESDfriends_v1.root"
350   mergingScript="mergeMakeOCDB.byComponent.sh"
351   qaFilesToMerge="qaFilesToMerge.list"
352   qaOutputFileName="QAresults*.root"
353   qaMergedOutputFileName="QAresults_merged.root"
354
355   echo goMergeCPass0 SETUP:
356   echo runNumber=$runNumber
357   echo outputDir=$outputDir
358   echo defaultOCDB=$defaultOCDB
359   echo calibrationFilesToMerge=$calibrationFilesToMerge
360   echo calibrationOutputFileName=$calibrationOutputFileName
361   echo mergingScript=$mergingScript
362   
363   # copy files in case they are not already there
364   filesMergeCPass0=(
365                     "$commonOutputPath/${calibrationFilesToMerge}"
366                     "$commonOutputPath/OCDB.root"
367                     "$commonOutputPath/localOCDBaccessConfig.C"
368                     "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/mergeMakeOCDB.byComponent.sh"
369                     "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/mergeByComponent.C"
370                     "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/makeOCDB.C"
371                     "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/merge.C"
372                     "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/mergeMakeOCDB.sh"
373   )
374   for file in ${filesMergeCPass0[*]}; do
375     [[ ! -f ${file##*/} && -f ${file} ]] && echo "copying ${file}" && cp -f ${file} .
376   done
377   
378   alirootInfo > ALICE_ROOT_svn.log
379
380   #
381   ls -lh
382
383   #merge calibration
384   chmod u+x $mergingScript  
385   mkdir -p ./OCDB
386   if [[ -z ${calibrationFilesToMergeExternal} ]]; then
387     echo "find $outputDir -name $calibrationOutputFileName > $calibrationFilesToMerge"
388     find $outputDir -name $calibrationOutputFileName > $calibrationFilesToMerge
389   fi
390   
391   echo "$mergingScript $calibrationFilesToMerge ${runNumber} local://./OCDB $defaultOCDB"
392   if [[ -n $pretend ]]; then
393     touch CalibObjects.root
394     touch ocdb.log
395     touch merge.log
396     mkdir -p ./OCDB/someDetector/
397     mkdir -p ./OCDB/otherDetector/
398     touch ./OCDB/someDetector/someCalibObject_0-999999_cpass0.root
399     touch ./OCDB/otherDetector/otherCalibObject_0-999999_cpass0.root
400   else
401     ./$mergingScript $calibrationFilesToMerge ${runNumber} "local://./OCDB" $defaultOCDB
402   fi
403
404   ### produce the output
405   #tar the produced OCDB for reuse
406   tar czf $commonOutputPath/cpass0.localOCDB.${runNumber}.tgz ./OCDB
407
408   ls -ltrh
409
410   #copy all to output dir
411   cp --recursive ${runpath}/* $outputDir
412   
413   #validate merging cpass0
414   cd ${outputDir}
415   calibDoneFile="${commonOutputPath}/merge.cpass0.run${runNumber}.done"
416   touch ${calibDoneFile}
417   [[ -f CalibObjects.root ]] && echo "calibfile $outputDir/CalibObjects.root" > ${calibDoneFile}
418   summarizeLogs >> ${calibDoneFile}
419
420   rm -rf ${runpath}
421 }
422
423 goMergeCPass1()
424 {
425   umask 0002
426   #
427   # find the output files and merge them
428   #
429
430   outputDir=$1
431   defaultOCDB=$2
432   configFile=$3
433   runNumber=$4
434   calibrationFilesToMergeExternal=$5
435   qaFilesToMergeExternal=$6
436
437   #clean up first:
438   rm -f $outputDir/*.log
439   rm -f $outputDir/*.root
440   rm -f $outputDir/*done
441
442   source $configFile
443   [[ -f ${setupAliROOTenvInCurrentShell} && -z ${alirootEnv} ]] && source $setupAliROOTenvInCurrentShell
444
445   runpath=${PWD}/rundir_cpass1_Merge_${runNumber}
446   [[ -z $commonOutputPath ]] && commonOutputPath=$PWD
447   [[ $reconstructInTemporaryDir -eq 1 && -n $TMPDIR ]] && runpath=$TMPDIR
448   [[ $reconstructInTemporaryDir -eq 1 && -z $TMPDIR ]] && runpath=$(mktemp -d)
449
450   mkdir -p $runpath
451   [[ ! -d $runpath ]] && echo "not able to make the runpath $runpath" && exit 1
452   cd $runpath
453
454   logOutputDir=$runpath
455   [[ -n $logToFinalDestination ]] && logOutputDir=$outputDir
456   [[ -z $dontRedirectStdOutToLog ]] && exec 2>&1 > $logOutputDir/mergeMakeOCDB.log
457   echo "$0 $*"
458
459   calibrationFilesToMerge=$calibrationFilesToMergeExternal
460   [[ -z $calibrationFilesToMerge ]] && calibrationFilesToMerge="calibrationFilesToMerge.list"
461   calibrationOutputFileName="AliESDfriends_v1.root"
462   mergingScript="mergeMakeOCDB.byComponent.sh"
463   qaFilesToMerge=$qaFilesToMergeExternal
464   [[ -z $qaFilesToMerge ]] && qaFilesToMerge="qaFilesToMerge.list"
465   qaOutputFileName="QAresults*.root"
466   qaMergedOutputFileName="QAresults_merged.root"
467
468   echo goMergeCPass1 SETUP:
469   echo runNumber=$runNumber
470   echo outputDir=$outputDir
471   echo defaultOCDB=$defaultOCDB
472   echo calibrationFilesToMerge=filesToMerge.list
473   echo calibrationOutputFileName=$calibrationOutputFileName
474   echo mergingScript=$mergingScript
475   
476   # copy files in case they are not already there
477   filesMergeCPass1=(
478                     "$commonOutputPath/${calibrationFilesToMerge}"
479                     "$commonOutputPath/${qaFilesToMerge}"
480                     "$commonOutputPath/OCDB.root"
481                     "$commonOutputPath/localOCDBaccessConfig.C"
482                     "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/mergeMakeOCDB.byComponent.sh"
483                     "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/mergeByComponent.C"
484                     "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/makeOCDB.C"
485                     "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/merge.C"
486                     "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/mergeMakeOCDB.sh"
487   )
488   for file in ${filesMergeCPass1[*]}; do
489     [[ ! -f ${file##*/} && -f ${file} ]] && echo "copying ${file}" && cp -f ${file} .
490   done
491
492   alirootInfo > ALICE_ROOT_svn.log
493
494   #
495   ls -lh
496
497   #merge calibration
498   chmod u+x $mergingScript  
499   mkdir -p OCDB
500   if [[ -z ${calibrationFilesToMergeExternal} ]]; then
501     echo "find $outputDir -name $calibrationOutputFileName > $calibrationFilesToMerge"
502     find $outputDir -name $calibrationOutputFileName > $calibrationFilesToMerge
503   fi
504   
505   echo "$mergingScript $calibrationFilesToMerge ${runNumber} local://./OCDB $defaultOCDB"
506   if [[ -n $pretend ]]; then
507     touch CalibObjects.root
508     touch ocdb.log
509     touch merge.log
510   else
511     ./$mergingScript $calibrationFilesToMerge ${runNumber} "local://./OCDB" $defaultOCDB
512   fi
513
514   tar czf localCPass1_${runNumber}.tgz ./OCDB
515
516   #merge QA
517   [[ -n ${AliAnalysisTaskFilteredTree_fLowPtTrackDownscaligF} ]] && export AliAnalysisTaskFilteredTree_fLowPtTrackDownscaligF
518   [[ -n ${AliAnalysisTaskFilteredTree_fLowPtV0DownscaligF} ]] && export AliAnalysisTaskFilteredTree_fLowPtV0DownscaligF
519
520   if [[ -z $qaFilesToMergeExternal ]]; then
521     echo "find $outputDir -name $qaOutputFileName > $qaFilesToMerge"
522     find $outputDir -name $qaOutputFileName > $qaFilesToMerge
523   fi
524   
525   echo aliroot -l -b -q "merge.C(\"$qaFilesToMerge\",\"\",kFALSE,\"$qaMergedOutputFileName\")"
526   if [[ -n $pretend ]]; then
527     touch $qaMergedOutputFileName
528     touch merge.log
529   else
530     aliroot -l -b -q "merge.C(\"$qaFilesToMerge\",\"\",kFALSE,\"$qaMergedOutputFileName\")"
531   fi
532
533   ls -ltrh
534
535   #copy all to output dir
536   cp --recursive ${runpath}/* ${outputDir}
537   
538   #validate merge cpass1
539   cd ${outputDir}
540   calibDoneFile="${commonOutputPath}/merge.cpass1.run${runNumber}.done"
541   touch ${calibDoneFile}
542   [[ -f CalibObjects.root ]] && echo "calibfile $outputDir/CalibObjects.root" > ${calibDoneFile}
543   [[ -f $qaMergedOutputFileName ]] && echo "qafile $outputDir/$qaMergedOutputFileName" >> ${calibDoneFile}
544   summarizeLogs >>  ${calibDoneFile}
545
546   rm -rf ${runpath}
547 }
548
549 goSubmit()
550 {
551   inputList=$1
552   productionID=$2
553   configFile="benchmark.config"
554   [[ -n "$3" ]] && configFile=$3
555   configFile=$(readlink -f $configFile)
556   [[ -n $4 ]] && runNumber=$4
557
558   #redirect all output to submit.log
559   echo "redirecting all output to ${PWD}/submit_${productionID//"/"/_}.log"
560   exec 7>&1
561   exec 1>submit_${productionID//"/"/_}.log 2>&1
562
563   umask 0002
564   echo $0" submit $*"
565   if [[ -z "$inputList" || -z "$productionID" ]]
566   then
567     echo
568     echo " Usage: $0 submit inputList productionID [configFile=benchmark.config]"
569     echo
570     exit
571   fi
572
573   date=`date +%Y-%m-%d_%H%M%S`
574
575   # check if config file is there
576   if [ ! -f $configFile ]; then
577     echo "ERROR! Config File '$configFile' not found" >&2
578     exit
579   else
580     echo "Using Config File: '$configFile'"
581   fi
582
583   # source the config file
584   # and print the configuration
585   source $configFile
586   [[ -f ${setupAliROOTenvInCurrentShell} && -z ${alirootEnv} ]] && source $setupAliROOTenvInCurrentShell
587
588   self=$(readlink -f "$0")
589   configPath=`dirname $self`
590   #exporting makes it available in the environment on the nodes - makes the summary output go there
591   export commonOutputPath=${baseOutputDirectory}/${productionID}
592
593   #[[ -z ${ALIROOT_RELEASE} ]] && ALIROOT_RELEASE=${ALICE_ROOT//"/"/"_"}
594   #ALIROOT_RELEASE_mod=${ALIROOT_RELEASE//"/"/"_"}
595   #ALIROOT_BASEDIR_mod=${ALIROOT_BASEDIR//"/"/"_"}
596   #productionID=${ALIROOT_BASEDIR_mod}_${ALIROOT_RELEASE_mod}/${productionID}
597
598   #convert to absolut pathnames
599   inputList=$(readlink -f "$inputList")
600   #make list of runs
601   if [[ -z $runNumber ]]; then
602     listOfRuns=($(while read x; do guessRunNumber $x; done < ${inputList} | sort | uniq))
603   else
604     listOfRuns=$runNumber
605   fi
606
607   setupAliROOTenvInCurrentShell=$(readlink -f "$setupAliROOTenvInCurrentShell")
608
609   echo ""
610   echo "### BEGIN CONFIGURATION ###"
611   echo ""
612   echo "GENERAL:"
613   echo ""
614   echo "    productionID:    $productionID"
615   echo "    batchCommand:    $batchCommand"
616   echo "    setupAliROOTenvInCurrentShell:      $setupAliROOTenvInCurrentShell"
617   echo "    ALICE_ROOT:      $ALICE_ROOT"
618   echo "    ALIROOT_RELEASE: $ALICE_RELEASE"
619   echo "    inputList:       $inputList"
620   echo "    configPath:      $configPath"
621   echo "    commonOutputPath:      $commonOutputPath"
622   echo "    defaultOCDB:     $defaultOCDB"
623   echo "      autoOCDB: $autoOCDB"
624   echo "    recoTriggerOptions:   $recoTriggerOptions"
625   echo "    runs:"
626   echo "      ${listOfRuns[*]}"
627   echo ""
628   echo "THE TRAIN WILL RUN:"
629
630   if [ $runCPass0reco -eq 1 ]; then
631     echo "    Pass0 - Recontruction"
632   fi
633
634   if [ $runCPass0MergeMakeOCDB -eq 1 ]; then
635     echo "    Pass0 - merging and OCDB export"
636   fi
637
638   if [ $runCPass1reco -eq 1 ]; then
639     echo "    Pass1 - Recontruction"
640   fi
641   if [ $runCPass1MergeMakeOCDB -eq 1 ]; then
642     echo "    Pass1 - merging and OCDB export"
643   fi
644
645   echo ""
646   echo "LIMITS:"
647   echo "    max. Events/Chunk:   $nEvents"
648   echo "    max. Number of Chunks per Run:     $nMaxChunks"
649   echo ""
650   echo "### END CONFIGURATION ###"
651   echo ""
652
653
654   # check if input file is there
655   if [ ! -f $inputList ]; then
656     echo "ERROR! Input List '$inputList' not found" >&2
657     exit
658   fi
659
660   # define jobid (for dependent jobs)
661   JOBID1=p0_${productionID//"/"/_}_${date}
662   JOBID1wait=w0_${productionID//"/"/_}_${date}
663   JOBID2=m0_${productionID//"/"/_}_${date}
664   JOBID2wait=wm0_${productionID//"/"/_}_${date}
665   JOBID3=op0_${productionID//"/"/_}_${date}
666   JOBID3wait=wop0_${productionID//"/"/_}_${date}
667   JOBID4=p1_${productionID//"/"/_}_${date}
668   JOBID4wait=w1_${productionID//"/"/_}_${date}
669   JOBID5=m1_${productionID//"/"/_}_${date}
670   JOBID5wait=wm1_${productionID//"/"/_}_${date}
671   JOBID6=s1_${productionID//"/"/_}_${date}
672   JOBID6wait=ws1_${productionID//"/"/_}_${date}
673   JOBID7=QA_${productionID//"/"/_}_${date}
674   LASTJOB=""
675
676   #for each run we submit one jobarray:
677   numberOfSubmittedCPass1MergingJobs=0
678   for runNumber in ${listOfRuns[*]}; do
679     [[ -z $runNumber ]] && continue
680     [[ ! ${runNumber} =~ ^[0-9]*[0-9]$ ]] && continue
681     oneInputFile=$(egrep -m1 "$runNumber\/" ${inputList})
682     currentDefaultOCDB=$defaultOCDB
683     [[ $autoOCDB -ne 0 ]] && currentDefaultOCDB=$(setYear $oneInputFile $defaultOCDB)
684     echo "submitting run $runNumber with OCDB $currentDefaultOCDB"
685
686     ################################################################################
687     ################################################################################
688     # run the CPass0 if requested
689
690     if [ $runCPass0reco -eq 1 ]; then
691
692       echo
693       echo "starting CPass0... for run $runNumber"
694       echo
695
696       # create directory and copy all files that are needed
697       targetDirectory="${commonOutputPath}/000${runNumber}/CPass0"
698       mkdir -p $targetDirectory
699       mkdir -p $targetDirectory/logs
700       
701       localInputList=$targetDirectory/${inputList##*/}
702       theScript="$targetDirectory/${self##*/}"
703       cp -f $self $theScript
704       chmod u+x $theScript
705
706       rm -f $localInputList
707       egrep "\/000$runNumber\/" $inputList >> $localInputList
708       cp -f $configFile $targetDirectory
709       [[ -f $configPath/runCPass0.sh ]] && cp -f $configPath/runCPass0.sh $targetDirectory && echo "## using local runCPass0.sh"
710       [[ -f $configPath/recCPass0.C ]] && cp -f $configPath/recCPass0.C $targetDirectory && echo "## using local recCPass0.C"
711       [[ -f $configPath/runCalibTrain.C ]] && cp -f $configPath/runCalibTrain.C $targetDirectory && echo "## using local runCalibTrain.C"
712       [[ -f $configPath/localOCDBaccessConfig.C ]] && cp -f $configPath/localOCDBaccessConfig.C $targetDirectory && echo "## using local localOCDBaccessConfig.C"
713
714       [[ -f $configPath/CPass0/runCPass0.sh ]] && cp -f $configPath/CPass0/runCPass0.sh $targetDirectory && echo "## using local runCPass0.sh"
715       [[ -f $configPath/CPass0/recCPass0.C ]] && cp -f $configPath/CPass0/recCPass0.C $targetDirectory && echo "## using local recCPass0.C"
716       [[ -f $configPath/CPass0/runCalibTrain.C ]] && cp -f $configPath/CPass0/runCalibTrain.C $targetDirectory && echo "## using local runCalibTrain.C"
717       [[ -f $configPath/CPass0/localOCDBaccessConfig.C ]] && cp -f $configPath/CPass0/localOCDBaccessConfig.C $targetDirectory && echo "## using local localOCDBaccessConfig.C"
718
719       echo "... files copied."
720       echo
721
722       # limit nFiles to nMaxChunks
723       nFiles=`wc -l < $localInputList`
724       [[ $nFiles -eq 0 ]] && echo "list contains ZERO files! exiting..." && exit 1
725       echo "raw files in list:    $nFiles"
726       if [[ $nMaxChunks -gt 0 && $nMaxChunks -le $nFiles ]]; then
727         nFiles=$nMaxChunks
728       fi
729       echo "raw files to process: $nFiles"
730       [[ -z "$percentProcessedFilesToContinue" ]] && percentProcessedFilesToContinue=100
731       if [[ $percentProcessedFilesToContinue -eq 100 ]]; then
732         nFilesToWaitFor=$nFiles
733       else
734         nFilesToWaitFor=$(( $nFiles-$nFiles/(100/(100-$percentProcessedFilesToContinue)) ))
735       fi
736       echo "requested success rate is $percentProcessedFilesToContinue%"
737       echo "merging will start after $nFilesToWaitFor jobs are done"
738
739       submit $JOBID1 1 $nFiles "" "$theScript" "CPass0 $targetDirectory $localInputList $nEvents $currentDefaultOCDB $configFile $runNumber"
740
741       ## submit a monitoring job that will run until a certain number of jobs are done with reconstruction
742       submit "$JOBID1wait" 1 1 "" "$theScript" "WaitForOutput ${commonOutputPath} 'cpass0.job*.run$runNumber.done' $nFilesToWaitFor $maxSecondsToWait '-maxdepth 1'"
743       LASTJOB=$JOBID1wait
744
745     fi #end running CPass0
746     ################################################################################
747
748
749     ################################################################################
750     # submit merging of CPass0, depends on the reconstruction
751
752     if [ $runCPass0MergeMakeOCDB -eq 1 ]; then
753
754       echo
755       echo "submit CPass0 merging for run $runNumber"
756       echo
757
758       targetDirectory="${commonOutputPath}/000${runNumber}/CPass0"
759       mkdir -p $targetDirectory
760
761       # copy the scripts
762       cp -f $self $targetDirectory
763       [[ -f $configPath/mergeMakeOCDB.sh ]] && cp -f $configPath/mergeMakeOCDB.sh $targetDirectory && echo "## using local mergeMakeOCDB.sh"
764       [[ -f $configPath/merge.C ]] && cp -f $configPath/merge.C $targetDirectory && echo "## using local merge.C"
765       [[ -f $configPath/mergeMakeOCDB.byComponent.sh ]] && cp -f $configPath/mergeMakeOCDB.byComponent.sh $targetDirectory && echo "## using local mergeMakeOCDB.byComponent.sh"
766       [[ -f $configPath/mergeByComponent.C ]] && cp -f $configPath/mergeByComponent.C $targetDirectory && echo "## using local mergeByComponent.C"
767       [[ -f $configPath/makeOCDB.C ]] && cp -f $configPath/makeOCDB.C $targetDirectory && echo "## using local makeOCDB.C"
768
769       theScript="$targetDirectory/${self##*/}"
770       chmod u+x $theScript
771
772       echo submit $JOBID2 1 1 "$LASTJOB" "$theScript" "MergeCPass0 $targetDirectory $currentDefaultOCDB $configFile $runNumber"
773       submit $JOBID2 1 1 "$LASTJOB" "$theScript" "MergeCPass0 $targetDirectory $currentDefaultOCDB $configFile $runNumber"
774       LASTJOB=$JOBID2
775
776       cd $configPath
777       echo
778     fi
779     # end of merging CPass0
780     ################################################################################
781
782     ################################################################################
783     ################################################################################
784     # run the CPass1 if requested
785
786     if [ $runCPass1reco -eq 1 ]; then
787
788       targetDirectory="${commonOutputPath}/000${runNumber}/CPass1"
789
790       # safety feature: if we are re-running for any reason we want to delete the previous output first.
791       [[ -d $targetDirectory ]] && rm -rf $targetDirectory/* && echo "removed old output at $targetDirectory/*"
792
793       ################################################################################
794       # for the CPass1, based on the OCDB entries produced, we need to create the script 
795       # to set the specific storages to the output of CPass0
796       # submit a job that will execute after merging/OCDB export that will do it.
797
798       mkdir -p $targetDirectory
799       mkdir -p $targetDirectory/logs
800       cp -f $self $targetDirectory
801       theScript="$targetDirectory/${self##*/}"
802
803       echo
804       echo submitting the OCDB specific storage config making script for run $runNumber
805       echo
806
807       [[ -f $configPath/localOCDBaccessConfig.C ]] && cp -f $configPath/localOCDBaccessConfig.C $targetDirectory && echo "## using local localOCDBaccessConfig.C"
808
809       submit $JOBID3 1 1 "$LASTJOB" "$theScript" "ConfOCDB ${commonOutputPath}/000${runNumber}/CPass0/OCDB ${targetDirectory} "
810       LASTJOB=$JOBID3
811       ################################################################################
812
813       echo
814       echo "starting CPass1... for run $runNumber"
815       echo
816
817       # create directory and copy all files that are needed
818       mkdir -p $targetDirectory
819       mkdir -p $targetDirectory/logs
820       
821       localInputList=$targetDirectory/${inputList##*/}
822       theScript="$targetDirectory/${self##*/}"
823       cp -f $self $theScript
824       chmod u+x $theScript
825
826       rm -f $localInputList
827       egrep "\/000$runNumber\/" $inputList >> $localInputList
828       cp -f $configFile $targetDirectory
829       [[ -f $configPath/runCPass1.sh ]] && cp -f $configPath/runCPass1.sh $targetDirectory && echo "## using local runCPass1.sh"
830       [[ -f $configPath/recCPass1.C ]] && cp -f $configPath/recCPass1.C $targetDirectory && echo "## using local recCPass1.C"
831       [[ -f $configPath/recCPass1_OuterDet.C ]] && cp -f $configPath/recCPass1_OuterDet.C $targetDirectory && echo "## using local recCPass1_OuterDet.C"
832       [[ -f $configPath/runCalibTrain.C ]] && cp -f $configPath/runCalibTrain.C $targetDirectory && echo "## using local runCalibTrain.C"
833       [[ -f $configPath/QAtrain.C ]] && cp -f $configPath/QAtrain.C $targetDirectory && echo "## using local QAtrain.C"
834       [[ -f $configPath/QAtrain_duo.C ]] && cp -f $configPath/QAtrain_duo.C $targetDirectory && echo "## using local QAtrain_duo.C"
835
836       [[ -f $configPath/CPass1/runCPass1.sh ]] && cp -f $configPath/CPass1/runCPass1.sh $targetDirectory && echo "## using local runCPass1.sh"
837       [[ -f $configPath/CPass1/recCPass1.C ]] && cp -f $configPath/CPass1/recCPass1.C $targetDirectory && echo "## using local recCPass1.C"
838       [[ -f $configPath/CPass1/recCPass1_OuterDet.C ]] && cp -f $configPath/CPass1/recCPass1_OuterDet.C $targetDirectory && echo "## using local recCPass1_OuterDet.C"
839       [[ -f $configPath/CPass1/runCalibTrain.C ]] && cp -f $configPath/CPass1/runCalibTrain.C $targetDirectory && echo "## using local runCalibTrain.C"
840       [[ -f $configPath/CPass1/QAtrain.C ]] && cp -f $configPath/CPass1/QAtrain.C $targetDirectory && echo "## using local QAtrain.C"
841       [[ -f $configPath/CPass1/QAtrain_duo.C ]] && cp -f $configPath/CPass1/QAtrain_duo.C $targetDirectory && echo "## using local QAtrain_duo.C"
842
843       echo "... files copied."
844       echo
845
846       # limit nFiles to nMaxChunks
847       nFiles=`wc -l < $localInputList`
848       [[ $nFiles -eq 0 ]] && echo "list contains ZERO files! exiting..." && exit 1
849       echo "raw files in list:    $nFiles"
850       if [[ $nMaxChunks -gt 0 && $nMaxChunks -le $nFiles ]]; then
851         nFiles=$nMaxChunks
852       fi
853       echo "raw files to process: $nFiles"
854       [[ -z "$percentProcessedFilesToContinue" ]] && percentProcessedFilesToContinue=100
855       if [[ $percentProcessedFilesToContinue -eq 100 ]]; then
856         nFilesToWaitFor=$nFiles
857       else
858         nFilesToWaitFor=$(( $nFiles-$nFiles/(100/(100-$percentProcessedFilesToContinue)) ))
859       fi
860       echo "requested success rate is $percentProcessedFilesToContinue%"
861       echo "merging will start after $nFilesToWaitFor jobs are done"
862
863       submit $JOBID4 1 $nFiles "$LASTJOB" "$theScript" "CPass1 $targetDirectory $localInputList $nEvents $currentDefaultOCDB $configFile $runNumber"
864
865       ################################################################################
866       ## submit a monitoring job that will run until a certain number of jobs are done with reconstruction
867       submit "$JOBID4wait" 1 1 "$LASTJOB" "$theScript" "WaitForOutput ${commonOutputPath} 'cpass1.job*.run${runNumber}.done' $nFilesToWaitFor $maxSecondsToWait '-maxdepth 1'"
868       LASTJOB=$JOBID4wait
869       ################################################################################
870
871       echo
872     fi #end running CPass1
873
874     ################################################################################
875     # submit merging of CPass1, depends on the reconstruction
876     if [ $runCPass1MergeMakeOCDB -eq 1 ]; then
877
878       echo
879       echo "submit CPass1 merging for run $runNumber"
880       echo
881
882       targetDirectory="${commonOutputPath}/000${runNumber}/CPass1"
883       mkdir -p $targetDirectory
884
885       # copy the scripts
886       cp -f $self $targetDirectory
887       [[ -f $configPath/mergeMakeOCDB.sh ]] && cp -f $configPath/mergeMakeOCDB.sh $targetDirectory && echo "## using local mergeMakeOCDB.sh"
888       [[ -f $configPath/merge.C ]] && cp -f $configPath/merge.C $targetDirectory && echo "## using local merge.C"
889       [[ -f $configPath/mergeMakeOCDB.byComponent.sh ]] && cp -f $configPath/mergeMakeOCDB.byComponent.sh $targetDirectory && echo "## using local mergeMakeOCDB.byComponent.sh"
890       [[ -f $configPath/mergeByComponent.C ]] && cp -f $configPath/mergeByComponent.C $targetDirectory && echo "## using local mergeByComponent.C"
891       [[ -f $configPath/makeOCDB.C ]] && cp -f $configPath/makeOCDB.C $targetDirectory && echo "## using local makeOCDB.C"
892
893       theScript="$targetDirectory/${self##*/}"
894       chmod u+x $theScript
895
896       echo submit "$JOBID5" 1 1 "$LASTJOB" "$theScript" "MergeCPass1 $targetDirectory $currentDefaultOCDB $configFile $runNumber"
897       submit "$JOBID5" 1 1 "$LASTJOB" "$theScript" "MergeCPass1 $targetDirectory $currentDefaultOCDB $configFile $runNumber"
898       ((numberOfSubmittedCPass1MergingJobs++))
899       LASTJOB=$JOBID5
900       echo
901     fi
902
903   done
904
905   ################################################################################
906   ################################################################################
907   [[ -z $runMakeSummary ]] && runMakeSummary=0
908   if [ $runMakeSummary -eq 1 ]; then
909     echo
910     echo "submit make a summary"
911     echo
912
913     targetDirectory="${commonOutputPath}"
914     mkdir -p $targetDirectory
915     mkdir -p $targetDirectory/logs
916     [[ ! -f $targetDirectory/${self##*/} ]] && cp -f $self $targetDirectory
917     theScript="$targetDirectory/${self##*/}"
918     submit "$JOBID6" 1 1 "$LASTJOB" "$theScript" "MakeSummary $targetDirectory $configFile"
919   fi
920   ################################################################################
921   
922   ################################################################################
923   ################################################################################
924   if [ $runMakeQAplots -eq 1 ]; then
925     echo
926     echo "submit make QA plots"
927     echo
928
929     ## submit a monitoring job that will wait for a specified number of files to appear somewhere
930     targetDirectory="${commonOutputPath}"
931     [[ ! -f $targetDirectory/${self##*/} ]] && cp -f $self $targetDirectory
932     theScript="$targetDirectory/${self##*/}"
933     echo submit "$JOBID5wait 1 1 $theScript WaitForOutput ${commonOutputPath} 'merge.cpass1.run*.done' $numberOfSubmittedCPass1MergingJobs $maxSecondsToWait '-maxdepth 1'"
934     submit "$JOBID5wait" 1 1 "" "$theScript" "WaitForOutput ${commonOutputPath} 'merge.cpass1.run*.done' $numberOfSubmittedCPass1MergingJobs $maxSecondsToWait '-maxdepth 1'"
935     LASTJOB=$JOBID5wait
936   
937     targetDirectory="${commonOutputPath}/QAplots/"
938     [[ -d $targetDirectory ]] && rm -rf $targetDirectory/*
939     mkdir -p $targetDirectory
940     mkdir -p $targetDirectory/logs
941     qaFilesDirectory="${commonOutputPath}"
942     [[ ! -f $targetDirectory/${self##*/} ]] && cp -f $self $targetDirectory
943     theScript="$targetDirectory/${self##*/}"
944
945     echo submit "$JOBID7" 1 1 "$LASTJOB" "$theScript" "CreateQAplots QAplots CPass1 $targetDirectory $qaFilesDirectory $qaPlotsScript $configFile"
946     submit "$JOBID7" 1 1 "$LASTJOB" "$theScript" "CreateQAplots QAplots CPass1 $targetDirectory $qaFilesDirectory $qaPlotsScript $configFile"
947     LASTJOB=$JOBID7
948   fi
949
950   #restore stdout
951   exec 1>&7 7>&-
952   echo "jobs submitted."
953 }
954
955 goMakeSummary()
956 {
957   configFile=$1
958   source $configFile
959   
960   # log filtering, script needs to take the base dir as argument
961   if [[ -x $logFilteringScript ]]; then
962     commonOutputPath=${baseOutputDirectory}/${productionID}
963     ${logFilteringScript} $commonOutputPath
964   fi
965
966   awk 'BEGIN {nFiles=0;} /^calibfile/ {nFiles++;} END {print     "cpass0 produced "nFiles" calib files";}' cpass0.job*done
967   awk 'BEGIN {nOK=0; nBAD=0;} /rec.*log OK/ {nOK++;} /rec.*log BAD/ {nBAD++;} END {print     "cpass0 reco:  OK: "nOK" BAD: "nBAD;}' cpass0.job*done
968   awk 'BEGIN {nOK=0; nBAD=0;} /calib.*log OK/ {nOK++;} /calib.*log BAD/ {nBAD++;} END {print "cpass0 calib: OK: "nOK" BAD: "nBAD;}' cpass0.job*done
969   
970   awk 'BEGIN {nOK=0; nBAD=0;} /merge.*log OK/ {nOK++;} /merge.*log BAD/ {nBAD++;} END {print "cpass0 merge: OK: "nOK" BAD: "nBAD;}' merge.cpass0*done
971   awk 'BEGIN {nOK=0; nBAD=0;} /ocdb.*log OK/ {nOK++;} /ocdb.*log BAD/ {nBAD++;} END {print   "cpass0 OCDB:  OK: "nOK" BAD: "nBAD;}' merge.cpass0*done
972   
973   awk 'BEGIN {nFiles=0;} /^calibfile/ {nFiles++;} END {print     "cpass1 produced "nFiles" calib files";}' cpass1.job*done
974   awk 'BEGIN {nOK=0; nBAD=0;} /rec.*log OK/ {nOK++;} /rec.*log BAD/ {nBAD++;} END {print     "cpass1 reco:  OK: "nOK" BAD: "nBAD;}' cpass1.job*done
975   awk 'BEGIN {nOK=0; nBAD=0;} /calib.*log OK/ {nOK++;} /calib.*log BAD/ {nBAD++;} END {print "cpass1 calib: OK: "nOK" BAD: "nBAD;}' cpass1.job*done
976
977   awk 'BEGIN {nOK=0; nBAD=0;} /merge.*log OK/ {nOK++;} /merge.*log BAD/ {nBAD++;} END {print "cpass1 merge: OK: "nOK" BAD: "nBAD;}' merge.cpass1*done
978   awk 'BEGIN {nOK=0; nBAD=0;} /ocdb.*log OK/ {nOK++;} /ocdb.*log BAD/ {nBAD++;} END {print   "cpass1 OCDB:  OK: "nOK" BAD: "nBAD;}' merge.cpass1*done
979   
980   #if set email the summary
981   [[ -n $mailSummaryTo ]] && cat $log | mail -s "benchmark $productionID done" $mailSummaryTo
982
983   return 0
984 }
985
986 goMakeflow()
987 {
988   #generate the makeflow file and run
989   inputFileList=$1
990   productionID=$2
991   configFile=$3
992   runNumber=$4
993
994   [[ -z ${configFile} ]] && configFile="benchmark.config"
995   [[ ! -f ${configFile} ]] && echo "no config file found (${configFile})" && return 1
996   source $configFile
997
998   source $configFile
999   goGenerateMakeflow "$@" > benchmark.makeflow
1000   makeflow ${makeflowOptions} benchmark.makeflow
1001 }
1002
1003 goGenerateMakeflow()
1004 {
1005   #generate the makeflow file
1006   inputFileList=$1
1007   productionID=$2
1008   configFile=$3
1009   runNumber=$4
1010
1011   [[ -z ${configFile} ]] && configFile="benchmark.config"
1012   [[ ! -f ${configFile} ]] && echo "no config file found (${configFile})" && return 1
1013   source $configFile
1014
1015   commonOutputPath=${baseOutputDirectory}/${productionID}
1016
1017   #these files will be made a dependency - will be copied to the working dir of the jobs
1018   declare -a copyFiles
1019   inputFiles=(
1020               "OCDB.root"
1021               "localOCDBaccessConfig.C"
1022   )
1023   for file in ${inputFiles[*]}; do
1024     [[ -f ${file} ]] && copyFiles+=("${file}")
1025   done
1026
1027   #create the makeflow file
1028   declare -a arr_cpass1_final
1029   declare -a arr_cpass1_QA_final
1030   listOfRuns=${runNumber}
1031   [[ -z ${runNumber} ]] && listOfRuns=($(while read x; do guessRunNumber $x; done < ${inputFileList} | sort | uniq))
1032   runindex=0
1033   for runNumber in ${listOfRuns[*]}; do
1034     [[ -z $runNumber ]] && continue
1035     [[ ! ${runNumber} =~ ^[0-9]*[0-9]$ ]] && continue
1036     jobindex=0
1037
1038     unset arr_cpass0_outputs
1039     unset arr_cpass1_outputs
1040     declare -a arr_cpass0_outputs
1041     declare -a arr_cpass1_outputs
1042     unset arr_cpass0_outputs
1043
1044     while read inputFile; do
1045       currentDefaultOCDB=${defaultOCDB}
1046       [[ ${autoOCDB} -ne 0 ]] && currentDefaultOCDB=$(setYear $inputFile $defaultOCDB)
1047
1048       #CPass0
1049       arr_cpass0_outputs[$jobindex]="cpass0.job${jobindex}.run${runNumber}.done"
1050       echo "${arr_cpass0_outputs[$jobindex]}: benchmark.sh ${configFile} ${copyFiles[@]}"
1051       echo " ${alirootEnv} ./benchmark.sh CPass0 ${commonOutputPath}/cpass0/000${runNumber} $inputFile $nEvents $currentDefaultOCDB $configFile $runNumber $jobindex"
1052       echo
1053
1054       #CPass1
1055       arr_cpass1_outputs[$jobindex]="cpass1.job${jobindex}.run${runNumber}.done"
1056       echo "${arr_cpass1_outputs[$jobindex]} : benchmark.sh ${configFile} cpass0.localOCDB.${runNumber}.tgz ${copyFiles[@]}"
1057       echo " ${alirootEnv} ./benchmark.sh CPass1 ${commonOutputPath}/cpass1/000${runNumber} $inputFile $nEvents $currentDefaultOCDB $configFile $runNumber $jobindex"
1058       echo
1059       ((jobindex++))
1060
1061     done< <(grep "/000$runNumber/" $inputFileList)
1062
1063     #CPass0 list of Calib files to merge
1064     echo "cpass0.calib.run${runNumber}.list: ${arr_cpass0_outputs[*]}"
1065     echo "  awk '/^calibfile / {print "'\$2'"}' ${arr_cpass0_outputs[*]} > cpass0.calib.run${runNumber}.list"
1066     echo
1067
1068     #CPass1 list of Calib/QA files to merge
1069     echo "cpass1.calib.run${runNumber}.list cpass1.QA.run${runNumber}.list: ${arr_cpass1_outputs[*]}"
1070     echo "  awk '/^calibfile / {print "'\$'"2}' ${arr_cpass1_outputs[*]} > cpass1.calib.run${runNumber}.list;  awk '/^qafile / {print "'\$'"2}' ${arr_cpass1_outputs[*]} > cpass1.QA.run${runNumber}.list"
1071     echo
1072
1073     #CPass0 merging
1074     arr_cpass0_final[$runindex]="merge.cpass0.run${runNumber}.done"
1075     echo "cpass0.localOCDB.${runNumber}.tgz ${arr_cpass0_final[$runindex]}: cpass0.calib.run${runNumber}.list benchmark.sh ${configFile} ${copyFiles[@]}"
1076     echo " ${alirootEnv} ./benchmark.sh MergeCPass0 ${commonOutputPath}/cpass0/000${runNumber} $currentDefaultOCDB ${configFile} $runNumber cpass0.run${runNumber}.list"
1077     echo
1078
1079     #CPass1 Calib/QA merging
1080     arr_cpass1_final[$runindex]="merge.cpass1.run${runNumber}.done"
1081     echo "${arr_cpass1_final[$runindex]}: cpass1.calib.run${runNumber}.list cpass1.QA.run${runNumber}.list benchmark.sh ${configFile} ${copyFiles[@]}"
1082     echo " ${alirootEnv} ./benchmark.sh MergeCPass1 ${commonOutputPath}/cpass1/000${runNumber} $currentDefaultOCDB ${configFile} $runNumber cpass1.calib.run${runNumber}.list cpass1.QA.run${runNumber}.list"
1083     echo
1084     ((runindex++))
1085   done
1086
1087   #CPass1 list of final Calib/QA files
1088   echo "cpass1.QA.list cpass1.calib.list: ${arr_cpass1_final[*]}"
1089   echo " awk '/^calibfile / {print "'\$'"2}' ${arr_cpass1_final[*]} > cpass1.calib.list; awk '/^qafile / {print "'\$'"2}' ${arr_cpass1_final[*]} > cpass1.QA.list"
1090   echo
1091
1092   #Summary
1093   echo "summary.log : ${arr_cpass0_outputs[*]} ${arr_cpass1_outputs[*]}  ${arr_cpass1_final[*]}  ${arr_cpass0_final[*]} benchmark.sh ${configFile}"
1094   echo " LOCAL ./benchmark.sh makeSummary ${configFile} |tee summary.log"
1095 }
1096
1097 goCreateQAplots()
1098 {
1099   umask 0002
1100   [[ $# -lt 5 ]] && echo "goCreateQAplots productionID pass outputDir qaFilesDirectory qaPlotScript" && exit 1
1101   productionID=$1
1102   pass=$2
1103   outputDir=$3
1104   qaFilesDirectory=$4
1105   qaPlotsScript=$5
1106   configFile=$6
1107
1108   source $configFile
1109   [[ -f ${setupAliROOTenvInCurrentShell} ]] && source $setupAliROOTenvInCurrentShell
1110
1111   runpath=${PWD}/rundir_cpass0_Merge_${runNumber}
1112   [[ -z $commonOutputPath ]] && commonOutputPath=$PWD
1113   [[ $reconstructInTemporaryDir -eq 1 && -n $TMPDIR ]] && runpath=$TMPDIR
1114   [[ $reconstructInTemporaryDir -eq 1 && -z $TMPDIR ]] && runpath=$(mktemp -d)
1115
1116   mkdir -p $runpath
1117   [[ ! -d $runpath ]] && echo "not able to make the runpath $runpath" && exit 1
1118   cd $runpath
1119
1120   [[ -z $logOutputDir ]] && logOutputDir=$runpath
1121   [[ -z $dontRedirectStdOutToLog ]] && exec 2>&1 > $logOutputDir/makeQAplots.log
1122   echo "$0 $*"
1123
1124   [[ -z "$qaPlotsScript" ]] && echo "qaPlotsScript not defined"&&exit 1
1125   
1126   mergedQAfileList=$outputDir/mergedQAfiles.list
1127   echo "MakeListOfQAresults $qaFilesDirectory QAresults.root | grep CPass1 > $mergedQAfileList"
1128   MakeListOfQAresults $qaFilesDirectory QAresults_merged.root | grep CPass1 |tee $mergedQAfileList
1129   echo $qaPlotsScript "$productionID" "cpass1" $mergedQAfileList $outputDir
1130   $qaPlotsScript "$productionID" "cpass1" $mergedQAfileList $outputDir
1131
1132   mkdir -p $outputDir
1133   [[ ! -d $outputDir ]] && echo "cannot make the output dir $outputDir" && exit 1
1134   mv -f $runpath/* $outputDir
1135   rm -rf $runpath
1136 }
1137
1138 goWaitForOutput()
1139 {
1140   umask 0002
1141   [[ $# -lt 3 ]] && echo "goWaitForOutput() wrong number of arguments, exiting.." && exit 1
1142   echo searchPath=$1
1143   echo fileName=$2
1144   echo numberOfFiles=$3
1145   echo maxSecondsToWait=$4
1146   searchPath=$1
1147   fileName=$2
1148   numberOfFiles=$3
1149   maxSecondsToWait=$4
1150   extraFindOptions=$5
1151   echo "command to be executed: find $searchPath -name "$fileName" ${extraFindOptions}"
1152   [[ -z "$maxSecondsToWait" ]] && maxSecondsToWait=$(( 3600*12 ))
1153   while sleep 60; do
1154     n=$(find $searchPath -name "$fileName" ${extraFindOptions}| wc -l)
1155     [[ $n -gt 0 ]] && echo "found $n X $fileName"
1156     [[ $n -ge $numberOfFiles ]] && break
1157     [[ $SECONDS -gt $maxSecondsToWait ]] && break
1158   done
1159   echo "DONE! exiting..."
1160 }
1161
1162 submit()
1163 {
1164   umask 0002
1165   [[ $# -ne 6 ]] && echo "6 args needed, you supplied $#" && exit 1
1166   JobID=$1
1167   startID=$2
1168   endID=$3
1169   waitForJOBID=$4
1170   command=$5
1171   commandArgs=$6
1172
1173   newFarm=$(which qsub|grep "^/usr/bin/qsub")
1174   
1175   batchSystem="SGE"
1176
1177   if [[ -z "$newFarm" ]]
1178   then
1179     #old LSF
1180     # submit it (as job array)
1181     nFiles=$(( $endID-$startID+1 ))
1182     while [ $startID -le $nFiles  ] ; do
1183       if [ `expr $nFiles - $startID` -gt 999 ] ; then 
1184         endID=`expr $startID + 999`
1185       else
1186         endID=$nFiles
1187       fi      
1188       if [[ -z "$waitForJOBID" ]]; then
1189         echo $batchCommand -J "$JobID[$startID-$endID]" -e "$targetDirectory/logs/job_%I.err" -o "$targetDirectory/logs/job_%I.out" "$command"     
1190         $batchCommand -J "$JobID[$startID-$endID]" -e "$targetDirectory/logs/job_%I.err" -o "$targetDirectory/logs/job_%I.out" "$command"     
1191       else
1192         echo $batchCommand -J "$JobID[$startID-$endID]" -w "ended($waitForJOBID)" -e "$targetDirectory/logs/job_%I.err" -o "$targetDirectory/logs/job_%I.out" "$command"     
1193         $batchCommand -J "$JobID[$startID-$endID]" -w "ended($waitForJOBID)" -e "$targetDirectory/logs/job_%I.err" -o "$targetDirectory/logs/job_%I.out" "$command"     
1194       fi
1195       startID=`expr $endID + 1`
1196     done
1197   else 
1198     #new SGE farm
1199     if [[ -z "$waitForJOBID" ]]; then
1200       echo $batchCommand -wd ${targetDirectory} -b y -V -N "$JobID" -t "$startID-$endID" -e "$targetDirectory/logs/" -o "$targetDirectory/logs/" "$command" $commandArgs
1201       $batchCommand -wd ${targetDirectory} -b y -V -N "$JobID" -t "$startID-$endID" -e "$targetDirectory/logs/" -o "$targetDirectory/logs/" "$command" $commandArgs
1202     else
1203       echo $batchCommand -wd ${targetDirectory} -b y -V -N "$JobID" -t "$startID-$endID" -hold_jid "$waitForJOBID" -e "$targetDirectory/logs/" -o "$targetDirectory/logs/" "$command" $commandArgs
1204       $batchCommand -wd ${targetDirectory} -b y -V -N "$JobID" -t "$startID-$endID" -hold_jid "$waitForJOBID" -e "$targetDirectory/logs/" -o "$targetDirectory/logs/" "$command" $commandArgs
1205     fi
1206   fi
1207 }
1208
1209 goTest()
1210 {
1211   umask 0002
1212   exec 2>&1
1213   exec > >(tee test.log)
1214   echo "$@"
1215   echo something
1216 }
1217
1218 alirootInfo()
1219 {
1220   (
1221   umask 0002
1222   # save aliroot svn info
1223   [[ -z "$ALICE_ROOT" ]] && exit 1
1224   prevdir=$PWD
1225   cd $ALICE_ROOT
1226   echo "\$ALICE_ROOT=$ALICE_ROOT"
1227   echo
1228   svn info 2>/dev/null
1229   echo ""
1230   echo ""
1231   svn diff 2>/dev/null
1232   cd $prevdir
1233   )
1234 }
1235
1236 MakeListOfQAresults()
1237 {
1238   (
1239   umask 0002
1240   if [[ $# -eq 0 ]]; then
1241     echo "make an input file list for the qa script"
1242     echo "Usage: $0 path filename"
1243     return 0
1244   fi
1245
1246   path=$1
1247   fileName=$2
1248   
1249   while read entry; do
1250     runNumber=$(guessRunNumber $entry)
1251     echo "$runNumber 0 1 10 $entry"
1252   done < <(find $path -name $fileName)
1253   )
1254 }
1255
1256 setYear()
1257 {
1258   #set the year
1259   #  $1 - year to be set
1260   #  $2 - where to set the year
1261   year1=$(guessYear $1)
1262   year2=$(guessYear $2)
1263   local path=$2
1264   [[ $year1 -ne $year2 && -n $year2 ]] && path=${2/\/$year2\//\/$year1\/}
1265   echo $path
1266 }
1267
1268 guessPeriod()
1269 {
1270   #guess the period from the path, pick the rightmost one
1271   local IFS="/"
1272   declare -a path=( $1 )
1273   local dirDepth=${#path[*]}
1274   for ((x=${dirDepth}-1;x>=0;x--)); do
1275     local field=${path[${x}]}
1276     [[ ${field} =~ ^LHC[0-9][0-9][a-z]$ ]] && period=${field#000} && break
1277   done
1278   echo $period
1279 }
1280
1281 guessYear()
1282 {
1283   #guess the year from the path, pick the rightmost one
1284   local IFS="/"
1285   declare -a path=( $1 )
1286   local dirDepth=${#path[*]}
1287   for ((x=${dirDepth}-1;x>=0;x--)); do
1288     local field=${path[${x}]}
1289     [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field#000} && break
1290   done
1291   echo $year
1292 }
1293
1294 guessRunNumber()
1295 {
1296   #guess the run number from the path, pick the rightmost one
1297   local IFS="/"
1298   declare -a path=( $1 )
1299   local dirDepth=${#path[*]}
1300   for ((x=${dirDepth}-1;x>=0;x--)); do
1301     local field=${path[${x}]}
1302     [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000} && break
1303   done
1304   echo $runNumber
1305 }
1306
1307 summarizeLogs()
1308 {
1309   #print a summary of logs
1310   logFiles=(
1311             "*.log"
1312   )
1313
1314   errorConditions=(
1315                     "There was a crash"
1316                     "floating"
1317                     "error while loading shared libraries"
1318                     "std::bad_alloc"
1319                     "s_err_syswatch_"
1320                     "Thread [0-9]* (Thread"
1321   )
1322   logstatus=0
1323   for log in ${logFiles[*]}; do
1324     finallog=${outputDir%/}/${log}
1325     [[ ! -f $log ]] && continue
1326     errorSummary=""
1327     for ((i=0; i<${#errorConditions[@]};i++)); do
1328       local tmp=$(grep -m1 -e "${errorConditions[$i]}" $log)
1329       [[ -n $tmp ]] && tmp+=" : "
1330       errorSummary+=$tmp
1331     done
1332     if [[ -z $errorSummary ]]; then 
1333       #in pretend mode randomly report an error in rec.log some cases
1334       if [[ -n $pretend && "$log" == "rec.log" ]]; then
1335         [[ $(( $RANDOM%2 )) -ge 1 ]] && echo "$finallog BAD random error" || echo "$finallog OK"
1336       else
1337         echo "$finallog OK"
1338       fi
1339     else 
1340       local logstatus=1
1341       echo "$finallog BAD $errorSummary"
1342     fi
1343   done
1344   return $logstatus
1345 }
1346
1347 spitOutLocalOCDBaccessConfig()
1348 {
1349   umask 0002
1350   find $1 -name "*root" | \
1351   while read line
1352   do 
1353     local tmp=${line#$1}
1354     echo ${tmp%/*} | \
1355     awk -v ocdb=$1 '{print "  man->SetSpecificStorage(\""$1"\",\"local://"ocdb"\");"}'
1356   done
1357 }
1358
1359 goConfigureOCDBforCPass1()
1360 {
1361   umask 0002
1362   # make a script that sets the specific storages form all the root files produced by CPass0
1363   # in this case the second argument is taken to be the path to the produced OCDB for specific storage
1364   local localOCDBpathCPass0=$1
1365   local outputDir=$2
1366   [[ -d $outputDir ]] && cd $outputDir
1367
1368   if [[ -f $localOCDBpathCPass0 && $localOCDBpathCPass0 =~ \.tgz$ ]]; then
1369     tar xzf $localOCDBpathCPass0
1370     local localOCDBpathCPass0="./OCDB"
1371   fi
1372
1373   echo
1374   echo creating the specific storage script
1375   echo   localOCDBaccessConfig.C
1376   echo   based on OCDB: $fileName
1377   echo
1378
1379   local tempLocalOCDB=""
1380   if [[ -f localOCDBaccessConfig.C ]]; then
1381     tempLocalOCDB=$(mktemp)
1382     echo "egrep "SetSpecificStorage" localOCDBaccessConfig.C > $tempLocalOCDB"
1383     egrep "SetSpecificStorage" localOCDBaccessConfig.C > $tempLocalOCDB
1384   fi
1385
1386   echo "localOCDBaccessConfig()"                               >  localOCDBaccessConfig.C
1387   echo "{"                                                     >> localOCDBaccessConfig.C
1388   echo "  AliCDBManager* man = AliCDBManager::Instance();"     >> localOCDBaccessConfig.C
1389   spitOutLocalOCDBaccessConfig $localOCDBpathCPass0|sort|uniq  >> localOCDBaccessConfig.C
1390   [[ -f "$tempLocalOCDB" ]] && cat $tempLocalOCDB              >> localOCDBaccessConfig.C
1391   echo "}"                                                     >> localOCDBaccessConfig.C
1392
1393   [[ -f "$tempLocalOCDB" ]] && rm -f $tempLocalOCDB
1394
1395   if ! grep SetSpecificStorage localOCDBaccessConfig.C; then 
1396     echo
1397     echo "!!!!!!! CPass0 produced no OCDB entries"
1398     return 1
1399   fi
1400 }
1401
1402 main "$@"