]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliLoader.h
Storing the alignable volume matrices. The matrixes transform from the tracking V2...
[u/mrichter/AliRoot.git] / STEER / AliLoader.h
1 #ifndef ALILOADER_H
2 #define ALILOADER_H
3
4 class TDirectory;
5 class TFile;
6 class TString;
7 class TTask;
8 class TTree;
9
10 #include <TFolder.h>
11 #include <TObjArray.h>
12
13 class AliDigitizer;
14 class AliRunLoader;
15
16 #include "AliDataLoader.h"
17 #include "AliTaskLoader.h"
18
19
20 //___________________________________________________________________
21 /////////////////////////////////////////////////////////////////////
22 //                                                                 //
23 //  class AliLoader                                                //
24 //                                                                 //
25 //  Base class for Loaders.                                        //
26 //  Loader provides base I/O fascilities for "standard" data.      //
27 //  Each detector has a laoder data member.                        //
28 //  Loader is always accessible via folder structure as well       //
29 //                                                                 //
30 /////////////////////////////////////////////////////////////////////
31
32 class AliLoader: public TNamed
33  {
34    public:
35     AliLoader();
36     AliLoader(const Char_t *detname,const Char_t *eventfoldername); //contructor with name of the top folder of the tree
37     AliLoader(const Char_t *detname,TFolder* eventfolder);
38     AliLoader(const AliLoader& source); //copy constructor
39     AliLoader& operator=(const AliLoader& source); //assignment operator
40
41     virtual ~AliLoader();//----------------- 
42  
43     virtual Int_t  GetEvent();//changes to root directory
44                              //relies on the event number defined in gAlice
45     virtual Int_t  SetEvent();//basically the same that GetEvent but do not post data to folders
46     virtual void   MakeTree(Option_t* opt);
47
48     //these methods are responsible for reading data
49     // 1. Opens the file (accordingly to gAlice->GetEvNumber()/Nevents per File
50     // 2. Changes to proper ROOT directory
51     // 3. Retrives data and posts to folders
52     //options: 
53     //   ""       - readonly file
54     //   "update" - update file
55     //   "recreate" 
56     AliDataLoader* GetHitsDataLoader()     const {return (AliDataLoader*)fDataLoaders->At(kHits);}
57     AliDataLoader* GetSDigitsDataLoader()  const {return (AliDataLoader*)fDataLoaders->At(kSDigits);}
58     AliDataLoader* GetDigitsDataLoader()   const {return (AliDataLoader*)fDataLoaders->At(kDigits);}
59     AliDataLoader* GetRecPointsDataLoader()const {return (AliDataLoader*)fDataLoaders->At(kRecPoints);}
60     AliDataLoader* GetTracksDataLoader()   const {return (AliDataLoader*)fDataLoaders->At(kTracks);}
61     AliDataLoader* GetRecParticlesDataLoader()const {return (AliDataLoader*)fDataLoaders->At(kRecParticles);}
62  
63     AliDataLoader* GetDataLoader(const char* name);
64     void           AddDataLoader(AliDataLoader* dl);
65         
66     
67     Int_t          SetEventFolder(TFolder* eventfolder);//sets the event folder
68     Int_t          Register(TFolder* eventFolder);//triggers creation of subfolders for a given detector
69       
70     TFolder*       GetTopFolder();  //returns top aliroot folder
71     TFolder*       GetEventFolder();//returns the folder that event is sitting
72     TFolder*       GetDataFolder(); //returns the folder that hits, sdigits, etc are sitting (this contains folders named like detectors)
73     TFolder*       GetDetectorDataFolder();//returns the folder that hits, sdigits, etc 
74                                      //are sitting for a given detector (subfolder of Data Folder)
75     TFolder*       GetModulesFolder();
76     TFolder*       GetTasksFolder();
77     TFolder*       GetQAFolder();
78    
79     TTask*         SDigitizer() const;//return detector SDigitizer()
80     AliDigitizer*  Digitizer() const;
81     TTask*         Reconstructioner() const;
82     TTask*         Tracker() const;
83     TTask*         PIDTask() const;
84     TTask*         QAtask(const char* name = 0x0) const;
85
86     TObject**      SDigitizerRef();
87     TObject**      DigitizerRef();
88     TObject**      ReconstructionerRef();
89     TObject**      TrackerRef();
90     TObject**      PIDTaskRef();
91     
92     virtual void   MakeHitsContainer() const {GetHitsDataLoader()->MakeTree();}
93     virtual void   MakeSDigitsContainer() const {GetSDigitsDataLoader()->MakeTree();}
94     virtual void   MakeDigitsContainer() const {GetDigitsDataLoader()->MakeTree();}
95     virtual void   MakeRecPointsContainer() const {GetRecPointsDataLoader()->MakeTree();}
96     virtual void   MakeTracksContainer() const {GetTracksDataLoader()->MakeTree();}
97     virtual void   MakeRecParticlesContainer() const {GetRecParticlesDataLoader()->MakeTree();}
98         
99     virtual void   CleanFolders();
100     virtual void   CloseFiles();
101
102     virtual Int_t  PostSDigitizer(TTask* sdzer) const;//adds it to Run SDigitizer
103     virtual Int_t  PostDigitizer(AliDigitizer* task) const;
104     virtual Int_t  PostReconstructioner(TTask* task) const;
105     virtual Int_t  PostTracker(TTask* task) const;
106     virtual Int_t  PostPIDTask(TTask* task) const;
107     
108     virtual Int_t  WriteSDigitizer(Option_t* opt="") const
109       {return GetSDigitsDataLoader()->GetBaseTaskLoader()->WriteData(opt);}
110     virtual Int_t  WriteDigitizer(Option_t* opt="") const
111       {return GetDigitsDataLoader()->GetBaseTaskLoader()->WriteData(opt);}
112     virtual Int_t  WriteReconstructioner(Option_t* opt="") const
113       {return GetRecPointsDataLoader()->GetBaseTaskLoader()->WriteData(opt);}
114     virtual Int_t  WriteTracker(Option_t* opt="") const
115       {return GetTracksDataLoader()->GetBaseTaskLoader()->WriteData(opt);}
116     virtual Int_t  WritePIDTask(Option_t* opt="") const
117       {return GetRecParticlesDataLoader()->GetBaseTaskLoader()->WriteData(opt);}
118
119     TTree*         TreeH() const
120       {return GetHitsDataLoader()->Tree();}      //returns the tree from folder; shortcut method
121     TTree*         TreeS() const
122       {return GetSDigitsDataLoader()->Tree();}   //returns the tree from folder; shortcut method
123     TTree*         TreeD() const
124       {return GetDigitsDataLoader()->Tree();}    //returns the tree from folder; shortcut method
125     TTree*         TreeR() const
126       {return GetRecPointsDataLoader()->Tree();} //returns the tree from folder; shortcut method
127     TTree*         TreeT() const
128       {return GetTracksDataLoader()->Tree();}    //returns the tree from folder; shortcut method
129     TTree*         TreeP() const
130       {return GetRecParticlesDataLoader()->Tree();} //returns the tree from folder; shortcut method
131
132     Int_t          LoadHits(Option_t* opt=""){
133       Int_t status = GetHitsDataLoader()->Load(opt);
134       SetTAddrInDet();
135       return status;
136     }
137     Int_t          LoadSDigits(Option_t* opt=""){
138       Int_t status = GetSDigitsDataLoader()->Load(opt);
139       SetTAddrInDet();
140       return status;
141     }
142     Int_t          LoadDigits(Option_t* opt=""){
143       Int_t status = GetDigitsDataLoader()->Load(opt);
144       SetTAddrInDet();
145       return status;
146     }
147     
148
149     Int_t          LoadRecPoints(Option_t* opt="") {
150       Int_t status = GetRecPointsDataLoader()->Load(opt);
151       SetTAddrInDet();
152       return status;
153     }
154     Int_t          LoadTracks(Option_t* opt="") {
155       Int_t status = GetTracksDataLoader()->Load(opt);
156       SetTAddrInDet();
157       return status;
158     }
159     Int_t          LoadRecParticles(Option_t* opt="") {
160       Int_t status = GetRecParticlesDataLoader()->Load(opt);
161       SetTAddrInDet();
162       return status;
163     }
164     
165     Int_t          LoadSDigitizer(Option_t* opt="") const {
166       return GetSDigitsDataLoader()->GetBaseTaskLoader()->Load(opt);
167     }
168     Int_t          LoadDigitizer(Option_t* opt="") const {
169       return GetDigitsDataLoader()->GetBaseTaskLoader()->Load(opt);
170     }
171     Int_t          LoadReconstructioner(Option_t* opt="") const {
172       return GetRecPointsDataLoader()->GetBaseTaskLoader()->Load(opt);
173     }
174     Int_t          LoadTracker(Option_t* opt="") const {
175       return GetTracksDataLoader()->GetBaseTaskLoader()->Load(opt);
176     }
177     Int_t          LoadPIDTask(Option_t* opt="") const {
178       return GetRecParticlesDataLoader()->GetBaseTaskLoader()->Load(opt);
179     }
180
181     void           UnloadHits() const {GetHitsDataLoader()->Unload();}
182     void           UnloadSDigits() const {GetSDigitsDataLoader()->Unload();}
183     void           UnloadDigits() const {GetDigitsDataLoader()->Unload();}
184     void           UnloadRecPoints() const{GetRecPointsDataLoader()->Unload();}
185     void           UnloadTracks() const {GetTracksDataLoader()->Unload();}
186     void           UnloadRecParticles() const {GetRecParticlesDataLoader()->Unload();}
187     void           UnloadAll();
188
189     virtual Int_t  ReloadHits() const {return GetHitsDataLoader()->Reload();}  //unload and load again Hits
190     virtual Int_t  ReloadSDigits() const {return GetSDigitsDataLoader()->Reload();} //unload and load again 
191     virtual Int_t  ReloadDigits() const {return GetDigitsDataLoader()->Reload();} //unload and load again 
192     virtual Int_t  ReloadRecPoints() const {return GetRecPointsDataLoader()->Reload();} //unload and load again 
193     virtual Int_t  ReloadTracks() const {return GetTracksDataLoader()->Reload();} //unload and load again 
194     virtual Int_t  ReloadRecParticles() const {return GetRecParticlesDataLoader()->Reload();} //unload and load again 
195     virtual Int_t  ReloadAll(); //unload and load again everything that was loaded 
196     
197   //these methods writes object from folder to proper file
198     virtual Int_t  WriteHits(Option_t* opt="") const;
199     virtual Int_t  WriteSDigits(Option_t* opt="") const;
200     virtual Int_t  WriteDigits(Option_t* opt="") const {return GetDigitsDataLoader()->WriteData(opt);}
201     virtual Int_t  WriteRecPoints(Option_t* opt="") const {return GetRecPointsDataLoader()->WriteData(opt);}
202     virtual Int_t  WriteTracks(Option_t* opt="") const {return GetTracksDataLoader()->WriteData(opt);}
203     virtual Int_t  WriteRecParticles(Option_t* opt="") const {return GetRecParticlesDataLoader()->WriteData(opt);}
204
205     
206   //void SetTopFolder(TString& str){}; //Sets root top folder for the run
207     
208     void           SetHitsFileName(const TString& fname) const 
209       {GetHitsDataLoader()->SetFileName(fname);}
210     void           SetSDigitsFileName(const TString& fname) const 
211       {GetSDigitsDataLoader()->SetFileName(fname);}
212     void           SetDigitsFileName(const TString& fname) const
213       {GetDigitsDataLoader()->SetFileName(fname);}
214     void           SetRecPointsFileName(const TString& fname) const
215       {GetRecPointsDataLoader()->SetFileName(fname);}
216     void           SetTracksFileName(const TString& fname) const
217       {GetTracksDataLoader()->SetFileName(fname);}
218     void           SetRecParticlesFileName(const TString& fname) const
219       {GetRecParticlesDataLoader()->SetFileName(fname);}
220
221     const TString& GetHitsFileName() const 
222       {return GetHitsDataLoader()->GetFileName();}
223     const TString& GetSDigitsFileName() const 
224       {return GetSDigitsDataLoader()->GetFileName();}
225     const TString& GetDigitsFileName() const
226       {return GetDigitsDataLoader()->GetFileName();}
227     const TString& GetRecPointsFileName() const
228       {return GetRecPointsDataLoader()->GetFileName();}
229     const TString& GetTracksFileName() const
230       {return GetTracksDataLoader()->GetFileName();}
231     const TString& GetRecParticlesFileName() const
232       {return GetRecParticlesDataLoader()->GetFileName();}
233    
234     virtual void  CleanHits() const
235       {GetHitsDataLoader()->Clean();}       //cleans hits from folder
236     virtual void  CleanSDigits() const
237       {GetSDigitsDataLoader()->Clean();}    //cleans digits from folder
238     virtual void  CleanDigits() const
239       {GetDigitsDataLoader()->Clean();}     //cleans sdigits from folder
240     virtual void  CleanRecPoints() const
241       {GetRecPointsDataLoader()->Clean();}  //cleans rec. points from folder
242     virtual void  CleanTracks() const
243       {GetTracksDataLoader()->Clean();}     //cleans tracks from folder
244     
245     virtual void  CleanSDigitizer();                    //cleans SDigitizer from folder
246     virtual void  CleanDigitizer();                     //cleans Digitizer from folder
247     virtual void  CleanReconstructioner();              //cleans Reconstructions (clusterizer) from folder
248     virtual void  CleanTracker();                       //cleans tracker from folder
249     virtual void  CleanPIDTask();              //cleans Reconstructions (clusterizer) from folder
250
251     virtual void  SetHitsFileOption(Option_t* newopt) const
252       {GetHitsDataLoader()->SetFileOption(newopt);}          //Sets Hits File Option in open
253     virtual void  SetSDigitsFileOption(Option_t* newopt) const
254       {GetSDigitsDataLoader()->SetFileOption(newopt);}    //Sets S. Digits File Option in open
255     virtual void  SetDigitsFileOption(Option_t* newopt) const
256       {GetDigitsDataLoader()->SetFileOption(newopt);}      //Sets Digits File Option in open
257     virtual void  SetRecPointsFileOption(Option_t* newopt) const
258       {GetRecPointsDataLoader()->SetFileOption(newopt);}//Sets Rec Ponoints File Option in open
259     virtual void  SetTracksFileOption(Option_t* newopt) const
260       {GetTracksDataLoader()->SetFileOption(newopt);}      //Sets Tracks File Option in open
261     virtual void  SetRecParticlesFileOption(Option_t* newopt) const
262       {GetRecParticlesDataLoader()->SetFileOption(newopt);}//Sets Rec Ponoints File Option in open
263     
264     virtual void  SetHitsComprLevel(Int_t cl) const
265       {GetHitsDataLoader()->SetCompressionLevel(cl);}
266     virtual void  SetDigitsComprLevel(Int_t cl) const
267       {GetSDigitsDataLoader()->SetCompressionLevel(cl);}
268     virtual void  SetSDigitsComprLevel(Int_t cl) const
269       {GetDigitsDataLoader()->SetCompressionLevel(cl);}
270     virtual void  SetRecPointsComprLevel(Int_t cl) const
271       {GetRecPointsDataLoader()->SetCompressionLevel(cl);}
272     virtual void  SetTracksComprLevel(Int_t cl) const
273       {GetTracksDataLoader()->SetCompressionLevel(cl);}
274     virtual void  SetRecParticlesComprLevel(Int_t cl) const
275       {GetRecParticlesDataLoader()->SetCompressionLevel(cl);}
276     
277     virtual void  SetCompressionLevel(Int_t cl);//Sets compression level in all the files
278     void          SetDirName(TString& name);//sets the directory name for all the I/O environment
279     
280     const TString& GetDetectorName() const{return fDetectorName;}//returns the name of the detector
281     AliRunLoader*  GetRunLoader();//gets the run-getter from event folder
282     
283     void          SetDigitsFileNameSuffix(const TString& suffix) const;//adds the suffix before ".root", 
284                                                           //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
285                                                               //made on Jiri Chudoba demand
286     void Synchronize();
287
288     /**********************************************/
289     /***********     P U B L I C     **************/
290     /*********       S T A T I C       ************/
291     /*********         METHODS         ************/
292     /*********     They are used by    ************/
293     /*********** AliRunLoader as well**************/
294     /**********************************************/
295     static TDirectory* ChangeDir(TFile* file, Int_t eventno); //changes the root directory in "file" to directory corresponing to eventno
296     static Bool_t      TestFileOption(Option_t* opt);//checks is file is created from scratch
297     static Bool_t      IsOptionWritable(const TString& opt);
298     
299     static void        SetDebug(Int_t deb = 1);//Sets debugging information
300     
301    protected:
302
303     /*********************************************/
304     /************    PROTECTED      **************/
305     /*********     M E T H O D S       ***********/
306     /*********************************************/
307     enum EDataTypes{kHits = 0,kSDigits,kDigits,kRecPoints,kTracks,kRecParticles,kNDataTypes};
308
309     //Opens hits file and jumps to directory cooresponding to current event.
310     //If dir does not exists try to create it
311     //opt is passed to TFile::Open
312     //reads data from the file and posts them into folder
313
314
315     virtual Int_t PostHits() const
316       {return GetHitsDataLoader()->GetBaseLoader(0)->Load();}
317     virtual Int_t PostSDigits() const
318       {return GetSDigitsDataLoader()->GetBaseLoader(0)->Load();}
319     virtual Int_t PostDigits() const
320       {return GetDigitsDataLoader()->GetBaseLoader(0)->Load();}
321     virtual Int_t PostRecPoints() const
322       {return GetRecPointsDataLoader()->GetBaseLoader(0)->Load();}
323     virtual Int_t PostTracks() const
324       {return GetTracksDataLoader()->GetBaseLoader(0)->Load();}
325     virtual Int_t PostRecParticles() const
326       {return GetRecParticlesDataLoader()->GetBaseLoader(0)->Load();}
327     
328     void          Clean();//calls clean for data loaders
329     void          Clean(const TString& name);//removes and deletes object from data folder 
330     
331     
332     TString       GetUnixDir() const;
333     TObject*      GetDetectorData(const char* name){return GetDetectorDataFolder()->FindObject(name);}
334     TObject**     GetDetectorDataRef(TObject* obj);
335     
336     virtual void InitDefaults();
337     void ResetDataInfo();
338     
339     void SetTAddrInDet();//Call SetTreeAddress for corresponding detector
340
341     /**********************************************/
342     /************    PROTECTED      ***************/
343     /*********        D A T A          ************/
344     /**********************************************/
345   
346     TObjArray*    fDataLoaders; // array with data loaders each corresponds to 
347                                 // one data type (Hits, Digits, ...) 
348
349     TString       fDetectorName;//detector name that this loader belongs to
350     
351     TFolder*      fEventFolder; //! Folder with data that changes from event to event, even in single run
352     TFolder*      fDataFolder;  //!  Folder with data (hits, sdigits, etc, grouped in folders named like detectors
353     TFolder*      fDetectorDataFolder;//!Folder that contains the detector data
354     TFolder*      fModuleFolder;      //!Folder that contains the modules 
355
356     TFolder*      fTasksFolder;       //!Folder that contains the Tasks (sdigitizer, digitizer, reconstructioner)
357     TFolder*      fQAFolder;          //!Folder that contains the QA objects
358     
359  // file option varible was introduced because if TFile is created with "recreate" 
360  // stored option in TFile is "CREATE". We need to remeber "recreate" for
361  // Max events per file functionality
362
363     static const TString   fgkDefaultHitsContainerName;//default name of conatiner (TREE) for hits
364     static const TString   fgkDefaultDigitsContainerName;//default name of conatiner (TREE) for digits
365     static const TString   fgkDefaultSDigitsContainerName;//default name of conatiner (TREE) for Sdigits
366     static const TString   fgkDefaultRecPointsContainerName;//default name of conatiner (TREE) for Rec Points
367     static const TString   fgkDefaultTracksContainerName;//default name of conatiner (TREE) for Tracks
368     static const TString   fgkDefaultRecParticlesContainerName;//default name of conatiner (TREE) for Reconstructed Particles
369     static const TString   fgkLoaderBaseName;//base name of Loader: fDetectorName+fgkLoaderBaseName. i.e. PHOSLoader
370     
371    private:
372     //descendant classes should
373     //use protected interface methods to access these folders
374
375     ClassDef(AliLoader,2)
376  };
377 /******************************************************************/
378 /************************ I N L I N E S ***************************/
379 /******************************************************************/
380
381 inline TFolder* AliLoader::GetDetectorDataFolder()
382  {
383  //helper function which returns the folder of name "name" in data folder
384    if(!fDetectorDataFolder)
385     {
386       fDetectorDataFolder = dynamic_cast<TFolder*>(GetDataFolder()->FindObject(fDetectorName.Data()));
387       if(!fDetectorDataFolder)
388        {
389          Fatal("GetDetectorDataFolder",
390                "Can not find folder %s in folder %s. Aborting",
391                fDetectorName.Data(),GetDataFolder()->GetName());
392          return 0x0;
393        }
394       
395     }
396    return fDetectorDataFolder;
397  }
398
399 #endif