1 /////////////////////////////////////////////////////////////////////////////////////////////
3 // class AliDataLoader //
5 // Container of all data needed for full //
6 // description of each data type //
7 // (Hits, Kine, ...) //
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 //
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 //
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 //
27 /////////////////////////////////////////////////////////////////////////////////////////////
36 #include "AliDataLoader.h"
38 #include "AliObjectLoader.h"
39 #include "AliRunLoader.h"
40 #include "AliTreeLoader.h"
42 ClassImp(AliDataLoader)
44 //______________________________________________________________________________
45 AliDataLoader::AliDataLoader():
62 //______________________________________________________________________________
63 AliDataLoader::AliDataLoader(const char* filename, const char* contname,
64 const char* name, Option_t* opt):
72 fBaseLoaders(new TObjArray(4)),
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
83 AliDebug(1, Form("File name is %s",fFileName.Data()));
87 if (option.CompareTo("T",TString::kIgnoreCase) == 0)
88 bl = new AliTreeLoader(contname,this);
90 bl = new AliObjectLoader(contname,this);
91 fBaseLoaders->AddAt(bl,kData);
95 //______________________________________________________________________________
96 AliDataLoader::AliDataLoader(const AliDataLoader& source) :
98 fFileName(source.fFileName),
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)
114 AliFatal("Copy constructor not implemented");
118 //______________________________________________________________________________
119 AliDataLoader& AliDataLoader::operator=(const AliDataLoader& /*source*/)
122 // Assignment operator
124 AliFatal("Assignment operator not implemented");
129 //______________________________________________________________________________
130 AliDataLoader::~AliDataLoader()
138 //______________________________________________________________________________
139 Int_t AliDataLoader::SetEvent()
142 // The same that GetEvent but do not post data to folders
144 AliRunLoader* rl = GetRunLoader();
147 AliError("Can not get RunGettr");
151 Int_t evno = rl->GetEventNumber();
153 TIter next(fBaseLoaders);
155 while ((bl = (AliBaseLoader*)next()))
157 if (bl->DoNotReload() == kFALSE) bl->Clean();
166 AliDebug(1, Form("Reloading new file. File opt is %s",fFileOption.Data()));
167 OpenFile(fFileOption);
170 fDirectory = AliLoader::ChangeDir(fFile,evno);
171 if (fDirectory == 0x0)
173 AliError(Form("Can not chage directory in file %s",fFile->GetName()));
180 //______________________________________________________________________________
181 Int_t AliDataLoader::GetEvent()
183 // posts all loaded data from files to White Board
184 // event number is defined in RunLoader
187 // 0 - in case of no error
188 // 1 - event not found
190 //for each base laoder post, if was loaded before GetEvent
192 //call set event to switch to new directory in file
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
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);
203 while ((bl = (AliBaseLoader*)nextbl()))
207 if (bl->DoNotReload() == kFALSE) bl->Post();
214 //______________________________________________________________________________
215 Int_t AliDataLoader::OpenFile(Option_t* opt)
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
222 if(fFile->IsOpen() == kTRUE)
224 AliWarning(Form(" File %s already opened. First close it.",fFile->GetName()));
229 AliWarning(Form("Pointer to file %s is not null, but file is not opened",
236 TString fname(SetFileOffset(fFileName));
238 fFile = (TFile *)(gROOT->GetListOfFiles()->FindObject(fname));
241 if(fFile->IsOpen() == kTRUE)
243 AliWarning(Form("File %s already opened by sombody else. First close it.",
250 fFile = TFile::Open(fname,fFileOption);//open the file
253 AliError(Form("Can not open file %s",fname.Data()));
256 if (fFile->IsOpen() == kFALSE)
258 AliError(Form("Can not open file %s",fname.Data()));
262 fFile->SetCompressionLevel(fCompressionLevel);
264 AliRunLoader* rg = GetRunLoader();
267 AliError("Can not find Run-Loader in folder.");
270 Int_t evno = rg->GetEventNumber();
272 fDirectory = AliLoader::ChangeDir(fFile,evno);
273 if (fDirectory == 0x0)
275 AliError(Form("Can not chage fDirectory in file %s.",fFile->GetName()));
281 //______________________________________________________________________________
282 void AliDataLoader::Unload()
285 //unloads main data - shortcut method
287 GetBaseLoader(0)->Unload();
290 //______________________________________________________________________________
291 void AliDataLoader::UnloadAll()
294 // Unloads all data and tasks
296 if ( fFile == 0x0 ) return; //nothing loaded
298 TIter next(fBaseLoaders);
300 while ((bl = (AliBaseLoader*)next()))
307 //______________________________________________________________________________
308 Int_t AliDataLoader::Reload()
311 // Unloads and loads data again
313 if ( fFile == 0x0 ) return 0;
315 TBits loaded(fBaseLoaders->GetEntries());
316 TIter next(fBaseLoaders);
320 while ((bl = (AliBaseLoader*)next()))
324 loaded.SetBitNumber(i++,kTRUE);
332 while ((bl = (AliBaseLoader*)next()))
334 if (loaded.TestBitNumber(i++))
336 retval = bl->Load(fFileOption);
339 AliError(Form("Error occur while loading %s",bl->GetName()));
348 //______________________________________________________________________________
349 Int_t AliDataLoader::WriteData(Option_t* opt)
352 // Writes primary data == first BaseLoader
354 AliDebug(1, Form("Writing %s container for %s data. Option is %s.",
355 GetBaseLoader(0)->GetName(),GetName(),opt));
356 return GetBaseLoader(0)->WriteData(opt);
359 //______________________________________________________________________________
360 Int_t AliDataLoader::Load(Option_t* opt)
363 // Writes primary data == first BaseLoader
365 return GetBaseLoader(0)->Load(opt);
368 //______________________________________________________________________________
369 Int_t AliDataLoader::SetEventFolder(TFolder* eventfolder)
372 // Sets the event folder
374 if (eventfolder == 0x0)
376 AliError("Stupid joke. Argument is NULL");
379 AliDebug(1, Form("name = %s Setting Event Folder named %s.",
380 GetName(),eventfolder->GetName()));
382 fEventFolder = eventfolder;
387 //______________________________________________________________________________
388 Int_t AliDataLoader::SetFolder(TFolder* folder)
390 // Sets the folder and the data loaders
393 AliError("Stupid joke. Argument is NULL");
397 AliDebug(1, Form("name = %s Setting folder named %s.",GetName(),folder->GetName()));
400 TIter next(fBaseLoaders);
403 while ((bl = (AliBaseLoader*)next()))
405 bl->SetDataLoader(this);
411 //______________________________________________________________________________
412 TFolder* AliDataLoader::GetEventFolder()
416 // Data that are changing from event to event, even in single run
418 AliDebug(1, "EF = %#x");
422 //______________________________________________________________________________
423 AliRunLoader* AliDataLoader::GetRunLoader()
426 // Gets the run-loader from event folder
428 AliRunLoader* rg = 0x0;
429 TFolder* ef = GetEventFolder();
432 AliError("Can not get event folder.");
435 rg = dynamic_cast<AliRunLoader*>(ef->FindObject(AliRunLoader::GetRunLoaderName()));
439 //______________________________________________________________________________
440 void AliDataLoader::CloseFile()
445 TIter next(fBaseLoaders);
447 while ((bl = (AliBaseLoader*)next()))
449 if (bl->IsLoaded()) return;
452 AliDebug(1, "Closing and deleting (object) file.");
460 //______________________________________________________________________________
461 void AliDataLoader::Clean()
466 GetBaseLoader(0)->Clean();
469 //______________________________________________________________________________
470 void AliDataLoader::CleanAll()
473 // Cleans all folders and tasks
475 TIter next(fBaseLoaders);
477 while ((bl = (AliBaseLoader*)next()))
483 //______________________________________________________________________________
484 void AliDataLoader::SetFileNameSuffix(const TString& suffix)
487 // adds the suffix before ".root",
488 // e.g. TPC.Digits.root -> TPC.DigitsMerged.root
489 // made on Jiri Chudoba demand
491 AliDebug(1, Form("suffix=%s",suffix.Data()));
492 AliDebug(1, Form(" Digits File Name before: %s",fFileName.Data()));
494 static TString dotroot(".root");
495 const TString& suffixdotroot = suffix + dotroot;
496 fFileName = fFileName.ReplaceAll(dotroot,suffixdotroot);
498 AliDebug(1, Form(" after : %s",fFileName.Data()));
501 //______________________________________________________________________________
502 Bool_t AliDataLoader::CheckReload()
505 // Checks if we have to reload given file
507 if (fFile == 0x0) return kFALSE;
508 TString tmp = SetFileOffset(fFileName);
509 if (tmp.CompareTo(fFile->GetName())) return kTRUE; //file must be reloaded
513 //______________________________________________________________________________
514 const TString AliDataLoader::SetFileOffset(const TString& fname)
519 Long_t offset = (Long_t)GetRunLoader()->GetFileOffset();
520 if (fNEventsPerFile > 0) {
521 offset = GetRunLoader()->GetEventNumber()/fNEventsPerFile;
523 if (offset < 1) return fname;
526 soffset += offset;//automatic conversion to string
527 TString dotroot(".root");
528 const TString& offfsetdotroot = offset + dotroot;
530 out = out.ReplaceAll(dotroot,offfsetdotroot);
531 AliDebug(1, Form("in=%s out=%s.",fname.Data(),out.Data()));
535 //______________________________________________________________________________
536 void AliDataLoader::SetFileOption(Option_t* newopt)
541 if (fFileOption.CompareTo(newopt) == 0) return;
542 fFileOption = newopt;
546 //______________________________________________________________________________
547 void AliDataLoader::SetCompressionLevel(Int_t cl)
550 // Sets comression level for data defined by di
552 fCompressionLevel = cl;
553 if (fFile) fFile->SetCompressionLevel(cl);
556 //______________________________________________________________________________
557 void AliDataLoader::MakeTree()
560 // Makes tree for the current data loader
562 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(fBaseLoaders->At(0));
565 AliError("Can not make a tree because main base loader is not a tree loader");
571 //______________________________________________________________________________
572 Bool_t AliDataLoader::IsFileWritable() const
575 // Returns true if file is writable
577 return (fFile)?fFile->IsWritable():kFALSE;
580 //______________________________________________________________________________
581 Bool_t AliDataLoader::IsFileOpen() const
584 // Returns true if file is writable
586 return (fFile)?fFile->IsOpen():kFALSE;
589 //______________________________________________________________________________
590 Bool_t AliDataLoader::IsOptionContrary(const TString& option) const
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
595 if (fFile == 0x0) return kFALSE; //file is not opened - no problem
597 if ( ( AliLoader::IsOptionWritable(option) == kTRUE ) && // passed option is writable and
598 ( AliLoader::IsOptionWritable(fFileOption) == kFALSE ) ) // existing one is not writable
607 //______________________________________________________________________________
608 void AliDataLoader::AddBaseLoader(AliBaseLoader* bl)
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,
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
618 AliWarning("Pointer is null.");
622 TObject* obj = fBaseLoaders->FindObject(bl->GetName());
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()));
630 fBaseLoaders->Add(bl);
633 //______________________________________________________________________________
634 AliBaseLoader* AliDataLoader::GetBaseLoader(const TString& name) const
637 // Return pointer to base loader
639 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->FindObject(name));
642 //______________________________________________________________________________
643 AliBaseLoader* AliDataLoader::GetBaseLoader(Int_t n) const
646 // Gets the n-th base loader (what is n?)
648 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->At(n));
651 //______________________________________________________________________________
652 TTree* AliDataLoader::Tree() const
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;
663 //______________________________________________________________________________
664 void AliDataLoader::SetDirName(TString& dirname)
667 // Sets the directory name where the files will be stored
669 AliDebug(10, Form("FileName before %s",fFileName.Data()));
670 Int_t n = fFileName.Last('/');
671 AliDebug(10, Form("Slash found on pos %d",n));
672 if (n > 0) fFileName = fFileName.Remove(0,n+1);
673 AliDebug(10, Form("Core FileName %s",fFileName.Data()));
674 fFileName = dirname + "/" + fFileName;
675 AliDebug(10, Form("FileName after %s",fFileName.Data()));
678 //______________________________________________________________________________
679 AliObjectLoader* AliDataLoader::GetBaseDataLoader()
682 // Gets the base data loader
684 return dynamic_cast<AliObjectLoader*>(GetBaseLoader(kData));
687 //______________________________________________________________________________
688 AliTaskLoader* AliDataLoader::GetBaseTaskLoader()
691 // Gets the base task loader
693 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kTask));
696 //______________________________________________________________________________
697 AliBaseLoader* AliDataLoader::GetBaseQALoader()
700 // Gets the base QA loader
702 return GetBaseLoader(kQA);
705 //______________________________________________________________________________
706 AliTaskLoader* AliDataLoader::GetBaseQATaskLoader()
709 // Returns pointer to QA base loader
711 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kQATask));
714 //______________________________________________________________________________
715 void AliDataLoader::SetBaseDataLoader(AliBaseLoader* bl)
718 // Sets data base loader
722 AliError("Parameter is null");
725 if (GetBaseDataLoader()) delete GetBaseDataLoader();
726 fBaseLoaders->AddAt(bl,kData);
729 //______________________________________________________________________________
730 void AliDataLoader::SetBaseTaskLoader(AliTaskLoader* bl)
733 // Sets Task base loader
737 AliError("Parameter is null");
740 if (GetBaseTaskLoader()) delete GetBaseTaskLoader();
741 fBaseLoaders->AddAt(bl,kTask);
744 //______________________________________________________________________________
745 void AliDataLoader::SetBaseQALoader(AliBaseLoader* bl)
748 // Sets QA base loader
752 AliError("Parameter is null");
755 if (GetBaseQALoader()) delete GetBaseQALoader();
756 fBaseLoaders->AddAt(bl,kQA);
759 //______________________________________________________________________________
760 void AliDataLoader::SetBaseQATaskLoader(AliTaskLoader* bl)
763 // Sets QA Task base loader
767 AliError("Parameter is null");
770 if (GetBaseQATaskLoader()) delete GetBaseQATaskLoader();
771 fBaseLoaders->AddAt(bl,kQATask);
774 //______________________________________________________________________________
775 void AliDataLoader::Synchronize()
778 // Synchronizes all writable files
780 if ( fFile ) fFile->Flush();