]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliLoader.h
Method for file synchronization (P.Skowronski)
[u/mrichter/AliRoot.git] / STEER / AliLoader.h
1 #ifndef ALILOADER_H
2 #define ALILOADER_H
3
4 #include <TFolder.h>
5 #include <TObjArray.h>
6
7 #include <AliConfig.h>
8 #include "AliDataLoader.h"
9
10 class TString;
11 class TFile;
12 class TTree;
13 class TTask;
14 class AliRunLoader;
15 class AliDigitizer;
16 class TDirectory;
17
18
19 //___________________________________________________________________
20 /////////////////////////////////////////////////////////////////////
21 //                                                                 //
22 //  class AliLoader                                                //
23 //                                                                 //
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       //
28 //                                                                 //
29 /////////////////////////////////////////////////////////////////////
30
31 class AliLoader: public TNamed
32  {
33    public:
34     AliLoader();
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);
37
38     virtual ~AliLoader();//----------------- 
39  
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);
44
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
49     //options: 
50     //   ""       - readonly file
51     //   "update" - update file
52     //   "recreate" 
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);}
59  
60     AliDataLoader* GetDataLoader(const char* name);
61         
62     
63     Int_t          SetEventFolder(TFolder* eventfolder);//sets the event folder
64     Int_t          Register(TFolder* eventFolder);//triggers creation of subfolders for a given detector
65       
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();
74    
75     TTask*         SDigitizer();//return detector SDigitizer()
76     AliDigitizer*  Digitizer();
77     TTask*         Reconstructioner();
78     TTask*         Tracker();
79     TTask*         PIDTask();
80     TTask*         QAtask(const char* name = 0x0);
81
82     TObject**      SDigitizerRef();
83     TObject**      DigitizerRef();
84     TObject**      ReconstructionerRef();
85     TObject**      TrackerRef();
86     TObject**      PIDTaskRef();
87     
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();}
94         
95     virtual void   CleanFolders();
96     virtual void   CloseFiles();
97
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);
103     
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);}
109
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
116
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);}
123     
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);}
129
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();}
136
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 
144     
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);}
152
153     
154   //void SetTopFolder(TString& str){}; //Sets root top folder for the run
155     
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);}
162
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();}
169    
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
175     
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
181
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
188     
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);}
195     
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
198     
199     const TString& GetDetectorName() const{return fDetectorName;}//returns the name of the detector
200     AliRunLoader*  GetRunLoader();//gets the run-getter from event folder
201     
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
205     void Synchronize();
206     
207    protected:
208
209     /*********************************************/
210     /************    PROTECTED      **************/
211     /*********     M E T H O D S       ***********/
212     /*********************************************/
213     enum EDataTypes{kHits = 0,kSDigits,kDigits,kRecPoints,kTracks,kRecParticles,kNDataTypes};
214
215     //Opens hits file and jumps to directory cooresponding to current event.
216     //If dir does not exists try to create it
217     //opt is passed to TFile::Open
218     //reads data from the file and posts them into folder
219
220
221     virtual Int_t PostHits(){return GetHitsDataLoader()->GetBaseLoader(0)->Load();}
222     virtual Int_t PostSDigits(){return GetSDigitsDataLoader()->GetBaseLoader(0)->Load();}
223     virtual Int_t PostDigits(){return GetDigitsDataLoader()->GetBaseLoader(0)->Load();}
224     virtual Int_t PostRecPoints(){return GetRecPointsDataLoader()->GetBaseLoader(0)->Load();}
225     virtual Int_t PostTracks(){return GetTracksDataLoader()->GetBaseLoader(0)->Load();}
226     virtual Int_t PostRecParticles(){return GetRecParticlesDataLoader()->GetBaseLoader(0)->Load();}
227     
228     void          Clean();//calls clean for data loaders
229     void          Clean(const TString& name);//removes and deletes object from data folder 
230     
231     
232     TString       GetUnixDir();
233     TObject*      GetDetectorData(const char* name){return GetDetectorDataFolder()->FindObject(name);}
234     TObject**     GetDetectorDataRef(TObject* obj);
235     
236     void InitDefaults();
237     void ResetDataInfo();
238     
239     void SetTAddrInDet();//Call SetTreeAddress for corresponding detector
240
241     /**********************************************/
242     /************    PROTECTED      ***************/
243     /*********        D A T A          ************/
244     /**********************************************/
245   
246     // array with data loaders each corresponds to 
247     // one data type (Hits, Digits, ...) 
248     TObjArray*    fDataLoaders; 
249
250     TString       fDetectorName;//detector name that this loader belongs to
251     
252     TFolder*      fEventFolder; //! Folder with data that changes from event to event, even in single run
253     TFolder*      fDataFolder;  //!  Folder with data (hits, sdigits, etc, grouped in folders named like detectors
254     TFolder*      fDetectorDataFolder;//!Folder that contains the detector data
255     TFolder*      fModuleFolder;      //!Folder that contains the modules 
256
257     TFolder*      fTasksFolder;       //!Folder that contains the Tasks (sdigitizer, digitizer, reconstructioner)
258     TFolder*      fQAFolder;          //!Folder that contains the QA objects
259     
260  // file option varible was introduced because if TFile is created with "recreate" 
261  // stored option in TFile is "CREATE". We need to remeber "recreate" for
262  // Max events per file functionality
263
264     static const TString   fgkDefaultHitsContainerName;//default name of conatiner (TREE) for hits
265     static const TString   fgkDefaultDigitsContainerName;//default name of conatiner (TREE) for digits
266     static const TString   fgkDefaultSDigitsContainerName;//default name of conatiner (TREE) for Sdigits
267     static const TString   fgkDefaultRecPointsContainerName;//default name of conatiner (TREE) for Rec Points
268     static const TString   fgkDefaultTracksContainerName;//default name of conatiner (TREE) for Tracks
269     static const TString   fgkDefaultRecParticlesContainerName;//default name of conatiner (TREE) for Reconstructed Particles
270     static const TString   fgkLoaderBaseName;//base name of Loader: fDetectorName+fgkLoaderBaseName. i.e. PHOSLoader
271     
272    private:
273     //descendant classes should
274     //use protected interface methods to access these folders
275
276     /**********************************************/
277     /***********     P U B L I C     **************/
278     /*********       S T A T I C       ************/
279     /*********         METHODS         ************/
280     /*********     They are used by    ************/
281     /*********** AliRunLoader as well**************/
282     /**********************************************/
283    public:
284     static TDirectory* ChangeDir(TFile* file, Int_t eventno); //changes the root directory in "file" to directory corresponing to eventno
285     static Bool_t      TestFileOption(Option_t* opt);//checks is file is created from scratch
286     static Bool_t      IsOptionWritable(const TString& opt);
287     
288     static Int_t GetDebug() {return fgDebug;}
289     static void        SetDebug(Int_t deb = 1){fgDebug = deb;}//Sets debugging information
290     static Int_t       fgDebug; //debug flag for loaders
291
292     ClassDef(AliLoader,2)
293  };
294 /******************************************************************/
295 /************************ I N L I N E S ***************************/
296 /******************************************************************/
297
298 inline TFolder* AliLoader::GetDetectorDataFolder()
299  {
300  //helper function which returns the folder of name "name" in data folder
301    if(!fDetectorDataFolder)
302     {
303       fDetectorDataFolder = dynamic_cast<TFolder*>(GetDataFolder()->FindObject(fDetectorName.Data()));
304       if(!fDetectorDataFolder)
305        {
306          Fatal("GetDetectorDataFolder",
307                "Can not find folder %s in folder %s. Aborting",
308                fDetectorName.Data(),GetDataFolder()->GetName());
309          return 0x0;
310        }
311       
312     }
313    return fDetectorDataFolder;
314  }
315
316 #endif