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