3 # This script runs the Forwardqq QA for the specified production number
5 # The scripts downloads and runs the single run QA in parallel
8 # --- Some aux files -------------------------------------------------
9 if test "X$QA_FWD" = "X" ; then
10 QA_FWD=$ALICE_ROOT/PWGLF/FORWARD/analysis2/qa
12 style=${QA_FWD}/style.css
13 favicon=${QA_FWD}/fmd_favicon.png
14 logo=${QA_FWD}/fmd_logo.png
15 script=${QA_FWD}/script.js
16 topmk=${QA_FWD}/makeIndex.sh
18 # --- Check AliEn token ----------------------------------------------
22 genv_file=/tmp/gclient_env_${uid}
24 if test ! -f ${genv_file} ; then
25 echo "No such file: ${genv_file}, please do alien-token-init" \
30 alien-token-info | grep -q "Token is still valid"
31 if test $? -ne 0 ; then
32 echo "Token not valid, please re-new" > /dev/stderr
37 # --- Diagnostics output ---------------------------------------------
43 if test $lvl -gt $verb; then return ; fi
47 echo -e ${opt} "\e[${col}m$*\e[0m"
48 # echo -e ${opt} "\e[${col}m$*\e[0m"
57 echo -e "\e[1mError: \e[91m$*\e[0m" > /dev/stderr
61 echo -e "\e[1mWarning: \e[93m$*\e[0m" > /dev/stderr
72 # --- Handling of exit -----------------------------------------------
76 if test "x$lock" = "x" ; then return ; fi
77 if test "x$store" != "x" && test "x${top}" != "x" ; then
78 chmod -R g+rwX ${top}/${proddir} >> ${redir} 2>&1
79 chmod -R g+rwX ${top}/$store >> ${redir} 2>&1
85 # --- Handling of errors ---------------------------------------------
101 # --- Check the lock -------------------------------------------------
107 if test -f $lock ; then
108 err "Another QA process is already running:"
109 err "Content of ${lock}:"
110 cat $lock > /dev/stderr
122 # --- Parse production information -----------------------------------
125 prodyear=`echo $prodfull | sed 's/LHC\(..\).*/\1/'`
126 prodletter=`echo $prodfull | sed "s/LHC${prodyear}\(.\).*/\1/"`
127 prodpost=`echo $prodfull | sed "s/LHC${prodyear}${prodletter}//"`
132 passno=`echo $passfull | sed 's/.*pass\([0-9]*\).*/\1/'`
133 passpost=`echo $passfull | sed -n "s/.*pass${passno}_//p"`
134 passpre=`echo $passfull | sed -n "s/pass.*//p"`
137 # --- Extract parts from the found path ------------------------------
152 # --- Append path element --------------------------------------------
157 if test "x$tmp" != "x" ; then tmp="${tmp}/" ; fi
161 # --- Get a list of files to get -------------------------------------
174 mess 3 "Getting file list"
178 if test ${barrel} -gt 0 ; then
181 if test ${barrel} -gt 1 ; then
182 file=trending_barrel.root
183 other=QAresults_barrel.root
185 if test $mc -gt 0 ; then
191 local post=${passpost}
195 *) post="_${post}" ;;
199 if test "x${passpre}pass${passno}${post}" != "x$passfull" ; then
203 elif echo "$passno" | grep -q -E '^[0-9]*[.]?[0-9]*$' ; then
204 if test "x$passfull" != "x" && test $passno -gt 0 ; then
213 if test $mc -gt 0 ; then passid="passMC" ; fi
216 if test "x$path" = "x" ; then
217 # Assume official productions
218 path=/alice/${datd}/${year}/${prodfull}/
219 search="${esdd}${passpre}${paid}${post}"
224 if test $qanumber -gt 0 ; then
225 qapost=`printf "QA%02d" $qanumber`
226 search=`append_to_path "$search" $qapost`
229 search=`append_to_path "$search" $file`
235 if test $from_local -lt 1 ; then
237 mess 1 "Get list of files from AliEn - can take minutes - be patient"
238 mess 2 "alien_find ${path} ${search}"
239 files=`alien_find ${path} ${search} | \
240 grep -v "\(files found\|AND THE\)" 2>> ${redir}`
242 files=`ls ${top}/${store}/*/input.root | \
243 sed 's,${top}/${store}/,,g'`
248 mess 1 -n "Total of $numf files ... "
250 if test $maxf -lt 0 ; then
253 mess 1 "using $maxf first of these"
259 # --- Change permissions on files ------------------------------------
264 if test -d $tgt ; then opt="-R" ; fi
265 chmod ${opt} g+rwX $tgt >> /dev/null 2>&1
266 chmod ${opt} o+rX $tgt >> /dev/null 2>&1
269 # --- Check if a file is OK ------------------------------------------
273 if test $docheck -lt 1 ; then return 0; fi
274 root -l -b <<EOF >> ${redir} 2>&1
275 .L ${QA_FWD}/CheckQAFile.C
276 CheckQAFile("$1","QA");
280 mess 2 "Check of $1 -> $ret"
285 # --- Analyse a file -------------------------------------------------
288 local dir=`dirname $1`
289 local inp=`basename $1`
291 local out=trending.root
292 # `echo $inp | sed 's/trending_/tree_/'`
294 mess 2 -n "Analysing $inp -> $out ... "
296 if test -f $dir/$out ; then
297 if test $force -lt 1 ; then
305 mess 3 "runQA.sh '$inp' '$type' '$prodyear' '$prodfull' '$passid' '$r'"
307 for i in QABase QAPlotter QARing QAStructs QATrender ; do
312 "$inp" "$type" $prodyear "$prodfull" "$passid" "$r" > runQA.log 2>&1
314 if test ! -f $dir/trending.root ; then ret=1 ; fi
316 if test $ret -ne 0 ; then
317 err "Failed to analyse $1"
322 # --- Download a single file -----------------------------------------
326 local source=$1 ; shift
327 local store=$1 ; shift
328 local r=`echo $1 | sed 's/^0*//'` ; shift
329 local rr=`printf %09d $r`
330 local o=${store}/${rr}/input.root
331 mkdir -p ${store}/${rr}
333 mess 2 -n "$source ($store) -> $o ... "
334 if test -f $o && test $force -lt 2; then
339 mess 2 -n "copying ... "
340 alien_cp alien:${source} file:${o} >> ${redir} 2>&1
344 if test ! -f $o ; then return 1 ; fi
346 if test $also_results -gt 0 ; then
347 local s=`dirname ${source}`/${other}
348 local q=${store}/`basename $other .root`_${r}.root
350 mess 2 -n "$s -> $q ... "
351 if test -f $q && test $force -lt 2 ; then
355 mess 2 -n "copying ... "
356 alien_cp alien:${s} file:${q} >> ${redir} 2>&1
367 1|3|4|5|6) return 2 ;;
370 analyse_file ${o} ${r}
375 # --- Submit run analysis to background ------------------------------
384 mess 5 "Submitting $maxjobs jobs from $sta/$maxf"
386 let cur=$sta+$counter
389 if test $from_local -lt 1 ; then
390 local b=`echo $i | sed -e "s,${path}/*,,"`
391 if test "x$search" != "x" ; then
392 b=`echo $b | sed -s "s,/*${search},,"`
394 r=`echo $b | sed -e "s,/.*,," | sed 's/^0*//'`
395 # local b=`basename $(dirname $i)`
396 # r=`echo $b | sed 's/^0*//'`
398 r=`basename \`dirname $i\` | sed 's/^0*//'`
401 local m=`printf "%3d/%3d: %s\n" $cur $max $r`
405 let counter=$counter+1
407 analyse_run $i $out $r &
408 j=`jobs %% | sed -e 's/^[^0-9]*//' -e 's/[^0-9]*$//'`
409 joblist="$joblist $j"
413 mess 5 "will wait for jobs $joblist"
414 for i in $joblist ; do
415 mess 5 "waiting for $i of $joblist"
417 mess 5 "Analysing ${runs[$counter]} returned $?"
418 let counter=$counter+1
422 # --- Analyse each run in turn ---------------------------------------
423 maxjobs=`grep "processor" /proc/cpuinfo | wc -l`
433 while test $# -gt 0 ; do
434 if test $counter -ge $max ; then
441 let counter=$counter+1
443 if test $queued -eq 1 ; then
447 if test $queued -ge $maxjobs ; then
448 mess 1 "Submitting $queued jobs from $start/$max"
449 submit_runs $out $start $max $list
454 if test $queued -gt 0 ; then
455 mess 1 "Submitting $queued jobs from $start/$max"
456 submit_runs $out $start $max $list
460 # --- Copy style -----------------------------------------------------
464 if test ! -f $file ; then return ; fi
465 base=`basename $file`
472 copy_aliroot_file $style
475 # --- Run the final trending -----------------------------------------
481 info -n "Analysing for trend $dir ... "
483 mess 1 "hadd trending.root 000*/trending.root"
485 hadd -k trending.root 000*/trending.root
486 if test $? -eq 0 && test -f trending.root ; then
487 ${QA_FWD}/periodQA.sh trending.root
493 if test $ret -ne 0 ; then
494 err "Failed to make trending in $dir"
502 # --- Help output ----------------------------------------------
506 Usage: $0 [OPTIONS] -p PRODUCTION [-P PASS]
509 -b,--barrel MODE Fetch barrel data [$barrel]
510 -d,--directory DIR Search custom AliEn directory [$path]
511 -f,--force Force re-run analysis [$force]
513 -i,--no-index Do not make index [$index]
514 -l,--log-file Log file output [$redir]
515 -L,--local Local trending_<X>.root files [$from_local]
516 -m,--max-files NUMBER Max number of files to get [$maxf]
517 -M,--max-jobs NUMBER Max number of consequtive jobs [$maxjobs]
518 -p,--production IDENTIFIER Production identifier [$prodfull]
519 -P,--pass IDENTIFIER Pass identifier [$passfull]
520 -Q,--qa-number NUMBER Custom QA id [$qanumber]
521 -R,--also-results Also get QAresults.root/run [$also_results]
522 -t,--top DIRECTORY Output directory [$top]
523 -T,--min-max Errors=min/max
524 -v,--verbose Increase verbosity [$verb]
525 -V,--variance Errors=variance [$variance]
527 Production identifiers are of the form LHC11h, LHC11h3, or LHC11h_2.
528 Pass identifers are of the form pass2, pass1_HLT, or cpass1.
529 If barrel mode>0, then do not assume ESD directory.
530 If barrel mode>1, then get trending_barrel.root and QAresults_barrel.root
531 Option -d is for hand-made QA passes.
532 If optiond -d is not specified then official QA passes are assumed.
537 # --- Parse command line options -------------------------------------
542 while test $# -gt 0 ; do
544 -b|--barrel) barrel=$2 ; shift ;;
545 -d|--directory) path=$2 ; shift ;;
546 -f|--force) let force=$force+1 ;;
547 -h|--help) usage ; exit 0 ;;
548 -i|--index) index=1 ;;
549 -l|--log-file) redir= ;;
550 -L|--local) from_local=1 ;;
551 -m|--max-files) maxf=$2 ; shift ;;
552 -M|--max-jobs) maxjobs=$2 ; shift ;;
553 -p|--production) prodfull=$2 ; shift ; parse_prod ;;
554 -P|--pass) passfull=$2 ; shift ; parse_pass ;;
555 -Q|--qa-number) qanumber=$2 ; shift ;;
556 -R|--also-results) also_results=1 ;;
557 -t|--top) top=$2 ; shift ;;
558 -T|--min-max) variance=0 ;;
559 -v|--verbose) let verb=$verb+1 ;;
560 -V|--variance) variance=1 ;;
561 -C|--no-check) docheck=0 ;;
562 *) echo "$0: Unknown argument: $1" > /dev/stderr ; exit 1 ;;
566 # === Initial setup ==================================================
567 # --- Check for AliEn token ------------------------------------------
570 # --- Check settings -------------------------------------------------
571 if test "x$prodfull" = "x" ; then
572 err "No production specified"
575 if test "x$prodpost" = "x" && test "x$passfull" = "x" ; then
576 err "No pass specified for non-MC production"
578 elif test "x$passfull" = "x" || test "x$passfull" = "xpassMC"; then
579 warn "No pass specified, assuming MC"
584 # --- Construct output -----------------------------------------------
589 if test $mc -gt 0 ; then
594 proddir=LHC${prodyear}${prodletter}
596 if test "x$passno" = "x" ; then
599 if test "x$passpre" != "x" ; then
602 passdir=${passdir}pass${passno}
603 if test "x$passpost" != "x" ; then
604 passdir=${passdir}_${passpost}
606 if test "x$remainder" != "x" ; then
607 passdir=${passdir}/${remainder}
610 store=${store}/${year}/${proddir}/${passdir}
611 if test ! "x$qanumber" = "x" && test $qanumber -gt 0 ; then
612 store=${store}_QA${qanumber}
614 mkdir -p ${top}/$store
615 fix_perm ${top}/$store
617 # --- Check for logging ----------------------------------------------
618 if test "x$redir" = "x" ; then
619 redir=${top}/$store/qa.log
624 check_lock ${top}/$store
626 # --- Some friendly information --------------------------------------
629 Production: $prodfull
639 Output directory: ${store}
643 Use variance: ${variance}
644 Use pre-downloaded: ${from_local}
647 # --- Do a search to find our files ----------------------------------
650 if test $nf -le 0 ; then
651 err "No files to process"
654 if test $maxf -gt 0 && test $maxf -lt $numf ; then
658 # --- Copy scripts to target and compile -----------------------------
659 for i in QABase.h QAPlotter.C QARing.h QAStructs.h QATrender.C ; do
660 cp ${QA_FWD}/$i ${store}/${i}
661 rm -f ${store}/`echo $i | tr '.' '_'`.{so,d}
662 fix_perm ${store}/${i}
664 mess 1 "Compiling QATrender.C"
665 (cd $store && root -l -b <<EOF
666 gROOT->LoadMacro("QABase.h++g");
667 gROOT->LoadMacro("QATrender.C++g");
671 mess 1 "Compiling QAPlotter.C"
672 (cd $store && root -l -b <<EOF
673 gROOT->LoadMacro("QABase.h++g");
674 gROOT->LoadMacro("QAPlotter.C++g");
678 (cd ${store} && for i in *.so *.d ; do fix_perm $i ; done)
680 # --- Now get and analyse each run -----------------------------------
681 analyse_runs ${top}/$store $numf $files
683 # --- Now analyse all runs -------------------------------------------
684 make_trend ${top}/$store
686 # --- Make index files -----------------------------------------------
687 if test $index -gt 0 ; then
688 info -n "Making index ... "
689 desc="For more information see <a href='https://twiki.cern.ch/twiki/"
690 desc="${desc}bin/viewauth/ALICE/FMDQA'>TWiki pages</a>."
691 $topmk --title "QA for the FMD" \
692 --description "$desc" \
698 copy_aliroot_file $script
701 chmod -R g+rwX ${top}/${proddir} >> ${redir} 2>&1