]>
Commit | Line | Data |
---|---|---|
312e6f8d | 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 | /* $Id$ */ | |
202374b1 | 17 | /////////////////////////////////////////////////////////////////////////////// |
18 | // // | |
19 | // class for running the QA makers // | |
20 | // // | |
21 | // AliQADataMakerSteer qas; // | |
22 | // qas.Run(AliQA::kRAWS, rawROOTFileName); // | |
23 | // qas.Run(AliQA::kHITS); // | |
24 | // qas.Run(AliQA::kSDIGITS); // | |
25 | // qas.Run(AliQA::kDIGITS); // | |
26 | // qas.Run(AliQA::kRECPOINTS); // | |
27 | // qas.Run(AliQA::kESDS); // | |
28 | // // | |
29 | /////////////////////////////////////////////////////////////////////////////// | |
312e6f8d | 30 | |
4edbc5bc | 31 | #include <TKey.h> |
312e6f8d | 32 | #include <TFile.h> |
567d83d9 | 33 | #include <TFileMerger.h> |
312e6f8d | 34 | #include <TPluginManager.h> |
35 | #include <TROOT.h> | |
36 | #include <TString.h> | |
37 | #include <TSystem.h> | |
38 | ||
4edbc5bc | 39 | #include "AliCDBManager.h" |
40 | #include "AliCDBEntry.h" | |
41 | #include "AliCDBId.h" | |
42 | #include "AliCDBMetaData.h" | |
312e6f8d | 43 | #include "AliESDEvent.h" |
f451171e | 44 | #include "AliGeomManager.h" |
6441b07a | 45 | #include "AliHeader.h" |
312e6f8d | 46 | #include "AliLog.h" |
007fcebb | 47 | #include "AliModule.h" |
312e6f8d | 48 | #include "AliQA.h" |
04236e67 | 49 | #include "AliQADataMakerRec.h" |
50 | #include "AliQADataMakerSim.h" | |
312e6f8d | 51 | #include "AliQADataMakerSteer.h" |
4ecde5fc | 52 | #include "AliRawReaderDate.h" |
53 | #include "AliRawReaderFile.h" | |
312e6f8d | 54 | #include "AliRawReaderRoot.h" |
55 | #include "AliRun.h" | |
56 | #include "AliRunLoader.h" | |
57 | ||
58 | ClassImp(AliQADataMakerSteer) | |
59 | ||
60 | //_____________________________________________________________________________ | |
61 | AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char * name, const char * title) : | |
62 | TNamed(name, title), | |
018c2b09 | 63 | fCurrentEvent(0), |
c65c502a | 64 | fCycleSame(kFALSE), |
fff5167b | 65 | fDetectors("ALL"), |
66 | fDetectorsW("ALL"), | |
312e6f8d | 67 | fESD(NULL), |
68 | fESDTree(NULL), | |
69 | fFirst(kTRUE), | |
70 | fGAliceFileName(gAliceFilename), | |
e30aef00 | 71 | fFirstEvent(0), |
72 | fMaxEvents(0), | |
774ac967 | 73 | fNumberOfEvents(999999), |
f0c6fb4b | 74 | fRunNumber(0), |
312e6f8d | 75 | fRawReader(NULL), |
6441b07a | 76 | fRawReaderDelete(kTRUE), |
56f4f5f4 | 77 | fRunLoader(NULL), |
78 | fQADataMakers() | |
79 | ||
312e6f8d | 80 | { |
81 | // default ctor | |
f0c6fb4b | 82 | fMaxEvents = fNumberOfEvents ; |
312e6f8d | 83 | for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) { |
4d52736b | 84 | if (IsSelected(AliQA::GetDetName(iDet))) { |
85 | fLoader[iDet] = NULL ; | |
86 | fQADataMaker[iDet] = NULL ; | |
87 | fQACycles[iDet] = 999999 ; | |
88 | } | |
312e6f8d | 89 | } |
90 | } | |
91 | ||
92 | //_____________________________________________________________________________ | |
93 | AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) : | |
94 | TNamed(qas), | |
018c2b09 | 95 | fCurrentEvent(qas.fCurrentEvent), |
c65c502a | 96 | fCycleSame(kFALSE), |
fff5167b | 97 | fDetectors(qas.fDetectors), |
98 | fDetectorsW(qas.fDetectorsW), | |
312e6f8d | 99 | fESD(NULL), |
100 | fESDTree(NULL), | |
101 | fFirst(qas.fFirst), | |
102 | fGAliceFileName(qas.fGAliceFileName), | |
e30aef00 | 103 | fFirstEvent(qas.fFirstEvent), |
104 | fMaxEvents(qas.fMaxEvents), | |
312e6f8d | 105 | fNumberOfEvents(qas.fNumberOfEvents), |
f0c6fb4b | 106 | fRunNumber(qas.fRunNumber), |
312e6f8d | 107 | fRawReader(NULL), |
6441b07a | 108 | fRawReaderDelete(kTRUE), |
56f4f5f4 | 109 | fRunLoader(NULL), |
110 | fQADataMakers() | |
312e6f8d | 111 | { |
112 | // cpy ctor | |
113 | for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
114 | fLoader[iDet] = qas.fLoader[iDet] ; | |
115 | fQADataMaker[iDet] = qas.fQADataMaker[iDet] ; | |
116 | fQACycles[iDet] = qas.fQACycles[iDet] ; | |
117 | } | |
118 | } | |
119 | ||
120 | //_____________________________________________________________________________ | |
121 | AliQADataMakerSteer & AliQADataMakerSteer::operator = (const AliQADataMakerSteer & qas) | |
122 | { | |
123 | // assignment operator | |
124 | this->~AliQADataMakerSteer() ; | |
125 | new(this) AliQADataMakerSteer(qas) ; | |
126 | return *this ; | |
127 | } | |
128 | ||
129 | //_____________________________________________________________________________ | |
130 | AliQADataMakerSteer::~AliQADataMakerSteer() | |
131 | { | |
132 | // dtor | |
133 | for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
4d52736b | 134 | if (IsSelected(AliQA::GetDetName(iDet))) { |
135 | fLoader[iDet] = NULL; | |
136 | if (fQADataMaker[iDet]) { | |
137 | (fQADataMaker[iDet])->Finish() ; | |
138 | delete fQADataMaker[iDet] ; | |
139 | fQADataMaker[iDet] = NULL ; | |
140 | } | |
141 | } | |
312e6f8d | 142 | } |
143 | ||
6441b07a | 144 | if (fRawReaderDelete) { |
145 | fRunLoader = NULL ; | |
146 | delete fRawReader ; | |
147 | fRawReader = NULL ; | |
148 | } | |
312e6f8d | 149 | } |
150 | ||
4d52736b | 151 | //_____________________________________________________________________________ |
96d67a8d | 152 | Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX_t taskIndex, const char * mode) |
4d52736b | 153 | { |
154 | // Runs all the QA data Maker for every detector | |
95932286 | 155 | |
4d52736b | 156 | Bool_t rv = kFALSE ; |
4d52736b | 157 | // Fill QA data in event loop |
95932286 | 158 | for (UInt_t iEvent = fFirstEvent ; iEvent < (UInt_t)fMaxEvents ; iEvent++) { |
018c2b09 | 159 | fCurrentEvent++ ; |
4d52736b | 160 | // Get the event |
a6f6970e | 161 | if ( iEvent%10 == 0 ) |
162 | AliInfo(Form("processing event %d", iEvent)); | |
4d52736b | 163 | if ( taskIndex == AliQA::kRAWS ) { |
164 | if ( !fRawReader->NextEvent() ) | |
165 | break ; | |
166 | } else if ( taskIndex == AliQA::kESDS ) { | |
774ac967 | 167 | if ( fESDTree->GetEntry(iEvent) == 0 ) |
168 | break ; | |
4d52736b | 169 | } else { |
774ac967 | 170 | if ( fRunLoader->GetEvent(iEvent) != 0 ) |
171 | break ; | |
4d52736b | 172 | } |
56f4f5f4 | 173 | // loop over active loaders |
174 | for (Int_t i = 0; i < fQADataMakers.GetEntriesFast() ; i++) { | |
95932286 | 175 | AliQADataMaker * qadm = static_cast<AliQADataMaker *>(fQADataMakers.At(i)) ; |
56f4f5f4 | 176 | if ( qadm->IsCycleDone() ) { |
177 | qadm->EndOfCycle(AliQA::kRAWS) ; | |
178 | qadm->StartOfCycle(AliQA::kRAWS) ; | |
4d52736b | 179 | } |
56f4f5f4 | 180 | TTree * data ; |
181 | Int_t iDet = qadm->GetUniqueID(); | |
182 | AliLoader* loader = GetLoader(iDet); | |
183 | switch (taskIndex) { | |
184 | case AliQA::kRAWS : | |
185 | qadm->Exec(taskIndex, fRawReader) ; | |
186 | break ; | |
187 | case AliQA::kHITS : | |
188 | loader->LoadHits() ; | |
189 | data = loader->TreeH() ; | |
190 | if ( ! data ) { | |
191 | AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ; | |
192 | } else { | |
193 | qadm->Exec(taskIndex, data) ; | |
194 | } | |
195 | break ; | |
196 | case AliQA::kSDIGITS : | |
197 | loader->LoadSDigits() ; | |
198 | data = loader->TreeS() ; | |
199 | if ( ! data ) { | |
200 | AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ; | |
201 | } else { | |
202 | qadm->Exec(taskIndex, data) ; | |
203 | } | |
204 | break; | |
205 | case AliQA::kDIGITS : | |
206 | loader->LoadDigits() ; | |
207 | data = loader->TreeD() ; | |
208 | if ( ! data ) { | |
209 | AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ; | |
210 | } else { | |
211 | qadm->Exec(taskIndex, data) ; | |
212 | } | |
213 | break; | |
214 | case AliQA::kRECPOINTS : | |
215 | loader->LoadRecPoints() ; | |
216 | data = loader->TreeR() ; | |
217 | if (!data) { | |
218 | AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ; | |
219 | } else { | |
220 | qadm->Exec(taskIndex, data) ; | |
221 | } | |
222 | break; | |
223 | case AliQA::kTRACKSEGMENTS : | |
224 | break; | |
225 | case AliQA::kRECPARTICLES : | |
226 | break; | |
227 | case AliQA::kESDS : | |
228 | qadm->Exec(taskIndex, fESD) ; | |
229 | break; | |
230 | case AliQA::kNTASKINDEX : | |
231 | break; | |
232 | } //task switch | |
233 | //qadm->Increment() ; | |
4d52736b | 234 | } // detector loop |
235 | } // event loop | |
a6f6970e | 236 | // // Save QA data for all detectors |
04236e67 | 237 | rv = Finish(taskIndex, mode) ; |
54b7165d | 238 | |
239 | if ( taskIndex == AliQA::kRAWS ) | |
240 | fRawReader->RewindEvents() ; | |
fff5167b | 241 | |
4d52736b | 242 | return rv ; |
243 | } | |
244 | ||
4edbc5bc | 245 | //_____________________________________________________________________________ |
56f4f5f4 | 246 | Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX_t taskIndex, const char * /*mode*/) |
4edbc5bc | 247 | { |
248 | // write output to file for all detectors | |
56f4f5f4 | 249 | for (Int_t i = 0; i < fQADataMakers.GetEntriesFast() ; i++) { |
250 | AliQADataMaker * qadm = static_cast<AliQADataMaker *>(fQADataMakers.At(i)); | |
251 | qadm->EndOfCycle(taskIndex) ; | |
252 | } | |
4edbc5bc | 253 | return kTRUE ; |
254 | } | |
255 | ||
256 | //_____________________________________________________________________________ | |
96d67a8d | 257 | TObjArray * AliQADataMakerSteer::GetFromOCDB(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, const char * year) const |
4edbc5bc | 258 | { |
259 | // Retrieve the list of QA data for a given detector and a given task | |
f73f556a | 260 | TObjArray * rv = NULL ; |
605cb8bb | 261 | if ( !strlen(AliQA::GetQARefStorage()) ) { |
f73f556a | 262 | AliError("No storage defined, use AliQA::SetQARefStorage") ; |
263 | return NULL ; | |
264 | } | |
4edbc5bc | 265 | AliCDBManager* man = AliCDBManager::Instance() ; |
f73f556a | 266 | if ( ! man->IsDefaultStorageSet() ) { |
11032e1d | 267 | TString tmp(AliQA::GetQARefDefaultStorage()) ; |
268 | tmp.Append(year) ; | |
269 | tmp.Append("/") ; | |
270 | man->SetDefaultStorage(tmp.Data()) ; | |
96d67a8d | 271 | man->SetSpecificStorage(Form("%s/*", AliQA::GetQAName()), AliQA::GetQARefStorage()) ; |
f73f556a | 272 | } |
614a7f99 | 273 | TString detOCDBDir(Form("%s/%s/%s", AliQA::GetQAName(), AliQA::GetDetName((Int_t)det), AliQA::GetRefOCDBDirName())) ; |
274 | AliInfo(Form("Retrieving reference data from %s/%s for %s", AliQA::GetQARefStorage(), detOCDBDir.Data(), AliQA::GetTaskName(task).Data())) ; | |
275 | AliCDBEntry* entry = man->Get(detOCDBDir.Data(), 0) ; //FIXME 0 --> Run Number | |
4edbc5bc | 276 | TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ; |
277 | if ( listDetQAD ) | |
f73f556a | 278 | rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ; |
4edbc5bc | 279 | return rv ; |
280 | } | |
281 | ||
312e6f8d | 282 | //_____________________________________________________________________________ |
283 | AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet) | |
284 | { | |
285 | // get the loader for a detector | |
56f4f5f4 | 286 | |
287 | if ( !fRunLoader ) | |
288 | return NULL ; | |
312e6f8d | 289 | |
290 | TString detName = AliQA::GetDetName(iDet) ; | |
291 | fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader"); | |
292 | if (fLoader[iDet]) | |
293 | return fLoader[iDet] ; | |
294 | ||
295 | // load the QA data maker object | |
296 | TPluginManager* pluginManager = gROOT->GetPluginManager() ; | |
297 | TString loaderName = "Ali" + detName + "Loader" ; | |
298 | ||
299 | AliLoader * loader = NULL ; | |
300 | // first check if a plugin is defined for the quality assurance data maker | |
301 | TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ; | |
302 | // if not, add a plugin for it | |
303 | if (!pluginHandler) { | |
304 | AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ; | |
305 | TString libs = gSystem->GetLibraries() ; | |
306 | if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) { | |
307 | pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ; | |
308 | } else { | |
309 | pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ; | |
310 | } | |
311 | pluginHandler = pluginManager->FindHandler("AliLoader", detName) ; | |
312 | } | |
313 | if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) { | |
314 | loader = (AliLoader *) pluginHandler->ExecPlugin(0) ; | |
315 | } | |
316 | if (loader) | |
317 | fLoader[iDet] = loader ; | |
318 | return loader ; | |
319 | } | |
320 | ||
321 | //_____________________________________________________________________________ | |
04236e67 | 322 | AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(const Int_t iDet, const char * mode ) |
312e6f8d | 323 | { |
324 | // get the quality assurance data maker for a detector | |
325 | ||
326 | if (fQADataMaker[iDet]) | |
327 | return fQADataMaker[iDet] ; | |
328 | ||
329 | AliQADataMaker * qadm = NULL ; | |
330 | ||
331 | if (fFirst) { | |
332 | // load the QA data maker object | |
333 | TPluginManager* pluginManager = gROOT->GetPluginManager() ; | |
334 | TString detName = AliQA::GetDetName(iDet) ; | |
9afca7a6 | 335 | TString tmp(mode) ; |
336 | if (tmp.Contains("sim")) | |
337 | tmp.ReplaceAll("s", "S") ; | |
338 | else if (tmp.Contains("rec")) | |
339 | tmp.ReplaceAll("r", "R") ; | |
340 | TString qadmName = "Ali" + detName + "QADataMaker" + tmp ; | |
312e6f8d | 341 | |
342 | // first check if a plugin is defined for the quality assurance data maker | |
343 | TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ; | |
344 | // if not, add a plugin for it | |
345 | if (!pluginHandler) { | |
346 | AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ; | |
347 | TString libs = gSystem->GetLibraries() ; | |
04236e67 | 348 | if (libs.Contains("lib" + detName + mode + ".so") || (gSystem->Load("lib" + detName + mode + ".so") >= 0)) { |
312e6f8d | 349 | pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ; |
350 | } else { | |
351 | pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ; | |
352 | } | |
353 | pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ; | |
354 | } | |
355 | if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) { | |
356 | qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ; | |
357 | } | |
358 | if (qadm) | |
359 | fQADataMaker[iDet] = qadm ; | |
360 | } | |
361 | return qadm ; | |
362 | } | |
363 | ||
364 | //_____________________________________________________________________________ | |
96d67a8d | 365 | Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX_t taskIndex, const char * mode, const char * input ) |
312e6f8d | 366 | { |
367 | // Initialize the event source and QA data makers | |
368 | ||
6441b07a | 369 | if (taskIndex == AliQA::kRAWS) { |
370 | if (!fRawReader) { | |
e64fcb90 | 371 | fRawReader = AliRawReader::Create(input); |
4ecde5fc | 372 | } |
312e6f8d | 373 | if ( ! fRawReader ) |
374 | return kFALSE ; | |
fff5167b | 375 | fRawReaderDelete = kTRUE ; |
312e6f8d | 376 | fRawReader->NextEvent() ; |
377 | fRunNumber = fRawReader->GetRunNumber() ; | |
04236e67 | 378 | AliCDBManager::Instance()->SetRun(fRunNumber) ; |
312e6f8d | 379 | fRawReader->RewindEvents(); |
380 | fNumberOfEvents = 999999 ; | |
f0c6fb4b | 381 | if ( fMaxEvents < 0 ) |
382 | fMaxEvents = fNumberOfEvents ; | |
383 | } else if (taskIndex == AliQA::kESDS) { | |
ad265f3e | 384 | if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists |
385 | TFile * esdFile = TFile::Open("AliESDs.root") ; | |
386 | fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ; | |
04236e67 | 387 | if ( !fESDTree ) { |
388 | AliError("esdTree not found") ; | |
389 | return kFALSE ; | |
390 | } else { | |
391 | fESD = new AliESDEvent() ; | |
392 | fESD->ReadFromTree(fESDTree) ; | |
393 | fESDTree->GetEntry(0) ; | |
394 | fRunNumber = fESD->GetRunNumber() ; | |
395 | fNumberOfEvents = fESDTree->GetEntries() ; | |
f0c6fb4b | 396 | if ( fMaxEvents < 0 ) |
397 | fMaxEvents = fNumberOfEvents ; | |
04236e67 | 398 | } |
ad265f3e | 399 | } else { |
400 | AliError("AliESDs.root not found") ; | |
401 | return kFALSE ; | |
402 | } | |
b37ee1e8 | 403 | } else { |
774ac967 | 404 | if ( !InitRunLoader() ) { |
405 | AliWarning("No Run Loader not found") ; | |
312e6f8d | 406 | } else { |
312e6f8d | 407 | fNumberOfEvents = fRunLoader->GetNumberOfEvents() ; |
f0c6fb4b | 408 | if ( fMaxEvents < 0 ) |
409 | fMaxEvents = fNumberOfEvents ; | |
410 | ||
312e6f8d | 411 | } |
ad265f3e | 412 | } |
fff5167b | 413 | |
56f4f5f4 | 414 | // Get Detectors |
415 | TObjArray* detArray = NULL ; | |
416 | if (fRunLoader) // check if RunLoader exists | |
b37ee1e8 | 417 | if ( fRunLoader->GetAliRun() ) { // check if AliRun exists in gAlice.root |
56f4f5f4 | 418 | detArray = fRunLoader->GetAliRun()->Detectors() ; |
b37ee1e8 | 419 | fRunNumber = fRunLoader->GetHeader()->GetRun() ; |
420 | } | |
56f4f5f4 | 421 | // Build array of QA data makers for all detectors |
422 | fQADataMakers.Clear(); | |
423 | for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) { | |
4d52736b | 424 | if (IsSelected(AliQA::GetDetName(iDet))) { |
04236e67 | 425 | AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ; |
4d52736b | 426 | if (!qadm) { |
fff5167b | 427 | AliError(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ; |
428 | fDetectorsW.ReplaceAll(AliQA::GetDetName(iDet), "") ; | |
4d52736b | 429 | } else { |
fff5167b | 430 | AliDebug(1, Form("Data Maker found for %s", qadm->GetName())) ; |
56f4f5f4 | 431 | // skip non active detectors |
432 | if (detArray) { | |
433 | AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ; | |
434 | if (!det || !det->IsActive()) | |
435 | continue ; | |
436 | } | |
437 | qadm->SetName(AliQA::GetDetName(iDet)); | |
438 | qadm->SetUniqueID(iDet); | |
439 | fQADataMakers.Add(qadm); | |
4d52736b | 440 | } |
312e6f8d | 441 | } |
442 | } | |
56f4f5f4 | 443 | // Initialize all QA data makers for all detectors |
9f12254a | 444 | fRunNumber = AliCDBManager::Instance()->GetRun() ; |
9f3d3ba0 | 445 | if ( ! AliGeomManager::GetGeometry() ) |
446 | AliGeomManager::LoadGeometry() ; | |
56f4f5f4 | 447 | for (Int_t i = 0; i < fQADataMakers.GetEntriesFast() ; i++) { |
448 | AliQADataMaker * qadm = static_cast<AliQADataMaker *>(fQADataMakers.At(i)); | |
449 | qadm->Init(taskIndex, fRunNumber, GetQACycles(qadm->GetUniqueID())) ; | |
450 | qadm->StartOfCycle(taskIndex, fCycleSame) ; | |
451 | } | |
312e6f8d | 452 | fFirst = kFALSE ; |
453 | return kTRUE ; | |
454 | } | |
455 | ||
456 | //_____________________________________________________________________________ | |
457 | Bool_t AliQADataMakerSteer::InitRunLoader() | |
458 | { | |
459 | // get or create the run loader | |
460 | if (fRunLoader) { | |
c65c502a | 461 | fCycleSame = kTRUE ; |
e4a998ed | 462 | } else { |
463 | if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists | |
464 | // load all base libraries to get the loader classes | |
465 | TString libs = gSystem->GetLibraries() ; | |
466 | for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
467 | if (!IsSelected(AliQA::GetDetName(iDet))) | |
468 | continue ; | |
469 | TString detName = AliQA::GetDetName(iDet) ; | |
470 | if (detName == "HLT") | |
471 | continue; | |
472 | if (libs.Contains("lib" + detName + "base.so")) | |
473 | continue; | |
474 | gSystem->Load("lib" + detName + "base.so"); | |
475 | } | |
476 | fRunLoader = AliRunLoader::Open(fGAliceFileName.Data()); | |
477 | if (!fRunLoader) { | |
478 | AliError(Form("no run loader found in file %s", fGAliceFileName.Data())); | |
479 | return kFALSE; | |
480 | } | |
481 | fRunLoader->CdGAFile(); | |
482 | if (fRunLoader->LoadgAlice() == 0) { | |
483 | gAlice = fRunLoader->GetAliRun(); | |
484 | } | |
485 | ||
486 | if (!gAlice) { | |
487 | AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data())); | |
488 | return kFALSE; | |
489 | } | |
4d52736b | 490 | |
e4a998ed | 491 | } else { // galice.root does not exist |
492 | AliError(Form("the file %s does not exist", fGAliceFileName.Data())); | |
312e6f8d | 493 | return kFALSE; |
494 | } | |
e4a998ed | 495 | } |
312e6f8d | 496 | |
e4a998ed | 497 | if (!fRunNumber) { |
498 | fRunLoader->LoadHeader(); | |
499 | fRunNumber = fRunLoader->GetHeader()->GetRun() ; | |
500 | } | |
501 | return kTRUE; | |
312e6f8d | 502 | } |
503 | ||
04236e67 | 504 | //_____________________________________________________________________________ |
505 | Bool_t AliQADataMakerSteer::IsSelected(const char * det) | |
506 | { | |
507 | // check whether detName is contained in detectors | |
508 | // if yes, it is removed from detectors | |
509 | ||
56f4f5f4 | 510 | Bool_t rv = kFALSE; |
04236e67 | 511 | const TString detName(det) ; |
512 | // check if all detectors are selected | |
56f4f5f4 | 513 | if (fDetectors.Contains("ALL")) { |
04236e67 | 514 | fDetectors = "ALL"; |
56f4f5f4 | 515 | rv = kTRUE; |
516 | } else if ((fDetectors.CompareTo(detName) == 0) || | |
517 | fDetectors.BeginsWith(detName+" ") || | |
518 | fDetectors.EndsWith(" "+detName) || | |
519 | fDetectors.Contains(" "+detName+" ")) { | |
04236e67 | 520 | // fDetectors.ReplaceAll(detName, ""); |
521 | rv = kTRUE; | |
522 | } | |
523 | ||
524 | // clean up the detectors string | |
525 | // while (fDetectors.Contains(" ")) | |
526 | // fDetectors.ReplaceAll(" ", " "); | |
527 | // while (fDetectors.BeginsWith(" ")) | |
528 | // fDetectors.Remove(0, 1); | |
529 | // while (fDetectors.EndsWith(" ")) | |
530 | // fDetectors.Remove(fDetectors.Length()-1, 1); | |
531 | ||
532 | return rv ; | |
533 | } | |
534 | ||
312e6f8d | 535 | //_____________________________________________________________________________ |
4edbc5bc | 536 | Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const |
315bba70 | 537 | { |
567d83d9 | 538 | // Merge all the cycles from all detectors in one single file per run |
614a7f99 | 539 | TString cmd ; |
4edbc5bc | 540 | if ( runNumber == -1 ) |
614a7f99 | 541 | cmd = Form(".! ls *%s*.*.*.root > tempo.txt", AliQA::GetQADataFileName()) ; |
4edbc5bc | 542 | else |
614a7f99 | 543 | cmd = Form(".! ls *%s*.%d.*.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ; |
544 | gROOT->ProcessLine(cmd.Data()) ; | |
567d83d9 | 545 | ifstream in("tempo.txt") ; |
546 | const Int_t runMax = 10 ; | |
547 | TString file[AliQA::kNDET*runMax] ; | |
95932286 | 548 | Int_t run[AliQA::kNDET*runMax] = {-1} ; |
567d83d9 | 549 | |
550 | Int_t index = 0 ; | |
551 | while ( 1 ) { | |
4edbc5bc | 552 | in >> file[index] ; |
567d83d9 | 553 | if ( !in.good() ) |
554 | break ; | |
e5dedfe2 | 555 | AliInfo(Form("index = %d file = %s", index, (file[index]).Data())) ; |
556 | index++ ; | |
4edbc5bc | 557 | } |
558 | ||
559 | if ( index == 0 ) { | |
560 | AliError(Form("run number %d not found", runNumber)) ; | |
561 | return kFALSE ; | |
567d83d9 | 562 | } |
4edbc5bc | 563 | |
fff5167b | 564 | Int_t runIndex = 0 ; |
565 | Int_t runIndexMax = 0 ; | |
614a7f99 | 566 | TString stmp(Form(".%s.", AliQA::GetQADataFileName())) ; |
dbf9dc0d | 567 | for (Int_t ifile = 0 ; ifile < index ; ifile++) { |
567d83d9 | 568 | TString tmp(file[ifile]) ; |
569 | tmp.ReplaceAll(".root", "") ; | |
570 | TString det = tmp(0, tmp.Index(".")) ; | |
4edbc5bc | 571 | tmp.Remove(0, tmp.Index(stmp)+4) ; |
567d83d9 | 572 | TString ttmp = tmp(0, tmp.Index(".")) ; |
573 | Int_t newRun = ttmp.Atoi() ; | |
fff5167b | 574 | for (Int_t irun = 0; irun <= runIndexMax; irun++) { |
436a9f16 | 575 | if (newRun == run[irun]) |
576 | break ; | |
567d83d9 | 577 | run[runIndex] = newRun ; |
567d83d9 | 578 | runIndex++ ; |
579 | } | |
fff5167b | 580 | runIndexMax = runIndex ; |
581 | ttmp = tmp(tmp.Index(".")+1, tmp.Length()) ; | |
567d83d9 | 582 | Int_t cycle = ttmp.Atoi() ; |
fff5167b | 583 | AliDebug(1, Form("%s : det = %s run = %d cycle = %d \n", file[ifile].Data(), det.Data(), newRun, cycle)) ; |
567d83d9 | 584 | } |
fff5167b | 585 | for (Int_t irun = 0 ; irun < runIndexMax ; irun++) { |
567d83d9 | 586 | TFileMerger merger ; |
614a7f99 | 587 | TString outFileName(Form("Merged.%s.%d.root",AliQA::GetQADataFileName(),run[irun])); |
588 | merger.OutputFile(outFileName.Data()) ; | |
567d83d9 | 589 | for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) { |
614a7f99 | 590 | TString pattern(Form("%s.%d.", AliQA::GetQADataFileName(), run[irun])) ; |
567d83d9 | 591 | TString tmp(file[ifile]) ; |
fff5167b | 592 | if (tmp.Contains(pattern)) { |
567d83d9 | 593 | merger.AddFile(tmp) ; |
fff5167b | 594 | } |
567d83d9 | 595 | } |
596 | merger.Merge() ; | |
597 | } | |
598 | ||
599 | return kTRUE ; | |
315bba70 | 600 | } |
601 | ||
c65c502a | 602 | //_____________________________________________________________________________ |
fff5167b | 603 | void AliQADataMakerSteer::Reset(const Bool_t sameCycle) |
c65c502a | 604 | { |
605 | // Reset the default data members | |
c65c502a | 606 | |
56f4f5f4 | 607 | for (Int_t i = 0; i < fQADataMakers.GetEntriesFast() ; i++) { |
608 | AliQADataMaker * qadm = static_cast<AliQADataMaker *>(fQADataMakers.At(i)); | |
609 | qadm->Reset(sameCycle); | |
610 | } | |
6441b07a | 611 | if (fRawReaderDelete) { |
612 | delete fRawReader ; | |
613 | fRawReader = NULL ; | |
614 | } | |
c65c502a | 615 | |
fff5167b | 616 | fCycleSame = sameCycle ; |
c65c502a | 617 | fESD = NULL ; |
618 | fESDTree = NULL ; | |
619 | fFirst = kTRUE ; | |
774ac967 | 620 | fNumberOfEvents = 999999 ; |
c65c502a | 621 | } |
622 | ||
6441b07a | 623 | //_____________________________________________________________________________ |
7c002d48 | 624 | TString AliQADataMakerSteer::Run(const char * detectors, AliRawReader * rawReader, const Bool_t sameCycle) |
6441b07a | 625 | { |
626 | //Runs all the QA data Maker for Raws only | |
7c002d48 | 627 | |
628 | fCycleSame = sameCycle ; | |
629 | fRawReader = rawReader ; | |
4d52736b | 630 | fDetectors = detectors ; |
7c002d48 | 631 | fDetectorsW = detectors ; |
632 | ||
95932286 | 633 | AliCDBManager* man = AliCDBManager::Instance() ; |
7930d770 | 634 | |
95932286 | 635 | if ( man->GetRun() == -1 ) {// check if run number not set previously and set it from raw data |
95932286 | 636 | rawReader->NextEvent() ; |
637 | man->SetRun(fRawReader->GetRunNumber()) ; | |
638 | rawReader->RewindEvents() ; | |
639 | } | |
640 | ||
ea9ce23f | 641 | if ( !Init(AliQA::kRAWS, "rec") ) |
642 | return kFALSE ; | |
643 | fRawReaderDelete = kFALSE ; | |
644 | ||
e5dedfe2 | 645 | DoIt(AliQA::kRAWS, "rec") ; |
646 | return fDetectorsW ; | |
04236e67 | 647 | } |
648 | ||
649 | //_____________________________________________________________________________ | |
7c002d48 | 650 | TString AliQADataMakerSteer::Run(const char * detectors, const char * fileName, const Bool_t sameCycle) |
04236e67 | 651 | { |
652 | //Runs all the QA data Maker for Raws only | |
7c002d48 | 653 | |
654 | fCycleSame = sameCycle ; | |
04236e67 | 655 | fDetectors = detectors ; |
e5dedfe2 | 656 | fDetectorsW = detectors ; |
04236e67 | 657 | |
95932286 | 658 | AliCDBManager* man = AliCDBManager::Instance() ; |
95932286 | 659 | if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun |
660 | AliRunLoader * rl = AliRunLoader::Open("galice.root") ; | |
661 | if ( ! rl ) { | |
662 | AliFatal("galice.root file not found in current directory") ; | |
663 | } else { | |
664 | rl->CdGAFile() ; | |
665 | rl->LoadgAlice() ; | |
666 | if ( ! rl->GetAliRun() ) { | |
667 | AliFatal("AliRun not found in galice.root") ; | |
668 | } else { | |
669 | rl->LoadHeader() ; | |
670 | man->SetRun(rl->GetHeader()->GetRun()); | |
671 | } | |
672 | } | |
673 | } | |
674 | ||
ea9ce23f | 675 | if ( !Init(AliQA::kRAWS, "rec", fileName) ) |
676 | return kFALSE ; | |
677 | ||
fff5167b | 678 | DoIt(AliQA::kRAWS, "rec") ; |
679 | return fDetectorsW ; | |
6441b07a | 680 | } |
681 | ||
312e6f8d | 682 | //_____________________________________________________________________________ |
7c002d48 | 683 | TString AliQADataMakerSteer::Run(const char * detectors, const AliQA::TASKINDEX_t taskIndex, Bool_t const sameCycle, const char * fileName ) |
312e6f8d | 684 | { |
685 | // Runs all the QA data Maker for every detector | |
7c002d48 | 686 | |
687 | fCycleSame = sameCycle ; | |
688 | fDetectors = detectors ; | |
689 | fDetectorsW = detectors ; | |
690 | ||
f6aa9d0e | 691 | TString mode ; |
04236e67 | 692 | if ( (taskIndex == AliQA::kHITS) || (taskIndex == AliQA::kSDIGITS) || (taskIndex == AliQA::kDIGITS) ) |
1aa42107 | 693 | mode = "sim" ; |
04236e67 | 694 | else if ( (taskIndex == AliQA::kRAWS) || (taskIndex == AliQA::kRECPOINTS) || (taskIndex == AliQA::kESDS) ) |
1aa42107 | 695 | mode = "rec" ; |
04236e67 | 696 | else { |
697 | AliError(Form("%s not implemented", AliQA::GetTaskName(taskIndex).Data())) ; | |
e5dedfe2 | 698 | return "" ; |
04236e67 | 699 | } |
fff5167b | 700 | |
65c771ca | 701 | AliCDBManager* man = AliCDBManager::Instance() ; |
95932286 | 702 | if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun |
703 | AliRunLoader * rl = AliRunLoader::Open("galice.root") ; | |
704 | if ( ! rl ) { | |
705 | AliFatal("galice.root file not found in current directory") ; | |
706 | } else { | |
707 | rl->CdGAFile() ; | |
708 | rl->LoadgAlice() ; | |
709 | if ( ! rl->GetAliRun() ) { | |
710 | AliFatal("AliRun not found in galice.root") ; | |
711 | } else { | |
712 | rl->LoadHeader() ; | |
713 | man->SetRun(rl->GetHeader()->GetRun()) ; | |
714 | } | |
715 | } | |
716 | } | |
717 | ||
ea9ce23f | 718 | if ( !Init(taskIndex, mode.Data(), fileName) ) |
719 | return kFALSE ; | |
720 | ||
f6aa9d0e | 721 | DoIt(taskIndex, mode.Data()) ; |
4d52736b | 722 | |
e5dedfe2 | 723 | return fDetectorsW ; |
6441b07a | 724 | |
14e1eccc | 725 | } |
4edbc5bc | 726 | |
727 | //_____________________________________________________________________________ | |
11032e1d | 728 | Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const char * year, const Int_t cycleNumber, const char * detectors) const |
4edbc5bc | 729 | { |
730 | // take the locasl QA data merge into a single file and save in OCDB | |
731 | Bool_t rv = kTRUE ; | |
732 | TString tmp(AliQA::GetQARefStorage()) ; | |
733 | if ( tmp.IsNull() ) { | |
734 | AliError("No storage defined, use AliQA::SetQARefStorage") ; | |
735 | return kFALSE ; | |
736 | } | |
737 | if ( !(tmp.Contains(AliQA::GetLabLocalOCDB()) || tmp.Contains(AliQA::GetLabAliEnOCDB())) ) { | |
738 | AliError(Form("%s is a wrong storage, use %s or %s", AliQA::GetQARefStorage(), AliQA::GetLabLocalOCDB().Data(), AliQA::GetLabAliEnOCDB().Data())) ; | |
739 | return kFALSE ; | |
740 | } | |
741 | TString sdet(detectors) ; | |
742 | sdet.ToUpper() ; | |
743 | TFile * inputFile ; | |
744 | if ( sdet.Contains("ALL") ) { | |
745 | rv = Merge(runNumber) ; | |
746 | if ( ! rv ) | |
747 | return kFALSE ; | |
614a7f99 | 748 | TString inputFileName(Form("Merged.%s.%d.root", AliQA::GetQADataFileName(), runNumber)) ; |
749 | inputFile = TFile::Open(inputFileName.Data()) ; | |
11032e1d | 750 | rv = SaveIt2OCDB(runNumber, inputFile, year) ; |
4edbc5bc | 751 | } else { |
752 | for (Int_t index = 0; index < AliQA::kNDET; index++) { | |
753 | if (sdet.Contains(AliQA::GetDetName(index))) { | |
614a7f99 | 754 | TString inputFileName(Form("%s.%s.%d.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber, cycleNumber)) ; |
755 | inputFile = TFile::Open(inputFileName.Data()) ; | |
11032e1d | 756 | rv *= SaveIt2OCDB(runNumber, inputFile, year) ; |
4edbc5bc | 757 | } |
758 | } | |
759 | } | |
760 | return rv ; | |
761 | } | |
762 | ||
763 | //_____________________________________________________________________________ | |
11032e1d | 764 | Bool_t AliQADataMakerSteer::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year) const |
4edbc5bc | 765 | { |
766 | // reads the TH1 from file and adds it to appropriate list before saving to OCDB | |
767 | Bool_t rv = kTRUE ; | |
768 | AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ; | |
769 | AliCDBManager* man = AliCDBManager::Instance() ; | |
f73f556a | 770 | if ( ! man->IsDefaultStorageSet() ) { |
a681ca96 | 771 | TString tmp( AliQA::GetQARefStorage() ) ; |
772 | if ( tmp.Contains(AliQA::GetLabLocalOCDB()) ) | |
773 | man->SetDefaultStorage(AliQA::GetQARefStorage()) ; | |
774 | else { | |
605cb8bb | 775 | TString tmp1(AliQA::GetQARefDefaultStorage()) ; |
776 | tmp1.Append(year) ; | |
777 | tmp1.Append("?user=alidaq") ; | |
778 | man->SetDefaultStorage(tmp1.Data()) ; | |
a681ca96 | 779 | } |
f73f556a | 780 | } |
a681ca96 | 781 | man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ; |
04236e67 | 782 | if(man->GetRun() < 0) |
783 | man->SetRun(runNumber); | |
784 | ||
11032e1d | 785 | AliCDBMetaData mdr ; |
786 | mdr.SetResponsible("yves schutz"); | |
787 | ||
4edbc5bc | 788 | for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) { |
789 | TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ; | |
790 | if ( detDir ) { | |
791 | AliInfo(Form("Entering %s", detDir->GetName())) ; | |
614a7f99 | 792 | TString detOCDBDir(Form("%s/%s/%s", AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName())) ; |
793 | AliCDBId idr(detOCDBDir.Data(), runNumber, AliCDBRunRange::Infinity()) ; | |
4edbc5bc | 794 | TList * listDetQAD = new TList() ; |
614a7f99 | 795 | TString listName(Form("%s QA data Reference", AliQA::GetDetName(detIndex))) ; |
11032e1d | 796 | mdr.SetComment("HMPID QA stuff"); |
4edbc5bc | 797 | listDetQAD->SetName(listName) ; |
798 | TList * taskList = detDir->GetListOfKeys() ; | |
799 | TIter nextTask(taskList) ; | |
800 | TKey * taskKey ; | |
801 | while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) { | |
802 | TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ; | |
803 | AliInfo(Form("Saving %s", taskDir->GetName())) ; | |
f73f556a | 804 | TObjArray * listTaskQAD = new TObjArray(100) ; |
4edbc5bc | 805 | listTaskQAD->SetName(taskKey->GetName()) ; |
806 | listDetQAD->Add(listTaskQAD) ; | |
807 | TList * histList = taskDir->GetListOfKeys() ; | |
808 | TIter nextHist(histList) ; | |
809 | TKey * histKey ; | |
810 | while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) { | |
811 | TObject * odata = taskDir->Get(histKey->GetName()) ; | |
a681ca96 | 812 | if ( !odata ) { |
813 | AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ; | |
814 | } else { | |
4edbc5bc | 815 | AliInfo(Form("Adding %s", histKey->GetName())) ; |
a681ca96 | 816 | if ( odata->IsA()->InheritsFrom("TH1") ) { |
817 | AliInfo(Form("Adding %s", histKey->GetName())) ; | |
818 | TH1 * hdata = static_cast<TH1*>(odata) ; | |
819 | listTaskQAD->Add(hdata) ; | |
820 | } | |
4edbc5bc | 821 | } |
822 | } | |
823 | } | |
4edbc5bc | 824 | man->Put(listDetQAD, idr, &mdr) ; |
825 | } | |
826 | } | |
827 | return rv ; | |
828 | } | |
a6f6970e | 829 |