]>
Commit | Line | Data |
---|---|---|
88cb7938 | 1 | #include <AliDataLoader.h> |
2 | //__________________________________________ | |
3 | ///////////////////////////////////////////////////////////////////////////////////////////// | |
4 | // // | |
5 | // class AliDataLoader // | |
6 | // // | |
7 | // Container of all data needed for full // | |
8 | // description of each data type // | |
9 | // (Hits, Kine, ...) // | |
10 | // // | |
11 | // Each data loader has a basic standard setup of BaseLoaders // | |
12 | // which can be identuified by indexes (defined by EStdBasicLoaders) // | |
13 | // Data managed by these standard base loaders has fixed naming convention // | |
14 | // e.g. - tree with hits is always named TreeH // | |
15 | // (defined in AliLoader::fgkDefaultHitsContainerName) // | |
16 | // - task DtectorName+Name defined // | |
17 | // // | |
18 | // EStdBasicLoaders idx Object Type Description // | |
19 | // kData 0 TTree or TObject main data itself (hits,digits,...) // | |
20 | // kTask 1 TTask object producing main data // | |
21 | // kQA 2 TTree quality assurance tree // | |
22 | // kQATask 3 TTask task producing QA object // | |
23 | // // | |
24 | // // | |
25 | // User can define and add more basic loaders even Run Time. // | |
26 | // Caution: in order to save information about added base loader // | |
27 | // user must rewrite Run Loader to galice.file, overwriting old setup // | |
28 | // // | |
29 | ///////////////////////////////////////////////////////////////////////////////////////////// | |
30 | ||
31 | #include <TROOT.h> | |
32 | #include <TFile.h> | |
33 | #include <TString.h> | |
34 | #include <TBits.h> | |
88cb7938 | 35 | |
21bf7095 | 36 | #include "AliLog.h" |
88cb7938 | 37 | #include "AliRunLoader.h" |
38 | ||
39 | ClassImp(AliDataLoader) | |
40 | ||
41 | AliDataLoader::AliDataLoader(): | |
42 | fFileName(0), | |
43 | fFile(0x0), | |
44 | fDirectory(0x0), | |
45 | fFileOption(), | |
46 | fCompressionLevel(2), | |
18b43626 | 47 | fNEventsPerFile(0), |
88cb7938 | 48 | fBaseLoaders(0x0), |
49 | fHasTask(kFALSE), | |
50 | fTaskName(), | |
51 | fParentalTask(0x0), | |
52 | fEventFolder(0x0), | |
53 | fFolder(0x0) | |
54 | { | |
55 | ||
56 | } | |
57 | /*****************************************************************************/ | |
58 | ||
59 | AliDataLoader::AliDataLoader(const char* filename, const char* contname, const char* name, Option_t* opt): | |
60 | TNamed(name,name), | |
61 | fFileName(filename), | |
62 | fFile(0x0), | |
63 | fDirectory(0x0), | |
64 | fFileOption(0), | |
65 | fCompressionLevel(2), | |
18b43626 | 66 | fNEventsPerFile(0), |
88cb7938 | 67 | fBaseLoaders(new TObjArray(4)), |
68 | fHasTask(kFALSE), | |
69 | fTaskName(), | |
70 | fParentalTask(0x0), | |
71 | fEventFolder(0x0), | |
72 | fFolder(0x0) | |
73 | { | |
74 | //constructor | |
75 | // creates a 0 loader, depending on option, default "T" is specialized loader for trees | |
76 | // else standard object loader | |
77 | // trees needs special care, becouse we need to set dir before writing | |
21bf7095 | 78 | AliDebug(1, Form("File name is %s",fFileName.Data())); |
88cb7938 | 79 | |
80 | TString option(opt); | |
81 | AliBaseLoader* bl; | |
82 | if (option.CompareTo("T",TString::kIgnoreCase) == 0) | |
83 | bl = new AliTreeLoader(contname,this); | |
84 | else | |
85 | bl = new AliObjectLoader(contname,this); | |
86 | fBaseLoaders->AddAt(bl,kData); | |
87 | ||
88 | } | |
89 | /*****************************************************************************/ | |
90e48c0c | 90 | AliDataLoader::AliDataLoader(const AliDataLoader& source) : |
91 | TNamed(source), | |
92 | fFileName(source.fFileName), | |
93 | fFile(source.fFile), | |
94 | fDirectory(source.fDirectory), | |
95 | fFileOption(source.fFileOption), | |
96 | fCompressionLevel(source.fCompressionLevel), | |
97 | fNEventsPerFile(source.fNEventsPerFile), | |
98 | fBaseLoaders(source.fBaseLoaders), | |
99 | fHasTask(source.fHasTask), | |
100 | fTaskName(source.fTaskName), | |
101 | fParentalTask(source.fParentalTask), | |
102 | fEventFolder(source.fEventFolder), | |
103 | fFolder(source.fFolder) | |
104 | { | |
d0d4a6b3 | 105 | // copy constructor |
21bf7095 | 106 | AliFatal("Copy constructor not implemented"); |
d0d4a6b3 | 107 | } |
108 | /*****************************************************************************/ | |
109 | AliDataLoader& AliDataLoader::operator=(const AliDataLoader& /*source*/) { | |
110 | // Assignment operator | |
21bf7095 | 111 | AliFatal("Assignment operator not implemented"); |
d0d4a6b3 | 112 | return *this; |
113 | } | |
114 | /*****************************************************************************/ | |
88cb7938 | 115 | |
116 | AliDataLoader::~AliDataLoader() | |
117 | { | |
118 | //dtor | |
119 | UnloadAll(); | |
120 | } | |
121 | /*****************************************************************************/ | |
122 | ||
123 | Int_t AliDataLoader::SetEvent() | |
124 | { | |
125 | //basically the same that GetEvent but do not post data to folders | |
126 | AliRunLoader* rl = GetRunLoader(); | |
127 | if (rl == 0x0) | |
128 | { | |
21bf7095 | 129 | AliError("Can not get RunGettr"); |
88cb7938 | 130 | return 1; |
131 | } | |
132 | ||
133 | Int_t evno = rl->GetEventNumber(); | |
134 | ||
135 | TIter next(fBaseLoaders); | |
136 | AliBaseLoader* bl; | |
137 | while ((bl = (AliBaseLoader*)next())) | |
138 | { | |
139 | if (bl->DoNotReload() == kFALSE) bl->Clean(); | |
140 | } | |
141 | ||
142 | if(fFile) | |
143 | { | |
144 | if (CheckReload()) | |
145 | { | |
146 | delete fFile; | |
147 | fFile = 0x0; | |
21bf7095 | 148 | AliDebug(1, Form("Reloading new file. File opt is %s",fFileOption.Data())); |
88cb7938 | 149 | OpenFile(fFileOption); |
150 | } | |
151 | ||
152 | fDirectory = AliLoader::ChangeDir(fFile,evno); | |
153 | if (fDirectory == 0x0) | |
154 | { | |
21bf7095 | 155 | AliError(Form("Can not chage directory in file %s",fFile->GetName())); |
88cb7938 | 156 | return 1; |
157 | } | |
158 | } | |
159 | return 0; | |
160 | } | |
161 | /*****************************************************************************/ | |
162 | ||
163 | Int_t AliDataLoader::GetEvent() | |
164 | { | |
165 | // posts all loaded data from files to White Board | |
166 | // event number is defined in RunLoader | |
167 | // | |
168 | //returns: | |
169 | // 0 - in case of no error | |
170 | // 1 - event not found | |
171 | // | |
172 | //for each base laoder post, if was loaded before GetEvent | |
173 | ||
174 | //call set event to switch to new directory in file | |
175 | ||
176 | ||
177 | //post all data that were loaded before | |
178 | // ->SetEvent does not call Unload, but only cleans White Board | |
179 | // such IsLoaded flag stays untached | |
180 | ||
181 | if ( AliLoader::TestFileOption(fFileOption) == kTRUE ) //if file is read or update mode try to post | |
182 | { //in other case there is no sense to post: file is new | |
183 | TIter nextbl(fBaseLoaders); | |
184 | AliBaseLoader* bl; | |
185 | while ((bl = (AliBaseLoader*)nextbl())) | |
186 | { | |
187 | if (bl->IsLoaded()) | |
188 | { | |
189 | if (bl->DoNotReload() == kFALSE) bl->Post(); | |
190 | } | |
191 | } | |
192 | } | |
193 | return 0; | |
194 | } | |
195 | /*****************************************************************************/ | |
196 | ||
197 | Int_t AliDataLoader::OpenFile(Option_t* opt) | |
198 | { | |
199 | //Opens file named 'filename', and assigns pointer to it to 'file' | |
200 | //jumps to fDirectoryectory corresponding to current event and stores the pointer to it in 'fDirectory' | |
201 | //option 'opt' is passed to TFile::Open | |
202 | if (fFile) | |
203 | { | |
204 | if(fFile->IsOpen() == kTRUE) | |
205 | { | |
21bf7095 | 206 | AliWarning(Form(" File %s already opened. First close it.",fFile->GetName())); |
88cb7938 | 207 | return 0; |
208 | } | |
209 | else | |
210 | { | |
21bf7095 | 211 | AliWarning(Form("Pointer to file %s is not null, but file is not opened", |
212 | fFile->GetName())); | |
88cb7938 | 213 | delete fFile; |
214 | fFile = 0x0; | |
215 | } | |
216 | } | |
217 | ||
218 | TString fname(SetFileOffset(fFileName)); | |
219 | ||
220 | fFile = (TFile *)(gROOT->GetListOfFiles()->FindObject(fname)); | |
221 | if (fFile) | |
222 | { | |
223 | if(fFile->IsOpen() == kTRUE) | |
224 | { | |
21bf7095 | 225 | AliWarning(Form("File %s already opened by sombody else. First close it.", |
226 | fFile->GetName())); | |
88cb7938 | 227 | return 0; |
228 | } | |
229 | } | |
230 | ||
231 | fFileOption = opt; | |
232 | fFile = TFile::Open(fname,fFileOption);//open the file | |
233 | if (fFile == 0x0) | |
234 | {//file is null | |
21bf7095 | 235 | AliError(Form("Can not open file %s",fname.Data())); |
88cb7938 | 236 | return 1; |
237 | } | |
238 | if (fFile->IsOpen() == kFALSE) | |
239 | {//file is null | |
21bf7095 | 240 | AliError(Form("Can not open file %s",fname.Data())); |
88cb7938 | 241 | return 1; |
242 | } | |
243 | ||
244 | fFile->SetCompressionLevel(fCompressionLevel); | |
245 | ||
246 | AliRunLoader* rg = GetRunLoader(); | |
247 | if (rg == 0x0) | |
248 | { | |
21bf7095 | 249 | AliError("Can not find Run-Loader in folder."); |
88cb7938 | 250 | return 2; |
251 | } | |
252 | Int_t evno = rg->GetEventNumber(); | |
253 | ||
254 | fDirectory = AliLoader::ChangeDir(fFile,evno); | |
255 | if (fDirectory == 0x0) | |
256 | { | |
21bf7095 | 257 | AliError(Form("Can not chage fDirectory in file %s.",fFile->GetName())); |
88cb7938 | 258 | return 3; |
259 | } | |
260 | return 0; | |
261 | } | |
262 | /*****************************************************************************/ | |
263 | ||
264 | void AliDataLoader::Unload() | |
265 | { | |
266 | //unloads main data - shortcut method | |
267 | GetBaseLoader(0)->Unload(); | |
268 | } | |
269 | /*****************************************************************************/ | |
270 | ||
271 | void AliDataLoader::UnloadAll() | |
272 | { | |
273 | //Unloads all data and tasks | |
1bb20a37 | 274 | if ( fFile == 0x0 ) return; //nothing loaded |
275 | ||
88cb7938 | 276 | TIter next(fBaseLoaders); |
277 | AliBaseLoader* bl; | |
278 | while ((bl = (AliBaseLoader*)next())) | |
279 | { | |
280 | bl->Unload(); | |
281 | } | |
282 | } | |
283 | /*****************************************************************************/ | |
284 | ||
285 | Int_t AliDataLoader::Reload() | |
286 | { | |
287 | //Unloads and loads data again | |
288 | if ( fFile == 0x0 ) return 0; | |
289 | ||
290 | TBits loaded(fBaseLoaders->GetEntries()); | |
291 | TIter next(fBaseLoaders); | |
292 | AliBaseLoader* bl; | |
293 | ||
294 | Int_t i = 0; | |
295 | while ((bl = (AliBaseLoader*)next())) | |
296 | { | |
297 | if (bl->IsLoaded()) | |
298 | { | |
299 | loaded.SetBitNumber(i++,kTRUE); | |
300 | bl->Unload(); | |
301 | } | |
302 | } | |
303 | ||
304 | Int_t retval; | |
305 | i = 0; | |
306 | next.Reset(); | |
307 | while ((bl = (AliBaseLoader*)next())) | |
308 | { | |
309 | if (loaded.TestBitNumber(i++)) | |
310 | { | |
311 | retval = bl->Load(fFileOption); | |
312 | if (retval) | |
313 | { | |
21bf7095 | 314 | AliError(Form("Error occur while loading %s",bl->GetName())); |
88cb7938 | 315 | return retval; |
316 | } | |
317 | } | |
318 | } | |
319 | ||
320 | ||
321 | return 0; | |
322 | } | |
323 | /*****************************************************************************/ | |
324 | Int_t AliDataLoader::WriteData(Option_t* opt) | |
325 | { | |
326 | //Writes primary data == first BaseLoader | |
21bf7095 | 327 | AliDebug(1, Form("Writing %s container for %s data. Option is %s.", |
328 | GetBaseLoader(0)->GetName(),GetName(),opt)); | |
88cb7938 | 329 | return GetBaseLoader(0)->WriteData(opt); |
330 | } | |
331 | /*****************************************************************************/ | |
332 | ||
333 | Int_t AliDataLoader::Load(Option_t* opt) | |
334 | { | |
335 | //Writes primary data == first BaseLoader | |
336 | return GetBaseLoader(0)->Load(opt); | |
337 | } | |
338 | /*****************************************************************************/ | |
339 | ||
340 | Int_t AliDataLoader::SetEventFolder(TFolder* eventfolder) | |
341 | { | |
342 | //sets the event folder | |
343 | if (eventfolder == 0x0) | |
344 | { | |
21bf7095 | 345 | AliError("Stupid joke. Argument is NULL"); |
88cb7938 | 346 | return 1; |
347 | } | |
21bf7095 | 348 | AliDebug(1, Form("name = %s Setting Event Folder named %s.", |
349 | GetName(),eventfolder->GetName())); | |
88cb7938 | 350 | |
351 | fEventFolder = eventfolder; | |
352 | return 0; | |
353 | } | |
354 | /*****************************************************************************/ | |
355 | ||
356 | Int_t AliDataLoader::SetFolder(TFolder* folder) | |
357 | { | |
d0d4a6b3 | 358 | // Sets the folder and the data loaders |
88cb7938 | 359 | if (folder == 0x0) |
360 | { | |
21bf7095 | 361 | AliError("Stupid joke. Argument is NULL"); |
88cb7938 | 362 | return 1; |
363 | } | |
364 | ||
21bf7095 | 365 | AliDebug(1, Form("name = %s Setting folder named %s.",GetName(),folder->GetName())); |
88cb7938 | 366 | |
367 | fFolder = folder; | |
368 | TIter next(fBaseLoaders); | |
369 | AliBaseLoader* bl; | |
370 | ||
371 | while ((bl = (AliBaseLoader*)next())) | |
372 | { | |
373 | bl->SetDataLoader(this); | |
374 | } | |
375 | ||
376 | return 0; | |
377 | } | |
378 | /******************************************************************/ | |
379 | ||
380 | TFolder* AliDataLoader::GetEventFolder() | |
381 | { | |
382 | //get EVENT folder (data that are changing from event to event, even in single run) | |
21bf7095 | 383 | AliDebug(1, "EF = %#x"); |
88cb7938 | 384 | return fEventFolder; |
385 | } | |
386 | /*****************************************************************************/ | |
387 | ||
388 | AliRunLoader* AliDataLoader::GetRunLoader() | |
389 | { | |
390 | //gets the run-loader from event folder | |
391 | AliRunLoader* rg = 0x0; | |
392 | TFolder* ef = GetEventFolder(); | |
393 | if (ef == 0x0) | |
394 | { | |
21bf7095 | 395 | AliError("Can not get event folder."); |
88cb7938 | 396 | return 0; |
397 | } | |
024a7e64 | 398 | rg = dynamic_cast<AliRunLoader*>(ef->FindObject(AliRunLoader::GetRunLoaderName())); |
88cb7938 | 399 | return rg; |
400 | } | |
401 | ||
402 | /*****************************************************************************/ | |
403 | void AliDataLoader::CloseFile() | |
404 | { | |
405 | //closes file | |
406 | TIter next(fBaseLoaders); | |
407 | AliBaseLoader* bl; | |
408 | while ((bl = (AliBaseLoader*)next())) | |
409 | { | |
410 | if (bl->IsLoaded()) return; | |
411 | } | |
412 | ||
21bf7095 | 413 | AliDebug(1, "Closing and deleting (object) file."); |
88cb7938 | 414 | |
415 | delete fFile; | |
416 | fFile = 0x0; | |
417 | fDirectory = 0x0; | |
418 | } | |
419 | /*****************************************************************************/ | |
420 | ||
421 | void AliDataLoader::Clean() | |
422 | { | |
423 | //Cleans main data | |
424 | GetBaseLoader(0)->Clean(); | |
425 | } | |
426 | /*****************************************************************************/ | |
427 | ||
428 | void AliDataLoader::CleanAll() | |
429 | { | |
430 | //Cleans all folders and tasks | |
431 | TIter next(fBaseLoaders); | |
432 | AliBaseLoader* bl; | |
433 | while ((bl = (AliBaseLoader*)next())) | |
434 | { | |
435 | bl->Clean(); | |
436 | } | |
437 | } | |
438 | /*****************************************************************************/ | |
439 | ||
440 | void AliDataLoader::SetFileNameSuffix(const TString& suffix) | |
441 | { | |
442 | //adds the suffix before ".root", | |
443 | //e.g. TPC.Digits.root -> TPC.DigitsMerged.root | |
444 | //made on Jiri Chudoba demand | |
21bf7095 | 445 | AliDebug(1, Form("suffix=%s",suffix.Data())); |
446 | AliDebug(1, Form(" Digits File Name before: %s",fFileName.Data())); | |
88cb7938 | 447 | |
448 | static TString dotroot(".root"); | |
449 | const TString& suffixdotroot = suffix + dotroot; | |
450 | fFileName = fFileName.ReplaceAll(dotroot,suffixdotroot); | |
451 | ||
21bf7095 | 452 | AliDebug(1, Form(" after : %s",fFileName.Data())); |
88cb7938 | 453 | } |
454 | /*****************************************************************************/ | |
455 | ||
456 | Bool_t AliDataLoader::CheckReload() | |
457 | { | |
458 | //checks if we have to reload given file | |
459 | if (fFile == 0x0) return kFALSE; | |
460 | TString tmp = SetFileOffset(fFileName); | |
461 | if (tmp.CompareTo(fFile->GetName())) return kTRUE; //file must be reloaded | |
462 | return kFALSE; | |
463 | } | |
464 | /*****************************************************************************/ | |
465 | ||
466 | const TString AliDataLoader::SetFileOffset(const TString& fname) | |
467 | { | |
468 | ||
469 | //return fname; | |
470 | Long_t offset = (Long_t)GetRunLoader()->GetFileOffset(); | |
18b43626 | 471 | if (fNEventsPerFile > 0) { |
472 | offset = GetRunLoader()->GetEventNumber()/fNEventsPerFile; | |
473 | } | |
88cb7938 | 474 | if (offset < 1) return fname; |
475 | ||
476 | TString soffset; | |
477 | soffset += offset;//automatic conversion to string | |
478 | TString dotroot(".root"); | |
479 | const TString& offfsetdotroot = offset + dotroot; | |
480 | TString out = fname; | |
481 | out = out.ReplaceAll(dotroot,offfsetdotroot); | |
21bf7095 | 482 | AliDebug(1, Form("in=%s out=%s.",fname.Data(),out.Data())); |
88cb7938 | 483 | return out; |
484 | ||
485 | } | |
486 | /*****************************************************************************/ | |
487 | ||
488 | void AliDataLoader::SetFileOption(Option_t* newopt) | |
489 | { | |
490 | //sets file option | |
491 | if (fFileOption.CompareTo(newopt) == 0) return; | |
492 | fFileOption = newopt; | |
493 | Reload(); | |
494 | } | |
495 | /*****************************************************************************/ | |
496 | ||
497 | void AliDataLoader::SetCompressionLevel(Int_t cl) | |
498 | { | |
499 | //sets comression level for data defined by di | |
500 | fCompressionLevel = cl; | |
501 | if (fFile) fFile->SetCompressionLevel(cl); | |
502 | } | |
503 | /*****************************************************************************/ | |
504 | ||
88cb7938 | 505 | void AliDataLoader::MakeTree() |
506 | { | |
d0d4a6b3 | 507 | // Makes tree for the current data loader |
88cb7938 | 508 | AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(fBaseLoaders->At(0)); |
509 | if (tl == 0x0) | |
510 | { | |
21bf7095 | 511 | AliError("Can not make a tree because main base loader is not a tree loader"); |
88cb7938 | 512 | return; |
513 | } | |
514 | tl->MakeTree(); | |
515 | } | |
516 | /*****************************************************************************/ | |
517 | ||
518 | Bool_t AliDataLoader::IsFileWritable() const | |
519 | { | |
520 | //returns true if file is writable | |
521 | return (fFile)?fFile->IsWritable():kFALSE; | |
522 | } | |
523 | /*****************************************************************************/ | |
524 | ||
525 | Bool_t AliDataLoader::IsFileOpen() const | |
526 | { | |
527 | //returns true if file is writable | |
528 | return (fFile)?fFile->IsOpen():kFALSE; | |
529 | } | |
530 | /*****************************************************************************/ | |
531 | ||
532 | Bool_t AliDataLoader::IsOptionContrary(const TString& option) const | |
533 | { | |
534 | //Checks if passed option is contrary with file open option | |
535 | //which is passed option "writable" and existing option not wriable | |
536 | //in reverse case it is no harm so it is NOT contrary | |
537 | if (fFile == 0x0) return kFALSE; //file is not opened - no problem | |
538 | ||
539 | if ( ( AliLoader::IsOptionWritable(option) == kTRUE ) && // passed option is writable and | |
540 | ( AliLoader::IsOptionWritable(fFileOption) == kFALSE ) ) // existing one is not writable | |
541 | { | |
542 | return kTRUE; | |
543 | } | |
544 | ||
545 | return kFALSE; | |
546 | } | |
547 | /*****************************************************************************/ | |
548 | void AliDataLoader::AddBaseLoader(AliBaseLoader* bl) | |
549 | { | |
550 | //Adds a base loader to lits of base loaders managed by this data loader | |
551 | //Managed data/task will be stored in proper root directory, | |
552 | //and posted to | |
553 | // - in case of tree/object - data folder connected with detector associated with this data loader | |
554 | // - in case of task - parental task which defined in this AliTaskLoader | |
555 | ||
556 | if (bl == 0x0) | |
557 | { | |
21bf7095 | 558 | AliWarning("Pointer is null."); |
88cb7938 | 559 | return; |
560 | } | |
561 | ||
562 | TObject* obj = fBaseLoaders->FindObject(bl->GetName()); | |
563 | if (obj) | |
564 | { | |
21bf7095 | 565 | AliError("Can not add this base loader."); |
566 | AliError(Form("There exists already base loader which manages data named %s for this detector.",obj->GetName())); | |
88cb7938 | 567 | return; |
568 | } | |
569 | ||
570 | ||
571 | fBaseLoaders->Add(bl); | |
572 | } | |
573 | ||
574 | /*****************************************************************************/ | |
575 | ||
576 | AliBaseLoader* AliDataLoader::GetBaseLoader(const TString& name) const | |
577 | { | |
578 | return dynamic_cast<AliBaseLoader*>(fBaseLoaders->FindObject(name)); | |
579 | } | |
580 | /*****************************************************************************/ | |
581 | ||
582 | AliBaseLoader* AliDataLoader::GetBaseLoader(Int_t n) const | |
583 | { | |
d0d4a6b3 | 584 | // Gets the n-th base loader (what is n?) |
88cb7938 | 585 | return dynamic_cast<AliBaseLoader*>(fBaseLoaders->At(n)); |
586 | } | |
587 | /*****************************************************************************/ | |
588 | ||
589 | TTree* AliDataLoader::Tree() const | |
590 | { | |
591 | //returns tree from the main base loader | |
592 | //it is just shortcut method for comfort of user | |
593 | //main storage object does not have to be Tree - | |
594 | //that is why first we need to check if it is a TreeLoader | |
595 | AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(GetBaseLoader(0)); | |
596 | if (tl == 0x0) return 0x0; | |
597 | return tl->Tree(); | |
598 | } | |
599 | /*****************************************************************************/ | |
600 | ||
601 | void AliDataLoader::SetDirName(TString& dirname) | |
602 | { | |
d0d4a6b3 | 603 | // Sets the directory name where the files will be stored |
21bf7095 | 604 | AliDebug(10, Form("FileName before %s",fFileName.Data())); |
88cb7938 | 605 | |
606 | Int_t n = fFileName.Last('/'); | |
607 | ||
21bf7095 | 608 | AliDebug(10, Form("Slash found on pos %d",n)); |
88cb7938 | 609 | |
610 | if (n > 0) fFileName = fFileName.Remove(0,n+1); | |
611 | ||
21bf7095 | 612 | AliDebug(10, Form("Core FileName %s",fFileName.Data())); |
88cb7938 | 613 | |
614 | fFileName = dirname + "/" + fFileName; | |
615 | ||
21bf7095 | 616 | AliDebug(10, Form("FileName after %s",fFileName.Data())); |
88cb7938 | 617 | } |
618 | /*****************************************************************************/ | |
619 | AliObjectLoader* AliDataLoader::GetBaseDataLoader() | |
620 | { | |
d0d4a6b3 | 621 | // Gets the base data loader |
88cb7938 | 622 | return dynamic_cast<AliObjectLoader*>(GetBaseLoader(kData)); |
623 | } | |
624 | /*****************************************************************************/ | |
625 | AliTaskLoader* AliDataLoader::GetBaseTaskLoader() | |
626 | { | |
d0d4a6b3 | 627 | // Gets the base task loader |
88cb7938 | 628 | return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kTask)); |
629 | } | |
630 | /*****************************************************************************/ | |
631 | AliBaseLoader* AliDataLoader::GetBaseQALoader() | |
632 | { | |
d0d4a6b3 | 633 | // Gets the base QA loader |
88cb7938 | 634 | return GetBaseLoader(kQA); |
635 | } | |
636 | /*****************************************************************************/ | |
637 | AliTaskLoader* AliDataLoader::GetBaseQATaskLoader() | |
638 | { | |
639 | //returns pointer to QA base loader | |
640 | return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kQATask)); | |
641 | } | |
642 | /*****************************************************************************/ | |
643 | void AliDataLoader::SetBaseDataLoader(AliBaseLoader* bl) | |
644 | { | |
645 | //sets data base loader | |
646 | if (bl == 0x0) | |
647 | { | |
21bf7095 | 648 | AliError("Parameter is null"); |
88cb7938 | 649 | return; |
650 | } | |
651 | if (GetBaseDataLoader()) delete GetBaseDataLoader(); | |
652 | fBaseLoaders->AddAt(bl,kData); | |
653 | } | |
654 | /*****************************************************************************/ | |
655 | void AliDataLoader::SetBaseTaskLoader(AliTaskLoader* bl) | |
656 | { | |
657 | //sets Task base loader | |
658 | if (bl == 0x0) | |
659 | { | |
21bf7095 | 660 | AliError("Parameter is null"); |
88cb7938 | 661 | return; |
662 | } | |
663 | if (GetBaseTaskLoader()) delete GetBaseTaskLoader(); | |
664 | fBaseLoaders->AddAt(bl,kTask); | |
665 | } | |
666 | /*****************************************************************************/ | |
667 | void AliDataLoader::SetBaseQALoader(AliBaseLoader* bl) | |
668 | { | |
669 | //sets QA base loader | |
670 | if (bl == 0x0) | |
671 | { | |
21bf7095 | 672 | AliError("Parameter is null"); |
88cb7938 | 673 | return; |
674 | } | |
675 | if (GetBaseQALoader()) delete GetBaseQALoader(); | |
676 | fBaseLoaders->AddAt(bl,kQA); | |
677 | } | |
678 | /*****************************************************************************/ | |
679 | void AliDataLoader::SetBaseQATaskLoader(AliTaskLoader* bl) | |
680 | { | |
681 | //sets QA Task base loader | |
682 | if (bl == 0x0) | |
683 | { | |
21bf7095 | 684 | AliError("Parameter is null"); |
88cb7938 | 685 | return; |
686 | } | |
687 | if (GetBaseQATaskLoader()) delete GetBaseQATaskLoader(); | |
688 | fBaseLoaders->AddAt(bl,kQATask); | |
689 | } | |
f0f6f856 | 690 | void AliDataLoader::Synchronize() |
691 | { | |
692 | //synchrinizes all writtable files | |
504b172d | 693 | if ( fFile ) fFile->Flush(); |
f0f6f856 | 694 | } |
88cb7938 | 695 | |
696 | /*****************************************************************************/ | |
697 | /*****************************************************************************/ | |
698 | /*****************************************************************************/ | |
699 | //__________________________________________ | |
700 | /////////////////////////////////////////////////////////////////////////////// | |
701 | // // | |
702 | // class AliBaseLoader // | |
703 | // // | |
704 | // // | |
705 | /////////////////////////////////////////////////////////////////////////////// | |
706 | ClassImp(AliBaseLoader) | |
707 | ||
708 | AliBaseLoader::AliBaseLoader(): | |
709 | fIsLoaded(kFALSE), | |
710 | fStoreInTopOfFile(kFALSE), | |
711 | fDoNotReload(kFALSE), | |
712 | fDataLoader(0x0) | |
713 | { | |
d0d4a6b3 | 714 | //default constructor |
88cb7938 | 715 | } |
716 | /*****************************************************************************/ | |
717 | ||
718 | AliBaseLoader::AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop): | |
719 | TNamed(name,name+" Base Loader"), | |
720 | fIsLoaded(kFALSE), | |
721 | fStoreInTopOfFile(storeontop), | |
722 | fDoNotReload(storeontop),//if stored on top of file - this object is loaded ones pe | |
723 | fDataLoader(dl) | |
724 | { | |
d0d4a6b3 | 725 | //constructor |
88cb7938 | 726 | } |
727 | ||
d0d4a6b3 | 728 | /*****************************************************************************/ |
90e48c0c | 729 | AliBaseLoader::AliBaseLoader(const AliBaseLoader& source) : |
730 | TNamed(source), | |
731 | fIsLoaded(source.fIsLoaded), | |
732 | fStoreInTopOfFile(source.fStoreInTopOfFile), | |
733 | fDoNotReload(source.fDoNotReload), | |
734 | fDataLoader(source.fDataLoader) | |
735 | { | |
d0d4a6b3 | 736 | // copy constructor |
21bf7095 | 737 | AliFatal("Copy constructor not implemented"); |
d0d4a6b3 | 738 | } |
739 | /*****************************************************************************/ | |
740 | AliBaseLoader& AliBaseLoader::operator=(const AliBaseLoader& /*source*/) { | |
741 | // Assignment operator | |
21bf7095 | 742 | AliFatal("Assignment operator not implemented"); |
d0d4a6b3 | 743 | return *this; |
744 | } | |
88cb7938 | 745 | /*****************************************************************************/ |
746 | ||
747 | Int_t AliBaseLoader::Load(Option_t* opt) | |
748 | { | |
d0d4a6b3 | 749 | // Loads and posts the data |
21bf7095 | 750 | AliDebug(1, Form("data type = %s, option = %s",GetName(),opt)); |
88cb7938 | 751 | |
752 | if (Get()) | |
753 | { | |
21bf7095 | 754 | AliWarning(Form("Data <<%s>> are already loaded. Use ReloadData to force reload. Nothing done",GetName())); |
f82d8b8c | 755 | return 0; |
88cb7938 | 756 | } |
757 | ||
758 | Int_t retval; | |
759 | ||
760 | if (GetDataLoader()->IsFileOpen() == kTRUE) | |
761 | { | |
762 | if (GetDataLoader()->IsOptionContrary(opt) == kTRUE) | |
763 | { | |
21bf7095 | 764 | AliError(Form("Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName())); |
765 | AliError("File was already opened in READ-ONLY mode, while now WRITEABLE access is requested."); | |
766 | AliError("Use AliDataLoader::SetOption to enforce change of access mode OR"); | |
767 | AliError("Load previosly loaded data with coherent option."); | |
88cb7938 | 768 | return 10; |
769 | } | |
770 | } | |
771 | else | |
772 | { | |
773 | retval = GetDataLoader()->OpenFile(opt); | |
774 | if (retval) | |
775 | { | |
21bf7095 | 776 | AliError(Form("Error occured while opening <<%s>> file",GetName())); |
88cb7938 | 777 | return retval; |
778 | } | |
779 | } | |
780 | //if file is recreated there is no sense to search for data to post and get Error message | |
781 | if (AliLoader::TestFileOption(opt) == kFALSE) | |
782 | { | |
783 | AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(this); | |
784 | if (tl) tl->MakeTree(); | |
785 | fIsLoaded = kTRUE; | |
786 | return 0; | |
787 | } | |
788 | ||
789 | retval = Post(); | |
790 | if (retval) | |
791 | { | |
21bf7095 | 792 | AliError(Form("Error occured while posting %s from file to folder.",GetName())); |
88cb7938 | 793 | return retval; |
794 | } | |
795 | ||
796 | fIsLoaded = kTRUE; | |
797 | return 0; | |
798 | } | |
799 | /*****************************************************************************/ | |
800 | ||
801 | Int_t AliBaseLoader::Post() | |
802 | { | |
803 | //Posts data container to proper folders | |
804 | ||
805 | if ( GetDirectory() == 0x0) | |
806 | { | |
21bf7095 | 807 | AliError(Form("%s directory is NULL. Load before.",GetDataLoader()->GetName())); |
88cb7938 | 808 | return 2; |
809 | } | |
810 | ||
811 | TObject* data = GetFromDirectory(fName); | |
812 | if(data) | |
813 | { | |
814 | //if such an obejct already exists - remove it first | |
815 | return Post(data); | |
816 | } | |
817 | else | |
818 | { | |
819 | //check if file is in update mode | |
820 | Int_t fileupdate = GetDataLoader()->GetFileOption().CompareTo("update",TString::kIgnoreCase); | |
821 | if ( fileupdate == 0) | |
822 | { //if it is, it is normal that there is no data yet | |
21bf7095 | 823 | AliDebug(1, Form("Can not find %s in file %s (file is opened in UPDATE mode).", |
824 | GetName(),GetDataLoader()->GetFile()->GetName())); | |
88cb7938 | 825 | } |
826 | else | |
827 | { | |
21bf7095 | 828 | AliError(Form("Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName())); |
c3983217 | 829 | return 5; |
88cb7938 | 830 | } |
831 | } | |
832 | return 0; | |
833 | } | |
834 | /*****************************************************************************/ | |
835 | ||
836 | Int_t AliBaseLoader::Post(TObject* data) | |
837 | { | |
838 | //Posts data container to proper folders | |
839 | if (data == 0x0) | |
840 | { | |
21bf7095 | 841 | AliError("Pointer to object is NULL"); |
88cb7938 | 842 | return 1; |
843 | } | |
3637d19d | 844 | |
845 | if ( fName.CompareTo(data->GetName()) != 0) | |
846 | { | |
21bf7095 | 847 | AliFatal(Form("Object name is <<%s>> while <<%s>> expected",data->GetName(),GetName())); |
3637d19d | 848 | return -1;//pro forma |
849 | } | |
850 | ||
88cb7938 | 851 | TObject* obj = Get(); |
852 | if (data == obj) | |
853 | { | |
21bf7095 | 854 | AliWarning("This object was already posted."); |
88cb7938 | 855 | return 0; |
856 | } | |
857 | if (obj) | |
858 | { | |
21bf7095 | 859 | AliWarning(Form("Object named %s already exitsts in data folder. Removing it",GetName())); |
88cb7938 | 860 | Clean(); |
861 | } | |
862 | return AddToBoard(data); | |
863 | } | |
864 | /*****************************************************************************/ | |
865 | ||
866 | Int_t AliBaseLoader::WriteData(Option_t* opt) | |
867 | { | |
868 | //Writes data defined by di object | |
869 | //opt might be "OVERWRITE" in case of forcing overwriting | |
21bf7095 | 870 | AliDebug(1, Form("Writing %s container for %s data. Option is %s.", |
871 | GetName(),GetDataLoader()->GetName(),opt)); | |
88cb7938 | 872 | |
873 | TObject *data = Get(); | |
874 | if(data == 0x0) | |
875 | {//did not get, nothing to write | |
21bf7095 | 876 | AliWarning(Form("Tree named %s not found in folder. Nothing to write.",GetName())); |
88cb7938 | 877 | return 0; |
878 | } | |
879 | ||
880 | //check if file is opened | |
881 | if (GetDirectory() == 0x0) | |
882 | { | |
883 | //if not try to open | |
884 | GetDataLoader()->SetFileOption("UPDATE"); | |
885 | if (GetDataLoader()->OpenFile("UPDATE")) | |
886 | { | |
887 | //oops, can not open the file, give an error message and return error code | |
21bf7095 | 888 | AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName())); |
88cb7938 | 889 | return 1; |
890 | } | |
891 | } | |
892 | ||
893 | if (GetDataLoader()->IsFileWritable() == kFALSE) | |
894 | { | |
21bf7095 | 895 | AliError(Form("File %s is not writable",GetDataLoader()->GetFileName().Data())); |
88cb7938 | 896 | return 2; |
897 | } | |
898 | ||
899 | GetDirectory()->cd(); //set the proper directory active | |
900 | ||
901 | //see if hits container already exists in this (root) directory | |
902 | TObject* obj = GetFromDirectory(GetName()); | |
903 | if (obj) | |
904 | { //if they exist, see if option OVERWRITE is used | |
905 | const char *oOverWrite = strstr(opt,"OVERWRITE"); | |
906 | if(!oOverWrite) | |
907 | {//if it is not used - give an error message and return an error code | |
21bf7095 | 908 | AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data"); |
88cb7938 | 909 | return 3; |
910 | } | |
911 | } | |
912 | ||
21bf7095 | 913 | AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s", |
914 | GetName(),opt,data->GetName())); | |
915 | AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s", | |
88cb7938 | 916 | GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(), |
21bf7095 | 917 | GetDirectory()->GetFile()->GetName())); |
88cb7938 | 918 | |
21bf7095 | 919 | AliDebug(1, "Writing data"); |
88cb7938 | 920 | data->Write(0,TObject::kOverwrite); |
921 | ||
922 | fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader. | |
923 | ||
924 | return 0; | |
925 | ||
926 | } | |
927 | /*****************************************************************************/ | |
928 | ||
929 | Int_t AliBaseLoader::Reload() | |
930 | { | |
931 | //Unloads and loads datat again - if loaded before | |
932 | if (IsLoaded()) | |
933 | { | |
934 | Unload(); | |
935 | return Load(GetDataLoader()->GetFileOption()); | |
936 | } | |
937 | return 0; | |
938 | } | |
939 | /*****************************************************************************/ | |
940 | ||
941 | void AliBaseLoader::Clean() | |
942 | { | |
943 | //removes objects from folder/task | |
21bf7095 | 944 | AliDebug(1, Form("%s %s",GetName(),GetDataLoader()->GetName())); |
88cb7938 | 945 | TObject* obj = Get(); |
946 | if(obj) | |
947 | { | |
21bf7095 | 948 | AliDebug(1, Form("cleaning %s.",GetName())); |
88cb7938 | 949 | RemoveFromBoard(obj); |
950 | delete obj; | |
951 | } | |
952 | } | |
953 | /*****************************************************************************/ | |
954 | ||
955 | void AliBaseLoader::Unload() | |
956 | { | |
d0d4a6b3 | 957 | // Unloads data and closes the files |
88cb7938 | 958 | Clean(); |
959 | fIsLoaded = kFALSE; | |
960 | GetDataLoader()->CloseFile(); | |
961 | } | |
962 | /*****************************************************************************/ | |
963 | AliDataLoader* AliBaseLoader::GetDataLoader() const | |
964 | { | |
d0d4a6b3 | 965 | // Returns pointer to the data loader |
88cb7938 | 966 | if (fDataLoader == 0x0) |
967 | { | |
21bf7095 | 968 | AliFatal("Pointer to Data Loader is NULL"); |
88cb7938 | 969 | } |
970 | return fDataLoader; | |
971 | } | |
972 | /*****************************************************************************/ | |
973 | ||
d0d4a6b3 | 974 | TDirectory* AliBaseLoader::GetDirectory() const |
88cb7938 | 975 | { |
976 | // returnd TDirectory where data are to be saved | |
977 | //if fStoreInTopOfFile flag is true - returns pointer to file | |
978 | return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory(); | |
979 | } | |
980 | /*****************************************************************************/ | |
981 | /*****************************************************************************/ | |
982 | /*****************************************************************************/ | |
983 | //__________________________________________ | |
984 | /////////////////////////////////////////////////////////////////////////////// | |
985 | // // | |
986 | // class AliObjectLoader // | |
987 | // // | |
988 | // // | |
989 | /////////////////////////////////////////////////////////////////////////////// | |
990 | ||
991 | ClassImp(AliObjectLoader) | |
992 | ||
993 | AliObjectLoader::AliObjectLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop): | |
994 | AliBaseLoader(name,dl,storeontop) | |
995 | { | |
996 | //constructor | |
997 | } | |
998 | /*****************************************************************************/ | |
999 | ||
1000 | TFolder* AliObjectLoader::GetFolder() const | |
1001 | { | |
d0d4a6b3 | 1002 | // Returns pointer to the object folder |
88cb7938 | 1003 | TFolder* df = GetDataLoader()->GetFolder(); |
1004 | if (df == 0x0) | |
1005 | { | |
21bf7095 | 1006 | AliFatal("Data Folder is NULL"); |
88cb7938 | 1007 | } |
1008 | return df; | |
1009 | } | |
1010 | /*****************************************************************************/ | |
d0d4a6b3 | 1011 | AliObjectLoader::AliObjectLoader(const AliObjectLoader& source): |
1012 | AliBaseLoader(source) { | |
1013 | // copy constructor | |
21bf7095 | 1014 | AliFatal("Copy constructor not implemented"); |
d0d4a6b3 | 1015 | } |
1016 | /*****************************************************************************/ | |
1017 | AliObjectLoader& AliObjectLoader::operator=(const AliObjectLoader& /*source*/) { | |
1018 | // Assignment operator | |
21bf7095 | 1019 | AliFatal("Assignment operator not implemented"); |
d0d4a6b3 | 1020 | return *this; |
1021 | } | |
1022 | /*****************************************************************************/ | |
88cb7938 | 1023 | |
1024 | void AliObjectLoader::RemoveFromBoard(TObject* obj) | |
1025 | { | |
d0d4a6b3 | 1026 | // Removes "obj" from the board |
88cb7938 | 1027 | GetFolder()->Remove(obj); |
1028 | } | |
1029 | /*****************************************************************************/ | |
1030 | Int_t AliObjectLoader::AddToBoard(TObject* obj) | |
1031 | { | |
d0d4a6b3 | 1032 | // Adds "obj" to the board |
88cb7938 | 1033 | GetFolder()->Add(obj); |
1034 | return 0; | |
1035 | } | |
1036 | /*****************************************************************************/ | |
1037 | ||
1038 | TObject* AliObjectLoader::Get() const | |
1039 | { | |
d0d4a6b3 | 1040 | // Returns pointer to the object loader |
88cb7938 | 1041 | return (GetFolder()) ? GetFolder()->FindObject(GetName()) : 0x0; |
1042 | } | |
1043 | ||
1044 | /*****************************************************************************/ | |
1045 | /*****************************************************************************/ | |
1046 | /*****************************************************************************/ | |
1047 | //__________________________________________ | |
1048 | /////////////////////////////////////////////////////////////////////////////// | |
1049 | // // | |
1050 | // class AliTreeLoader // | |
1051 | // // | |
1052 | // // | |
1053 | /////////////////////////////////////////////////////////////////////////////// | |
1054 | ||
1055 | ClassImp(AliTreeLoader) | |
1056 | ||
1057 | AliTreeLoader::AliTreeLoader(const TString& name, AliDataLoader* dl,Bool_t storeontop): | |
1058 | AliObjectLoader(name,dl,storeontop) | |
1059 | { | |
1060 | //constructor | |
1061 | } | |
d0d4a6b3 | 1062 | /*****************************************************************************/ |
1063 | AliTreeLoader::AliTreeLoader(const AliTreeLoader& source): | |
1064 | AliObjectLoader(source) { | |
1065 | // copy constructor | |
21bf7095 | 1066 | AliFatal("Copy constructor not implemented"); |
d0d4a6b3 | 1067 | } |
1068 | /*****************************************************************************/ | |
1069 | AliTreeLoader& AliTreeLoader::operator=(const AliTreeLoader& /*source*/) { | |
1070 | // Assignment operator | |
21bf7095 | 1071 | AliFatal("Assignment operator not implemented"); |
d0d4a6b3 | 1072 | return *this; |
1073 | } | |
88cb7938 | 1074 | |
1075 | /*****************************************************************************/ | |
1076 | ||
1077 | Int_t AliTreeLoader::WriteData(Option_t* opt) | |
1078 | { | |
1079 | //Writes data defined by di object | |
1080 | //opt might be "OVERWRITE" in case of forcing overwriting | |
1081 | ||
21bf7095 | 1082 | AliDebug(1, Form("Writing %s container for %s data. Option is %s.", |
1083 | GetName(),GetDataLoader()->GetName(),opt)); | |
88cb7938 | 1084 | |
1085 | TObject *data = Get(); | |
1086 | if(data == 0x0) | |
1087 | {//did not get, nothing to write | |
21bf7095 | 1088 | AliWarning(Form("Tree named %s not found in folder. Nothing to write.",GetName())); |
88cb7938 | 1089 | return 0; |
1090 | } | |
1091 | ||
1092 | //check if file is opened | |
1093 | if (GetDirectory() == 0x0) | |
1094 | { | |
1095 | //if not try to open | |
1096 | GetDataLoader()->SetFileOption("UPDATE"); | |
1097 | if (GetDataLoader()->OpenFile("UPDATE")) | |
1098 | { | |
1099 | //oops, can not open the file, give an error message and return error code | |
21bf7095 | 1100 | AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName())); |
88cb7938 | 1101 | return 1; |
1102 | } | |
1103 | } | |
1104 | ||
1105 | if (GetDataLoader()->IsFileWritable() == kFALSE) | |
1106 | { | |
21bf7095 | 1107 | AliError(Form("File %s is not writable",GetDataLoader()->GetFileName().Data())); |
88cb7938 | 1108 | return 2; |
1109 | } | |
1110 | ||
1111 | GetDirectory()->cd(); //set the proper directory active | |
1112 | ||
1113 | //see if hits container already exists in this (root) directory | |
1114 | TObject* obj = GetFromDirectory(GetName()); | |
1115 | if (obj) | |
1116 | { //if they exist, see if option OVERWRITE is used | |
1117 | const char *oOverWrite = strstr(opt,"OVERWRITE"); | |
1118 | if(!oOverWrite) | |
1119 | {//if it is not used - give an error message and return an error code | |
21bf7095 | 1120 | AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data"); |
88cb7938 | 1121 | return 3; |
1122 | } | |
1123 | } | |
1124 | ||
21bf7095 | 1125 | AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s", |
1126 | GetName(),opt,data->GetName())); | |
1127 | AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s", | |
88cb7938 | 1128 | GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(), |
21bf7095 | 1129 | GetDirectory()->GetFile()->GetName())); |
88cb7938 | 1130 | |
1131 | //if a data object is a tree set the directory | |
1132 | TTree* tree = dynamic_cast<TTree*>(data); | |
1133 | if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above) | |
1134 | ||
21bf7095 | 1135 | AliDebug(1, "Writing tree"); |
88cb7938 | 1136 | data->Write(0,TObject::kOverwrite); |
1137 | ||
1138 | fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader. | |
1139 | ||
1140 | return 0; | |
1141 | ||
1142 | } | |
1143 | /*****************************************************************************/ | |
1144 | ||
1145 | void AliTreeLoader::MakeTree() | |
1146 | { | |
f2a509af | 1147 | //this virtual method creates the tree in the file |
88cb7938 | 1148 | if (Tree()) |
1149 | { | |
21bf7095 | 1150 | AliDebug(1, Form("name = %s, Data Name = %s Tree already exists.", |
1151 | GetName(),GetDataLoader()->GetName())); | |
88cb7938 | 1152 | return;//tree already made |
1153 | } | |
21bf7095 | 1154 | AliDebug(1, Form("Making Tree named %s.",GetName())); |
88cb7938 | 1155 | |
1156 | TString dtypename(GetDataLoader()->GetName()); | |
1157 | TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree | |
1158 | if (tree == 0x0) | |
1159 | { | |
21bf7095 | 1160 | AliError(Form("Can not create %s tree.",GetName())); |
88cb7938 | 1161 | return; |
1162 | } | |
1163 | tree->SetAutoSave(1000000000); //no autosave | |
1164 | GetFolder()->Add(tree); | |
1165 | WriteData("OVERWRITE");//write tree to the file | |
1166 | } | |
1167 | ||
1168 | ||
1169 | /*****************************************************************************/ | |
1170 | /*****************************************************************************/ | |
1171 | /*****************************************************************************/ | |
1172 | //__________________________________________ | |
1173 | /////////////////////////////////////////////////////////////////////////////// | |
1174 | // // | |
1175 | // class AliTaskLoader // | |
1176 | // // | |
1177 | // // | |
1178 | /////////////////////////////////////////////////////////////////////////////// | |
1179 | ||
1180 | ClassImp(AliTaskLoader) | |
1181 | ||
1182 | AliTaskLoader::AliTaskLoader(const TString& name, AliDataLoader* dl, TTask* parentaltask, Bool_t storeontop): | |
1183 | AliBaseLoader(name,dl,storeontop), | |
1184 | fParentalTask(parentaltask) | |
1185 | { | |
1186 | //constructor | |
1187 | } | |
1188 | ||
d0d4a6b3 | 1189 | /*****************************************************************************/ |
1190 | AliTaskLoader::AliTaskLoader(const AliTaskLoader& source): | |
90e48c0c | 1191 | AliBaseLoader(source), |
1192 | fParentalTask(source.fParentalTask) | |
1193 | { | |
d0d4a6b3 | 1194 | // copy constructor |
21bf7095 | 1195 | AliFatal("Copy constructor not implemented"); |
d0d4a6b3 | 1196 | } |
1197 | /*****************************************************************************/ | |
1198 | AliTaskLoader& AliTaskLoader::operator=(const AliTaskLoader& /*source*/) { | |
1199 | // Assignment operator | |
21bf7095 | 1200 | AliFatal("Assignment operator not implemented"); |
d0d4a6b3 | 1201 | return *this; |
1202 | } | |
88cb7938 | 1203 | /*****************************************************************************/ |
3637d19d | 1204 | void AliTaskLoader::Clean() |
1205 | { | |
1206 | //removes tasl from parental task | |
1207 | // DO NOT DELETE OBJECT contrary to BaseLoader | |
1208 | // | |
21bf7095 | 1209 | AliDebug(1, Form("Clean","%s %s",GetName(),GetDataLoader()->GetName())); |
3637d19d | 1210 | TObject* obj = Get(); |
1211 | if(obj) | |
1212 | { | |
21bf7095 | 1213 | AliDebug(1, Form("cleaning %s.",GetName())); |
3637d19d | 1214 | RemoveFromBoard(obj); |
1215 | } | |
1216 | } | |
1217 | /*****************************************************************************/ | |
88cb7938 | 1218 | |
1219 | void AliTaskLoader::RemoveFromBoard(TObject* obj) | |
1220 | { | |
d0d4a6b3 | 1221 | // Removes the task "obj" from the board |
88cb7938 | 1222 | GetParentalTask()->GetListOfTasks()->Remove(obj); |
1223 | } | |
1224 | /*****************************************************************************/ | |
1225 | ||
1226 | Int_t AliTaskLoader::AddToBoard(TObject* obj) | |
1227 | { | |
d0d4a6b3 | 1228 | // Adds task "obj" to the board |
88cb7938 | 1229 | TTask* task = dynamic_cast<TTask*>(obj); |
1230 | if (task == 0x0) | |
1231 | { | |
21bf7095 | 1232 | AliError("To TTask board can be added only tasks."); |
88cb7938 | 1233 | return 1; |
1234 | } | |
1235 | GetParentalTask()->Add(task); | |
1236 | return 0; | |
1237 | } | |
1238 | /*****************************************************************************/ | |
1239 | ||
1240 | TObject* AliTaskLoader::Get() const | |
1241 | { | |
d0d4a6b3 | 1242 | // Returns pointer to the current task |
88cb7938 | 1243 | return (GetParentalTask()) ? GetParentalTask()->GetListOfTasks()->FindObject(GetName()) : 0x0; |
1244 | } | |
1245 | /*****************************************************************************/ | |
1246 | ||
1247 | TTask* AliTaskLoader::GetParentalTask() const | |
1248 | { | |
1249 | //returns parental tasks for this task | |
1250 | return fParentalTask; | |
1251 | } | |
1252 | ||
1253 | /*****************************************************************************/ | |
1254 | ||
1255 | /*****************************************************************************/ | |
1256 | /*****************************************************************************/ | |
1257 | /*****************************************************************************/ | |
1258 | ||
1259 |