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();SetTAddrInDet();}
89 virtual void MakeSDigitsContainer(){GetSDigitsDataLoader()->MakeTree();SetTAddrInDet();}
90 virtual void MakeDigitsContainer(){GetDigitsDataLoader()->MakeTree();SetTAddrInDet();}
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();}
137 virtual Int_t ReloadHits(){return GetHitsDataLoader()->Reload();} //unload and load again Hits
138 virtual Int_t ReloadSDigits(){return GetSDigitsDataLoader()->Reload();} //unload and load again
139 virtual Int_t ReloadDigits(){return GetDigitsDataLoader()->Reload();} //unload and load again
140 virtual Int_t ReloadRecPoints(){return GetRecPointsDataLoader()->Reload();} //unload and load again
141 virtual Int_t ReloadTracks(){return GetTracksDataLoader()->Reload();} //unload and load again
142 virtual Int_t ReloadRecParticles(){return GetRecParticlesDataLoader()->Reload();} //unload and load again
143 virtual Int_t ReloadAll(); //unload and load again everything that was loaded
145 //these methods writes object from folder to proper file
146 virtual Int_t WriteHits(Option_t* opt="");
147 virtual Int_t WriteSDigits(Option_t* opt="");
148 virtual Int_t WriteDigits(Option_t* opt=""){return GetDigitsDataLoader()->WriteData(opt);}
149 virtual Int_t WriteRecPoints(Option_t* opt=""){return GetRecPointsDataLoader()->WriteData(opt);}
150 virtual Int_t WriteTracks(Option_t* opt=""){return GetTracksDataLoader()->WriteData(opt);}
151 virtual Int_t WriteRecParticles(Option_t* opt=""){return GetRecParticlesDataLoader()->WriteData(opt);}
154 //void SetTopFolder(TString& str){}; //Sets root top folder for the run
156 void SetHitsFileName(const TString& fname){GetHitsDataLoader()->SetFileName(fname);}
157 void SetSDigitsFileName(const TString& fname){GetSDigitsDataLoader()->SetFileName(fname);}
158 void SetDigitsFileName(const TString& fname){GetDigitsDataLoader()->SetFileName(fname);}
159 void SetRecPointsFileName(const TString& fname){GetRecPointsDataLoader()->SetFileName(fname);}
160 void SetTracksFileName(const TString& fname){GetTracksDataLoader()->SetFileName(fname);}
161 void SetRecParticlesFileName(const TString& fname){GetRecParticlesDataLoader()->SetFileName(fname);}
163 const TString& GetHitsFileName(){return GetHitsDataLoader()->GetFileName();}
164 const TString& GetSDigitsFileName(){return GetSDigitsDataLoader()->GetFileName();}
165 const TString& GetDigitsFileName(){return GetDigitsDataLoader()->GetFileName();}
166 const TString& GetRecPointsFileName(){return GetRecPointsDataLoader()->GetFileName();}
167 const TString& GetTracksFileName(){return GetTracksDataLoader()->GetFileName();}
168 const TString& GetRecParticlesFileName(){return GetRecParticlesDataLoader()->GetFileName();}
170 virtual void CleanHits() {GetHitsDataLoader()->Clean();} //cleans hits from folder
171 virtual void CleanSDigits() {GetSDigitsDataLoader()->Clean();} //cleans digits from folder
172 virtual void CleanDigits() {GetDigitsDataLoader()->Clean();} //cleans sdigits from folder
173 virtual void CleanRecPoints(){GetRecPointsDataLoader()->Clean();} //cleans rec. points from folder
174 virtual void CleanTracks() {GetTracksDataLoader()->Clean();} //cleans tracks from folder
176 virtual void CleanSDigitizer(); //cleans SDigitizer from folder
177 virtual void CleanDigitizer(); //cleans Digitizer from folder
178 virtual void CleanReconstructioner(); //cleans Reconstructions (clusterizer) from folder
179 virtual void CleanTracker(); //cleans tracker from folder
180 virtual void CleanPIDTask(); //cleans Reconstructions (clusterizer) from folder
182 virtual void SetHitsFileOption(Option_t* newopt){GetHitsDataLoader()->SetFileOption(newopt);} //Sets Hits File Option in open
183 virtual void SetSDigitsFileOption(Option_t* newopt){GetSDigitsDataLoader()->SetFileOption(newopt);} //Sets S. Digits File Option in open
184 virtual void SetDigitsFileOption(Option_t* newopt){GetDigitsDataLoader()->SetFileOption(newopt);} //Sets Digits File Option in open
185 virtual void SetRecPointsFileOption(Option_t* newopt){GetRecPointsDataLoader()->SetFileOption(newopt);}//Sets Rec Ponoints File Option in open
186 virtual void SetTracksFileOption(Option_t* newopt){GetTracksDataLoader()->SetFileOption(newopt);} //Sets Tracks File Option in open
187 virtual void SetRecParticlesFileOption(Option_t* newopt){GetRecParticlesDataLoader()->SetFileOption(newopt);}//Sets Rec Ponoints File Option in open
189 virtual void SetHitsComprLevel(Int_t cl){GetHitsDataLoader()->SetCompressionLevel(cl);}
190 virtual void SetDigitsComprLevel(Int_t cl){GetSDigitsDataLoader()->SetCompressionLevel(cl);}
191 virtual void SetSDigitsComprLevel(Int_t cl){GetDigitsDataLoader()->SetCompressionLevel(cl);}
192 virtual void SetRecPointsComprLevel(Int_t cl){GetRecPointsDataLoader()->SetCompressionLevel(cl);}
193 virtual void SetTracksComprLevel(Int_t cl){GetTracksDataLoader()->SetCompressionLevel(cl);}
194 virtual void SetRecParticlesComprLevel(Int_t cl){GetRecParticlesDataLoader()->SetCompressionLevel(cl);}
196 virtual void SetCompressionLevel(Int_t cl);//Sets compression level in all the files
197 void SetDirName(TString& name);//sets the directory name for all the I/O environment
199 const TString& GetDetectorName() const{return fDetectorName;}//returns the name of the detector
200 AliRunLoader* GetRunLoader();//gets the run-getter from event folder
202 void SetDigitsFileNameSuffix(const TString& suffix);//adds the suffix before ".root",
203 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
204 //made on Jiri Chudoba demand
207 /*********************************************/
208 /************ PROTECTED **************/
209 /********* M E T H O D S ***********/
210 /*********************************************/
211 enum EDataTypes{kHits = 0,kSDigits,kDigits,kRecPoints,kTracks,kRecParticles,kNDataTypes};
213 //Opens hits file and jumps to directory cooresponding to current event.
214 //If dir does not exists try to create it
215 //opt is passed to TFile::Open
216 //reads data from the file and posts them into folder
219 virtual Int_t PostHits(){return GetHitsDataLoader()->GetBaseLoader(0)->Load();}
220 virtual Int_t PostSDigits(){return GetSDigitsDataLoader()->GetBaseLoader(0)->Load();}
221 virtual Int_t PostDigits(){return GetDigitsDataLoader()->GetBaseLoader(0)->Load();}
222 virtual Int_t PostRecPoints(){return GetRecPointsDataLoader()->GetBaseLoader(0)->Load();}
223 virtual Int_t PostTracks(){return GetTracksDataLoader()->GetBaseLoader(0)->Load();}
224 virtual Int_t PostRecParticles(){return GetRecParticlesDataLoader()->GetBaseLoader(0)->Load();}
226 void Clean();//calls clean for data loaders
227 void Clean(const TString& name);//removes and deletes object from data folder
230 TString GetUnixDir();
231 TObject* GetDetectorData(const char* name){return GetDetectorDataFolder()->FindObject(name);}
232 TObject** GetDetectorDataRef(TObject* obj);
235 void ResetDataInfo();
237 void SetTAddrInDet();//Call SetTreeAddress for corresponding detector
239 /**********************************************/
240 /************ PROTECTED ***************/
241 /********* D A T A ************/
242 /**********************************************/
244 // array with data loaders each corresponds to
245 // one data type (Hits, Digits, ...)
246 TObjArray* fDataLoaders;
248 TString fDetectorName;//detector name that this loader belongs to
250 TFolder* fEventFolder; //! Folder with data that changes from event to event, even in single run
251 TFolder* fDataFolder; //! Folder with data (hits, sdigits, etc, grouped in folders named like detectors
252 TFolder* fDetectorDataFolder;//!Folder that contains the detector data
253 TFolder* fModuleFolder; //!Folder that contains the modules
255 TFolder* fTasksFolder; //!Folder that contains the Tasks (sdigitizer, digitizer, reconstructioner)
256 TFolder* fQAFolder; //!Folder that contains the QA objects
258 // file option varible was introduced because if TFile is created with "recreate"
259 // stored option in TFile is "CREATE". We need to remeber "recreate" for
260 // Max events per file functionality
262 static const TString fgkDefaultHitsContainerName;//default name of conatiner (TREE) for hits
263 static const TString fgkDefaultDigitsContainerName;//default name of conatiner (TREE) for digits
264 static const TString fgkDefaultSDigitsContainerName;//default name of conatiner (TREE) for Sdigits
265 static const TString fgkDefaultRecPointsContainerName;//default name of conatiner (TREE) for Rec Points
266 static const TString fgkDefaultTracksContainerName;//default name of conatiner (TREE) for Tracks
267 static const TString fgkDefaultRecParticlesContainerName;//default name of conatiner (TREE) for Reconstructed Particles
268 static const TString fgkLoaderBaseName;//base name of Loader: fDetectorName+fgkLoaderBaseName. i.e. PHOSLoader
271 //descendant classes should
272 //use protected interface methods to access these folders
274 /**********************************************/
275 /*********** P U B L I C **************/
276 /********* S T A T I C ************/
277 /********* METHODS ************/
278 /********* They are used by ************/
279 /*********** AliRunLoader as well**************/
280 /**********************************************/
282 static TDirectory* ChangeDir(TFile* file, Int_t eventno); //changes the root directory in "file" to directory corresponing to eventno
283 static Bool_t TestFileOption(Option_t* opt);//checks is file is created from scratch
284 static Bool_t IsOptionWritable(const TString& opt);
286 static Int_t GetDebug() {return fgDebug;}
287 static void SetDebug(Int_t deb = 1){fgDebug = deb;}//Sets debugging information
288 static Int_t fgDebug; //debug flag for loaders
290 ClassDef(AliLoader,2)
292 /******************************************************************/
293 /************************ I N L I N E S ***************************/
294 /******************************************************************/
296 inline TFolder* AliLoader::GetDetectorDataFolder()
298 //helper function which returns the folder of name "name" in data folder
299 if(!fDetectorDataFolder)
301 fDetectorDataFolder = dynamic_cast<TFolder*>(GetDataFolder()->FindObject(fDetectorName.Data()));
302 if(!fDetectorDataFolder)
304 Fatal("GetDetectorDataFolder",
305 "Can not find folder %s in folder %s. Aborting",
306 fDetectorName.Data(),GetDataFolder()->GetName());
311 return fDetectorDataFolder;