]>
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) ; |
fff5167b | 238 | |
4d52736b | 239 | return rv ; |
240 | } | |
241 | ||
4edbc5bc | 242 | //_____________________________________________________________________________ |
56f4f5f4 | 243 | Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX_t taskIndex, const char * /*mode*/) |
4edbc5bc | 244 | { |
245 | // write output to file for all detectors | |
56f4f5f4 | 246 | for (Int_t i = 0; i < fQADataMakers.GetEntriesFast() ; i++) { |
247 | AliQADataMaker * qadm = static_cast<AliQADataMaker *>(fQADataMakers.At(i)); | |
248 | qadm->EndOfCycle(taskIndex) ; | |
249 | } | |
4edbc5bc | 250 | return kTRUE ; |
251 | } | |
252 | ||
253 | //_____________________________________________________________________________ | |
96d67a8d | 254 | TObjArray * AliQADataMakerSteer::GetFromOCDB(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, const char * year) const |
4edbc5bc | 255 | { |
256 | // Retrieve the list of QA data for a given detector and a given task | |
f73f556a | 257 | TObjArray * rv = NULL ; |
605cb8bb | 258 | if ( !strlen(AliQA::GetQARefStorage()) ) { |
f73f556a | 259 | AliError("No storage defined, use AliQA::SetQARefStorage") ; |
260 | return NULL ; | |
261 | } | |
4edbc5bc | 262 | AliCDBManager* man = AliCDBManager::Instance() ; |
f73f556a | 263 | if ( ! man->IsDefaultStorageSet() ) { |
11032e1d | 264 | TString tmp(AliQA::GetQARefDefaultStorage()) ; |
265 | tmp.Append(year) ; | |
266 | tmp.Append("/") ; | |
267 | man->SetDefaultStorage(tmp.Data()) ; | |
96d67a8d | 268 | man->SetSpecificStorage(Form("%s/*", AliQA::GetQAName()), AliQA::GetQARefStorage()) ; |
f73f556a | 269 | } |
614a7f99 | 270 | TString detOCDBDir(Form("%s/%s/%s", AliQA::GetQAName(), AliQA::GetDetName((Int_t)det), AliQA::GetRefOCDBDirName())) ; |
271 | AliInfo(Form("Retrieving reference data from %s/%s for %s", AliQA::GetQARefStorage(), detOCDBDir.Data(), AliQA::GetTaskName(task).Data())) ; | |
272 | AliCDBEntry* entry = man->Get(detOCDBDir.Data(), 0) ; //FIXME 0 --> Run Number | |
4edbc5bc | 273 | TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ; |
274 | if ( listDetQAD ) | |
f73f556a | 275 | rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ; |
4edbc5bc | 276 | return rv ; |
277 | } | |
278 | ||
312e6f8d | 279 | //_____________________________________________________________________________ |
280 | AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet) | |
281 | { | |
282 | // get the loader for a detector | |
56f4f5f4 | 283 | |
284 | if ( !fRunLoader ) | |
285 | return NULL ; | |
312e6f8d | 286 | |
287 | TString detName = AliQA::GetDetName(iDet) ; | |
288 | fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader"); | |
289 | if (fLoader[iDet]) | |
290 | return fLoader[iDet] ; | |
291 | ||
292 | // load the QA data maker object | |
293 | TPluginManager* pluginManager = gROOT->GetPluginManager() ; | |
294 | TString loaderName = "Ali" + detName + "Loader" ; | |
295 | ||
296 | AliLoader * loader = NULL ; | |
297 | // first check if a plugin is defined for the quality assurance data maker | |
298 | TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ; | |
299 | // if not, add a plugin for it | |
300 | if (!pluginHandler) { | |
301 | AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ; | |
302 | TString libs = gSystem->GetLibraries() ; | |
303 | if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) { | |
304 | pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ; | |
305 | } else { | |
306 | pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ; | |
307 | } | |
308 | pluginHandler = pluginManager->FindHandler("AliLoader", detName) ; | |
309 | } | |
310 | if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) { | |
311 | loader = (AliLoader *) pluginHandler->ExecPlugin(0) ; | |
312 | } | |
313 | if (loader) | |
314 | fLoader[iDet] = loader ; | |
315 | return loader ; | |
316 | } | |
317 | ||
318 | //_____________________________________________________________________________ | |
04236e67 | 319 | AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(const Int_t iDet, const char * mode ) |
312e6f8d | 320 | { |
321 | // get the quality assurance data maker for a detector | |
322 | ||
323 | if (fQADataMaker[iDet]) | |
324 | return fQADataMaker[iDet] ; | |
325 | ||
326 | AliQADataMaker * qadm = NULL ; | |
327 | ||
328 | if (fFirst) { | |
329 | // load the QA data maker object | |
330 | TPluginManager* pluginManager = gROOT->GetPluginManager() ; | |
331 | TString detName = AliQA::GetDetName(iDet) ; | |
9afca7a6 | 332 | TString tmp(mode) ; |
333 | if (tmp.Contains("sim")) | |
334 | tmp.ReplaceAll("s", "S") ; | |
335 | else if (tmp.Contains("rec")) | |
336 | tmp.ReplaceAll("r", "R") ; | |
337 | TString qadmName = "Ali" + detName + "QADataMaker" + tmp ; | |
312e6f8d | 338 | |
339 | // first check if a plugin is defined for the quality assurance data maker | |
340 | TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ; | |
341 | // if not, add a plugin for it | |
342 | if (!pluginHandler) { | |
343 | AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ; | |
344 | TString libs = gSystem->GetLibraries() ; | |
04236e67 | 345 | if (libs.Contains("lib" + detName + mode + ".so") || (gSystem->Load("lib" + detName + mode + ".so") >= 0)) { |
312e6f8d | 346 | pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ; |
347 | } else { | |
348 | pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ; | |
349 | } | |
350 | pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ; | |
351 | } | |
352 | if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) { | |
353 | qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ; | |
354 | } | |
355 | if (qadm) | |
356 | fQADataMaker[iDet] = qadm ; | |
357 | } | |
358 | return qadm ; | |
359 | } | |
360 | ||
361 | //_____________________________________________________________________________ | |
96d67a8d | 362 | Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX_t taskIndex, const char * mode, const char * input ) |
312e6f8d | 363 | { |
364 | // Initialize the event source and QA data makers | |
365 | ||
6441b07a | 366 | if (taskIndex == AliQA::kRAWS) { |
367 | if (!fRawReader) { | |
e64fcb90 | 368 | fRawReader = AliRawReader::Create(input); |
4ecde5fc | 369 | } |
312e6f8d | 370 | if ( ! fRawReader ) |
371 | return kFALSE ; | |
fff5167b | 372 | fRawReaderDelete = kTRUE ; |
312e6f8d | 373 | fRawReader->NextEvent() ; |
374 | fRunNumber = fRawReader->GetRunNumber() ; | |
04236e67 | 375 | AliCDBManager::Instance()->SetRun(fRunNumber) ; |
312e6f8d | 376 | fRawReader->RewindEvents(); |
377 | fNumberOfEvents = 999999 ; | |
f0c6fb4b | 378 | if ( fMaxEvents < 0 ) |
379 | fMaxEvents = fNumberOfEvents ; | |
380 | } else if (taskIndex == AliQA::kESDS) { | |
ad265f3e | 381 | if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists |
382 | TFile * esdFile = TFile::Open("AliESDs.root") ; | |
383 | fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ; | |
04236e67 | 384 | if ( !fESDTree ) { |
385 | AliError("esdTree not found") ; | |
386 | return kFALSE ; | |
387 | } else { | |
388 | fESD = new AliESDEvent() ; | |
389 | fESD->ReadFromTree(fESDTree) ; | |
390 | fESDTree->GetEntry(0) ; | |
391 | fRunNumber = fESD->GetRunNumber() ; | |
392 | fNumberOfEvents = fESDTree->GetEntries() ; | |
f0c6fb4b | 393 | if ( fMaxEvents < 0 ) |
394 | fMaxEvents = fNumberOfEvents ; | |
04236e67 | 395 | } |
ad265f3e | 396 | } else { |
397 | AliError("AliESDs.root not found") ; | |
398 | return kFALSE ; | |
399 | } | |
b37ee1e8 | 400 | } else { |
774ac967 | 401 | if ( !InitRunLoader() ) { |
402 | AliWarning("No Run Loader not found") ; | |
312e6f8d | 403 | } else { |
312e6f8d | 404 | fNumberOfEvents = fRunLoader->GetNumberOfEvents() ; |
f0c6fb4b | 405 | if ( fMaxEvents < 0 ) |
406 | fMaxEvents = fNumberOfEvents ; | |
407 | ||
312e6f8d | 408 | } |
ad265f3e | 409 | } |
fff5167b | 410 | |
56f4f5f4 | 411 | // Get Detectors |
412 | TObjArray* detArray = NULL ; | |
413 | if (fRunLoader) // check if RunLoader exists | |
b37ee1e8 | 414 | if ( fRunLoader->GetAliRun() ) { // check if AliRun exists in gAlice.root |
56f4f5f4 | 415 | detArray = fRunLoader->GetAliRun()->Detectors() ; |
b37ee1e8 | 416 | fRunNumber = fRunLoader->GetHeader()->GetRun() ; |
417 | } | |
56f4f5f4 | 418 | // Build array of QA data makers for all detectors |
419 | fQADataMakers.Clear(); | |
420 | for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) { | |
4d52736b | 421 | if (IsSelected(AliQA::GetDetName(iDet))) { |
04236e67 | 422 | AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ; |
4d52736b | 423 | if (!qadm) { |
fff5167b | 424 | AliError(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ; |
425 | fDetectorsW.ReplaceAll(AliQA::GetDetName(iDet), "") ; | |
4d52736b | 426 | } else { |
fff5167b | 427 | AliDebug(1, Form("Data Maker found for %s", qadm->GetName())) ; |
56f4f5f4 | 428 | // skip non active detectors |
429 | if (detArray) { | |
430 | AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ; | |
431 | if (!det || !det->IsActive()) | |
432 | continue ; | |
433 | } | |
434 | qadm->SetName(AliQA::GetDetName(iDet)); | |
435 | qadm->SetUniqueID(iDet); | |
436 | fQADataMakers.Add(qadm); | |
4d52736b | 437 | } |
312e6f8d | 438 | } |
439 | } | |
56f4f5f4 | 440 | // Initialize all QA data makers for all detectors |
9f12254a | 441 | fRunNumber = AliCDBManager::Instance()->GetRun() ; |
9f3d3ba0 | 442 | if ( ! AliGeomManager::GetGeometry() ) |
443 | AliGeomManager::LoadGeometry() ; | |
56f4f5f4 | 444 | for (Int_t i = 0; i < fQADataMakers.GetEntriesFast() ; i++) { |
445 | AliQADataMaker * qadm = static_cast<AliQADataMaker *>(fQADataMakers.At(i)); | |
446 | qadm->Init(taskIndex, fRunNumber, GetQACycles(qadm->GetUniqueID())) ; | |
447 | qadm->StartOfCycle(taskIndex, fCycleSame) ; | |
448 | } | |
312e6f8d | 449 | fFirst = kFALSE ; |
450 | return kTRUE ; | |
451 | } | |
452 | ||
453 | //_____________________________________________________________________________ | |
454 | Bool_t AliQADataMakerSteer::InitRunLoader() | |
455 | { | |
456 | // get or create the run loader | |
457 | if (fRunLoader) { | |
c65c502a | 458 | fCycleSame = kTRUE ; |
e4a998ed | 459 | } else { |
460 | if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists | |
461 | // load all base libraries to get the loader classes | |
462 | TString libs = gSystem->GetLibraries() ; | |
463 | for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
464 | if (!IsSelected(AliQA::GetDetName(iDet))) | |
465 | continue ; | |
466 | TString detName = AliQA::GetDetName(iDet) ; | |
467 | if (detName == "HLT") | |
468 | continue; | |
469 | if (libs.Contains("lib" + detName + "base.so")) | |
470 | continue; | |
471 | gSystem->Load("lib" + detName + "base.so"); | |
472 | } | |
473 | fRunLoader = AliRunLoader::Open(fGAliceFileName.Data()); | |
474 | if (!fRunLoader) { | |
475 | AliError(Form("no run loader found in file %s", fGAliceFileName.Data())); | |
476 | return kFALSE; | |
477 | } | |
478 | fRunLoader->CdGAFile(); | |
479 | if (fRunLoader->LoadgAlice() == 0) { | |
480 | gAlice = fRunLoader->GetAliRun(); | |
481 | } | |
482 | ||
483 | if (!gAlice) { | |
484 | AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data())); | |
485 | return kFALSE; | |
486 | } | |
4d52736b | 487 | |
e4a998ed | 488 | } else { // galice.root does not exist |
489 | AliError(Form("the file %s does not exist", fGAliceFileName.Data())); | |
312e6f8d | 490 | return kFALSE; |
491 | } | |
e4a998ed | 492 | } |
312e6f8d | 493 | |
e4a998ed | 494 | if (!fRunNumber) { |
495 | fRunLoader->LoadHeader(); | |
496 | fRunNumber = fRunLoader->GetHeader()->GetRun() ; | |
497 | } | |
498 | return kTRUE; | |
312e6f8d | 499 | } |
500 | ||
04236e67 | 501 | //_____________________________________________________________________________ |
502 | Bool_t AliQADataMakerSteer::IsSelected(const char * det) | |
503 | { | |
504 | // check whether detName is contained in detectors | |
505 | // if yes, it is removed from detectors | |
506 | ||
56f4f5f4 | 507 | Bool_t rv = kFALSE; |
04236e67 | 508 | const TString detName(det) ; |
509 | // check if all detectors are selected | |
56f4f5f4 | 510 | if (fDetectors.Contains("ALL")) { |
04236e67 | 511 | fDetectors = "ALL"; |
56f4f5f4 | 512 | rv = kTRUE; |
513 | } else if ((fDetectors.CompareTo(detName) == 0) || | |
514 | fDetectors.BeginsWith(detName+" ") || | |
515 | fDetectors.EndsWith(" "+detName) || | |
516 | fDetectors.Contains(" "+detName+" ")) { | |
04236e67 | 517 | // fDetectors.ReplaceAll(detName, ""); |
518 | rv = kTRUE; | |
519 | } | |
520 | ||
521 | // clean up the detectors string | |
522 | // while (fDetectors.Contains(" ")) | |
523 | // fDetectors.ReplaceAll(" ", " "); | |
524 | // while (fDetectors.BeginsWith(" ")) | |
525 | // fDetectors.Remove(0, 1); | |
526 | // while (fDetectors.EndsWith(" ")) | |
527 | // fDetectors.Remove(fDetectors.Length()-1, 1); | |
528 | ||
529 | return rv ; | |
530 | } | |
531 | ||
312e6f8d | 532 | //_____________________________________________________________________________ |
4edbc5bc | 533 | Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const |
315bba70 | 534 | { |
567d83d9 | 535 | // Merge all the cycles from all detectors in one single file per run |
614a7f99 | 536 | TString cmd ; |
4edbc5bc | 537 | if ( runNumber == -1 ) |
614a7f99 | 538 | cmd = Form(".! ls *%s*.*.*.root > tempo.txt", AliQA::GetQADataFileName()) ; |
4edbc5bc | 539 | else |
614a7f99 | 540 | cmd = Form(".! ls *%s*.%d.*.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ; |
541 | gROOT->ProcessLine(cmd.Data()) ; | |
567d83d9 | 542 | ifstream in("tempo.txt") ; |
543 | const Int_t runMax = 10 ; | |
544 | TString file[AliQA::kNDET*runMax] ; | |
95932286 | 545 | Int_t run[AliQA::kNDET*runMax] = {-1} ; |
567d83d9 | 546 | |
547 | Int_t index = 0 ; | |
548 | while ( 1 ) { | |
4edbc5bc | 549 | in >> file[index] ; |
567d83d9 | 550 | if ( !in.good() ) |
551 | break ; | |
e5dedfe2 | 552 | AliInfo(Form("index = %d file = %s", index, (file[index]).Data())) ; |
553 | index++ ; | |
4edbc5bc | 554 | } |
555 | ||
556 | if ( index == 0 ) { | |
557 | AliError(Form("run number %d not found", runNumber)) ; | |
558 | return kFALSE ; | |
567d83d9 | 559 | } |
4edbc5bc | 560 | |
fff5167b | 561 | Int_t runIndex = 0 ; |
562 | Int_t runIndexMax = 0 ; | |
614a7f99 | 563 | TString stmp(Form(".%s.", AliQA::GetQADataFileName())) ; |
dbf9dc0d | 564 | for (Int_t ifile = 0 ; ifile < index ; ifile++) { |
567d83d9 | 565 | TString tmp(file[ifile]) ; |
566 | tmp.ReplaceAll(".root", "") ; | |
567 | TString det = tmp(0, tmp.Index(".")) ; | |
4edbc5bc | 568 | tmp.Remove(0, tmp.Index(stmp)+4) ; |
567d83d9 | 569 | TString ttmp = tmp(0, tmp.Index(".")) ; |
570 | Int_t newRun = ttmp.Atoi() ; | |
fff5167b | 571 | for (Int_t irun = 0; irun <= runIndexMax; irun++) { |
436a9f16 | 572 | if (newRun == run[irun]) |
573 | break ; | |
567d83d9 | 574 | run[runIndex] = newRun ; |
567d83d9 | 575 | runIndex++ ; |
576 | } | |
fff5167b | 577 | runIndexMax = runIndex ; |
578 | ttmp = tmp(tmp.Index(".")+1, tmp.Length()) ; | |
567d83d9 | 579 | Int_t cycle = ttmp.Atoi() ; |
fff5167b | 580 | AliDebug(1, Form("%s : det = %s run = %d cycle = %d \n", file[ifile].Data(), det.Data(), newRun, cycle)) ; |
567d83d9 | 581 | } |
fff5167b | 582 | for (Int_t irun = 0 ; irun < runIndexMax ; irun++) { |
567d83d9 | 583 | TFileMerger merger ; |
614a7f99 | 584 | TString outFileName(Form("Merged.%s.%d.root",AliQA::GetQADataFileName(),run[irun])); |
585 | merger.OutputFile(outFileName.Data()) ; | |
567d83d9 | 586 | for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) { |
614a7f99 | 587 | TString pattern(Form("%s.%d.", AliQA::GetQADataFileName(), run[irun])) ; |
567d83d9 | 588 | TString tmp(file[ifile]) ; |
fff5167b | 589 | if (tmp.Contains(pattern)) { |
567d83d9 | 590 | merger.AddFile(tmp) ; |
fff5167b | 591 | } |
567d83d9 | 592 | } |
593 | merger.Merge() ; | |
594 | } | |
595 | ||
596 | return kTRUE ; | |
315bba70 | 597 | } |
598 | ||
c65c502a | 599 | //_____________________________________________________________________________ |
fff5167b | 600 | void AliQADataMakerSteer::Reset(const Bool_t sameCycle) |
c65c502a | 601 | { |
602 | // Reset the default data members | |
c65c502a | 603 | |
56f4f5f4 | 604 | for (Int_t i = 0; i < fQADataMakers.GetEntriesFast() ; i++) { |
605 | AliQADataMaker * qadm = static_cast<AliQADataMaker *>(fQADataMakers.At(i)); | |
606 | qadm->Reset(sameCycle); | |
607 | } | |
6441b07a | 608 | if (fRawReaderDelete) { |
609 | delete fRawReader ; | |
610 | fRawReader = NULL ; | |
611 | } | |
c65c502a | 612 | |
fff5167b | 613 | fCycleSame = sameCycle ; |
c65c502a | 614 | fESD = NULL ; |
615 | fESDTree = NULL ; | |
616 | fFirst = kTRUE ; | |
774ac967 | 617 | fNumberOfEvents = 999999 ; |
c65c502a | 618 | } |
619 | ||
6441b07a | 620 | //_____________________________________________________________________________ |
7c002d48 | 621 | TString AliQADataMakerSteer::Run(const char * detectors, AliRawReader * rawReader, const Bool_t sameCycle) |
6441b07a | 622 | { |
623 | //Runs all the QA data Maker for Raws only | |
7c002d48 | 624 | |
625 | fCycleSame = sameCycle ; | |
626 | fRawReader = rawReader ; | |
4d52736b | 627 | fDetectors = detectors ; |
7c002d48 | 628 | fDetectorsW = detectors ; |
629 | ||
95932286 | 630 | AliCDBManager* man = AliCDBManager::Instance() ; |
7930d770 | 631 | |
95932286 | 632 | if ( man->GetRun() == -1 ) {// check if run number not set previously and set it from raw data |
95932286 | 633 | rawReader->NextEvent() ; |
634 | man->SetRun(fRawReader->GetRunNumber()) ; | |
635 | rawReader->RewindEvents() ; | |
636 | } | |
637 | ||
ea9ce23f | 638 | if ( !Init(AliQA::kRAWS, "rec") ) |
639 | return kFALSE ; | |
640 | fRawReaderDelete = kFALSE ; | |
641 | ||
e5dedfe2 | 642 | DoIt(AliQA::kRAWS, "rec") ; |
643 | return fDetectorsW ; | |
04236e67 | 644 | } |
645 | ||
646 | //_____________________________________________________________________________ | |
7c002d48 | 647 | TString AliQADataMakerSteer::Run(const char * detectors, const char * fileName, const Bool_t sameCycle) |
04236e67 | 648 | { |
649 | //Runs all the QA data Maker for Raws only | |
7c002d48 | 650 | |
651 | fCycleSame = sameCycle ; | |
04236e67 | 652 | fDetectors = detectors ; |
e5dedfe2 | 653 | fDetectorsW = detectors ; |
04236e67 | 654 | |
95932286 | 655 | AliCDBManager* man = AliCDBManager::Instance() ; |
95932286 | 656 | if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun |
657 | AliRunLoader * rl = AliRunLoader::Open("galice.root") ; | |
658 | if ( ! rl ) { | |
659 | AliFatal("galice.root file not found in current directory") ; | |
660 | } else { | |
661 | rl->CdGAFile() ; | |
662 | rl->LoadgAlice() ; | |
663 | if ( ! rl->GetAliRun() ) { | |
664 | AliFatal("AliRun not found in galice.root") ; | |
665 | } else { | |
666 | rl->LoadHeader() ; | |
667 | man->SetRun(rl->GetHeader()->GetRun()); | |
668 | } | |
669 | } | |
670 | } | |
671 | ||
ea9ce23f | 672 | if ( !Init(AliQA::kRAWS, "rec", fileName) ) |
673 | return kFALSE ; | |
674 | ||
fff5167b | 675 | DoIt(AliQA::kRAWS, "rec") ; |
676 | return fDetectorsW ; | |
6441b07a | 677 | } |
678 | ||
312e6f8d | 679 | //_____________________________________________________________________________ |
7c002d48 | 680 | TString AliQADataMakerSteer::Run(const char * detectors, const AliQA::TASKINDEX_t taskIndex, Bool_t const sameCycle, const char * fileName ) |
312e6f8d | 681 | { |
682 | // Runs all the QA data Maker for every detector | |
7c002d48 | 683 | |
684 | fCycleSame = sameCycle ; | |
685 | fDetectors = detectors ; | |
686 | fDetectorsW = detectors ; | |
687 | ||
f6aa9d0e | 688 | TString mode ; |
04236e67 | 689 | if ( (taskIndex == AliQA::kHITS) || (taskIndex == AliQA::kSDIGITS) || (taskIndex == AliQA::kDIGITS) ) |
1aa42107 | 690 | mode = "sim" ; |
04236e67 | 691 | else if ( (taskIndex == AliQA::kRAWS) || (taskIndex == AliQA::kRECPOINTS) || (taskIndex == AliQA::kESDS) ) |
1aa42107 | 692 | mode = "rec" ; |
04236e67 | 693 | else { |
694 | AliError(Form("%s not implemented", AliQA::GetTaskName(taskIndex).Data())) ; | |
e5dedfe2 | 695 | return "" ; |
04236e67 | 696 | } |
fff5167b | 697 | |
65c771ca | 698 | AliCDBManager* man = AliCDBManager::Instance() ; |
95932286 | 699 | if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun |
700 | AliRunLoader * rl = AliRunLoader::Open("galice.root") ; | |
701 | if ( ! rl ) { | |
702 | AliFatal("galice.root file not found in current directory") ; | |
703 | } else { | |
704 | rl->CdGAFile() ; | |
705 | rl->LoadgAlice() ; | |
706 | if ( ! rl->GetAliRun() ) { | |
707 | AliFatal("AliRun not found in galice.root") ; | |
708 | } else { | |
709 | rl->LoadHeader() ; | |
710 | man->SetRun(rl->GetHeader()->GetRun()) ; | |
711 | } | |
712 | } | |
713 | } | |
714 | ||
ea9ce23f | 715 | if ( !Init(taskIndex, mode.Data(), fileName) ) |
716 | return kFALSE ; | |
717 | ||
f6aa9d0e | 718 | DoIt(taskIndex, mode.Data()) ; |
4d52736b | 719 | |
e5dedfe2 | 720 | return fDetectorsW ; |
6441b07a | 721 | |
14e1eccc | 722 | } |
4edbc5bc | 723 | |
724 | //_____________________________________________________________________________ | |
11032e1d | 725 | Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const char * year, const Int_t cycleNumber, const char * detectors) const |
4edbc5bc | 726 | { |
727 | // take the locasl QA data merge into a single file and save in OCDB | |
728 | Bool_t rv = kTRUE ; | |
729 | TString tmp(AliQA::GetQARefStorage()) ; | |
730 | if ( tmp.IsNull() ) { | |
731 | AliError("No storage defined, use AliQA::SetQARefStorage") ; | |
732 | return kFALSE ; | |
733 | } | |
734 | if ( !(tmp.Contains(AliQA::GetLabLocalOCDB()) || tmp.Contains(AliQA::GetLabAliEnOCDB())) ) { | |
735 | AliError(Form("%s is a wrong storage, use %s or %s", AliQA::GetQARefStorage(), AliQA::GetLabLocalOCDB().Data(), AliQA::GetLabAliEnOCDB().Data())) ; | |
736 | return kFALSE ; | |
737 | } | |
738 | TString sdet(detectors) ; | |
739 | sdet.ToUpper() ; | |
740 | TFile * inputFile ; | |
741 | if ( sdet.Contains("ALL") ) { | |
742 | rv = Merge(runNumber) ; | |
743 | if ( ! rv ) | |
744 | return kFALSE ; | |
614a7f99 | 745 | TString inputFileName(Form("Merged.%s.%d.root", AliQA::GetQADataFileName(), runNumber)) ; |
746 | inputFile = TFile::Open(inputFileName.Data()) ; | |
11032e1d | 747 | rv = SaveIt2OCDB(runNumber, inputFile, year) ; |
4edbc5bc | 748 | } else { |
749 | for (Int_t index = 0; index < AliQA::kNDET; index++) { | |
750 | if (sdet.Contains(AliQA::GetDetName(index))) { | |
614a7f99 | 751 | TString inputFileName(Form("%s.%s.%d.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber, cycleNumber)) ; |
752 | inputFile = TFile::Open(inputFileName.Data()) ; | |
11032e1d | 753 | rv *= SaveIt2OCDB(runNumber, inputFile, year) ; |
4edbc5bc | 754 | } |
755 | } | |
756 | } | |
757 | return rv ; | |
758 | } | |
759 | ||
760 | //_____________________________________________________________________________ | |
11032e1d | 761 | Bool_t AliQADataMakerSteer::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year) const |
4edbc5bc | 762 | { |
763 | // reads the TH1 from file and adds it to appropriate list before saving to OCDB | |
764 | Bool_t rv = kTRUE ; | |
765 | AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ; | |
766 | AliCDBManager* man = AliCDBManager::Instance() ; | |
f73f556a | 767 | if ( ! man->IsDefaultStorageSet() ) { |
a681ca96 | 768 | TString tmp( AliQA::GetQARefStorage() ) ; |
769 | if ( tmp.Contains(AliQA::GetLabLocalOCDB()) ) | |
770 | man->SetDefaultStorage(AliQA::GetQARefStorage()) ; | |
771 | else { | |
605cb8bb | 772 | TString tmp1(AliQA::GetQARefDefaultStorage()) ; |
773 | tmp1.Append(year) ; | |
774 | tmp1.Append("?user=alidaq") ; | |
775 | man->SetDefaultStorage(tmp1.Data()) ; | |
a681ca96 | 776 | } |
f73f556a | 777 | } |
a681ca96 | 778 | man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ; |
04236e67 | 779 | if(man->GetRun() < 0) |
780 | man->SetRun(runNumber); | |
781 | ||
11032e1d | 782 | AliCDBMetaData mdr ; |
783 | mdr.SetResponsible("yves schutz"); | |
784 | ||
4edbc5bc | 785 | for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) { |
786 | TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ; | |
787 | if ( detDir ) { | |
788 | AliInfo(Form("Entering %s", detDir->GetName())) ; | |
614a7f99 | 789 | TString detOCDBDir(Form("%s/%s/%s", AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName())) ; |
790 | AliCDBId idr(detOCDBDir.Data(), runNumber, AliCDBRunRange::Infinity()) ; | |
4edbc5bc | 791 | TList * listDetQAD = new TList() ; |
614a7f99 | 792 | TString listName(Form("%s QA data Reference", AliQA::GetDetName(detIndex))) ; |
11032e1d | 793 | mdr.SetComment("HMPID QA stuff"); |
4edbc5bc | 794 | listDetQAD->SetName(listName) ; |
795 | TList * taskList = detDir->GetListOfKeys() ; | |
796 | TIter nextTask(taskList) ; | |
797 | TKey * taskKey ; | |
798 | while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) { | |
799 | TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ; | |
800 | AliInfo(Form("Saving %s", taskDir->GetName())) ; | |
f73f556a | 801 | TObjArray * listTaskQAD = new TObjArray(100) ; |
4edbc5bc | 802 | listTaskQAD->SetName(taskKey->GetName()) ; |
803 | listDetQAD->Add(listTaskQAD) ; | |
804 | TList * histList = taskDir->GetListOfKeys() ; | |
805 | TIter nextHist(histList) ; | |
806 | TKey * histKey ; | |
807 | while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) { | |
808 | TObject * odata = taskDir->Get(histKey->GetName()) ; | |
a681ca96 | 809 | if ( !odata ) { |
810 | AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ; | |
811 | } else { | |
4edbc5bc | 812 | AliInfo(Form("Adding %s", histKey->GetName())) ; |
a681ca96 | 813 | if ( odata->IsA()->InheritsFrom("TH1") ) { |
814 | AliInfo(Form("Adding %s", histKey->GetName())) ; | |
815 | TH1 * hdata = static_cast<TH1*>(odata) ; | |
816 | listTaskQAD->Add(hdata) ; | |
817 | } | |
4edbc5bc | 818 | } |
819 | } | |
820 | } | |
4edbc5bc | 821 | man->Put(listDetQAD, idr, &mdr) ; |
822 | } | |
823 | } | |
824 | return rv ; | |
825 | } | |
a6f6970e | 826 |