]>
Commit | Line | Data |
---|---|---|
88cb7938 | 1 | ///////////////////////////////////////////////////////////////////////////////////////////// |
2 | // // | |
3 | // class AliDataLoader // | |
4 | // // | |
5 | // Container of all data needed for full // | |
6 | // description of each data type // | |
7 | // (Hits, Kine, ...) // | |
8 | // // | |
9 | // Each data loader has a basic standard setup of BaseLoaders // | |
10 | // which can be identuified by indexes (defined by EStdBasicLoaders) // | |
11 | // Data managed by these standard base loaders has fixed naming convention // | |
12 | // e.g. - tree with hits is always named TreeH // | |
13 | // (defined in AliLoader::fgkDefaultHitsContainerName) // | |
14 | // - task DtectorName+Name defined // | |
15 | // // | |
16 | // EStdBasicLoaders idx Object Type Description // | |
17 | // kData 0 TTree or TObject main data itself (hits,digits,...) // | |
18 | // kTask 1 TTask object producing main data // | |
19 | // kQA 2 TTree quality assurance tree // | |
20 | // kQATask 3 TTask task producing QA object // | |
21 | // // | |
22 | // // | |
23 | // User can define and add more basic loaders even Run Time. // | |
24 | // Caution: in order to save information about added base loader // | |
25 | // user must rewrite Run Loader to galice.file, overwriting old setup // | |
26 | // // | |
27 | ///////////////////////////////////////////////////////////////////////////////////////////// | |
28 | ||
a9bbb414 | 29 | /* $Id$ */ |
30 | ||
31 | #include <TBits.h> | |
88cb7938 | 32 | #include <TFile.h> |
a9bbb414 | 33 | #include <TROOT.h> |
88cb7938 | 34 | #include <TString.h> |
88cb7938 | 35 | |
a9bbb414 | 36 | #include "AliDataLoader.h" |
21bf7095 | 37 | #include "AliLog.h" |
a9bbb414 | 38 | #include "AliObjectLoader.h" |
88cb7938 | 39 | #include "AliRunLoader.h" |
a9bbb414 | 40 | #include "AliTreeLoader.h" |
88cb7938 | 41 | |
42 | ClassImp(AliDataLoader) | |
43 | ||
a9bbb414 | 44 | //______________________________________________________________________________ |
88cb7938 | 45 | AliDataLoader::AliDataLoader(): |
46 | fFileName(0), | |
47 | fFile(0x0), | |
48 | fDirectory(0x0), | |
49 | fFileOption(), | |
50 | fCompressionLevel(2), | |
18b43626 | 51 | fNEventsPerFile(0), |
88cb7938 | 52 | fBaseLoaders(0x0), |
53 | fHasTask(kFALSE), | |
54 | fTaskName(), | |
55 | fParentalTask(0x0), | |
56 | fEventFolder(0x0), | |
57 | fFolder(0x0) | |
58 | { | |
59 | ||
60 | } | |
88cb7938 | 61 | |
a9bbb414 | 62 | //______________________________________________________________________________ |
63 | AliDataLoader::AliDataLoader(const char* filename, const char* contname, | |
64 | const char* name, Option_t* opt): | |
88cb7938 | 65 | TNamed(name,name), |
66 | fFileName(filename), | |
67 | fFile(0x0), | |
68 | fDirectory(0x0), | |
69 | fFileOption(0), | |
70 | fCompressionLevel(2), | |
18b43626 | 71 | fNEventsPerFile(0), |
88cb7938 | 72 | fBaseLoaders(new TObjArray(4)), |
73 | fHasTask(kFALSE), | |
74 | fTaskName(), | |
75 | fParentalTask(0x0), | |
76 | fEventFolder(0x0), | |
77 | fFolder(0x0) | |
78 | { | |
a9bbb414 | 79 | //constructor |
80 | // creates a 0 loader, depending on option, default "T" is specialized loader for trees | |
81 | // else standard object loader | |
82 | // trees needs special care, becouse we need to set dir before writing | |
21bf7095 | 83 | AliDebug(1, Form("File name is %s",fFileName.Data())); |
a9bbb414 | 84 | |
88cb7938 | 85 | TString option(opt); |
86 | AliBaseLoader* bl; | |
87 | if (option.CompareTo("T",TString::kIgnoreCase) == 0) | |
88 | bl = new AliTreeLoader(contname,this); | |
89 | else | |
90 | bl = new AliObjectLoader(contname,this); | |
91 | fBaseLoaders->AddAt(bl,kData); | |
92 | ||
93 | } | |
a9bbb414 | 94 | |
95 | //______________________________________________________________________________ | |
90e48c0c | 96 | AliDataLoader::AliDataLoader(const AliDataLoader& source) : |
97 | TNamed(source), | |
98 | fFileName(source.fFileName), | |
99 | fFile(source.fFile), | |
100 | fDirectory(source.fDirectory), | |
101 | fFileOption(source.fFileOption), | |
102 | fCompressionLevel(source.fCompressionLevel), | |
103 | fNEventsPerFile(source.fNEventsPerFile), | |
104 | fBaseLoaders(source.fBaseLoaders), | |
105 | fHasTask(source.fHasTask), | |
106 | fTaskName(source.fTaskName), | |
107 | fParentalTask(source.fParentalTask), | |
108 | fEventFolder(source.fEventFolder), | |
109 | fFolder(source.fFolder) | |
110 | { | |
a9bbb414 | 111 | // |
d0d4a6b3 | 112 | // copy constructor |
a9bbb414 | 113 | // |
21bf7095 | 114 | AliFatal("Copy constructor not implemented"); |
d0d4a6b3 | 115 | } |
a9bbb414 | 116 | |
117 | ||
118 | //______________________________________________________________________________ | |
119 | AliDataLoader& AliDataLoader::operator=(const AliDataLoader& /*source*/) | |
120 | { | |
121 | // | |
d0d4a6b3 | 122 | // Assignment operator |
a9bbb414 | 123 | // |
21bf7095 | 124 | AliFatal("Assignment operator not implemented"); |
d0d4a6b3 | 125 | return *this; |
126 | } | |
88cb7938 | 127 | |
a9bbb414 | 128 | |
129 | //______________________________________________________________________________ | |
88cb7938 | 130 | AliDataLoader::~AliDataLoader() |
131 | { | |
a9bbb414 | 132 | // |
133 | //dtor | |
134 | // | |
135 | UnloadAll(); | |
88cb7938 | 136 | } |
88cb7938 | 137 | |
a9bbb414 | 138 | //______________________________________________________________________________ |
88cb7938 | 139 | Int_t AliDataLoader::SetEvent() |
140 | { | |
a9bbb414 | 141 | // |
142 | // The same that GetEvent but do not post data to folders | |
143 | // | |
144 | AliRunLoader* rl = GetRunLoader(); | |
145 | if (rl == 0x0) | |
146 | { | |
147 | AliError("Can not get RunGettr"); | |
148 | return 1; | |
149 | } | |
150 | ||
151 | Int_t evno = rl->GetEventNumber(); | |
152 | ||
153 | TIter next(fBaseLoaders); | |
154 | AliBaseLoader* bl; | |
155 | while ((bl = (AliBaseLoader*)next())) | |
156 | { | |
157 | if (bl->DoNotReload() == kFALSE) bl->Clean(); | |
158 | } | |
159 | ||
160 | if(fFile) | |
161 | { | |
162 | if (CheckReload()) | |
163 | { | |
164 | delete fFile; | |
165 | fFile = 0x0; | |
166 | AliDebug(1, Form("Reloading new file. File opt is %s",fFileOption.Data())); | |
167 | OpenFile(fFileOption); | |
168 | } | |
169 | ||
170 | fDirectory = AliLoader::ChangeDir(fFile,evno); | |
171 | if (fDirectory == 0x0) | |
172 | { | |
173 | AliError(Form("Can not chage directory in file %s",fFile->GetName())); | |
174 | return 1; | |
175 | } | |
176 | } | |
177 | return 0; | |
88cb7938 | 178 | } |
88cb7938 | 179 | |
a9bbb414 | 180 | //______________________________________________________________________________ |
88cb7938 | 181 | Int_t AliDataLoader::GetEvent() |
182 | { | |
a9bbb414 | 183 | // posts all loaded data from files to White Board |
184 | // event number is defined in RunLoader | |
185 | // | |
186 | //returns: | |
187 | // 0 - in case of no error | |
188 | // 1 - event not found | |
189 | // | |
190 | //for each base laoder post, if was loaded before GetEvent | |
191 | ||
192 | //call set event to switch to new directory in file | |
193 | ||
194 | ||
195 | //post all data that were loaded before | |
196 | // ->SetEvent does not call Unload, but only cleans White Board | |
197 | // such IsLoaded flag stays untached | |
198 | ||
199 | if ( AliLoader::TestFileOption(fFileOption) == kTRUE ) //if file is read or update mode try to post | |
200 | { //in other case there is no sense to post: file is new | |
201 | TIter nextbl(fBaseLoaders); | |
202 | AliBaseLoader* bl; | |
203 | while ((bl = (AliBaseLoader*)nextbl())) | |
204 | { | |
205 | if (bl->IsLoaded()) | |
206 | { | |
207 | if (bl->DoNotReload() == kFALSE) bl->Post(); | |
208 | } | |
209 | } | |
210 | } | |
211 | return 0; | |
88cb7938 | 212 | } |
88cb7938 | 213 | |
a9bbb414 | 214 | //______________________________________________________________________________ |
88cb7938 | 215 | Int_t AliDataLoader::OpenFile(Option_t* opt) |
216 | { | |
a9bbb414 | 217 | //Opens file named 'filename', and assigns pointer to it to 'file' |
218 | //jumps to fDirectoryectory corresponding to current event and stores the pointer to it in 'fDirectory' | |
219 | //option 'opt' is passed to TFile::Open | |
88cb7938 | 220 | if (fFile) |
a9bbb414 | 221 | { |
222 | if(fFile->IsOpen() == kTRUE) | |
223 | { | |
224 | AliWarning(Form(" File %s already opened. First close it.",fFile->GetName())); | |
225 | return 0; | |
226 | } | |
227 | else | |
228 | { | |
229 | AliWarning(Form("Pointer to file %s is not null, but file is not opened", | |
230 | fFile->GetName())); | |
231 | delete fFile; | |
232 | fFile = 0x0; | |
233 | } | |
234 | } | |
88cb7938 | 235 | |
236 | TString fname(SetFileOffset(fFileName)); | |
237 | ||
238 | fFile = (TFile *)(gROOT->GetListOfFiles()->FindObject(fname)); | |
239 | if (fFile) | |
a9bbb414 | 240 | { |
241 | if(fFile->IsOpen() == kTRUE) | |
242 | { | |
243 | AliWarning(Form("File %s already opened by sombody else. First close it.", | |
244 | fFile->GetName())); | |
245 | return 0; | |
246 | } | |
247 | } | |
88cb7938 | 248 | |
249 | fFileOption = opt; | |
250 | fFile = TFile::Open(fname,fFileOption);//open the file | |
251 | if (fFile == 0x0) | |
a9bbb414 | 252 | {//file is null |
253 | AliError(Form("Can not open file %s",fname.Data())); | |
254 | return 1; | |
255 | } | |
88cb7938 | 256 | if (fFile->IsOpen() == kFALSE) |
a9bbb414 | 257 | {//file is null |
258 | AliError(Form("Can not open file %s",fname.Data())); | |
259 | return 1; | |
260 | } | |
261 | ||
88cb7938 | 262 | fFile->SetCompressionLevel(fCompressionLevel); |
263 | ||
264 | AliRunLoader* rg = GetRunLoader(); | |
265 | if (rg == 0x0) | |
a9bbb414 | 266 | { |
267 | AliError("Can not find Run-Loader in folder."); | |
268 | return 2; | |
269 | } | |
88cb7938 | 270 | Int_t evno = rg->GetEventNumber(); |
271 | ||
272 | fDirectory = AliLoader::ChangeDir(fFile,evno); | |
273 | if (fDirectory == 0x0) | |
a9bbb414 | 274 | { |
275 | AliError(Form("Can not chage fDirectory in file %s.",fFile->GetName())); | |
276 | return 3; | |
277 | } | |
88cb7938 | 278 | return 0; |
279 | } | |
88cb7938 | 280 | |
a9bbb414 | 281 | //______________________________________________________________________________ |
88cb7938 | 282 | void AliDataLoader::Unload() |
283 | { | |
a9bbb414 | 284 | // |
285 | //unloads main data - shortcut method | |
286 | // | |
88cb7938 | 287 | GetBaseLoader(0)->Unload(); |
288 | } | |
88cb7938 | 289 | |
a9bbb414 | 290 | //______________________________________________________________________________ |
88cb7938 | 291 | void AliDataLoader::UnloadAll() |
292 | { | |
a9bbb414 | 293 | // |
294 | // Unloads all data and tasks | |
295 | // | |
296 | if ( fFile == 0x0 ) return; //nothing loaded | |
297 | ||
298 | TIter next(fBaseLoaders); | |
299 | AliBaseLoader* bl; | |
300 | while ((bl = (AliBaseLoader*)next())) | |
301 | { | |
302 | bl->Unload(); | |
303 | } | |
88cb7938 | 304 | } |
88cb7938 | 305 | |
a9bbb414 | 306 | |
307 | //______________________________________________________________________________ | |
88cb7938 | 308 | Int_t AliDataLoader::Reload() |
309 | { | |
a9bbb414 | 310 | // |
311 | // Unloads and loads data again | |
312 | // | |
313 | if ( fFile == 0x0 ) return 0; | |
314 | ||
315 | TBits loaded(fBaseLoaders->GetEntries()); | |
316 | TIter next(fBaseLoaders); | |
317 | AliBaseLoader* bl; | |
318 | ||
319 | Int_t i = 0; | |
320 | while ((bl = (AliBaseLoader*)next())) | |
321 | { | |
322 | if (bl->IsLoaded()) | |
323 | { | |
324 | loaded.SetBitNumber(i++,kTRUE); | |
325 | bl->Unload(); | |
326 | } | |
327 | } | |
328 | ||
329 | Int_t retval; | |
330 | i = 0; | |
331 | next.Reset(); | |
332 | while ((bl = (AliBaseLoader*)next())) | |
333 | { | |
334 | if (loaded.TestBitNumber(i++)) | |
335 | { | |
336 | retval = bl->Load(fFileOption); | |
337 | if (retval) | |
338 | { | |
339 | AliError(Form("Error occur while loading %s",bl->GetName())); | |
340 | return retval; | |
341 | } | |
342 | } | |
343 | } | |
344 | return 0; | |
345 | } | |
88cb7938 | 346 | |
88cb7938 | 347 | |
a9bbb414 | 348 | //______________________________________________________________________________ |
88cb7938 | 349 | Int_t AliDataLoader::WriteData(Option_t* opt) |
350 | { | |
a9bbb414 | 351 | // |
352 | // Writes primary data == first BaseLoader | |
353 | // | |
21bf7095 | 354 | AliDebug(1, Form("Writing %s container for %s data. Option is %s.", |
355 | GetBaseLoader(0)->GetName(),GetName(),opt)); | |
88cb7938 | 356 | return GetBaseLoader(0)->WriteData(opt); |
357 | } | |
88cb7938 | 358 | |
a9bbb414 | 359 | //______________________________________________________________________________ |
88cb7938 | 360 | Int_t AliDataLoader::Load(Option_t* opt) |
361 | { | |
a9bbb414 | 362 | // |
363 | // Writes primary data == first BaseLoader | |
364 | // | |
88cb7938 | 365 | return GetBaseLoader(0)->Load(opt); |
366 | } | |
88cb7938 | 367 | |
a9bbb414 | 368 | //______________________________________________________________________________ |
88cb7938 | 369 | Int_t AliDataLoader::SetEventFolder(TFolder* eventfolder) |
370 | { | |
a9bbb414 | 371 | // |
372 | // Sets the event folder | |
373 | // | |
374 | if (eventfolder == 0x0) | |
375 | { | |
376 | AliError("Stupid joke. Argument is NULL"); | |
377 | return 1; | |
378 | } | |
379 | AliDebug(1, Form("name = %s Setting Event Folder named %s.", | |
380 | GetName(),eventfolder->GetName())); | |
381 | ||
382 | fEventFolder = eventfolder; | |
383 | return 0; | |
88cb7938 | 384 | } |
88cb7938 | 385 | |
a9bbb414 | 386 | |
387 | //______________________________________________________________________________ | |
88cb7938 | 388 | Int_t AliDataLoader::SetFolder(TFolder* folder) |
389 | { | |
d0d4a6b3 | 390 | // Sets the folder and the data loaders |
a9bbb414 | 391 | if (folder == 0x0) |
392 | { | |
393 | AliError("Stupid joke. Argument is NULL"); | |
88cb7938 | 394 | return 1; |
a9bbb414 | 395 | } |
396 | ||
397 | AliDebug(1, Form("name = %s Setting folder named %s.",GetName(),folder->GetName())); | |
398 | ||
399 | fFolder = folder; | |
400 | TIter next(fBaseLoaders); | |
401 | AliBaseLoader* bl; | |
402 | ||
403 | while ((bl = (AliBaseLoader*)next())) | |
404 | { | |
405 | bl->SetDataLoader(this); | |
406 | } | |
407 | ||
408 | return 0; | |
88cb7938 | 409 | } |
88cb7938 | 410 | |
a9bbb414 | 411 | //______________________________________________________________________________ |
88cb7938 | 412 | TFolder* AliDataLoader::GetEventFolder() |
413 | { | |
a9bbb414 | 414 | // |
415 | // Get EVENT folder | |
416 | // Data that are changing from event to event, even in single run | |
417 | // | |
21bf7095 | 418 | AliDebug(1, "EF = %#x"); |
88cb7938 | 419 | return fEventFolder; |
420 | } | |
88cb7938 | 421 | |
a9bbb414 | 422 | //______________________________________________________________________________ |
88cb7938 | 423 | AliRunLoader* AliDataLoader::GetRunLoader() |
424 | { | |
a9bbb414 | 425 | // |
426 | // Gets the run-loader from event folder | |
427 | // | |
88cb7938 | 428 | AliRunLoader* rg = 0x0; |
429 | TFolder* ef = GetEventFolder(); | |
430 | if (ef == 0x0) | |
431 | { | |
21bf7095 | 432 | AliError("Can not get event folder."); |
88cb7938 | 433 | return 0; |
434 | } | |
024a7e64 | 435 | rg = dynamic_cast<AliRunLoader*>(ef->FindObject(AliRunLoader::GetRunLoaderName())); |
88cb7938 | 436 | return rg; |
437 | } | |
438 | ||
a9bbb414 | 439 | //______________________________________________________________________________ |
88cb7938 | 440 | void AliDataLoader::CloseFile() |
441 | { | |
a9bbb414 | 442 | // |
443 | // Closes file | |
444 | // | |
88cb7938 | 445 | TIter next(fBaseLoaders); |
446 | AliBaseLoader* bl; | |
447 | while ((bl = (AliBaseLoader*)next())) | |
a9bbb414 | 448 | { |
449 | if (bl->IsLoaded()) return; | |
450 | } | |
88cb7938 | 451 | |
21bf7095 | 452 | AliDebug(1, "Closing and deleting (object) file."); |
a9bbb414 | 453 | |
88cb7938 | 454 | delete fFile; |
455 | fFile = 0x0; | |
456 | fDirectory = 0x0; | |
457 | } | |
88cb7938 | 458 | |
a9bbb414 | 459 | |
460 | //______________________________________________________________________________ | |
88cb7938 | 461 | void AliDataLoader::Clean() |
462 | { | |
a9bbb414 | 463 | // |
464 | // Cleans main data | |
465 | // | |
88cb7938 | 466 | GetBaseLoader(0)->Clean(); |
a9bbb414 | 467 | } |
88cb7938 | 468 | |
a9bbb414 | 469 | //______________________________________________________________________________ |
88cb7938 | 470 | void AliDataLoader::CleanAll() |
471 | { | |
a9bbb414 | 472 | // |
473 | // Cleans all folders and tasks | |
474 | // | |
88cb7938 | 475 | TIter next(fBaseLoaders); |
476 | AliBaseLoader* bl; | |
477 | while ((bl = (AliBaseLoader*)next())) | |
a9bbb414 | 478 | { |
88cb7938 | 479 | bl->Clean(); |
a9bbb414 | 480 | } |
88cb7938 | 481 | } |
88cb7938 | 482 | |
a9bbb414 | 483 | //______________________________________________________________________________ |
88cb7938 | 484 | void AliDataLoader::SetFileNameSuffix(const TString& suffix) |
485 | { | |
a9bbb414 | 486 | // |
487 | // adds the suffix before ".root", | |
488 | // e.g. TPC.Digits.root -> TPC.DigitsMerged.root | |
489 | // made on Jiri Chudoba demand | |
490 | // | |
21bf7095 | 491 | AliDebug(1, Form("suffix=%s",suffix.Data())); |
492 | AliDebug(1, Form(" Digits File Name before: %s",fFileName.Data())); | |
a9bbb414 | 493 | |
88cb7938 | 494 | static TString dotroot(".root"); |
495 | const TString& suffixdotroot = suffix + dotroot; | |
496 | fFileName = fFileName.ReplaceAll(dotroot,suffixdotroot); | |
a9bbb414 | 497 | |
21bf7095 | 498 | AliDebug(1, Form(" after : %s",fFileName.Data())); |
88cb7938 | 499 | } |
88cb7938 | 500 | |
a9bbb414 | 501 | //______________________________________________________________________________ |
88cb7938 | 502 | Bool_t AliDataLoader::CheckReload() |
503 | { | |
a9bbb414 | 504 | // |
505 | // Checks if we have to reload given file | |
506 | // | |
507 | if (fFile == 0x0) return kFALSE; | |
508 | TString tmp = SetFileOffset(fFileName); | |
509 | if (tmp.CompareTo(fFile->GetName())) return kTRUE; //file must be reloaded | |
510 | return kFALSE; | |
88cb7938 | 511 | } |
88cb7938 | 512 | |
a9bbb414 | 513 | //______________________________________________________________________________ |
88cb7938 | 514 | const TString AliDataLoader::SetFileOffset(const TString& fname) |
515 | { | |
a9bbb414 | 516 | // |
517 | // Return fname | |
518 | // | |
88cb7938 | 519 | Long_t offset = (Long_t)GetRunLoader()->GetFileOffset(); |
18b43626 | 520 | if (fNEventsPerFile > 0) { |
521 | offset = GetRunLoader()->GetEventNumber()/fNEventsPerFile; | |
522 | } | |
88cb7938 | 523 | if (offset < 1) return fname; |
a9bbb414 | 524 | |
88cb7938 | 525 | TString soffset; |
526 | soffset += offset;//automatic conversion to string | |
527 | TString dotroot(".root"); | |
528 | const TString& offfsetdotroot = offset + dotroot; | |
529 | TString out = fname; | |
530 | out = out.ReplaceAll(dotroot,offfsetdotroot); | |
21bf7095 | 531 | AliDebug(1, Form("in=%s out=%s.",fname.Data(),out.Data())); |
88cb7938 | 532 | return out; |
88cb7938 | 533 | } |
88cb7938 | 534 | |
a9bbb414 | 535 | //______________________________________________________________________________ |
88cb7938 | 536 | void AliDataLoader::SetFileOption(Option_t* newopt) |
537 | { | |
a9bbb414 | 538 | // |
539 | // Sets file option | |
540 | // | |
88cb7938 | 541 | if (fFileOption.CompareTo(newopt) == 0) return; |
542 | fFileOption = newopt; | |
543 | Reload(); | |
544 | } | |
88cb7938 | 545 | |
a9bbb414 | 546 | //______________________________________________________________________________ |
88cb7938 | 547 | void AliDataLoader::SetCompressionLevel(Int_t cl) |
548 | { | |
a9bbb414 | 549 | // |
550 | // Sets comression level for data defined by di | |
551 | // | |
88cb7938 | 552 | fCompressionLevel = cl; |
553 | if (fFile) fFile->SetCompressionLevel(cl); | |
554 | } | |
88cb7938 | 555 | |
a9bbb414 | 556 | //______________________________________________________________________________ |
88cb7938 | 557 | void AliDataLoader::MakeTree() |
558 | { | |
a9bbb414 | 559 | // |
d0d4a6b3 | 560 | // Makes tree for the current data loader |
a9bbb414 | 561 | // |
88cb7938 | 562 | AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(fBaseLoaders->At(0)); |
563 | if (tl == 0x0) | |
564 | { | |
21bf7095 | 565 | AliError("Can not make a tree because main base loader is not a tree loader"); |
88cb7938 | 566 | return; |
567 | } | |
568 | tl->MakeTree(); | |
569 | } | |
88cb7938 | 570 | |
a9bbb414 | 571 | //______________________________________________________________________________ |
88cb7938 | 572 | Bool_t AliDataLoader::IsFileWritable() const |
573 | { | |
a9bbb414 | 574 | // |
575 | // Returns true if file is writable | |
576 | // | |
577 | return (fFile)?fFile->IsWritable():kFALSE; | |
88cb7938 | 578 | } |
88cb7938 | 579 | |
a9bbb414 | 580 | //______________________________________________________________________________ |
88cb7938 | 581 | Bool_t AliDataLoader::IsFileOpen() const |
582 | { | |
a9bbb414 | 583 | // |
584 | // Returns true if file is writable | |
585 | // | |
586 | return (fFile)?fFile->IsOpen():kFALSE; | |
88cb7938 | 587 | } |
88cb7938 | 588 | |
a9bbb414 | 589 | //______________________________________________________________________________ |
88cb7938 | 590 | Bool_t AliDataLoader::IsOptionContrary(const TString& option) const |
591 | { | |
a9bbb414 | 592 | // Checks if passed option is contrary with file open option |
593 | // which is passed option "writable" and existing option not wriable | |
594 | // in reverse case it is no harm so it is NOT contrary | |
88cb7938 | 595 | if (fFile == 0x0) return kFALSE; //file is not opened - no problem |
596 | ||
597 | if ( ( AliLoader::IsOptionWritable(option) == kTRUE ) && // passed option is writable and | |
598 | ( AliLoader::IsOptionWritable(fFileOption) == kFALSE ) ) // existing one is not writable | |
599 | { | |
600 | return kTRUE; | |
601 | } | |
a9bbb414 | 602 | |
88cb7938 | 603 | return kFALSE; |
604 | } | |
a9bbb414 | 605 | |
606 | ||
607 | //______________________________________________________________________________ | |
88cb7938 | 608 | void AliDataLoader::AddBaseLoader(AliBaseLoader* bl) |
609 | { | |
a9bbb414 | 610 | //Adds a base loader to lits of base loaders managed by this data loader |
611 | //Managed data/task will be stored in proper root directory, | |
612 | //and posted to | |
613 | // - in case of tree/object - data folder connected with detector associated with this data loader | |
614 | // - in case of task - parental task which defined in this AliTaskLoader | |
615 | ||
616 | if (bl == 0x0) | |
617 | { | |
618 | AliWarning("Pointer is null."); | |
619 | return; | |
620 | } | |
621 | ||
622 | TObject* obj = fBaseLoaders->FindObject(bl->GetName()); | |
623 | if (obj) | |
624 | { | |
625 | AliError("Can not add this base loader."); | |
626 | AliError(Form("There exists already base loader which manages data named %s for this detector.",obj->GetName())); | |
627 | return; | |
628 | } | |
88cb7938 | 629 | |
a9bbb414 | 630 | fBaseLoaders->Add(bl); |
88cb7938 | 631 | } |
632 | ||
a9bbb414 | 633 | //______________________________________________________________________________ |
88cb7938 | 634 | AliBaseLoader* AliDataLoader::GetBaseLoader(const TString& name) const |
635 | { | |
a9bbb414 | 636 | // |
637 | // Return pointer to base loader | |
638 | // | |
88cb7938 | 639 | return dynamic_cast<AliBaseLoader*>(fBaseLoaders->FindObject(name)); |
640 | } | |
88cb7938 | 641 | |
a9bbb414 | 642 | //______________________________________________________________________________ |
88cb7938 | 643 | AliBaseLoader* AliDataLoader::GetBaseLoader(Int_t n) const |
644 | { | |
a9bbb414 | 645 | // |
d0d4a6b3 | 646 | // Gets the n-th base loader (what is n?) |
a9bbb414 | 647 | // |
648 | return dynamic_cast<AliBaseLoader*>(fBaseLoaders->At(n)); | |
88cb7938 | 649 | } |
88cb7938 | 650 | |
a9bbb414 | 651 | //______________________________________________________________________________ |
88cb7938 | 652 | TTree* AliDataLoader::Tree() const |
653 | { | |
a9bbb414 | 654 | // Returns tree from the main base loader |
655 | // it is just shortcut method for comfort of user | |
656 | // main storage object does not have to be Tree - | |
657 | // that is why first we need to check if it is a TreeLoader | |
658 | AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(GetBaseLoader(0)); | |
659 | if (tl == 0x0) return 0x0; | |
660 | return tl->Tree(); | |
88cb7938 | 661 | } |
88cb7938 | 662 | |
a9bbb414 | 663 | //______________________________________________________________________________ |
88cb7938 | 664 | void AliDataLoader::SetDirName(TString& dirname) |
665 | { | |
a9bbb414 | 666 | // |
d0d4a6b3 | 667 | // Sets the directory name where the files will be stored |
a9bbb414 | 668 | // |
21bf7095 | 669 | AliDebug(10, Form("FileName before %s",fFileName.Data())); |
88cb7938 | 670 | Int_t n = fFileName.Last('/'); |
21bf7095 | 671 | AliDebug(10, Form("Slash found on pos %d",n)); |
88cb7938 | 672 | if (n > 0) fFileName = fFileName.Remove(0,n+1); |
21bf7095 | 673 | AliDebug(10, Form("Core FileName %s",fFileName.Data())); |
fca6cd9f | 674 | fFileName = dirname + fFileName; |
21bf7095 | 675 | AliDebug(10, Form("FileName after %s",fFileName.Data())); |
88cb7938 | 676 | } |
a9bbb414 | 677 | |
678 | //______________________________________________________________________________ | |
88cb7938 | 679 | AliObjectLoader* AliDataLoader::GetBaseDataLoader() |
680 | { | |
a9bbb414 | 681 | // |
d0d4a6b3 | 682 | // Gets the base data loader |
a9bbb414 | 683 | // |
684 | return dynamic_cast<AliObjectLoader*>(GetBaseLoader(kData)); | |
88cb7938 | 685 | } |
a9bbb414 | 686 | |
687 | //______________________________________________________________________________ | |
88cb7938 | 688 | AliTaskLoader* AliDataLoader::GetBaseTaskLoader() |
689 | { | |
a9bbb414 | 690 | // |
d0d4a6b3 | 691 | // Gets the base task loader |
a9bbb414 | 692 | // |
693 | return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kTask)); | |
88cb7938 | 694 | } |
a9bbb414 | 695 | |
696 | //______________________________________________________________________________ | |
88cb7938 | 697 | AliBaseLoader* AliDataLoader::GetBaseQALoader() |
698 | { | |
a9bbb414 | 699 | // |
d0d4a6b3 | 700 | // Gets the base QA loader |
a9bbb414 | 701 | // |
88cb7938 | 702 | return GetBaseLoader(kQA); |
703 | } | |
a9bbb414 | 704 | |
705 | //______________________________________________________________________________ | |
88cb7938 | 706 | AliTaskLoader* AliDataLoader::GetBaseQATaskLoader() |
707 | { | |
a9bbb414 | 708 | // |
709 | // Returns pointer to QA base loader | |
710 | // | |
711 | return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kQATask)); | |
88cb7938 | 712 | } |
a9bbb414 | 713 | |
714 | //______________________________________________________________________________ | |
88cb7938 | 715 | void AliDataLoader::SetBaseDataLoader(AliBaseLoader* bl) |
716 | { | |
a9bbb414 | 717 | // |
718 | // Sets data base loader | |
719 | // | |
88cb7938 | 720 | if (bl == 0x0) |
a9bbb414 | 721 | { |
722 | AliError("Parameter is null"); | |
723 | return; | |
724 | } | |
88cb7938 | 725 | if (GetBaseDataLoader()) delete GetBaseDataLoader(); |
726 | fBaseLoaders->AddAt(bl,kData); | |
727 | } | |
a9bbb414 | 728 | |
729 | //______________________________________________________________________________ | |
88cb7938 | 730 | void AliDataLoader::SetBaseTaskLoader(AliTaskLoader* bl) |
731 | { | |
a9bbb414 | 732 | // |
733 | // Sets Task base loader | |
734 | // | |
88cb7938 | 735 | if (bl == 0x0) |
736 | { | |
21bf7095 | 737 | AliError("Parameter is null"); |
88cb7938 | 738 | return; |
739 | } | |
740 | if (GetBaseTaskLoader()) delete GetBaseTaskLoader(); | |
741 | fBaseLoaders->AddAt(bl,kTask); | |
742 | } | |
a9bbb414 | 743 | |
744 | //______________________________________________________________________________ | |
88cb7938 | 745 | void AliDataLoader::SetBaseQALoader(AliBaseLoader* bl) |
746 | { | |
a9bbb414 | 747 | // |
748 | // Sets QA base loader | |
749 | // | |
88cb7938 | 750 | if (bl == 0x0) |
a9bbb414 | 751 | { |
752 | AliError("Parameter is null"); | |
753 | return; | |
754 | } | |
88cb7938 | 755 | if (GetBaseQALoader()) delete GetBaseQALoader(); |
756 | fBaseLoaders->AddAt(bl,kQA); | |
757 | } | |
a9bbb414 | 758 | |
759 | //______________________________________________________________________________ | |
88cb7938 | 760 | void AliDataLoader::SetBaseQATaskLoader(AliTaskLoader* bl) |
761 | { | |
a9bbb414 | 762 | // |
763 | // Sets QA Task base loader | |
764 | // | |
88cb7938 | 765 | if (bl == 0x0) |
a9bbb414 | 766 | { |
767 | AliError("Parameter is null"); | |
768 | return; | |
88cb7938 | 769 | } |
770 | if (GetBaseQATaskLoader()) delete GetBaseQATaskLoader(); | |
771 | fBaseLoaders->AddAt(bl,kQATask); | |
772 | } | |
a9bbb414 | 773 | |
774 | //______________________________________________________________________________ | |
f0f6f856 | 775 | void AliDataLoader::Synchronize() |
776 | { | |
a9bbb414 | 777 | // |
778 | // Synchronizes all writable files | |
779 | // | |
504b172d | 780 | if ( fFile ) fFile->Flush(); |
f0f6f856 | 781 | } |
88cb7938 | 782 | |
88cb7938 | 783 | |
784 |