]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMaker.cxx
added EOL
[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
53 ClassImp(AliQADataMaker)
54              
55 //____________________________________________________________________________ 
56 AliQADataMaker::AliQADataMaker(const char * name, const char * title) : 
57   TNamed(name, title), 
58   fOutput(0x0),
59   fDetectorDir(0x0),
60   fDetectorDirName(""), 
61   fCurrentCycle(0), 
62   fCycle(9999999), 
63   fCycleCounter(0), 
64   fWriteExpert(kFALSE),
65   fParameterList(new TList*[AliRecoParam::kNSpecies]), 
66   fRun(0), 
67   fEventSpecie(AliRecoParam::kDefault)
68 {
69   // ctor
70   fDetectorDirName = GetName() ; 
71   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
72     fParameterList[specie] = NULL ; 
73 }
74
75 //____________________________________________________________________________ 
76 AliQADataMaker::AliQADataMaker(const AliQADataMaker& qadm) :
77   TNamed(qadm.GetName(), qadm.GetTitle()),
78   fOutput(qadm.fOutput),
79   fDetectorDir(qadm.fDetectorDir),
80   fDetectorDirName(qadm.fDetectorDirName),
81   fCurrentCycle(qadm.fCurrentCycle), 
82   fCycle(qadm.fCycle), 
83   fCycleCounter(qadm.fCycleCounter), 
84   fWriteExpert(qadm.fWriteExpert),
85   fParameterList(qadm.fParameterList),  
86   fRun(qadm.fRun), 
87   fEventSpecie(qadm.fEventSpecie)
88 {
89   //copy ctor
90   fDetectorDirName = GetName() ; 
91 }
92
93 //____________________________________________________________________________
94 Int_t AliQADataMaker::Add2List(TH1 * hist, const Int_t index, TObjArray ** list, const Bool_t expert, const Bool_t saveForCorr) 
95
96         // Set histograms memory resident and add to the list
97         // Maximm allowed is 10000
98   
99   Int_t rv = -1 ; 
100   TClass * classType = hist->Class() ;
101   TString className(classType->GetName()) ; 
102   if( ! className.BeginsWith("T") && ! classType->InheritsFrom("TH1") ) {
103     AliError(Form("QA data Object must be a generic ROOT object and derive fom TH1 and not %s", className.Data())) ; 
104         } else if ( index > 10000 ) {
105                 AliError("Max number of authorized QA objects is 10000") ; 
106   } else {    
107     if (expert) 
108       hist->SetBit(AliQAv1::GetExpertBit()) ; 
109                 TH1 * histClone[AliRecoParam::kNSpecies] ; 
110     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
111       histClone[specie] = CloneMe(hist, specie) ; 
112       histClone[specie]->SetDirectory(0) ; 
113       list[specie]->AddAtAndExpand(histClone[specie], index) ; 
114       if(saveForCorr) {  
115         char * name = Form("%s_%s", list[AliRecoParam::kDefault]->GetName(), hist->GetName()) ;  
116         TParameter<double> * p = new TParameter<double>(name, 9999.9999) ;
117         if ( fParameterList[specie] == NULL )
118           fParameterList[specie] = new TList() ; 
119         fParameterList[specie]->Add(p) ;
120       }
121     }
122     rv = list[AliRecoParam::kDefault]->GetLast() ;
123   }
124   delete hist ; 
125   return rv ; 
126 }
127
128 //____________________________________________________________________________
129 TH1 *  AliQADataMaker::CloneMe(TH1 * hist, Int_t specie) const  
130 {
131   // clones a histogram 
132   char * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(specie), hist->GetName()) ;
133   TH1 * hClone = dynamic_cast<TH1 *>(hist->Clone(name)) ; 
134   if ( hist->TestBit(AliQAv1::GetExpertBit()) )
135        hClone->SetBit(AliQAv1::GetExpertBit()) ; 
136   return hClone ; 
137 }
138
139 //____________________________________________________________________________
140 void AliQADataMaker::DefaultEndOfDetectorCycle(AliQAv1::TASKINDEX_t task) 
141 {
142         // this method must be oveloaded by detectors
143         // sets the QA result to Fatal
144         AliQAv1::Instance(AliQAv1::GetDetIndex(GetName())) ;
145         AliQAv1 * qa = AliQAv1::Instance(task) ;
146   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
147     qa->Set(AliQAv1::kFATAL, specie) ; 
148         AliQAv1::GetQAResultFile()->cd() ; 
149         qa->Write(AliQAv1::GetQAName(), kWriteDelete) ;   
150         AliQAv1::GetQAResultFile()->Close() ; 
151 }
152
153 //____________________________________________________________________________ 
154 void AliQADataMaker::Finish() const 
155
156         // write to the output File
157         if (fOutput) 
158                 fOutput->Close() ; 
159
160
161 //____________________________________________________________________________ 
162 TObject * AliQADataMaker::GetData(TObjArray ** list, const Int_t index)  
163
164         // Returns the QA object at index. Limit is 100. 
165   if ( ! list ) {
166                 AliError("Data list is NULL !!") ; 
167                 return NULL ;           
168         }
169         if (list[AliRecoParam::AConvert(fEventSpecie)]) {
170                 if ( index > 10000 ) {
171                         AliError("Max number of authorized QA objects is 10000") ; 
172                         return NULL ; 
173                 } else {
174       Int_t esindex = AliRecoParam::AConvert(fEventSpecie) ; 
175       return list[esindex]->At(index) ; 
176                 }       
177   } else {
178                 AliError("Data list is NULL !!") ; 
179                 return NULL ;           
180         }
181 }