]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMaker.cxx
Another round of fixes in order to use the event specie in the QA. The procedure...
[u/mrichter/AliRoot.git] / STEER / AliQADataMaker.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 /* $Id$ */
18
19 //
20 //  Base Class
21 //  Produces the data needed to calculate the quality assurance. 
22 //  All data must be mergeable objects.
23 //  Y. Schutz CERN July 2007
24 //
25
26 // --- ROOT system ---
27 #include <TSystem.h> 
28 #include <TFile.h>
29 #include <TList.h> 
30 #include <TTree.h>
31 #include <TClonesArray.h>
32 #include <TParameter.h>
33 #include <TH1K.h>
34 #include <TH2C.h>
35 #include <TH2D.h>
36 #include <TH2F.h>
37 #include <TH2I.h>
38 #include <TH3C.h>
39 #include <TH3D.h>
40 #include <TH3F.h>
41 #include <TH3I.h>
42 #include <TH3S.h>
43
44 // --- Standard library ---
45
46 // --- AliRoot header files ---
47 #include "AliLog.h"
48 #include "AliQADataMaker.h"
49 #include "AliQAChecker.h"
50 #include "AliESDEvent.h"
51 #include "AliRawReader.h"
52 #include "AliDetectorRecoParam.h"
53
54
55 ClassImp(AliQADataMaker)
56              
57 //____________________________________________________________________________ 
58 AliQADataMaker::AliQADataMaker(const char * name, const char * title) : 
59   TNamed(name, title), 
60   fOutput(0x0),
61   fDetectorDir(0x0),
62   fDetectorDirName(""), 
63   fCurrentCycle(0), 
64   fCycle(9999999), 
65   fCycleCounter(0), 
66   fWriteExpert(kFALSE),
67   fParameterList(new TList*[AliRecoParam::kNSpecies]), 
68   fRun(0), 
69   fEventSpecie(AliRecoParam::kDefault)
70 {
71   // ctor
72   fDetectorDirName = GetName() ; 
73   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
74     fParameterList[specie] = NULL ; 
75 }
76
77 //____________________________________________________________________________ 
78 AliQADataMaker::AliQADataMaker(const AliQADataMaker& qadm) :
79   TNamed(qadm.GetName(), qadm.GetTitle()),
80   fOutput(qadm.fOutput),
81   fDetectorDir(qadm.fDetectorDir),
82   fDetectorDirName(qadm.fDetectorDirName),
83   fCurrentCycle(qadm.fCurrentCycle), 
84   fCycle(qadm.fCycle), 
85   fCycleCounter(qadm.fCycleCounter), 
86   fWriteExpert(qadm.fWriteExpert),
87   fParameterList(qadm.fParameterList),  
88   fRun(qadm.fRun), 
89   fEventSpecie(qadm.fEventSpecie)
90 {
91   //copy ctor
92   fDetectorDirName = GetName() ; 
93 }
94
95 //____________________________________________________________________________
96 Int_t AliQADataMaker::Add2List(TH1 * hist, const Int_t index, TObjArray ** list, const Bool_t expert, const Bool_t image, const Bool_t saveForCorr) 
97
98         // Set histograms memory resident and add to the list
99         // Maximm allowed is 10000
100   
101   Int_t rv = -1 ; 
102   TClass * classType = hist->Class() ;
103   TString className(classType->GetName()) ; 
104   if( ! className.BeginsWith("T") && ! classType->InheritsFrom("TH1") ) {
105     AliError(Form("QA data Object must be a generic ROOT object and derive fom TH1 and not %s", className.Data())) ; 
106         } else if ( index > 10000 ) {
107                 AliError("Max number of authorized QA objects is 10000") ; 
108   } else {    
109     if (expert) 
110       hist->SetBit(AliQAv1::GetExpertBit()) ;
111     if (image) 
112       hist->SetBit(AliQAv1::GetImageBit()) ;  
113     TH1 * histClone[AliRecoParam::kNSpecies] ; 
114     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
115       histClone[specie] = CloneMe(hist, specie) ; 
116       histClone[specie]->SetDirectory(0) ; 
117       list[specie]->AddAtAndExpand(histClone[specie], index) ; 
118       if(saveForCorr) {  
119         char * name = Form("%s_%s", list[AliRecoParam::AConvert(AliRecoParam::kDefault)]->GetName(), hist->GetName()) ;  
120         TParameter<double> * p = new TParameter<double>(name, 9999.9999) ;
121         if ( fParameterList[specie] == NULL )
122           fParameterList[specie] = new TList() ; 
123         fParameterList[specie]->Add(p) ;
124       }
125     }
126     rv = list[AliRecoParam::kDefault]->GetLast() ;
127   }
128   delete hist ; 
129   return rv ; 
130 }
131
132 //____________________________________________________________________________
133 TH1 *  AliQADataMaker::CloneMe(TH1 * hist, Int_t specie) const  
134 {
135   // clones a histogram 
136   char * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(specie), hist->GetName()) ;
137   TH1 * hClone = dynamic_cast<TH1 *>(hist->Clone(name)) ; 
138   if ( hist->TestBit(AliQAv1::GetExpertBit()) )
139     hClone->SetBit(AliQAv1::GetExpertBit()) ; 
140   if ( hist->TestBit(AliQAv1::GetImageBit()) )
141     hClone->SetBit(AliQAv1::GetImageBit()) ; 
142   return hClone ; 
143 }
144
145 //____________________________________________________________________________
146 void AliQADataMaker::DefaultEndOfDetectorCycle(AliQAv1::TASKINDEX_t task) 
147 {
148         // this method must be oveloaded by detectors
149         // sets the QA result to Fatal
150         AliQAv1::Instance(AliQAv1::GetDetIndex(GetName())) ;
151         AliQAv1 * qa = AliQAv1::Instance(task) ;
152   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
153     qa->Set(AliQAv1::kFATAL, specie) ; 
154         AliQAv1::GetQAResultFile()->cd() ; 
155         qa->Write(AliQAv1::GetQAName(), kWriteDelete) ;   
156         AliQAv1::GetQAResultFile()->Close() ; 
157 }
158
159 //____________________________________________________________________________ 
160 void AliQADataMaker::Finish() const 
161
162         // write to the output File
163         if (fOutput) 
164                 fOutput->Close() ; 
165
166
167 //____________________________________________________________________________ 
168 TObject * AliQADataMaker::GetData(TObjArray ** list, const Int_t index)  
169
170         // Returns the QA object at index. Limit is 100. 
171   if ( ! list ) {
172                 AliError("Data list is NULL !!") ; 
173                 return NULL ;           
174         }
175
176   SetEventSpecie(fEventSpecie) ;  
177   if ( GetRecoParam() ) {
178     if ( AliRecoParam::Convert(GetRecoParam()->GetEventSpecie()) != AliRecoParam::kDefault) {
179       SetEventSpecie(GetRecoParam()->GetEventSpecie()) ; 
180     } else { 
181       AliError(Form("Event Specie from RecoParam of %s is = %d\n", GetName(), fEventSpecie));
182     }
183   }
184         if (list[AliRecoParam::AConvert(fEventSpecie)]) {
185                 if ( index > 10000 ) {
186                         AliError("Max number of authorized QA objects is 10000") ; 
187                         return NULL ; 
188                 } else {
189       Int_t esindex = AliRecoParam::AConvert(fEventSpecie) ; 
190       return list[esindex]->At(index) ; 
191                 }       
192   } else {
193                 AliError("Data list is NULL !!") ; 
194                 return NULL ;           
195         }
196 }
197