1 #include "AliRunLoader.h"
2 //_____________________________________
3 /////////////////////////////////////////////////////////////////////////////////////
7 //This class aims to be the only one interface for manging data
8 //It stores Loaders for all modules which knows the filenames
9 //of the data files to be stored.
10 //It aims to substitude AliRun in automatic maging of data positioning
11 //thus there won't be necessity of loading gAlice from file in order to
12 //get fast ccess to the data
14 //logical place for putting the Loader specific to the given detector is detector itself
15 // but, to load detector one need to load gAlice, and by the way all other detectors
16 // with their geometries and so on.
17 // So, if one need to open TPC clusters there is no principal need to read everything
19 // When RunLoader is read from the file it does not connect to the folder structure
20 // it must be connected (mounted) manualy in the macro or class code.
21 // Default event folder is defined by AliConfig::fgkDefaultEventFolderName
22 // but can be mounted elsewhere. Usefull specially in merging, when more than session
25 //////////////////////////////////////////////////////////////////////////////////////
26 /**************************************************************************/
34 #include <TGeometry.h>
39 #include "AliConfig.h"
40 #include "AliLoader.h"
41 #include "AliHeader.h"
43 #include "TObjArray.h"
44 #include "AliDetector.h"
45 #include "AliRunDigitizer.h"
47 ClassImp(AliRunLoader)
49 AliRunLoader* AliRunLoader::fgRunLoader = 0x0;
51 const TString AliRunLoader::fgkRunLoaderName("RunLoader");
53 const TString AliRunLoader::fgkHeaderBranchName("Header");
54 const TString AliRunLoader::fgkHeaderContainerName("TE");
55 const TString AliRunLoader::fgkKineContainerName("TreeK");
56 const TString AliRunLoader::fgkTrackRefsContainerName("TreeTR");
57 const TString AliRunLoader::fgkKineBranchName("Particles");
58 const TString AliRunLoader::fgkDefaultKineFileName("Kinematics.root");
59 const TString AliRunLoader::fgkDefaultTrackRefsFileName("TrackRefs.root");
60 const TString AliRunLoader::fgkGAliceName("gAlice");
61 /**************************************************************************/
63 AliRunLoader::AliRunLoader():
71 fTrackRefsDataLoader(0x0),
75 AliConfig::Instance();//force to build the folder structure
77 /**************************************************************************/
79 AliRunLoader::AliRunLoader(const char* eventfoldername):
80 TNamed(fgkRunLoaderName,fgkRunLoaderName),
81 fLoaders(new TObjArray()),
87 fKineDataLoader(new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics")),
88 fTrackRefsDataLoader(new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References")),
93 SetEventFolderName(eventfoldername);
95 /**************************************************************************/
97 AliRunLoader::~AliRunLoader()
104 fLoaders->SetOwner();
108 delete fKineDataLoader;
109 delete fTrackRefsDataLoader;
114 //fEventFolder is deleted by the way of removing - TopAliceFolder owns it
119 /**************************************************************************/
121 AliRunLoader::AliRunLoader(TFolder* topfolder):TNamed(fgkRunLoaderName,fgkRunLoaderName)
126 Fatal("AliRunLoader(TFolder*)","Parameter is NULL");
129 fEventFolder = topfolder;
131 TObject* obj = fEventFolder->FindObject(fgkRunLoaderName);
133 { //if it is, then sth. is going wrong... exits aliroot session
134 Fatal("AliRunLoader(const char*)",
135 "In Event Folder Named %s object named %s already exists. I am confused ...",
136 fEventFolder->GetName(),fgkRunLoaderName.Data());
137 return;//never reached
140 fLoaders = new TObjArray();
141 fEventFolder->Add(this);//put myself to the folder to accessible for all
144 /**************************************************************************/
146 Int_t AliRunLoader::GetEvent(Int_t evno)
148 //Gets event number evno
149 //Reloads all data properly
150 if (fCurrentEvent == evno) return 0;
154 Error("GetEvent","Can not give the event with negative number");
158 if (evno >= GetNumberOfEvents())
160 Error("GetEvent","There is no event with number %d",evno);
166 Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
167 Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
168 Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
169 Info("GetEvent"," GETTING EVENT %d",evno);
170 Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
171 Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
172 Info("GetEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
175 fCurrentEvent = evno;
179 //Reload header (If header was loaded)
182 retval = TreeE()->GetEvent(fCurrentEvent);
185 Error("GetEvent","Cannot find event: %d\n ",fCurrentEvent);
189 //Reload stack (If header was loaded)
190 if (TreeE()) fStack = GetHeader()->Stack();
191 //Set event folder in stack (it does not mean that we read kinematics from file)
194 fStack->SetEventFolderName(fEventFolder->GetName());
198 Warning("GetEvent","Stack not found in header");
204 Error("GetEvent","Error occured while setting event %d",evno);
208 //Post Track References
209 retval = fTrackRefsDataLoader->GetEvent();
212 Error("GetEvent","Error occured while GetEvent for Track References. Event %d",evno);
216 //Read Kinematics if loaded
217 fKineDataLoader->GetEvent();
220 Error("GetEvent","Error occured while GetEvent for Kinematics. Event %d",evno);
224 if (fStack && fKineDataLoader->GetBaseLoader(0)->IsLoaded()) fStack->GetEvent();
226 //Trigger data reloading in all loaders
227 TIter next(fLoaders);
229 while((loader = (AliLoader*)next()))
231 retval = loader->GetEvent();
234 Error("GetEvent","Error occured while getting event for %s. Event %d.",
235 loader->GetDetectorName().Data(), evno);
240 SetDetectorAddresses();
244 /**************************************************************************/
245 Int_t AliRunLoader::SetEvent()
247 //if kinematics was loaded Cleans folder data
251 retval = fKineDataLoader->SetEvent();
254 Error("SetEvent","SetEvent for Kinamtics Data Loader retutned error.");
257 retval = fTrackRefsDataLoader->SetEvent();
260 Error("SetEvent","SetEvent for Track References Data Loader retutned error.");
264 TIter next(fLoaders);
266 while((loader = (AliLoader*)next()))
268 retval = loader->SetEvent();
271 Error("SetEvent","SetEvent for %s Data Loader retutned error.",loader->GetName());
278 /**************************************************************************/
280 Int_t AliRunLoader::SetEventNumber(Int_t evno)
282 //cleans folders and sets the root dirs in files
283 if (fCurrentEvent == evno) return 0;
284 fCurrentEvent = evno;
288 /**************************************************************************/
289 AliRunLoader* AliRunLoader::Open
290 (const char* filename, const char* eventfoldername, Option_t* option)
292 //Opens a desired file 'filename'
293 //gets the the run-Loader and mounts it desired folder
294 //returns the pointer to run Loader which can be further used for accessing data
295 //in case of error returns NULL
297 static const TString webaddress("http://alisoft.cern.ch/people/skowron/codedoc/split/index.html");
298 if (AliLoader::fgDebug)
299 ::Info("AliRunLoader::Open",
300 "\n\n\nNew I/O strcture: See more info:\n %s\n\n\n",webaddress.Data());
302 AliRunLoader* result = 0x0;
304 /* ************************************************ */
305 /* Chceck if folder with given name already exists */
306 /* ************************************************ */
308 TObject* obj = AliConfig::Instance()->GetTopFolder()->FindObject(eventfoldername);
311 TFolder* fold = dynamic_cast<TFolder*>(obj);
314 ::Error("AliRunLoader::Open","Such a obejct already exists in top alice folder and it is not a folder.");
318 //check if we can get RL from that folder
319 result = AliRunLoader::GetRunLoader(eventfoldername);
322 ::Error("AliRunLoader::Open",
323 "Folder %s already exists, and can not find session there. Can not mount.",eventfoldername);
327 if (result->GetFileName().CompareTo(filename) != 0)
329 ::Error("AliRunLoader::Open","Other file is mounted in demanded folder. Can not mount.");
333 //check if now is demanded (re)creation
334 if ( AliLoader::TestFileOption(option) == kFALSE)
336 ::Error("AliRunLoader::Open",
337 "Session already exists in folder %s and this session option is %s. Unable to proceed.",
338 eventfoldername,option);
342 //check if demanded option is update and existing one
343 TString tmpstr(option);
344 if ( (tmpstr.CompareTo("update",TString::kIgnoreCase) == 0) &&
345 (result->fGAFile->IsWritable() == kFALSE) )
347 ::Error("AliRunLoader::Open",
348 "Session already exists in folder %s and is not writable while this session option is %s. Unable to proceed.",
349 eventfoldername,option);
353 ::Warning("AliRunLoader::Open","Session is already opened and mounted in demanded folder");
355 } //end of checking in case of existance of object named identically that folder session is being opened
358 TFile * gAliceFile = TFile::Open(filename,option);//open a file
360 {//null pointer returned
361 ::Error("AliRunLoader::Open","Can not open file %s.",filename);
365 if (gAliceFile->IsOpen() == kFALSE)
366 {//pointer to valid object returned but file is not opened
367 ::Error("AliRunLoader::Open","Can not open file %s.",filename);
371 //if file is "read" or "update" than we try to find AliRunLoader there - if not found cry and exit
372 //else create new AliRunLoader
373 if ( AliLoader::TestFileOption(option) )
375 if (AliLoader::fgDebug)
376 ::Info("AliRunLoader::Open","Reading RL from file");
378 result = dynamic_cast<AliRunLoader*>(gAliceFile->Get(fgkRunLoaderName));//get the run Loader from the file
381 ::Error("AliRunLoader::Open","Can not find run-Loader in file %s.",filename);
382 delete gAliceFile;//close the file
385 Int_t tmp = result->SetEventFolderName(eventfoldername);//mount a event folder
386 if (tmp)//if SetEvent returned error
388 ::Error("AliRunLoader::Open","Can not mount event in folder %s.",eventfoldername);
389 delete result; //delete run-Loader
390 delete gAliceFile;//close the file
396 if (AliLoader::fgDebug)
397 ::Info("AliRunLoader::Open","Creating new AliRunLoader. Folder name is %s",eventfoldername);
398 result = new AliRunLoader(eventfoldername);
401 //procedure for extracting dir name from the file name
402 TString fname(filename);
403 Int_t nsl = fname.Last('/');//look for slash in file name
407 Int_t nsl = fname.Last(':');//look for colon e.g. rfio:galice.root
408 if (nsl < 0) dirname = ".";//not found
409 else dirname = fname.Remove(nsl);//found
411 else dirname = fname.Remove(nsl);//slash found
413 if (AliLoader::fgDebug)
414 ::Info("AliRunLoader::Open","Dir name is : %s",dirname.Data());
416 result->SetDirName(dirname);
417 result->SetGAliceFile(gAliceFile);//set the pointer to gAliceFile
418 fgRunLoader = result; //PH get access from any place
421 /**************************************************************************/
422 Int_t AliRunLoader::GetNumberOfEvents()
424 //returns number of events in Run
428 retval = LoadHeader();
431 Error("GetNumberOfEvents","Error occured while loading header");
435 return (Int_t)TreeE()->GetEntries();
437 /**************************************************************************/
439 void AliRunLoader::MakeHeader()
441 //Makes header and connects it to header tree (if it exists)
442 if (GetDebug()) Info("MakeHeader","");
445 if (GetDebug()) Info("MakeHeader","Creating new Header Object");
446 fHeader= new AliHeader();
448 TTree* tree = TreeE();
451 if (GetDebug()) Info("MakeHeader","Got Tree from folder.");
452 TBranch* branch = tree->GetBranch(fgkHeaderBranchName);
455 if (GetDebug()) Info("MakeHeader","Creating new branch");
456 branch = tree->Branch(fgkHeaderBranchName, "AliHeader", &fHeader, 4000, 0);
457 branch->SetAutoDelete(kFALSE);
461 if (GetDebug()) Info("MakeHeader","Got Branch from Tree");
462 branch->SetAddress(&fHeader);
463 tree->GetEvent(fCurrentEvent);
464 fStack = fHeader->Stack(); //should be safe - if we created Stack, header returns pointer to the same object
467 fStack->SetEventFolderName(fEventFolder->GetName());
468 if (TreeK()) fStack->GetEvent();
472 if (GetDebug()) Info("MakeHeader","Haeder do not have a stack.");
476 if (GetDebug()) Info("MakeHeader","Exiting MakeHeader method");
478 /**************************************************************************/
480 void AliRunLoader::MakeStack()
482 //Creates the stack object - do not connect the tree
485 fStack = new AliStack(10000);
486 fStack->SetEventFolderName(fEventFolder->GetName());
490 /**************************************************************************/
492 void AliRunLoader::MakeTree(Option_t *option)
495 const char *oK = strstr(option,"K"); //Kine
496 const char *oE = strstr(option,"E"); //Header
500 if (fKineDataLoader->GetBaseLoader(0)->IsLoaded() == kFALSE)
502 Error("MakeTree(\"K\")","Load Kinematics first");
506 fKineDataLoader->MakeTree();
508 fStack->ConnectTree();
509 WriteKinematics("OVERWRITE");
516 TTree* tree = new TTree(fgkHeaderContainerName,"Tree with Headers");
517 GetEventFolder()->Add(tree);
519 WriteHeader("OVERWRITE");
522 TIter next(fLoaders);
524 while((loader = (AliLoader*)next()))
526 loader->MakeTree(option);
530 /**************************************************************************/
532 Int_t AliRunLoader::LoadgAlice()
534 //Loads gAlice from file
537 Warning("LoadgAlice","AliRun is already in folder. Unload first.");
540 AliRun* alirun = dynamic_cast<AliRun*>(fGAFile->Get(fgkGAliceName));
543 Error("LoadgAlice"," Can not find gAlice in file %s",fGAFile->GetName());
546 alirun->SetRunLoader(this);
549 Warning("LoadgAlice","gAlice already exists. Putting retrived object in folder named %s",
550 GetEventFolder()->GetName());
556 SetDetectorAddresses();//calls SetTreeAddress for all detectors
559 /**************************************************************************/
561 Int_t AliRunLoader::LoadHeader()
563 //loads treeE and reads header object for current event
566 Warning("LoadHeader","Header is already loaded. Use ReloadHeader to force reload. Nothing done");
570 if (GetEventFolder() == 0x0)
572 Error("LoadHaeder","Event folder not specified yet");
578 Error("LoadHaeder","Session not opened. Use AliRunLoader::Open");
582 if (fGAFile->IsOpen() == kFALSE)
584 Error("LoadHaeder","Session not opened. Use AliRunLoader::Open");
588 TTree* tree = dynamic_cast<TTree*>(fGAFile->Get(fgkHeaderContainerName));
591 Fatal("LoadHaeder","Can not find header tree named %s in file %s",
592 fgkHeaderContainerName.Data(),fGAFile->GetName());
596 if (tree == TreeE()) return 0;
599 GetEventFolder()->Add(tree);
600 MakeHeader();//creates header object and connects to tree
604 /**************************************************************************/
606 Int_t AliRunLoader::LoadKinematics(Option_t* option)
608 //Loads the kinematics
609 Int_t retval = fKineDataLoader->GetBaseLoader(0)->Load(option);
612 Error("LoadKinematics","Error occured while loading kinamatics tree.");
615 if (fStack) fStack->GetEvent();
618 /**************************************************************************/
620 Int_t AliRunLoader::OpenDataFile(const TString& filename,TFile*& file,TDirectory*& dir,Option_t* opt,Int_t cl)
622 //Opens File with kinematics
625 if (file->IsOpen() == kFALSE)
626 {//pointer is not null but file is not opened
627 Warning("OpenDataFile","Pointer to file is not null, but file is not opened");//risky any way
629 file = 0x0; //proceed with opening procedure
633 Warning("OpenDataFile","File %s already opened",filename.Data());
637 //try to find if that file is opened somewere else
638 file = (TFile *)( gROOT->GetListOfFiles()->FindObject(filename) );
641 if(file->IsOpen() == kTRUE)
643 Warning("OpenDataFile","File %s already opened by sombody else.",file->GetName());
648 file = TFile::Open(filename,opt);
651 Error("LoadKinematics","Can not open file %s",filename.Data());
654 if (file->IsOpen() == kFALSE)
655 {//file is not opened
656 Error("LoadKinematics","Can not open file %s",filename.Data());
660 file->SetCompressionLevel(cl);
662 dir = AliLoader::ChangeDir(file,fCurrentEvent);
665 Error("OpenKineFile","Can not change to root directory in file %s",filename.Data());
670 /**************************************************************************/
672 TTree* AliRunLoader::TreeE() const
674 //returns the tree from folder; shortcut method
675 TObject *obj = fEventFolder->FindObject(fgkHeaderContainerName);
676 return (obj)?dynamic_cast<TTree*>(obj):0x0;
678 /**************************************************************************/
680 AliHeader* AliRunLoader::GetHeader() const
682 //returns pointer header object
685 /**************************************************************************/
687 TTree* AliRunLoader::TreeK() const
689 //returns the tree from folder; shortcut method
690 TObject *obj = GetEventFolder()->FindObject(fgkKineContainerName);
691 return (obj)?dynamic_cast<TTree*>(obj):0x0;
693 /**************************************************************************/
695 TTree* AliRunLoader::TreeTR() const
697 //returns the tree from folder; shortcut method
698 TObject* obj = GetEventFolder()->FindObject(fgkTrackRefsContainerName);
699 return (obj)?dynamic_cast<TTree*>(obj):0x0;
701 /**************************************************************************/
703 AliRun* AliRunLoader::GetAliRun() const
705 //returns AliRun which sits in the folder
706 if (fEventFolder == 0x0) return 0x0;
707 TObject *obj = fEventFolder->FindObject(fgkGAliceName);
708 return (obj)?dynamic_cast<AliRun*>(obj):0x0;
710 /**************************************************************************/
712 Int_t AliRunLoader::WriteGeometry(Option_t* opt)
714 //writes geometry to the file
716 TGeometry* geo = GetAliRun()->GetGeometry();
719 Error("WriteGeometry","Can not get geometry from gAlice");
725 /**************************************************************************/
727 Int_t AliRunLoader::WriteHeader(Option_t* opt)
730 if (GetDebug()) Info("WriteHeader"," WRITING HEADER");
732 TTree* tree = TreeE();
735 Warning("WriteHeader","Can not find Header Tree in Folder");
738 if (fGAFile->IsWritable() == kFALSE)
740 Error("WriteHeader","File %s is not writable",fGAFile->GetName());
744 TObject* obj = fGAFile->Get(fgkHeaderContainerName);
746 { //if they exist, see if option OVERWRITE is used
748 if(tmp.Contains("OVERWRITE",TString::kIgnoreCase) == 0)
749 {//if it is not used - give an error message and return an error code
750 Error("WriteHeader","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
755 tree->SetDirectory(fGAFile);
756 tree->Write(0,TObject::kOverwrite);
758 if (GetDebug()) Info("WriteHeader","WRITTEN\n\n");
762 /**************************************************************************/
764 Int_t AliRunLoader::WriteAliRun(Option_t* opt)
766 //writes AliRun object to the file
768 if (GetAliRun()) GetAliRun()->Write();
771 /**************************************************************************/
773 Int_t AliRunLoader::WriteKinematics(Option_t* opt)
776 return fKineDataLoader->GetBaseLoader(0)->WriteData(opt);
778 /**************************************************************************/
779 Int_t AliRunLoader::WriteTrackRefs(Option_t* opt)
781 //writes Track References tree
782 return fTrackRefsDataLoader->GetBaseLoader(0)->WriteData(opt);
784 /**************************************************************************/
786 Int_t AliRunLoader::WriteHits(Option_t* opt)
788 //Calls WriteHits for all loaders
791 TIter next(fLoaders);
793 while((loader = (AliLoader*)next()))
795 res = loader->WriteHits(opt);
798 Error("WriteHits","Failed to write hits for %s (%d)",loader->GetDetectorName().Data(),res);
804 /**************************************************************************/
806 Int_t AliRunLoader::WriteSDigits(Option_t* opt)
808 //Calls WriteSDigits for all loaders
811 TIter next(fLoaders);
813 while((loader = (AliLoader*)next()))
815 res = loader->WriteSDigits(opt);
818 Error("WriteSDigits","Failed to write summable digits for %s.",loader->GetDetectorName().Data());
824 /**************************************************************************/
826 Int_t AliRunLoader::WriteDigits(Option_t* opt)
828 //Calls WriteDigits for all loaders
831 TIter next(fLoaders);
833 while((loader = (AliLoader*)next()))
835 res = loader->WriteDigits(opt);
838 Error("WriteDigits","Failed to write digits for %s.",loader->GetDetectorName().Data());
844 /**************************************************************************/
846 Int_t AliRunLoader::WriteRecPoints(Option_t* opt)
848 //Calls WriteRecPoints for all loaders
851 TIter next(fLoaders);
853 while((loader = (AliLoader*)next()))
855 res = loader->WriteRecPoints(opt);
858 Error("WriteRecPoints","Failed to write Reconstructed Points for %s.",
859 loader->GetDetectorName().Data());
865 /**************************************************************************/
867 Int_t AliRunLoader::WriteTracks(Option_t* opt)
869 //Calls WriteTracks for all loaders
872 TIter next(fLoaders);
874 while((loader = (AliLoader*)next()))
876 res = loader->WriteTracks(opt);
879 Error("WriteTracks","Failed to write Tracks for %s.",
880 loader->GetDetectorName().Data());
886 /**************************************************************************/
888 Int_t AliRunLoader::WriteRunLoader(Option_t* opt)
890 //Writes itself to the file
892 this->Write(0,TObject::kOverwrite);
895 /**************************************************************************/
897 Int_t AliRunLoader::SetEventFolderName(const TString& name)
899 //sets top folder name for this run; of alread
902 Error("SetTopFolderName","Name is empty");
906 //check if such a folder already exists - try to find it in alice top folder
907 TObject* obj = AliConfig::Instance()->GetTopFolder()->FindObject(name);
910 TFolder* fold = dynamic_cast<TFolder*>(obj);
913 Error("SetTopFolderName","Such a obejct already exists in top alice folder and it is not a folder.");
916 //folder which was found is our folder
917 if (fEventFolder == fold)
923 Error("SetTopFolderName","Such a folder already exists in top alice folder. Can not mount.");
928 //event is alredy connected, just change name of the folder
931 fEventFolder->SetName(name);
935 if (fKineDataLoader == 0x0)
936 fKineDataLoader = new AliDataLoader(fgkDefaultKineFileName,fgkKineContainerName,"Kinematics");
938 if ( fTrackRefsDataLoader == 0x0)
939 fTrackRefsDataLoader = new AliDataLoader(fgkDefaultTrackRefsFileName,fgkTrackRefsContainerName,"Track References");
941 //build the event folder structure
942 if (GetDebug()) Info("SetEventFolderName","Creating new event folder named %s",name.Data());
943 fEventFolder = AliConfig::Instance()->BuildEventFolder(name,"Event Folder");
944 fEventFolder->Add(this);//put myself to the folder to accessible for all
946 if (Stack()) Stack()->SetEventFolderName(fEventFolder->GetName());
947 TIter next(fLoaders);
949 while((loader = (AliLoader*)next()))
951 loader->Register(fEventFolder);//build folder structure for this detector
954 fKineDataLoader->SetEventFolder(GetEventFolder());
955 fTrackRefsDataLoader->SetEventFolder(GetEventFolder());
956 fKineDataLoader->SetFolder(GetEventFolder());
957 fTrackRefsDataLoader->SetFolder(GetEventFolder());
959 fEventFolder->SetOwner();
962 /**************************************************************************/
964 void AliRunLoader::AddLoader(AliLoader* loader)
966 //Adds the Loader for given detector
967 if (loader == 0x0) //if null shout and exit
969 Error("AddLoader","Parameter is NULL");
972 loader->SetDirName(fUnixDirName);
973 if (fEventFolder) loader->SetEventFolder(fEventFolder); //if event folder is already defined,
974 //pass information to the Loader
975 fLoaders->Add(loader);//add the Loader to the array
977 /**************************************************************************/
979 void AliRunLoader::AddLoader(AliDetector* det)
981 //Asks module (detector) ro make a Loader and stores in the array
982 if (det == 0x0) return;
983 AliLoader* get = det->GetLoader();//try to get loader
984 if (get == 0x0) get = det->MakeLoader(fEventFolder->GetName());//if did not obtain, ask to make it
988 if (GetDebug()) Info("AddLoader","Detector: %s Loader : %s",det->GetName(),get->GetName());
993 /**************************************************************************/
995 AliLoader* AliRunLoader::GetLoader(const char* detname) const
997 //returns loader for given detector
998 //note that naming convention is TPCLoader not just TPC
999 return (AliLoader*)fLoaders->FindObject(detname);
1002 /**************************************************************************/
1004 AliLoader* AliRunLoader::GetLoader(AliDetector* det) const
1006 //get loader for detector det
1007 if(det == 0x0) return 0x0;
1008 TString getname(det->GetName());
1010 if (GetDebug()) Info("GetLoader(AliDetector* det)"," Loader name is %s",getname.Data());
1011 return GetLoader(getname);
1014 /**************************************************************************/
1016 void AliRunLoader::CleanFolders()
1018 // fEventFolder->Add(this);//put myself to the folder to accessible for all
1024 /**************************************************************************/
1026 void AliRunLoader::CleanDetectors()
1028 //Calls CleanFolders for all detectors
1029 TIter next(fLoaders);
1031 while((Loader = (AliLoader*)next()))
1033 Loader->CleanFolders();
1036 /**************************************************************************/
1038 void AliRunLoader::RemoveEventFolder()
1040 //remove all the tree of event
1041 //all the stuff changing EbE stays untached (PDGDB, tasks, etc.)
1043 if (fEventFolder == 0x0) return;
1044 fEventFolder->SetOwner(kFALSE);//don't we want to deleted while removing the folder that we are sitting in
1045 fEventFolder->Remove(this);//remove us drom folder
1047 AliConfig::Instance()->GetTopFolder()->SetOwner(); //brings ownership back for fEventFolder since it sits in top folder
1048 AliConfig::Instance()->GetTopFolder()->Remove(fEventFolder); //remove the event tree
1049 delete fEventFolder;
1051 /**************************************************************************/
1053 void AliRunLoader::SetGAliceFile(TFile* gafile)
1055 //sets pointer to galice.root file
1059 /**************************************************************************/
1061 Int_t AliRunLoader::LoadHits(Option_t* detectors,Option_t* opt)
1063 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1065 if (GetDebug()) Info("LoadHits","Loading Hits");
1069 const char* oAll = strstr(detectors,"all");
1072 if (GetDebug()) Info("LoadHits","Option is All");
1077 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1078 loaders = &arr;//get the pointer array
1081 if (GetDebug()) Info("LoadHits","For detectors. Number of detectors chosen for loading %d",loaders->GetEntries());
1083 TIter next(loaders);
1085 while((loader = (AliLoader*)next()))
1087 if (GetDebug()) Info("LoadHits"," Calling LoadHits(%s) for %s",opt,loader->GetName());
1088 loader->LoadHits(opt);
1090 if (GetDebug()) Info("LoadHits","Done");
1094 /**************************************************************************/
1096 Int_t AliRunLoader::LoadSDigits(Option_t* detectors,Option_t* opt)
1098 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1103 const char* oAll = strstr(detectors,"all");
1110 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1111 loaders = &arr;//get the pointer array
1114 TIter next(loaders);
1116 while((loader = (AliLoader*)next()))
1118 loader->LoadSDigits(opt);
1123 /**************************************************************************/
1125 Int_t AliRunLoader::LoadDigits(Option_t* detectors,Option_t* opt)
1127 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1132 const char* oAll = strstr(detectors,"all");
1139 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1140 Loaders = &arr;//get the pointer array
1143 TIter next(Loaders);
1145 while((Loader = (AliLoader*)next()))
1147 Loader->LoadDigits(opt);
1152 /**************************************************************************/
1154 Int_t AliRunLoader::LoadRecPoints(Option_t* detectors,Option_t* opt)
1156 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1161 const char* oAll = strstr(detectors,"all");
1168 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1169 Loaders = &arr;//get the pointer array
1172 TIter next(Loaders);
1174 while((Loader = (AliLoader*)next()))
1176 Loader->LoadRecPoints(opt);
1181 /**************************************************************************/
1183 Int_t AliRunLoader::LoadTracks(Option_t* detectors,Option_t* opt)
1185 //LoadHits in selected detectors i.e. detectors="ITS TPC TRD" or "all"
1190 const char* oAll = strstr(detectors,"all");
1197 GetListOfDetectors(detectors,arr);//this method looks for all Loaders corresponding to names (many) specified in detectors option
1198 Loaders = &arr;//get the pointer array
1201 TIter next(Loaders);
1203 while((Loader = (AliLoader*)next()))
1205 Loader->LoadTracks(opt);
1210 /**************************************************************************/
1212 AliRunLoader* AliRunLoader::GetRunLoader(const char* eventfoldername)
1214 //returns RunLoader from folder named eventfoldername
1215 TFolder* evfold= dynamic_cast<TFolder*>(AliConfig::Instance()->GetTopFolder()->FindObject(eventfoldername));
1220 AliRunLoader* runget = dynamic_cast<AliRunLoader*>(evfold->FindObject(AliRunLoader::fgkRunLoaderName));
1224 /**************************************************************************/
1226 AliLoader* AliRunLoader::GetDetectorLoader(const char* detname)
1228 //get the loader of the detector with the given name from the global
1230 AliRunLoader* runLoader = GetRunLoader();
1232 cerr << "AliRunLoader::GetDetectorLoader: no run loader found\n";
1235 char loadername[256];
1236 sprintf(loadername, "%sLoader", detname);
1237 AliLoader* loader = runLoader->GetLoader(loadername);
1239 runLoader->Error("GetDetectorLoader", "no loader for %s found", detname);
1245 /**************************************************************************/
1247 TTree* AliRunLoader::GetTreeH(const char* detname, Bool_t maketree)
1249 //get the tree with hits of the detector with the given name
1250 //if maketree is true and the tree does not exist, the tree is created
1251 AliLoader* loader = GetDetectorLoader(detname);
1252 if (!loader) return NULL;
1253 if (!loader->TreeH() && maketree) loader->MakeTree("H");
1254 return loader->TreeH();
1257 /**************************************************************************/
1259 TTree* AliRunLoader::GetTreeS(const char* detname, Bool_t maketree)
1261 //get the tree with summable digits of the detector with the given name
1262 //if maketree is true and the tree does not exist, the tree is created
1263 AliLoader* loader = GetDetectorLoader(detname);
1264 if (!loader) return NULL;
1265 if (!loader->TreeS() && maketree) loader->MakeTree("S");
1266 return loader->TreeS();
1269 /**************************************************************************/
1271 TTree* AliRunLoader::GetTreeD(const char* detname, Bool_t maketree)
1273 //get the tree with digits of the detector with the given name
1274 //if maketree is true and the tree does not exist, the tree is created
1275 AliLoader* loader = GetDetectorLoader(detname);
1276 if (!loader) return NULL;
1277 if (!loader->TreeD() && maketree) loader->MakeTree("D");
1278 return loader->TreeD();
1281 /**************************************************************************/
1283 TTree* AliRunLoader::GetTreeR(const char* detname, Bool_t maketree)
1285 //get the tree with clusters of the detector with the given name
1286 //if maketree is true and the tree does not exist, the tree is created
1287 AliLoader* loader = GetDetectorLoader(detname);
1288 if (!loader) return NULL;
1289 if (!loader->TreeR() && maketree) loader->MakeTree("R");
1290 return loader->TreeR();
1293 /**************************************************************************/
1295 TTree* AliRunLoader::GetTreeT(const char* detname, Bool_t maketree)
1297 //get the tree with tracks of the detector with the given name
1298 //if maketree is true and the tree does not exist, the tree is created
1299 AliLoader* loader = GetDetectorLoader(detname);
1300 if (!loader) return NULL;
1301 if (!loader->TreeT() && maketree) loader->MakeTree("T");
1302 return loader->TreeT();
1305 /**************************************************************************/
1307 TTree* AliRunLoader::GetTreeP(const char* detname, Bool_t maketree)
1309 //get the tree with particles of the detector with the given name
1310 //if maketree is true and the tree does not exist, the tree is created
1311 AliLoader* loader = GetDetectorLoader(detname);
1312 if (!loader) return NULL;
1313 if (!loader->TreeP() && maketree) loader->MakeTree("P");
1314 return loader->TreeP();
1317 /**************************************************************************/
1319 void AliRunLoader::CdGAFile()
1321 //sets gDirectory to galice file
1323 if(fGAFile) fGAFile->cd();
1326 /**************************************************************************/
1328 void AliRunLoader::GetListOfDetectors(const char * namelist,TObjArray& pointerarray) const
1330 //this method looks for all Loaders corresponding
1331 //to names (many) specified in namelist i.e. namelist ("ITS TPC TRD")
1335 strcpy(dets,namelist);//compiler cries when char* = const Option_t*;
1336 dets[strlen(dets)+1] = '\n';//set endl at the end of string
1341 tmp = sscanf(pdet,"%s",buff);//read the string from the input string pdet into buff
1342 if ( (buff[0] == 0) || (tmp == 0) ) break; //if not read
1344 pdet = strstr(pdet,buff) + strlen(buff);//move the input pointer about number of bytes (letters) read
1345 //I am aware that is a little complicated. I don't know the number of spaces between detector names
1346 //so I read the string, than I find where it starts (strstr) and move the pointer about length of a string
1347 //If there is a better way, please write me (Piotr.Skowronski@cern.ch)
1348 //construct the Loader name
1349 TString getname(buff);
1351 AliLoader* loader = GetLoader(getname);//get the Loader
1354 pointerarray.Add(loader);
1358 Error("GetListOfDetectors","Can not find Loader for %s",buff);
1364 /*****************************************************************************/
1366 void AliRunLoader::Clean(const TString& name)
1368 //removes object with given name from event folder and deletes it
1369 if (GetEventFolder() == 0x0) return;
1370 TObject* obj = GetEventFolder()->FindObject(name);
1373 if (GetDebug()) Info("Clean(const TString&)","name=%s, cleaning %s.",GetName(),name.Data());
1374 GetEventFolder()->Remove(obj);
1379 /*****************************************************************************/
1381 TTask* AliRunLoader::GetRunDigitizer()
1383 //returns Run Digitizer from folder
1385 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1386 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetDigitizerTaskName());
1387 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1389 /*****************************************************************************/
1391 TTask* AliRunLoader::GetRunSDigitizer()
1393 //returns SDigitizer Task from folder
1395 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1396 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetSDigitizerTaskName());
1397 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1399 /*****************************************************************************/
1401 TTask* AliRunLoader::GetRunReconstructioner()
1403 //returns Reconstructioner Task from folder
1404 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1405 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetReconstructionerTaskName());
1406 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1408 /*****************************************************************************/
1410 TTask* AliRunLoader::GetRunTracker()
1412 //returns Tracker Task from folder
1413 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1414 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetTrackerTaskName());
1415 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1417 /*****************************************************************************/
1419 TTask* AliRunLoader::GetRunPIDTask()
1421 //returns Tracker Task from folder
1422 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1423 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetPIDTaskName());
1424 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1426 /*****************************************************************************/
1428 TTask* AliRunLoader::GetRunQATask()
1430 //returns Quality Assurance Task from folder
1431 TFolder* topf = AliConfig::Instance()->GetTaskFolder();
1434 ::Error("AliRunLoader::GetRunQATask","Can not get task folder from AliConfig");
1437 TObject* obj = topf->FindObjectAny(AliConfig::Instance()->GetQATaskName());
1438 return (obj)?dynamic_cast<TTask*>(obj):0x0;
1441 /*****************************************************************************/
1443 void AliRunLoader::SetCompressionLevel(Int_t cl)
1445 //Sets Compression Level in all files
1446 if (fGAFile) fGAFile->SetCompressionLevel(cl);
1447 SetKineComprLevel(cl);
1448 SetTrackRefsComprLevel(cl);
1449 TIter next(fLoaders);
1451 while((loader = (AliLoader*)next()))
1453 loader->SetCompressionLevel(cl);
1456 /**************************************************************************/
1458 void AliRunLoader::SetKineComprLevel(Int_t cl)
1460 //Sets comression level in Kine File
1461 fKineDataLoader->SetCompressionLevel(cl);
1463 /**************************************************************************/
1465 void AliRunLoader::SetTrackRefsComprLevel(Int_t cl)
1467 //Sets comression level in Track Refences File
1468 fTrackRefsDataLoader->SetCompressionLevel(cl);
1470 /**************************************************************************/
1472 void AliRunLoader::UnloadHeader()
1474 //removes TreeE from folder and deletes it
1475 // as well as fHeader object
1480 /**************************************************************************/
1482 void AliRunLoader::UnloadKinematics()
1484 //Unloads Kinematics
1485 fKineDataLoader->GetBaseLoader(0)->Unload();
1487 /**************************************************************************/
1489 void AliRunLoader::UnloadTrackRefs()
1491 //Unloads Track Refernces
1492 fTrackRefsDataLoader->GetBaseLoader(0)->Unload();
1494 /**************************************************************************/
1496 void AliRunLoader::UnloadgAlice()
1499 if (gAlice == GetAliRun())
1501 if (GetDebug()) Info("UnloadgAlice","Set gAlice = 0x0");
1502 gAlice = 0x0;//if gAlice is the same that in folder (to be deleted by the way of folder)
1504 AliRun* alirun = GetAliRun();
1505 if (GetEventFolder()) GetEventFolder()->Remove(alirun);
1508 /**************************************************************************/
1510 void AliRunLoader::MakeTrackRefsContainer()
1512 // Makes a tree for Track References
1513 fTrackRefsDataLoader->MakeTree();
1515 /**************************************************************************/
1517 Int_t AliRunLoader::LoadTrackRefs(Option_t* option)
1519 //Load track references from file (opens file and posts tree to folder)
1521 return fTrackRefsDataLoader->GetBaseLoader(0)->Load(option);
1523 /**************************************************************************/
1525 void AliRunLoader::SetDirName(TString& dirname)
1527 //sets directory name
1528 if (dirname.IsNull()) return;
1529 fUnixDirName = dirname;
1530 fKineDataLoader->SetDirName(dirname);
1531 fTrackRefsDataLoader->SetDirName(dirname);
1533 TIter next(fLoaders);
1535 while((loader = (AliLoader*)next()))
1537 loader->SetDirName(dirname);
1541 /*****************************************************************************/
1543 Int_t AliRunLoader::GetFileOffset() const
1545 //returns the file number that is added to the file name for current event
1546 return Int_t(fCurrentEvent/fNEventsPerFile);
1549 /*****************************************************************************/
1550 const TString AliRunLoader::SetFileOffset(const TString& fname)
1552 //adds the the number to the file name at proper place for current event
1553 Long_t offset = (Long_t)GetFileOffset();
1554 if (offset < 1) return fname;
1556 soffset += offset;//automatic conversion to string
1557 TString dotroot(".root");
1558 const TString& offfsetdotroot = offset + dotroot;
1559 TString out = fname;
1560 out = out.ReplaceAll(dotroot,offfsetdotroot);
1561 if (GetDebug()) Info("SetFileOffset"," in=%s out=%s",fname.Data(),out.Data());
1564 /*****************************************************************************/
1566 void AliRunLoader::SetDigitsFileNameSuffix(const TString& suffix)
1568 //adds the suffix before ".root",
1569 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
1570 //made on Jiri Chudoba demand
1572 TIter next(fLoaders);
1574 while((Loader = (AliLoader*)next()))
1576 Loader->SetDigitsFileNameSuffix(suffix);
1579 /*****************************************************************************/
1581 TString AliRunLoader::GetFileName() const
1583 //returns name of galice file
1585 if (fGAFile == 0x0) return result;
1586 result = fGAFile->GetName();
1589 /*****************************************************************************/
1591 void AliRunLoader::SetDetectorAddresses()
1593 //calls SetTreeAddress for all detectors
1594 if (GetAliRun()==0x0) return;
1595 TIter next(GetAliRun()->Modules());
1597 while((mod = (AliModule*)next()))
1599 AliDetector* det = dynamic_cast<AliDetector*>(mod);
1600 if (det) det->SetTreeAddress();
1603 /*****************************************************************************/
1604 /*****************************************************************************/
1605 /*****************************************************************************/