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