Extra header added to the list
[u/mrichter/AliRoot.git] / test / QA / MergeAndCheck.sh
1 #! /bin/bash    
2 # 1. Merge all the QAData files from a given Run
3 # 2. Run rge QA Checker on the merged file
4 PRODYEAR=$2
5 PRODCYCLE=$3
6 RUNNUMBER=$4
7 BASEDIR=""
8 MODE=""
9 XMLCOLL="QA"_$RUNNUMBER".xml"
10 PATTERN="Merged.QA.Data.root"
11 MERGEDOUT="Merged.QA.Data.$RUNNUMBER.root"
12 dialog=/sw/bin/dialog
13 Help(){
14 echo "Usage: MergeAndCheck.sh -h|s|r|c [xxxx, yyyy, zzzz]"
15 echo "                        -h : get this list"
16 echo "                        -s <production year> <production cycle> <run number> : processes MC data"
17 echo "                        -r <year> <production cycle> <run number> : processes RAW data"
18 echo "                        -c <run number> : processes RAW data only"
19 }
20
21 SetupAliEnEnv(){
22 echo "...............Setting up AliEn environment"
23 if [ ! -e "$HOME/.globus/usercert.pem" ]; then
24   echo "No grid certificate found in $HOME/.globus"
25   exit 1
26 fi  
27 if [ ! -e "/tmp/gclient_env_$UID" ]; then
28   alien-token-init
29   if [ ! "$?" -eq "0" ]; then
30     echo "alien-token-init failed"
31     exit 1
32   fi
33 else
34   source /tmp/gclient_env_$UID
35 fi
36 }
37
38 MakeXML(){
39 echo "...............Make XML for" $BASEDIR
40 gbbox find -x MergedQACollection $BASEDIR $PATTERN > $XMLCOLL
41 if [ ! "$?" -eq "0" ]; then
42   echo "MergeXML failed"
43   exit 1
44 fi
45 }
46
47 Merge(){
48 echo "...............Make Merge of" $BASEDIR
49 aliroot -b << EOF
50   AliQAManager * qam = AliQAManager::QAManager($MODE) ; 
51   qam->MergeXML("$XMLCOLL", NULL, "$MERGEDOUT")
52  .q
53 EOF
54 if [ ! "$?" -eq "0" ]; then
55   echo "Merge failed"
56   exit 1
57 fi
58 }
59
60 Check(){
61 echo "...............Make Check of $MERGEDOUT"
62 if [ -e "QA.$RUNNUMBER.root" ] ; then 
63   rm QA.$RUNNUMBER.root
64 fi  
65 if [ -e "QA.root" ] ; then 
66   rm QA.root
67 fi
68 aliroot -b << EOF
69   AliQAv1::SetQARefStorage("local://$ALICE_ROOT/QAref") ;
70   AliQAChecker::Instance()->Run("$MERGEDOUT")
71  .q
72 EOF
73 mv QA.root QA.$RUNNUMBER.root
74 if [ ! "$?" -eq "0" ]; then
75   echo "Check failed"
76   exit 1
77 fi
78 }
79
80 Save(){
81 echo "...............Save $MERGEDOUT and QA.$RUNNUMBER.root in alien://$BASEDIR"
82 gbbox cp file:$MERGEDOUT $BASEDIR
83 gbbox cp file:QA$.RUNNUMBER.root $BASEDIR 
84 if [ ! "$?" -eq "0" ]; then
85   echo "Save failed"
86   exit 1
87 fi
88 }
89
90 # Start
91 if [ $# -eq 0 ] ; then
92  Help 
93  exit 1
94 fi
95 # help
96 if [ "$1" == "-h" ] ; then
97  Help
98  exit 0
99 fi
100 # run
101 if [ "$1" == "-s" -o "$1" == "-r" -o "$1" == -a ] ; then
102   if [ $# -lt 4 ] ; then
103     echo "Missing data !"
104     Help
105     exit 1
106   fi
107   if [ "$1" == "-s" ] ; then 
108     BASEDIR="/alice/sim/"$PRODYEAR"/"$PRODCYCLE"/"$RUNNUMBER 
109     MODE="AliQAv1::kSIMMODE"
110    fi
111   if [ "$1" == "-r" ] ; then 
112     BASEDIR="/alice/data/"$PRODYEAR"/"$PRODCYCLE"/"$RUNNUMBER 
113     MODE="AliQAv1::kRECMODE"
114   fi
115   SetupAliEnEnv 
116   MakeXML
117   Merge
118   Check
119   Save
120 fi
121 if [ "$1" == "-c" ] ; then 
122   if [ $# -lt 2 ] ; then
123     echo "Missing data !"
124     Help
125     exit 1
126   fi
127   RUNNUMBER=$2
128   MERGEDOUT="Merged.QA.Data.$RUNNUMBER.root"
129   Check
130 fi
131
132 # Done 
133 if [ -e $XMLCOLL ] ; then 
134   rm $XMLCOLL
135 fi
136 exit 0