8 #include "AliDataLoader.h"
19 //___________________________________________________________________
20 /////////////////////////////////////////////////////////////////////
24 // Base class for Loaders. //
25 // Loader provides base I/O fascilities for "standard" data. //
26 // Each detector has a laoder data member. //
27 // Loader is always accessible via folder structure as well //
29 /////////////////////////////////////////////////////////////////////
31 class AliLoader: public TNamed
35 AliLoader(const Char_t *detname,const Char_t *eventfoldername); //contructor with name of the top folder of the tree
36 AliLoader(const Char_t *detname,TFolder* eventfolder);
38 virtual ~AliLoader();//-----------------
40 virtual Int_t GetEvent();//changes to root directory
41 //relies on the event number defined in gAlice
42 virtual Int_t SetEvent();//basically the same that GetEvent but do not post data to folders
43 virtual void MakeTree(Option_t* opt);
45 //these methods are responsible for reading data
46 // 1. Opens the file (accordingly to gAlice->GetEvNumber()/Nevents per File
47 // 2. Changes to proper ROOT directory
48 // 3. Retrives data and posts to folders
51 // "update" - update file
53 AliDataLoader* GetHitsDataLoader() const {return (AliDataLoader*)fDataLoaders->At(kHits);}
54 AliDataLoader* GetSDigitsDataLoader() const {return (AliDataLoader*)fDataLoaders->At(kSDigits);}
55 AliDataLoader* GetDigitsDataLoader() const {return (AliDataLoader*)fDataLoaders->At(kDigits);}
56 AliDataLoader* GetRecPointsDataLoader()const {return (AliDataLoader*)fDataLoaders->At(kRecPoints);}
57 AliDataLoader* GetTracksDataLoader() const {return (AliDataLoader*)fDataLoaders->At(kTracks);}
58 AliDataLoader* GetRecParticlesDataLoader()const {return (AliDataLoader*)fDataLoaders->At(kRecParticles);}
60 AliDataLoader* GetDataLoader(const char* name);
63 Int_t SetEventFolder(TFolder* eventfolder);//sets the event folder
64 Int_t Register(TFolder* eventFolder);//triggers creation of subfolders for a given detector
66 TFolder* GetTopFolder(); //returns top aliroot folder
67 TFolder* GetEventFolder();//returns the folder that event is sitting
68 TFolder* GetDataFolder(); //returns the folder that hits, sdigits, etc are sitting (this contains folders named like detectors)
69 TFolder* GetDetectorDataFolder();//returns the folder that hits, sdigits, etc
70 //are sitting for a given detector (subfolder of Data Folder)
71 TFolder* GetModulesFolder();
72 TFolder* GetTasksFolder();
73 TFolder* GetQAFolder();
75 TTask* SDigitizer();//return detector SDigitizer()
76 AliDigitizer* Digitizer();
77 TTask* Reconstructioner();
80 TTask* QAtask(const char* name = 0x0);
82 TObject** SDigitizerRef();
83 TObject** DigitizerRef();
84 TObject** ReconstructionerRef();
85 TObject** TrackerRef();
86 TObject** PIDTaskRef();
88 virtual void MakeHitsContainer(){GetHitsDataLoader()->MakeTree();}
89 virtual void MakeSDigitsContainer(){GetSDigitsDataLoader()->MakeTree();}
90 virtual void MakeDigitsContainer(){GetDigitsDataLoader()->MakeTree();}
91 virtual void MakeRecPointsContainer(){GetRecPointsDataLoader()->MakeTree();}
92 virtual void MakeTracksContainer(){GetTracksDataLoader()->MakeTree();}
93 virtual void MakeRecParticlesContainer(){GetRecParticlesDataLoader()->MakeTree();}
95 virtual void CleanFolders();
96 virtual void CloseFiles();
98 virtual Int_t PostSDigitizer(TTask* sdzer);//adds it to Run SDigitizer
99 virtual Int_t PostDigitizer(AliDigitizer* task);
100 virtual Int_t PostReconstructioner(TTask* task);
101 virtual Int_t PostTracker(TTask* task);
102 virtual Int_t PostPIDTask(TTask* task);
104 virtual Int_t WriteSDigitizer(Option_t* opt=""){return GetSDigitsDataLoader()->GetBaseTaskLoader()->WriteData(opt);}
105 virtual Int_t WriteDigitizer(Option_t* opt=""){return GetDigitsDataLoader()->GetBaseTaskLoader()->WriteData(opt);}
106 virtual Int_t WriteReconstructioner(Option_t* opt=""){return GetRecPointsDataLoader()->GetBaseTaskLoader()->WriteData(opt);}
107 virtual Int_t WriteTracker(Option_t* opt=""){return GetTracksDataLoader()->GetBaseTaskLoader()->WriteData(opt);}
108 virtual Int_t WritePIDTask(Option_t* opt=""){return GetRecParticlesDataLoader()->GetBaseTaskLoader()->WriteData(opt);}
110 TTree* TreeH(){return GetHitsDataLoader()->Tree();} //returns the tree from folder; shortcut method
111 TTree* TreeS(){return GetSDigitsDataLoader()->Tree();} //returns the tree from folder; shortcut method
112 TTree* TreeD(){return GetDigitsDataLoader()->Tree();} //returns the tree from folder; shortcut method
113 TTree* TreeR(){return GetRecPointsDataLoader()->Tree();} //returns the tree from folder; shortcut method
114 TTree* TreeT(){return GetTracksDataLoader()->Tree();} //returns the tree from folder; shortcut method
115 TTree* TreeP(){return GetRecParticlesDataLoader()->Tree();} //returns the tree from folder; shortcut method
117 Int_t LoadHits(Option_t* opt=""){Int_t status = GetHitsDataLoader()->Load(opt);SetTAddrInDet();return status;}
118 Int_t LoadSDigits(Option_t* opt=""){Int_t status = GetSDigitsDataLoader()->Load(opt);SetTAddrInDet(); return status;}
119 Int_t LoadDigits(Option_t* opt=""){Int_t status = GetDigitsDataLoader()->Load(opt);SetTAddrInDet();return status;}
120 Int_t LoadRecPoints(Option_t* opt=""){return GetRecPointsDataLoader()->Load(opt);}
121 Int_t LoadTracks(Option_t* opt=""){return GetTracksDataLoader()->Load(opt);}
122 Int_t LoadRecParticles(Option_t* opt=""){return GetRecParticlesDataLoader()->Load(opt);}
124 Int_t LoadSDigitizer(Option_t* opt=""){return GetSDigitsDataLoader()->GetBaseTaskLoader()->Load(opt);}
125 Int_t LoadDigitizer(Option_t* opt=""){return GetDigitsDataLoader()->GetBaseTaskLoader()->Load(opt);}
126 Int_t LoadReconstructioner(Option_t* opt=""){return GetRecPointsDataLoader()->GetBaseTaskLoader()->Load(opt);}
127 Int_t LoadTracker(Option_t* opt=""){return GetTracksDataLoader()->GetBaseTaskLoader()->Load(opt);}
128 Int_t LoadPIDTask(Option_t* opt=""){return GetRecParticlesDataLoader()->GetBaseTaskLoader()->Load(opt);}
130 void UnloadHits(){GetHitsDataLoader()->Unload();}
131 void UnloadSDigits(){GetSDigitsDataLoader()->Unload();}
132 void UnloadDigits(){GetDigitsDataLoader()->Unload();}
133 void UnloadRecPoints(){GetRecPointsDataLoader()->Unload();}
134 void UnloadTracks(){GetTracksDataLoader()->Unload();}
135 void UnloadRecParticles(){GetRecParticlesDataLoader()->Unload();}
138 virtual Int_t ReloadHits(){return GetHitsDataLoader()->Reload();} //unload and load again Hits
139 virtual Int_t ReloadSDigits(){return GetSDigitsDataLoader()->Reload();} //unload and load again
140 virtual Int_t ReloadDigits(){return GetDigitsDataLoader()->Reload();} //unload and load again
141 virtual Int_t ReloadRecPoints(){return GetRecPointsDataLoader()->Reload();} //unload and load again
142 virtual Int_t ReloadTracks(){return GetTracksDataLoader()->Reload();} //unload and load again
143 virtual Int_t ReloadRecParticles(){return GetRecParticlesDataLoader()->Reload();} //unload and load again
144 virtual Int_t ReloadAll(); //unload and load again everything that was loaded
146 //these methods writes object from folder to proper file
147 virtual Int_t WriteHits(Option_t* opt="");
148 virtual Int_t WriteSDigits(Option_t* opt="");
149 virtual Int_t WriteDigits(Option_t* opt=""){return GetDigitsDataLoader()->WriteData(opt);}
150 virtual Int_t WriteRecPoints(Option_t* opt=""){return GetRecPointsDataLoader()->WriteData(opt);}
151 virtual Int_t WriteTracks(Option_t* opt=""){return GetTracksDataLoader()->WriteData(opt);}
152 virtual Int_t WriteRecParticles(Option_t* opt=""){return GetRecParticlesDataLoader()->WriteData(opt);}
155 //void SetTopFolder(TString& str){}; //Sets root top folder for the run
157 void SetHitsFileName(const TString& fname){GetHitsDataLoader()->SetFileName(fname);}
158 void SetSDigitsFileName(const TString& fname){GetSDigitsDataLoader()->SetFileName(fname);}
159 void SetDigitsFileName(const TString& fname){GetDigitsDataLoader()->SetFileName(fname);}
160 void SetRecPointsFileName(const TString& fname){GetRecPointsDataLoader()->SetFileName(fname);}
161 void SetTracksFileName(const TString& fname){GetTracksDataLoader()->SetFileName(fname);}
162 void SetRecParticlesFileName(const TString& fname){GetRecParticlesDataLoader()->SetFileName(fname);}
164 const TString& GetHitsFileName(){return GetHitsDataLoader()->GetFileName();}
165 const TString& GetSDigitsFileName(){return GetSDigitsDataLoader()->GetFileName();}
166 const TString& GetDigitsFileName(){return GetDigitsDataLoader()->GetFileName();}
167 const TString& GetRecPointsFileName(){return GetRecPointsDataLoader()->GetFileName();}
168 const TString& GetTracksFileName(){return GetTracksDataLoader()->GetFileName();}
169 const TString& GetRecParticlesFileName(){return GetRecParticlesDataLoader()->GetFileName();}
171 virtual void CleanHits() {GetHitsDataLoader()->Clean();} //cleans hits from folder
172 virtual void CleanSDigits() {GetSDigitsDataLoader()->Clean();} //cleans digits from folder
173 virtual void CleanDigits() {GetDigitsDataLoader()->Clean();} //cleans sdigits from folder
174 virtual void CleanRecPoints(){GetRecPointsDataLoader()->Clean();} //cleans rec. points from folder
175 virtual void CleanTracks() {GetTracksDataLoader()->Clean();} //cleans tracks from folder
177 virtual void CleanSDigitizer(); //cleans SDigitizer from folder
178 virtual void CleanDigitizer(); //cleans Digitizer from folder
179 virtual void CleanReconstructioner(); //cleans Reconstructions (clusterizer) from folder
180 virtual void CleanTracker(); //cleans tracker from folder
181 virtual void CleanPIDTask(); //cleans Reconstructions (clusterizer) from folder
183 virtual void SetHitsFileOption(Option_t* newopt){GetHitsDataLoader()->SetFileOption(newopt);} //Sets Hits File Option in open
184 virtual void SetSDigitsFileOption(Option_t* newopt){GetSDigitsDataLoader()->SetFileOption(newopt);} //Sets S. Digits File Option in open
185 virtual void SetDigitsFileOption(Option_t* newopt){GetDigitsDataLoader()->SetFileOption(newopt);} //Sets Digits File Option in open
186 virtual void SetRecPointsFileOption(Option_t* newopt){GetRecPointsDataLoader()->SetFileOption(newopt);}//Sets Rec Ponoints File Option in open
187 virtual void SetTracksFileOption(Option_t* newopt){GetTracksDataLoader()->SetFileOption(newopt);} //Sets Tracks File Option in open
188 virtual void SetRecParticlesFileOption(Option_t* newopt){GetRecParticlesDataLoader()->SetFileOption(newopt);}//Sets Rec Ponoints File Option in open
190 virtual void SetHitsComprLevel(Int_t cl){GetHitsDataLoader()->SetCompressionLevel(cl);}
191 virtual void SetDigitsComprLevel(Int_t cl){GetSDigitsDataLoader()->SetCompressionLevel(cl);}
192 virtual void SetSDigitsComprLevel(Int_t cl){GetDigitsDataLoader()->SetCompressionLevel(cl);}
193 virtual void SetRecPointsComprLevel(Int_t cl){GetRecPointsDataLoader()->SetCompressionLevel(cl);}
194 virtual void SetTracksComprLevel(Int_t cl){GetTracksDataLoader()->SetCompressionLevel(cl);}
195 virtual void SetRecParticlesComprLevel(Int_t cl){GetRecParticlesDataLoader()->SetCompressionLevel(cl);}
197 virtual void SetCompressionLevel(Int_t cl);//Sets compression level in all the files
198 void SetDirName(TString& name);//sets the directory name for all the I/O environment
200 const TString& GetDetectorName() const{return fDetectorName;}//returns the name of the detector
201 AliRunLoader* GetRunLoader();//gets the run-getter from event folder
203 void SetDigitsFileNameSuffix(const TString& suffix);//adds the suffix before ".root",
204 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
205 //made on Jiri Chudoba demand
210 /*********************************************/
211 /************ PROTECTED **************/
212 /********* M E T H O D S ***********/
213 /*********************************************/
214 enum EDataTypes{kHits = 0,kSDigits,kDigits,kRecPoints,kTracks,kRecParticles,kNDataTypes};
216 //Opens hits file and jumps to directory cooresponding to current event.
217 //If dir does not exists try to create it
218 //opt is passed to TFile::Open
219 //reads data from the file and posts them into folder
222 virtual Int_t PostHits(){return GetHitsDataLoader()->GetBaseLoader(0)->Load();}
223 virtual Int_t PostSDigits(){return GetSDigitsDataLoader()->GetBaseLoader(0)->Load();}
224 virtual Int_t PostDigits(){return GetDigitsDataLoader()->GetBaseLoader(0)->Load();}
225 virtual Int_t PostRecPoints(){return GetRecPointsDataLoader()->GetBaseLoader(0)->Load();}
226 virtual Int_t PostTracks(){return GetTracksDataLoader()->GetBaseLoader(0)->Load();}
227 virtual Int_t PostRecParticles(){return GetRecParticlesDataLoader()->GetBaseLoader(0)->Load();}
229 void Clean();//calls clean for data loaders
230 void Clean(const TString& name);//removes and deletes object from data folder
233 TString GetUnixDir();
234 TObject* GetDetectorData(const char* name){return GetDetectorDataFolder()->FindObject(name);}
235 TObject** GetDetectorDataRef(TObject* obj);
238 void ResetDataInfo();
240 void SetTAddrInDet();//Call SetTreeAddress for corresponding detector
242 /**********************************************/
243 /************ PROTECTED ***************/
244 /********* D A T A ************/
245 /**********************************************/
247 // array with data loaders each corresponds to
248 // one data type (Hits, Digits, ...)
249 TObjArray* fDataLoaders;
251 TString fDetectorName;//detector name that this loader belongs to
253 TFolder* fEventFolder; //! Folder with data that changes from event to event, even in single run
254 TFolder* fDataFolder; //! Folder with data (hits, sdigits, etc, grouped in folders named like detectors
255 TFolder* fDetectorDataFolder;//!Folder that contains the detector data
256 TFolder* fModuleFolder; //!Folder that contains the modules
258 TFolder* fTasksFolder; //!Folder that contains the Tasks (sdigitizer, digitizer, reconstructioner)
259 TFolder* fQAFolder; //!Folder that contains the QA objects
261 // file option varible was introduced because if TFile is created with "recreate"
262 // stored option in TFile is "CREATE". We need to remeber "recreate" for
263 // Max events per file functionality
265 static const TString fgkDefaultHitsContainerName;//default name of conatiner (TREE) for hits
266 static const TString fgkDefaultDigitsContainerName;//default name of conatiner (TREE) for digits
267 static const TString fgkDefaultSDigitsContainerName;//default name of conatiner (TREE) for Sdigits
268 static const TString fgkDefaultRecPointsContainerName;//default name of conatiner (TREE) for Rec Points
269 static const TString fgkDefaultTracksContainerName;//default name of conatiner (TREE) for Tracks
270 static const TString fgkDefaultRecParticlesContainerName;//default name of conatiner (TREE) for Reconstructed Particles
271 static const TString fgkLoaderBaseName;//base name of Loader: fDetectorName+fgkLoaderBaseName. i.e. PHOSLoader
274 //descendant classes should
275 //use protected interface methods to access these folders
277 /**********************************************/
278 /*********** P U B L I C **************/
279 /********* S T A T I C ************/
280 /********* METHODS ************/
281 /********* They are used by ************/
282 /*********** AliRunLoader as well**************/
283 /**********************************************/
285 static TDirectory* ChangeDir(TFile* file, Int_t eventno); //changes the root directory in "file" to directory corresponing to eventno
286 static Bool_t TestFileOption(Option_t* opt);//checks is file is created from scratch
287 static Bool_t IsOptionWritable(const TString& opt);
289 static Int_t GetDebug() {return fgDebug;}
290 static void SetDebug(Int_t deb = 1){fgDebug = deb;}//Sets debugging information
291 static Int_t fgDebug; //debug flag for loaders
293 ClassDef(AliLoader,2)
295 /******************************************************************/
296 /************************ I N L I N E S ***************************/
297 /******************************************************************/
299 inline TFolder* AliLoader::GetDetectorDataFolder()
301 //helper function which returns the folder of name "name" in data folder
302 if(!fDetectorDataFolder)
304 fDetectorDataFolder = dynamic_cast<TFolder*>(GetDataFolder()->FindObject(fDetectorName.Data()));
305 if(!fDetectorDataFolder)
307 Fatal("GetDetectorDataFolder",
308 "Can not find folder %s in folder %s. Aborting",
309 fDetectorName.Data(),GetDataFolder()->GetName());
314 return fDetectorDataFolder;