3 # This script runs the Forward QA for the specified production number
5 # The scripts downloads and runs the single run QA in parallel
8 # --- Some aux files -------------------------------------------------
9 style=$ALICE_ROOT/PWGLF/FORWARD/analysis2/qa/style.css
10 favicon=$ALICE_ROOT/PWGLF/FORWARD/analysis2/qa/fmd_favicon.png
11 logo=$ALICE_ROOT/PWGLF/FORWARD/analysis2/qa/fmd_logo.png
13 # --- Help output ----------------------------------------------
17 Usage: $0 [OPTIONS] -j [JOBID]
18 $0 [OPTIONS] -p PRODUCTION -P PASS
22 -j,--jobid NUMBER The master job id of the production [$jobid]
23 -v,--verbose Increase verbosity [$verb]
24 -m,--max-files NUMBER Max number of files to get [$maxf]
25 -M,--max-jobs NUMBER Max number of consequtive jobs [$maxjobs]
26 -t,--top DIRECTORY Output directory [$top]
27 -R,--also-results Also get QAresults.root for each run
28 -Q,--qa-number NUMBER Custom QA id [$qanumber]
29 -p,--production IDENTIFIER Production identifier [$prodfull]
30 -P,--pass IDENTIFIER Pass identifier [$passfull]
31 -l,--log-file Log file output [$redir]
32 -b,--barrel MODE Fetch barrel data [$barrel]
33 -f,--force Force re-run analysis [$force]
35 Note the option -j and the options -p and -P are mutually exclusive,
36 The option -Q is only used if the options -p and -P are given.
37 Production identifiers are of the form LHC11h, LHC11h3, or LHC11h_2.
38 Pass identifers are of the form pass2, pass1_HLT, or cpass1. If barrel mode
39 is >0, then do not assume ESD directory. If mode>1, then get
40 trending_barrel.root and QAresults_barrel.root
44 # --- Check AliEn token ----------------------------------------------
48 genv_file=/tmp/gclient_env_${uid}
50 if test ! -f ${genv_file} ; then
51 echo "No such file: ${genv_file}, please do alien-token-init" \
56 alien-token-info | grep -q "Token is still valid"
57 if test $? -ne 0 ; then
58 echo "Token not valid, please re-new" > /dev/stderr
63 # --- Diagnostics output ---------------------------------------------
67 if test $1 -gt $verb ; then return ; fi
72 # --- Handling of exit -----------------------------------------------
76 if test "x$lock" = "x" ; then return ; fi
81 # --- Handling of errors ---------------------------------------------
97 # --- Check the lock -------------------------------------------------
103 if test -f $lock ; then
104 echo "Another QA process is already running:" > /dev/stderr
105 echo "Content of ${lock}:" > /dev/stderr
106 cat $lock > /dev/stderr
118 # --- Parse production information -----------------------------------
121 prodyear=`echo $prodfull | sed 's/LHC\(..\).*/\1/'`
122 prodletter=`echo $prodfull | sed "s/LHC${prodyear}\(.\).*/\1/"`
123 prodpost=`echo $prodfull | sed "s/LHC${prodyear}${prodletter}//"`
128 passno=`echo $passfull | sed 's/.*pass\([0-9]*\).*/\1/'`
129 passpost=`echo $passfull | sed -n "s/.*pass${passno}_//p"`
130 passpre=`echo $passfull | sed -n "s/pass.*//p"`
133 # --- Extract parts from the found path ------------------------------
149 mess 1 "Parsing information from job $@"
152 local lrunn=$1 ; shift
153 local ltype=$1 ; shift
158 mess 10 "prodfull=$prodfull"
159 mess 10 "lrunn=$lrunn"
160 mess 10 "ltype=$ltype"
161 mess 10 "passfull=$passfull"
162 mess 10 "remainder=$remainder"
164 if test "x$passfull" = "x" ; then
170 *) remainder=$passfull
178 xQA*) qanumber=`echo $remainder | sed 's/QA//'` ;;
183 # --- Get the index for information ----------------------------------
185 jobu="http://alimonitor.cern.ch/prod/jobs.jsp?t="
189 mess 1 "Getting the job information"
190 wget -q ${jobu}${jobid} -O job.html
193 p=`grep "/catalogue/index.jsp?path" job.html | head -n $lskip | tail -n 1 | sed -e 's,.*/alice/\(data\|sim\)/\([^<]*\)<.*,\2,' | tr '/' ' '`
198 # --- Append path element --------------------------------------------
203 if test "x$tmp" != "x" ; then tmp="${tmp}/" ; fi
207 # --- Get a list of files to get -------------------------------------
215 mess 3 "Getting file list"
219 if test ${barrel} -gt 0 ; then
222 if test ${barrel} -gt 1 ; then
223 file=trending_barrel.root
224 other=QAresults_barrel.root
229 *) mess 3 "Assuming simulation output"
236 if echo "$passno" | grep -q -E '^[0-9]*[.]?[0-9]*$' ; then
237 if test "x$passfull" != "x" && test $passno -gt 0 ; then
245 local post=${passpost}
249 *) post="_${post}" ;;
252 path=/alice/${datd}/${year}/${prodfull}/
253 local search="${esdd}${passpre}${paid}${post}"
255 if test $qanumber -gt 0 ; then
256 qapost=`printf "QA%02d" $qanumber`
257 search=`append_to_path "$search" $qapost`
260 search=`append_to_path "$search" $file`
266 mess 1 "Getting list of files from AliEn - can take minutes - be patient"
267 mess 2 "alien_find ${path} ${search}"
268 files=`alien_find ${path} ${search} | grep -v "\(files found\|AND THE\)" 2>> ${redir}`
272 mess 1 -n "Total of $numf files ... "
273 if test $maxf -lt 0 ; then
276 mess 1 "using $maxf first of these"
280 # --- Change permissions on files ------------------------------------
283 if test ! -f $1 ; then return ; fi
288 # --- Check if a file is OK ------------------------------------------
292 if test $docheck -lt 1 ; then return 0; fi
293 root -l -b <<EOF >> ${redir} 2>&1
294 .L $ALICE_ROOT/PWGLF/FORWARD/analysis2/qa/CheckQAFile.C
299 mess 2 "Check of $1 -> $ret"
304 # --- Analyse a file -------------------------------------------------
307 local dir=`dirname $1`
308 local inp=`basename $1`
309 local out=`echo $inp | sed 's/trending_/tree_/'`
311 mess 2 -n "Analysing $inp -> $out ... "
313 if test -f $dir/$out ; then
314 if test $force -lt 1 ; then
324 RunFileQA("$inp", "$out", $prodyear, "$prodletter");
334 # --- Download a single file -----------------------------------------
338 local source=$1 ; shift
339 local store=$1 ; shift
341 local o=${store}/`basename $file .root`_${r}.root
343 mess 2 -n "$source -> $o ... "
344 if test -f $o && test $force -lt 2; then
349 mess 2 -n "copying ... "
350 alien_cp alien:${source} file:${o} >> ${redir} 2>&1
354 if test ! -f $o ; then return 1 ; fi
356 if test $also_results -gt 0 ; then
357 local s=`dirname ${source}`/${other}
358 local q=${store}/`basename $other .root`_${r}.root
360 mess 2 -n "$s -> $q ... "
361 if test -f $q && test $force -lt 2 ; then
365 mess 2 -n "copying ... "
366 alien_cp alien:${s} file:${q} >> ${redir} 2>&1
377 1|3|4|5|6) return 2 ;;
385 # --- Submit run analysis to background ------------------------------
394 mess 5 "Submitting $maxjobs jobs from $sta/$maxf"
396 let cur=$sta+$counter
398 local b=`echo $i | sed -e "s,${path},,"`
399 local r=`echo $b | sed -e "s,/.*,,"`
401 printf "%3d/%3d: %s\n" $cur $max $r
404 let counter=$counter+1
406 analyse_run $i $out $r &
407 j=`jobs %% | sed -e 's/^[^0-9]*//' -e 's/[^0-9]*$//'`
408 joblist="$joblist $j"
412 mess 5 "will wait for jobs $joblist"
413 for i in $joblist ; do
414 mess 5 "waiting for $i of $joblist"
416 mess 5 "Analysing ${runs[$counter]} returned $?"
417 let counter=$counter+1
421 # --- Analyse each run in turn ---------------------------------------
422 maxjobs=`grep "processor" /proc/cpuinfo | wc -l`
432 while test $# -gt 0 ; do
433 if test $counter -ge $max ; then
440 let counter=$counter+1
442 if test $queued -eq 1 ; then
446 if test $queued -ge $maxjobs ; then
447 mess 1 "Submitting $queued jobs from $start/$max"
448 submit_runs $out $start $max $list
453 if test $queued -gt 0 ; then
454 mess 1 "Submitting $queued jobs from $start/$max"
455 submit_runs $out $start $max $list
459 # --- Copy style -----------------------------------------------------
463 if test ! -f $file ; then return ; fi
464 base=`basename $file`
471 copy_aliroot_file $style
474 # --- Run the final trending -----------------------------------------
479 mess 1 -n "Analysing $dir ... "
487 RunFinalQA(".", $prodyear, "$prodletter");
491 # mess 3 -n "root -l -b -q ${scr}.C "
492 # root -l -b -q ${scr}.C > /dev/null 2>&1
498 local idx=`ls trend_*_*.html 2> /dev/null`
500 mess 1 "Making index.html point to $i"
501 sed -e 's,index.html,../index.html,' \
502 -e "s,!--JOBID--,a target='_blank' href='${jobu}${jobid}'>Job</a," \
507 if test ! -f index.html ; then
508 echo "No index file found"
512 fix_perm . > /dev/null 2>&1
516 copy_aliroot_file $favicon
517 copy_aliroot_file $logo
522 # --- Make index file ------------------------------------------------
526 local title=$1 ; shift
527 local desc=$1 ; shift
528 mess 1 "Making index in $dir ($title)"
535 cat <<EOF > index.html
539 <title>$title</title>
540 <link rel='stylesheet' href='style.css'>
541 <link rel='shortcut icon' href='fmd_favicon.png' type='image/x-png'>
544 <h1><img style='width: 200px;' src='fmd_logo.png'> $title</h1>
546 if test ! "x$desc" = "x" ; then
547 echo "<p>$desc</p>" >> index.html
549 echo " <ul>" >> index.html
551 if test ! -d $i ; then continue ; fi
552 echo " <li><a href='$i'>$i</a></li>" >> index.html
554 echo " </ul>" >> index.html
555 if test "x$desc" = "x" ; then
556 echo " <div class='back'><a href='../'>Back</a></div>" \
559 cat <<EOF >> index.html
560 <div class='change'>Last update: $date</div>
565 copy_aliroot_file $favicon
566 copy_aliroot_file $logo
568 fix_perm . > /dev/null 2>&1
573 # --- Pass command line options --------------------------------------
577 while test $# -gt 0 ; do
579 -h|--help) usage ; exit 0 ;;
580 -v|--verbose) let verb=$verb+1 ;;
581 -j|--jobid) jobid=$2 ; shift ;;
582 -m|--max-files) maxf=$2 ; shift ;;
583 -M|--max-jobs) maxjobs=$2 ; shift ;;
584 -t|--top) top=$2 ; shift ;;
585 -R|--also-results) also_results=1 ;;
586 -Q|--qa-number) qanumber=$2 ; shift ;;
587 -l|--log-file) redir= ;;
588 -b|--barrel) barrel=$2 ; shift ;;
589 -f|--force) let force=$force+1 ;;
591 prodfull=$2; shift; parse_prod ; year=20${prodyear} ;;
593 passfull=$2; shift; parse_pass ;;
594 *) echo "$0: Unknown argument: $1" > /dev/stderr ; exit 1 ;;
598 # --- Initial setup --------------------------------------------------
599 # First, check we have a valid AliEn token, then retrieve the job
600 # information to parse out the location of the files we need, and
601 # finally make our output directory and check the lock
604 if test ! "x$jobid" = x ; then
605 if test ! "x$prodfull" = "x" || test ! "x$passfull" = "x" ; then
606 cat <<EOF > /dev/stderr
607 Option -j ${jobid} and options -p and -P are mutually exclusive
613 if test "x$prodfull" = "x" || test "x$passfull" = "x" ; then
614 cat<<EOF > /dev/stderr
615 When specifying prodcution and/or pass both options -p and -P _must_
619 elif test ! "x$jobid" = "x" ; then
620 cat <<EOF > /dev/stderr
621 Option -j and options -p ${prodfull} and -P ${passfull} are mutually exclusive
627 proddir=LHC${prodyear}${prodletter}
629 if test ! "x$passno" = "x" ; then
630 if test "x${passpre}" = "xv" ; then
631 store=${store}/${passpre}pass${passno}
633 store=${store}/pass${passno}
635 elif test ! "x$prodpost" = "x" ; then
636 proddir=${proddir}${prodpost}
639 if test ! "x$qanumber" = "x" && test $qanumber -gt 0 ; then
640 store=${store}_QA${qanumber}
642 mkdir -p ${top}/$store
643 fix_perm ${top}/${proddir}
644 fix_perm ${top}/$store
646 if test "x$redir" = "x" ; then
647 redir=${top}/$store/qa.log
652 check_lock ${top}/$store
654 # --- Some friendly information --------------------------------------
657 Production: $prodfull
667 Output directory: ${store}
672 # --- Do a search to find our files ----------------------------------
675 if test $maxf -gt 0 && test $maxf -lt $numf ; then
679 # --- Copy scripts to target and compile -----------------------------
680 for i in QABase.h QAPlotter.C QARing.h QAStructs.h QATrender.C \
681 RunFileQA.C RunFinalQA.C ; do
682 cp $ALICE_ROOT/PWGLF/FORWARD/analysis2/qa/$i ${store}/${i}
683 rm -f ${store}/`echo $i | tr '.' '_'`.{so,d}
685 mess 1 "Compiling QATrender.C"
686 (cd $store && root -l -b <<EOF
687 gROOT->LoadMacro("QABase.h++g");
688 gROOT->LoadMacro("QATrender.C++g");
692 mess 1 "Compiling QAPlotter.C"
693 (cd $store && root -l -b <<EOF
694 gROOT->LoadMacro("QABase.h++g");
695 gROOT->LoadMacro("QAPlotter.C++g");
701 # --- Now get and analyse each run -----------------------------------
702 analyse_runs ${top}/$store $numf $files
704 # --- Now analyse all runs -------------------------------------------
705 make_trend ${top}/$store
707 # --- Make index files -----------------------------------------------
708 make_index ${top}/${proddir} ${proddir}
709 make_index ${top} "QA for the FMD" \
710 "For more information see <a href='https://twiki.cern.ch/twiki/bin/viewauth/ALICE/FMDQA'>TWiki pages</a>."