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 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 -------------------------------------
173 mess 3 "Getting file list"
177 if test ${barrel} -gt 0 ; then
180 if test ${barrel} -gt 1 ; then
181 file=trending_barrel.root
182 other=QAresults_barrel.root
184 if test $mc -gt 0 ; then
190 local post=${passpost}
194 *) post="_${post}" ;;
198 if test "x${passpre}pass${passno}${post}" != "x$passfull" ; then
202 elif echo "$passno" | grep -q -E '^[0-9]*[.]?[0-9]*$' ; then
203 if test "x$passfull" != "x" && test $passno -gt 0 ; then
212 if test $mc -gt 0 ; then passid="passMC" ; fi
215 if test "x$path" = "x" ; then
216 # Assume official productions
217 path=/alice/${datd}/${year}/${prodfull}/
218 search="${esdd}${passpre}${paid}${post}"
223 if test $qanumber -gt 0 ; then
224 qapost=`printf "QA%02d" $qanumber`
225 search=`append_to_path "$search" $qapost`
228 search=`append_to_path "$search" $file`
234 if test $from_local -lt 1 ; then
236 mess 1 "Get list of files from AliEn - can take minutes - be patient"
237 mess 2 "alien_find ${path} ${search}"
238 files=`alien_find ${path} ${search} | \
239 grep -v "\(files found\|AND THE\)" 2>> ${redir}`
241 files=`ls ${top}/${store}/*/input.root | \
242 sed 's,${top}/${store}/,,g'`
247 mess 1 -n "Total of $numf files ... "
249 if test $maxf -lt 0 ; then
252 mess 1 "using $maxf first of these"
258 # --- Change permissions on files ------------------------------------
263 if test -d $tgt ; then opt="-R" ; fi
264 chmod ${opt} g+rwX $tgt >> /dev/null 2>&1
265 chmod ${opt} o+rX $tgt >> /dev/null 2>&1
268 # --- Check if a file is OK ------------------------------------------
272 if test $docheck -lt 1 ; then return 0; fi
273 root -l -b <<EOF >> ${redir} 2>&1
274 .L ${QA_FWD}/CheckQAFile.C
275 CheckQAFile("$1","QA");
279 mess 2 "Check of $1 -> $ret"
284 # --- Analyse a file -------------------------------------------------
287 local dir=`dirname $1`
288 local inp=`basename $1`
290 local out=trending.root
291 # `echo $inp | sed 's/trending_/tree_/'`
293 mess 2 -n "Analysing $inp -> $out ... "
295 if test -f $dir/$out ; then
296 if test $force -lt 1 ; then
304 mess 3 "runQA.sh '$inp' '$type' '$prodyear' '$prodfull' '$passid' '$r'"
306 for i in QABase QAPlotter QARing QAStructs QATrender ; do
311 "$inp" "$type" $prodyear "$prodfull" "$passid" "$r" > runQA.log 2>&1
313 if test ! -f $dir/trending.root ; then ret=1 ; fi
315 if test $ret -ne 0 ; then
316 err "Failed to analyse $1"
321 # --- Download a single file -----------------------------------------
325 local source=$1 ; shift
326 local store=$1 ; shift
327 local r=`echo $1 | sed 's/^0*//'` ; shift
328 local rr=`printf %09d $r`
329 local o=${store}/${rr}/input.root
330 mkdir -p ${store}/${rr}
332 mess 2 -n "$source -> $o ... "
333 if test -f $o && test $force -lt 2; then
338 mess 2 -n "copying ... "
339 alien_cp alien:${source} file:${o} >> ${redir} 2>&1
343 if test ! -f $o ; then return 1 ; fi
345 if test $also_results -gt 0 ; then
346 local s=`dirname ${source}`/${other}
347 local q=${store}/`basename $other .root`_${r}.root
349 mess 2 -n "$s -> $q ... "
350 if test -f $q && test $force -lt 2 ; then
354 mess 2 -n "copying ... "
355 alien_cp alien:${s} file:${q} >> ${redir} 2>&1
366 1|3|4|5|6) return 2 ;;
369 analyse_file ${o} ${r}
374 # --- Submit run analysis to background ------------------------------
383 mess 5 "Submitting $maxjobs jobs from $sta/$maxf"
385 let cur=$sta+$counter
388 if test $from_local -lt 1 ; then
389 local b=`echo $i | sed -e "s,${path},,"`
390 r=`echo $b | sed -e "s,/.*,,"`
392 r=`basename \`dirname $i\` | sed 's/^0*//'`
395 local m=`printf "%3d/%3d: %s\n" $cur $max $r`
399 let counter=$counter+1
401 analyse_run $i $out $r &
402 j=`jobs %% | sed -e 's/^[^0-9]*//' -e 's/[^0-9]*$//'`
403 joblist="$joblist $j"
407 mess 5 "will wait for jobs $joblist"
408 for i in $joblist ; do
409 mess 5 "waiting for $i of $joblist"
411 mess 5 "Analysing ${runs[$counter]} returned $?"
412 let counter=$counter+1
416 # --- Analyse each run in turn ---------------------------------------
417 maxjobs=`grep "processor" /proc/cpuinfo | wc -l`
427 while test $# -gt 0 ; do
428 if test $counter -ge $max ; then
435 let counter=$counter+1
437 if test $queued -eq 1 ; then
441 if test $queued -ge $maxjobs ; then
442 mess 1 "Submitting $queued jobs from $start/$max"
443 submit_runs $out $start $max $list
448 if test $queued -gt 0 ; then
449 mess 1 "Submitting $queued jobs from $start/$max"
450 submit_runs $out $start $max $list
454 # --- Copy style -----------------------------------------------------
458 if test ! -f $file ; then return ; fi
459 base=`basename $file`
466 copy_aliroot_file $style
469 # --- Run the final trending -----------------------------------------
475 info -n "Analysing for trend $dir ... "
477 mess 1 "hadd trending.root 000*/trending.root"
479 hadd -k trending.root 000*/trending.root
480 if test $? -eq 0 && test -f trending.root ; then
481 ${QA_FWD}/periodQA.sh trending.root
487 if test $ret -ne 0 ; then
488 err "Failed to make trending in $dir"
496 # --- Help output ----------------------------------------------
500 Usage: $0 [OPTIONS] -p PRODUCTION [-P PASS]
503 -b,--barrel MODE Fetch barrel data [$barrel]
504 -d,--directory DIR Search custom AliEn directory [$path]
505 -f,--force Force re-run analysis [$force]
507 -i,--no-index Do not make index [$index]
508 -l,--log-file Log file output [$redir]
509 -L,--local Local trending_<X>.root files [$from_local]
510 -m,--max-files NUMBER Max number of files to get [$maxf]
511 -M,--max-jobs NUMBER Max number of consequtive jobs [$maxjobs]
512 -p,--production IDENTIFIER Production identifier [$prodfull]
513 -P,--pass IDENTIFIER Pass identifier [$passfull]
514 -Q,--qa-number NUMBER Custom QA id [$qanumber]
515 -R,--also-results Also get QAresults.root/run [$also_results]
516 -t,--top DIRECTORY Output directory [$top]
517 -T,--min-max Errors=min/max
518 -v,--verbose Increase verbosity [$verb]
519 -V,--variance Errors=variance [$variance]
521 Production identifiers are of the form LHC11h, LHC11h3, or LHC11h_2.
522 Pass identifers are of the form pass2, pass1_HLT, or cpass1.
523 If barrel mode>0, then do not assume ESD directory.
524 If barrel mode>1, then get trending_barrel.root and QAresults_barrel.root
525 Option -d is for hand-made QA passes.
526 If optiond -d is not specified then official QA passes are assumed.
531 # --- Parse command line options -------------------------------------
536 while test $# -gt 0 ; do
538 -b|--barrel) barrel=$2 ; shift ;;
539 -d|--directory) path=$2 ; shift ;;
540 -f|--force) let force=$force+1 ;;
541 -h|--help) usage ; exit 0 ;;
542 -i|--index) index=1 ;;
543 -l|--log-file) redir= ;;
544 -L|--local) from_local=1 ;;
545 -m|--max-files) maxf=$2 ; shift ;;
546 -M|--max-jobs) maxjobs=$2 ; shift ;;
547 -p|--production) prodfull=$2 ; shift ; parse_prod ;;
548 -P|--pass) passfull=$2 ; shift ; parse_pass ;;
549 -Q|--qa-number) qanumber=$2 ; shift ;;
550 -R|--also-results) also_results=1 ;;
551 -t|--top) top=$2 ; shift ;;
552 -T|--min-max) variance=0 ;;
553 -v|--verbose) let verb=$verb+1 ;;
554 -V|--variance) variance=1 ;;
555 *) echo "$0: Unknown argument: $1" > /dev/stderr ; exit 1 ;;
559 # === Initial setup ==================================================
560 # --- Check for AliEn token ------------------------------------------
563 # --- Check settings -------------------------------------------------
564 if test "x$prodfull" = "x" ; then
565 err "No production specified"
568 if test "x$prodpost" = "x" && test "x$passfull" = "x" ; then
569 err "No pass specified for non-MC production"
571 elif test "x$passfull" = "x" || test "x$passfull" = "xpassMC"; then
572 warn "No pass specified, assuming MC"
577 # --- Construct output -----------------------------------------------
582 if test $mc -gt 0 ; then
587 proddir=LHC${prodyear}${prodletter}
589 if test "x$passno" = "x" ; then
592 if test "x$passpre" != "x" ; then
595 passdir=${passdir}pass${passno}
596 if test "x$passpost" != "x" ; then
597 passdir=${passdir}_${passpost}
599 if test "x$remainder" != "x" ; then
600 passdir=${passdir}/${remainder}
603 store=${store}/${year}/${proddir}/${passdir}
604 if test ! "x$qanumber" = "x" && test $qanumber -gt 0 ; then
605 store=${store}_QA${qanumber}
607 mkdir -p ${top}/$store
608 fix_perm ${top}/$store
610 # --- Check for logging ----------------------------------------------
611 if test "x$redir" = "x" ; then
612 redir=${top}/$store/qa.log
617 check_lock ${top}/$store
619 # --- Some friendly information --------------------------------------
622 Production: $prodfull
632 Output directory: ${store}
636 Use variance: ${variance}
637 Use pre-downloaded: ${from_local}
640 # --- Do a search to find our files ----------------------------------
643 if test $nf -le 0 ; then
644 err "No files to process"
647 if test $maxf -gt 0 && test $maxf -lt $numf ; then
651 # --- Copy scripts to target and compile -----------------------------
652 for i in QABase.h QAPlotter.C QARing.h QAStructs.h QATrender.C ; do
653 cp ${QA_FWD}/$i ${store}/${i}
654 rm -f ${store}/`echo $i | tr '.' '_'`.{so,d}
655 fix_perm ${store}/${i}
657 mess 1 "Compiling QATrender.C"
658 (cd $store && root -l -b <<EOF
659 gROOT->LoadMacro("QABase.h++g");
660 gROOT->LoadMacro("QATrender.C++g");
664 mess 1 "Compiling QAPlotter.C"
665 (cd $store && root -l -b <<EOF
666 gROOT->LoadMacro("QABase.h++g");
667 gROOT->LoadMacro("QAPlotter.C++g");
671 (cd ${store} && for i in *.so *.d ; do fix_perm $i ; done)
673 # --- Now get and analyse each run -----------------------------------
674 analyse_runs ${top}/$store $numf $files
676 # --- Now analyse all runs -------------------------------------------
677 make_trend ${top}/$store
679 # --- Make index files -----------------------------------------------
680 if test $index -gt 0 ; then
681 info -n "Making index ... "
682 desc="For more information see <a href='https://twiki.cern.ch/twiki/"
683 desc="${desc}bin/viewauth/ALICE/FMDQA'>TWiki pages</a>."
684 $topmk --title "QA for the FMD" \
685 --description "$desc" \
691 copy_aliroot_file $script
694 chmod -R g+rwX ${top}/${proddir} >> ${redir} 2>&1