2 //Class (base) responsible for management of data:
3 // - opening and closing proper files
4 // - posting data to folders
5 // - writing data from folders to proper files
7 //Author: Alice Offline Group http://alisoft.cern.ch
8 //Responsible: Piotr.Skowronski@cern.ch
10 #include "AliLoader.h"
20 #include "AliConfig.h"
21 #include "AliDetector.h"
22 #include "AliDigitizer.h"
25 #include "AliRunLoader.h"
27 const TString AliLoader::fgkDefaultHitsContainerName("TreeH");
28 const TString AliLoader::fgkDefaultDigitsContainerName = "TreeD";
29 const TString AliLoader::fgkDefaultSDigitsContainerName = "TreeS";
30 const TString AliLoader::fgkDefaultRecPointsContainerName = "TreeR";
31 const TString AliLoader::fgkDefaultTracksContainerName = "TreeT";
32 const TString AliLoader::fgkDefaultRecParticlesContainerName = "TreeP";
33 const TString AliLoader::fgkLoaderBaseName("Loader");
36 //___________________________________________________________________
37 /////////////////////////////////////////////////////////////////////
41 // Base class for Loaders. //
42 // Loader provides base I/O fascilities for "standard" data. //
43 // Each detector has a laoder data member //
44 // loader is accessible via folder structure as well //
46 /////////////////////////////////////////////////////////////////////
48 /*****************************************************************************/
50 AliLoader::AliLoader():
55 fDetectorDataFolder(0x0),
63 /******************************************************************/
65 AliLoader::AliLoader(const Char_t* detname,const Char_t* eventfoldername):
66 fDataLoaders(new TObjArray(kNDataTypes)),
70 fDetectorDataFolder(0x0),
76 AliDebug(1, Form("detname = %s eventfoldername = %s",detname,eventfoldername));
78 //try to find folder eventfoldername in top alice folder
79 //safe because GetTopFolder will abort in case of failure
81 fDetectorName = detname;
82 fName = fDetectorName+"Loader";
85 TObject* fobj = GetTopFolder()->FindObject(eventfoldername);
86 fEventFolder = (fobj)?dynamic_cast<TFolder*>(fobj):0x0;//in case FindObject returns NULL dynamic cast cause seg. fault
87 SetEventFolder(fEventFolder);
90 /*****************************************************************************/
92 AliLoader::AliLoader(const Char_t * detname,TFolder* eventfolder):
93 fDataLoaders(new TObjArray(kNDataTypes)),
94 fDetectorName(detname),
97 fDetectorDataFolder(0x0),
103 fDetectorName = detname;
104 fName = fDetectorName+"Loader";
106 SetEventFolder(eventfolder);
107 //fileoption's don't need to initialized because default TString ctor does it correctly
110 /*****************************************************************************/
111 AliLoader::~AliLoader()
114 if (fDataLoaders) fDataLoaders->SetOwner();
117 /*****************************************************************************/
119 void AliLoader::InitDefaults()
123 dl = new AliDataLoader(fDetectorName + ".Hits.root",fgkDefaultHitsContainerName, "Hits" );
124 fDataLoaders->AddAt(dl,kHits);
127 // S U M M A B L E D I G I T S
128 dl = new AliDataLoader(fDetectorName + ".SDigits.root",fgkDefaultSDigitsContainerName, "Summable Digits");
129 AliTaskLoader* tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetSDigitizerTaskName(),
130 dl,AliRunLoader::GetRunSDigitizer(),kTRUE);
131 dl->SetBaseTaskLoader(tl);
132 fDataLoaders->AddAt(dl,kSDigits);
135 dl = new AliDataLoader(fDetectorName + ".Digits.root",fgkDefaultDigitsContainerName, "Digits");
136 tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetDigitizerTaskName(),
137 dl,AliRunLoader::GetRunDigitizer(),kTRUE);
138 dl->SetBaseTaskLoader(tl);
139 fDataLoaders->AddAt(dl,kDigits);
141 // R E C O N S T R U C T E D P O I N T S aka C L U S T E R S
142 dl = new AliDataLoader(fDetectorName + ".RecPoints.root",fgkDefaultRecPointsContainerName, "Reconstructed Points");
143 tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetReconstructionerTaskName(),
144 dl,AliRunLoader::GetRunReconstructioner(),kTRUE);
145 dl->SetBaseTaskLoader(tl);
146 fDataLoaders->AddAt(dl,kRecPoints);
149 dl = new AliDataLoader(fDetectorName + ".Tracks.root",fgkDefaultTracksContainerName, "Tracks");
150 tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetTrackerTaskName(),
151 dl,AliRunLoader::GetRunTracker(),kTRUE);
152 dl->SetBaseTaskLoader(tl);
153 fDataLoaders->AddAt(dl,kTracks);
155 // R E C O N S T R U C T E D P O I N T S aka C L U S T E R S
156 dl = new AliDataLoader(fDetectorName + ".RecParticles.root",fgkDefaultRecParticlesContainerName, "Reconstructed Particles");
157 tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetPIDTaskName(),
158 dl,AliRunLoader::GetRunPIDTask(),kTRUE);
159 dl->SetBaseTaskLoader(tl);
160 fDataLoaders->AddAt(dl,kRecParticles);
163 /*****************************************************************************/
165 AliDataLoader* AliLoader::GetDataLoader(const char* name)
167 //returns Data Loader with specified name
168 return dynamic_cast<AliDataLoader*>(fDataLoaders->FindObject(name));
170 /*****************************************************************************/
171 void AliLoader::AddDataLoader(AliDataLoader* dl)
174 // Adds a data loader
178 AliError("Pointer is NULL");
181 if (fDataLoaders->FindObject(dl->GetName()))
183 AliError("Such a loader exists");
186 fDataLoaders->AddLast(dl);
187 dl->SetEventFolder(fEventFolder);
188 dl->SetFolder(GetDetectorDataFolder()); //Must exists - ensure register is called before
190 /*****************************************************************************/
192 Int_t AliLoader::SetEvent()
194 //basically the same that GetEvent but do not post data to folders
195 TIter next(fDataLoaders);
197 while ((dl = (AliDataLoader*)next()))
203 /******************************************************************/
205 void AliLoader::UnloadAll()
207 //calls UnloadAll for all base laoders
209 TIter next(fDataLoaders);
211 while ((dl = (AliDataLoader*)next()))
216 /******************************************************************/
218 Int_t AliLoader::GetEvent()
220 //changes to proper root directory and tries to load data from files to folders
221 // event number is defined in RunLoader
224 // 0 - in case of no error
225 // 1 - event not found
229 TIter next(fDataLoaders);
231 while ((dl = (AliDataLoader*)next()))
233 retval = dl->GetEvent();
236 AliError(Form("Error occured while GetEvent for %s",dl->GetName()));
244 /******************************************************************/
246 TFolder* AliLoader::GetTopFolder()
248 //returns TOP aliroot folder, just a simple interface to AliConfig (gives shorter notation)
249 return AliConfig::Instance()->GetTopFolder();
252 /******************************************************************/
254 TFolder* AliLoader::GetEventFolder()
256 //get EVENT folder (data that are changing from event to event, even in single run)
259 /******************************************************************/
260 TFolder* AliLoader::GetDataFolder()
262 //returns the folder speciofic to given detector e.g. /Folders/Event/Data/
265 fDataFolder = dynamic_cast<TFolder*>(GetEventFolder()->FindObject(AliConfig::Instance()->GetDataFolderName()));
269 AliFatal("Can not find AliRoot data folder. Aborting");
276 /*****************************************************************************/
278 TFolder* AliLoader::GetTasksFolder()
280 //Returns pointer to Folder with Alice Tasks
283 fTasksFolder = dynamic_cast<TFolder*>(GetTopFolder()->FindObject(AliConfig::GetTasksFolderName()));
287 AliFatal("Can not find tasks folder. Aborting");
294 /*****************************************************************************/
296 TFolder* AliLoader::GetModulesFolder()
298 //returns pointer to the folder containing modules
301 fModuleFolder = dynamic_cast<TFolder*>(GetEventFolder()->FindObjectAny(AliConfig::GetModulesFolderName()));
305 AliFatal("Can not find modules folder. Aborting");
309 return fModuleFolder;
312 /*****************************************************************************/
314 TFolder* AliLoader::GetQAFolder()
316 //returns folder with Quality assurance
317 if (fQAFolder == 0x0)
319 TObject *obj = GetEventFolder()->FindObjectAny(AliConfig::Instance()->GetQAFolderName());
320 fQAFolder = (obj)?dynamic_cast<TFolder*>(obj):0x0;
322 if (fQAFolder == 0x0)
324 AliFatal("Can not find Quality Assurance folder. Aborting");
331 /*****************************************************************************/
332 TTask* AliLoader::SDigitizer() const
334 //returns SDigitizer task for this detector
335 return GetSDigitsDataLoader()->GetBaseTaskLoader()->Task();
338 /*****************************************************************************/
340 AliDigitizer* AliLoader::Digitizer() const
342 //returns Digitizer task for this detector
343 return dynamic_cast<AliDigitizer*>(GetDigitsDataLoader()->GetBaseTaskLoader()->Task());
345 /*****************************************************************************/
347 TTask* AliLoader::Reconstructioner() const
349 //returns Recontructioner (Cluster Finder, Cluster Maker,
350 //or whatever you want to call it) task for this detector
351 return GetRecPointsDataLoader()->GetBaseTaskLoader()->Task();
353 /*****************************************************************************/
355 TTask* AliLoader::Tracker() const
358 return dynamic_cast<TTask*>(GetTracksDataLoader()->GetBaseTaskLoader()->Task());
361 /*****************************************************************************/
362 TTask* AliLoader::PIDTask() const
365 return dynamic_cast<TTask*>(GetRecParticlesDataLoader()->GetBaseTaskLoader()->Task());
368 /*****************************************************************************/
370 TTask* AliLoader::QAtask(const char* name) const
372 // Returns pointer to the quality assurance task
373 TTask* qat = AliRunLoader::GetRunQATask();
376 AliError(Form("Can not get RunQATask. (Name:%s)",GetName()));
380 TString dqatname(fDetectorName + AliConfig::Instance()->GetQATaskName());
381 TTask* dqat = dynamic_cast<TTask*>(qat->GetListOfTasks()->FindObject(dqatname));
385 AliError(Form("Can not find QATask in RunQATask for %s",GetDetectorName().Data()));
389 if (strlen(name) == 0) return dqat;
391 TList* list = dqat->GetListOfTasks();
395 while((task = static_cast<TTask *>(it.Next()) ))
397 TString taskname(task->GetName()) ;
398 if(taskname.BeginsWith(name))
401 AliError(Form("Can not find sub-task with name starting with %s in task %s",name,dqat->GetName()));
404 /*****************************************************************************/
406 TDirectory* AliLoader::ChangeDir(TFile* file, Int_t eventno)
408 //changes the root directory in "file" to "dirname" which corresponds to event 'eventno'
409 //in case of success returns the pointer to directory
414 AliErrorClass("File is null");
417 if (file->IsOpen() == kFALSE)
419 AliErrorClass("File is not opened");
423 TString dirname("Event");
425 AliDebugClass(1, Form("Changing Dir to %s in file %s.",dirname.Data(),file->GetName()));
429 TDirectory* dir = dynamic_cast<TDirectory*>(file->Get(dirname));
433 AliDebugClass(1, Form("Can not find directory %s in file %s, creating...",
434 dirname.Data(),file->GetName()));
436 if (file->IsWritable() == kFALSE)
438 AliErrorClass(Form("Can not create directory. File %s in not writable.",
443 TDirectory* newdir = file->mkdir(dirname);
446 AliErrorClass(Form("Failed to create new directory in file %s.",
450 result = file->cd(dirname);
451 if (result == kFALSE)
458 file->cd();//make a file active
459 file->cd(dirname);//cd event dir
464 /*****************************************************************************/
466 TString AliLoader::GetUnixDir() const
468 //This Method will manage jumping through unix directories in case of
469 //run with more events per run than defined in gAlice
475 /*****************************************************************************/
476 /************************************************************/
478 void AliLoader::MakeTree(Option_t *option)
480 //Makes a tree depending on option
483 // S: - Summable Digits
484 // R: - Reconstructed Points (clusters)
485 // T: - Tracks (tracklets)
487 const char *oH = strstr(option,"H");
488 const char *oD = strstr(option,"D");
489 const char *oS = strstr(option,"S");
490 const char *oR = strstr(option,"R");
491 const char *oT = strstr(option,"T");
492 const char *oP = strstr(option,"P");
494 if (oH) MakeHitsContainer();
495 if (oD) MakeDigitsContainer();
496 if (oS) MakeSDigitsContainer();
497 if (oR) MakeRecPointsContainer();
498 if (oT) MakeTracksContainer();
499 if (oP) MakeRecParticlesContainer();
502 /*****************************************************************************/
503 Int_t AliLoader::WriteHits(Option_t* opt) const
506 AliDataLoader* dl = GetHitsDataLoader();
507 Int_t ret = dl->WriteData(opt);
510 /*****************************************************************************/
512 Int_t AliLoader::WriteSDigits(Option_t* opt) const
514 // Writes summable digits
515 AliDataLoader* dl = GetSDigitsDataLoader();
516 Int_t ret = dl->WriteData(opt);
520 /*****************************************************************************/
522 Int_t AliLoader::PostSDigitizer(TTask* sdzer) const
525 return GetSDigitsDataLoader()->GetBaseTaskLoader()->Post(sdzer);
527 /*****************************************************************************/
529 Int_t AliLoader::PostDigitizer(AliDigitizer* task) const
532 return GetDigitsDataLoader()->GetBaseTaskLoader()->Post(task);
534 /*****************************************************************************/
536 Int_t AliLoader::PostReconstructioner(TTask* task) const
538 // Posts Reconstructioner
539 return GetRecPointsDataLoader()->GetBaseTaskLoader()->Post(task);
541 /*****************************************************************************/
543 Int_t AliLoader::PostTracker(TTask* task) const
546 return GetTracksDataLoader()->GetBaseTaskLoader()->Post(task);
548 /*****************************************************************************/
550 Int_t AliLoader::PostPIDTask(TTask* task) const
552 // Posts particle identification task
553 return GetRecParticlesDataLoader()->GetBaseTaskLoader()->Post(task);
555 /*****************************************************************************/
557 TObject** AliLoader::GetDetectorDataRef(TObject *obj)
559 // Returns pointer to an entry in the list of folders pointing to "obj"
564 return GetDetectorDataFolder()->GetListOfFolders()->GetObjectRef(obj) ;
566 /*****************************************************************************/
568 TObject** AliLoader::SDigitizerRef()
570 // Returns pointer to a Runloader's task-list entry pointing to SDigitizer
571 TTask* rsd = AliRunLoader::GetRunSDigitizer();
576 return rsd->GetListOfTasks()->GetObjectRef(SDigitizer());
578 /*****************************************************************************/
580 TObject** AliLoader::DigitizerRef()
582 // Returns pointer to a Runloader's task-list entry pointing to Digitizer
583 TTask* rd = AliRunLoader::GetRunDigitizer();
588 return rd->GetListOfTasks()->GetObjectRef(Digitizer()) ;
590 /*****************************************************************************/
592 TObject** AliLoader::ReconstructionerRef()
594 // Returns pointer to a Runloader's task-list entry pointing to Reconstructioner
595 TTask* rrec = AliRunLoader::GetRunReconstructioner();
600 return rrec->GetListOfTasks()->GetObjectRef(Reconstructioner());
602 /*****************************************************************************/
604 TObject** AliLoader::TrackerRef()
606 // Returns pointer to a Runloader's task-list entry pointing to Tracker
607 TTask* rrec = AliRunLoader::GetRunTracker();
612 return rrec->GetListOfTasks()->GetObjectRef(Tracker());
614 /*****************************************************************************/
616 TObject** AliLoader::PIDTaskRef()
618 // Returns pointer to a Runloader's task-list entry pointing to PIDTask
619 TTask* rrec = AliRunLoader::GetRunPIDTask();
624 return rrec->GetListOfTasks()->GetObjectRef(PIDTask());
627 /*****************************************************************************/
628 void AliLoader::CleanFolders()
630 //Cleans all posted objects == removes from folders and deletes them
631 TIter next(fDataLoaders);
633 while ((dl = (AliDataLoader*)next()))
635 AliDebug(1, Form("name = %s cleaning",dl->GetName()));
639 /*****************************************************************************/
641 /*****************************************************************************/
643 void AliLoader::CleanSDigitizer()
645 //removes and deletes detector task from Run Task
646 if ( GetSDigitsDataLoader()->GetBaseTaskLoader() == 0x0 )
648 AliWarning("Task Loader for SDigits does not exist");
651 GetSDigitsDataLoader()->GetBaseTaskLoader()->Clean();
653 /*****************************************************************************/
655 void AliLoader::CleanDigitizer()
657 //removes and deletes detector task from Run Task
658 if ( GetDigitsDataLoader()->GetBaseTaskLoader() == 0x0 )
660 AliWarning("Task Loader for Digits does not exist");
663 GetDigitsDataLoader()->GetBaseTaskLoader()->Clean();
665 /*****************************************************************************/
667 void AliLoader::CleanReconstructioner()
669 //removes and deletes detector Reconstructioner from Run Reconstructioner
670 if ( GetRecPointsDataLoader()->GetBaseTaskLoader() == 0x0 )
672 AliWarning("Task Loader for SDigits does not exist");
675 GetRecPointsDataLoader()->GetBaseTaskLoader()->Clean();
677 /*****************************************************************************/
679 void AliLoader::CleanTracker()
681 //removes and deletes detector task from Run Task
682 if ( GetTracksDataLoader()->GetBaseTaskLoader() == 0x0 )
684 AliWarning("Task Loader for Tracks does not exist");
687 GetTracksDataLoader()->GetBaseTaskLoader()->Clean();
689 /*****************************************************************************/
691 void AliLoader::CleanPIDTask()
693 //removes and deletes detector Reconstructioner from Run Reconstructioner
695 if ( GetRecParticlesDataLoader()->GetBaseTaskLoader() == 0x0 )
697 AliWarning("Task Loader for Reconstructed Particles does not exist");
700 GetRecParticlesDataLoader()->GetBaseTaskLoader()->Clean();
702 /*****************************************************************************/
704 Int_t AliLoader::ReloadAll()
706 // Calling Reload function for all the data loaders
707 TIter next(fDataLoaders);
710 while((dl = (AliDataLoader*)next()))
712 Int_t err = dl->Reload();
715 AliError(Form("Reload returned error for %s",dl->GetName()));
721 /*****************************************************************************/
723 void AliLoader::CloseFiles()
725 //close files for data loaders
726 TIter next(fDataLoaders);
728 while((dl = (AliDataLoader*)next()))
733 /*****************************************************************************/
735 Int_t AliLoader::SetEventFolder(TFolder* eventfolder)
737 //sets the event folder
738 if (eventfolder == 0x0)
740 AliError("Stupid joke. Argument is NULL");
744 fEventFolder = eventfolder;
745 TIter next(fDataLoaders);
748 while((dl = (AliDataLoader*)next()))
750 dl->SetEventFolder(fEventFolder);
751 dl->SetFolder(GetDetectorDataFolder()); //Must exists - ensure register is called before
755 }//sets the event folder
756 /*****************************************************************************/
758 Int_t AliLoader::Register(TFolder* eventFolder)
760 //triggers creation of subfolders for a given detector
761 //this method is called when session is read from disk
763 //warning: AliDetector in constructor (not default) calls
764 //creation of folder structure as well (some detectors needs folders
765 //alrady in constructors)
767 AliDebug(1, Form("Name is %s.",GetName()));
768 if (eventFolder == 0x0)
770 AliError("Event folder is not set.");
773 Int_t retval = AliConfig::Instance()->AddDetector(eventFolder,fDetectorName,fDetectorName);
776 AliError(Form("Can not create tasks and/or folders for %s. Event folder name is %s",
777 fDetectorName.Data(),eventFolder->GetName()));
780 SetEventFolder(eventFolder);
783 /*****************************************************************************/
784 AliRunLoader* AliLoader::GetRunLoader()
786 //gets the run-loader from event folder
787 AliRunLoader* rg = 0x0;
788 TObject * obj = GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
789 if (obj) rg = dynamic_cast<AliRunLoader*>(obj);
792 /*****************************************************************************/
793 Bool_t AliLoader::TestFileOption(Option_t* opt)
795 //tests the TFile::Option
796 //if file is truncated at opening moment ("recreate", "new" or "create") returns kFALSE;
797 //else kTRUE (means opened with "read" or "update" mode)
799 if (option.CompareTo("recreate",TString::kIgnoreCase) == 0) return kFALSE;
800 if (option.CompareTo("new",TString::kIgnoreCase) == 0) return kFALSE;
801 if (option.CompareTo("create",TString::kIgnoreCase) == 0) return kFALSE;
804 /*****************************************************************************/
805 void AliLoader::SetDirName(TString& dirname)
807 //adds "dirname" to each file. Dirname should end with "#","/", or ":"
808 TIter next(fDataLoaders);
810 while((dl = (AliDataLoader*)next()))
812 dl->SetDirName(dirname);
816 /*****************************************************************************/
818 void AliLoader::SetDigitsFileNameSuffix(const TString& suffix) const
820 //adds the suffix before ".root",
821 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
822 //made on Jiri Chudoba demand
823 GetDigitsDataLoader()->SetFileNameSuffix(suffix);
825 /*****************************************************************************/
827 void AliLoader::SetCompressionLevel(Int_t cl)
829 //sets comression level for data defined by di
830 TIter next(fDataLoaders);
832 while((dl = (AliDataLoader*)next()))
834 dl->SetCompressionLevel(cl);
837 /*****************************************************************************/
839 void AliLoader::Clean()
841 //Cleans all data loaders
842 TIter next(fDataLoaders);
844 while((dl = (AliDataLoader*)next()))
849 /*****************************************************************************/
851 void AliLoader::Clean(const TString& name)
853 // Removes object with "name" from the detector's data folder
854 // and from the memory
855 TObject* obj = GetDetectorDataFolder()->FindObject(name);
858 AliDebug(1, Form("name=%s, cleaning %s.",GetName(),name.Data()));
859 GetDetectorDataFolder()->Remove(obj);
864 /*****************************************************************************/
866 Bool_t AliLoader::IsOptionWritable(const TString& opt)
868 // Returns "true" if the option means also "writable"
869 if (opt.CompareTo("recreate",TString::kIgnoreCase)) return kTRUE;
870 if (opt.CompareTo("new",TString::kIgnoreCase)) return kTRUE;
871 if (opt.CompareTo("create",TString::kIgnoreCase)) return kTRUE;
872 if (opt.CompareTo("update",TString::kIgnoreCase)) return kTRUE;
876 /*****************************************************************************/
878 void AliLoader::SetDebug(Int_t deb)
881 AliLog::SetClassDebugLevel("AliRunLoader", deb);
882 AliLog::SetClassDebugLevel("AliLoader", deb);
883 AliLog::SetClassDebugLevel("AliDataLoader", deb);
884 AliLog::SetClassDebugLevel("AliBaseLoader", deb);
885 AliLog::SetClassDebugLevel("AliObjectLoader", deb);
886 AliLog::SetClassDebugLevel("AliTreeLoader", deb);
887 AliLog::SetClassDebugLevel("AliTaskLoader", deb);
888 AliLog::SetClassDebugLevel("AliConfig", deb);
890 /*****************************************************************************/
892 void AliLoader::SetTAddrInDet()
894 //calls SetTreeAddress for corresponding detector
895 AliRunLoader* rl = GetRunLoader();
896 if (rl == 0x0) return;
897 AliRun* ar = rl->GetAliRun();
898 if (ar == 0x0) return;
899 AliDetector* det = ar->GetDetector(fDetectorName);
900 if (det == 0x0) return;
901 det->SetTreeAddress();
903 /*****************************************************************************/
905 void AliLoader::Synchronize()
907 //synchrinizes all writtable files
908 TIter next(fDataLoaders);
910 while ((dl = (AliDataLoader*)next()))
916 /*****************************************************************************/
917 /*****************************************************************************/
918 /*****************************************************************************/