]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliDataLoader.h
Logging of Debug, Info and Error Messages follwing AliRoot Standard http://aliweb...
[u/mrichter/AliRoot.git] / STEER / AliDataLoader.h
1 #ifndef ALIDATALOADER_H
2 #define ALIDATALOADER_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 //__________________________________________
9 ////////////////////////////////////////////
10 //                                        //
11 //  class AliDataLoader                   //
12 //                                        //
13 //  Loader responsible for one data type  //
14 //  i.e. Hits, Kine, etc.                 //
15 //  many objects type can be assciated    //
16 //  with one data type: storing object    //
17 //  (usually tree), task producing it,    //
18 //  Quality Assurance(QA), QA Task, and   //
19 //  others.                               //
20 //                                        //
21 //                                        //
22 ////////////////////////////////////////////
23
24 #include <TDirectory.h>
25 #include <TNamed.h>
26 #include <TString.h>
27 #include <TTask.h>
28 #include <TTree.h>
29 class TFile;
30 class TFolder;
31
32 class AliBaseLoader;
33 class AliLoader;
34 class AliObjectLoader;
35 class AliRunLoader;
36 class AliTaskLoader;
37 class AliTreeLoader;
38
39 class AliDataLoader: public TNamed
40  {
41   public:
42    AliDataLoader();
43    AliDataLoader(const char* filename, const char* contname, const char* name, Option_t* opt = "t");
44    AliDataLoader(const AliDataLoader& source);
45    AliDataLoader& operator=(const AliDataLoader& source);
46    virtual ~AliDataLoader();
47
48    virtual Int_t      SetEvent();
49    virtual Int_t      GetEvent();
50
51    //shrtcuts method to basic data base loader 0  
52    virtual Int_t      Load(Option_t* opt="");
53    virtual void       Unload();
54    virtual Int_t      Reload(); 
55    virtual Int_t      WriteData(Option_t* opt="");
56    virtual TTree*     Tree() const;
57    virtual void       Clean();
58    virtual void       MakeTree();
59    virtual Int_t      OpenFile(Option_t* opt);
60
61    virtual void       CloseFile();
62    void               UnloadAll();
63    void               CleanAll();
64    const TString&     GetFileName() const {return fFileName;}
65    TFile*             GetFile() const {return fFile;}
66    TDirectory*        GetDirectory() const {return fDirectory;}
67    const TString&     GetFileOption() const {return fFileOption;}
68    const Int_t&       GetCompressionLevel() const {return fCompressionLevel;}
69    
70    Bool_t             Cd(){return (fDirectory)?fDirectory->cd():kFALSE;}
71    
72    virtual void       SetFileName(const TString& filename){fFileName = filename;}
73    virtual void       SetFileOption(const Option_t* fileopt);
74    virtual void       SetCompressionLevel(Int_t cl);
75
76    Int_t              SetEventFolder(TFolder* eventfolder);//sets the event folder
77    Int_t              SetFolder(TFolder* folder);//sets the data folder ??????
78    TFolder*           GetEventFolder();
79    TFolder*           GetFolder() const {return fFolder;}
80    
81 //   TObject*           GetFromDirectory(const char *name){return (fDirectory)?fDirectory->Get(name):0x0;}
82    void               SetFileNameSuffix(const TString& suffix);//adds the suffix before ".root", 
83                                                                //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
84                                                                //made on Jiri Chudoba demand
85    void               SetNumberOfEventsPerFile(Int_t nevpf) 
86      {fNEventsPerFile = nevpf;}
87    const TString      SetFileOffset(const TString& fname);//adds the proper number before .root extension suffix
88    void               SetDirName(TString& dirname);
89
90    void               AddBaseLoader(AliBaseLoader* bl);
91    enum EStdBasicLoaders {kData = 0,kTask,kQA,kQATask};//standard basic loaders identifiers
92
93    AliBaseLoader*     GetBaseLoader(const TString& name) const;
94    AliBaseLoader*     GetBaseLoader(Int_t n) const;
95    AliObjectLoader*   GetBaseDataLoader();
96    AliTaskLoader*     GetBaseTaskLoader();
97    AliBaseLoader*     GetBaseQALoader();
98    AliTaskLoader*     GetBaseQATaskLoader();
99    
100    void               SetBaseDataLoader(AliBaseLoader* bl);
101    void               SetBaseTaskLoader(AliTaskLoader* bl);
102    void               SetBaseQALoader(AliBaseLoader* bl);
103    void               SetBaseQATaskLoader(AliTaskLoader* bl);
104    
105    Bool_t             CheckReload();//checks if we have to reload given file
106    Bool_t             IsFileWritable() const;
107    Bool_t             IsFileOpen() const;
108    Bool_t             IsOptionContrary(const TString& option) const;
109    
110    void Synchronize();
111
112   protected:
113    Int_t              GetDebug() const;
114    AliRunLoader*      GetRunLoader();//gets the run-loader from event folder
115
116   private:
117       
118    TString      fFileName; //name of the file 
119    TFile*       fFile; //! pointer to file 
120    TDirectory*  fDirectory; //!pointer to TDirectory
121    TString      fFileOption; //!file option while opened 
122    Int_t        fCompressionLevel; //Compression Level of File
123    Int_t        fNEventsPerFile;  //defines number of events stored per one file
124    
125    TObjArray*   fBaseLoaders;//base loaders
126    Bool_t       fHasTask;// flag if has a task
127    TString      fTaskName;// name of the task
128    TTask*       fParentalTask;//Parental task
129
130    TFolder*     fEventFolder;//!event folder
131    TFolder*     fFolder;//! folder with data
132    
133    ClassDef(AliDataLoader,2)
134  };
135
136
137 //__________________________________________
138 ////////////////////////////////////////////
139 //                                        //
140 //  class AliBaseLoader                   //
141 //                                        //
142 //                                        //
143 ////////////////////////////////////////////
144
145
146 class AliBaseLoader: public TNamed
147 {
148   public:
149     AliBaseLoader();
150     AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop = kFALSE);
151    AliBaseLoader(const AliBaseLoader& source);
152    AliBaseLoader& operator=(const AliBaseLoader& source);
153     
154     virtual ~AliBaseLoader(){};
155      
156     virtual Int_t      Load(Option_t* opt="");
157     virtual void       Unload();
158     virtual Int_t      Reload();
159     virtual Int_t      WriteData(Option_t* opt="");
160     virtual void       Clean();
161     virtual Int_t      Post();//Takes from file and sends to proper TFolder (Data Folder)
162     virtual Int_t      Post(TObject* data);//Sends to proper TFolder (Data Folder)
163     virtual TObject*   Get() const = 0; 
164     Bool_t             IsLoaded()const{return fIsLoaded;}
165     void               SetDataLoader(AliDataLoader* dl){fDataLoader = dl;}
166     void               SetEventFolder(TFolder* /*ef*/){;}
167     void               SetDoNotReload(Bool_t flag){fDoNotReload = flag;}
168     Bool_t             DoNotReload() const {return fDoNotReload;}
169     TDirectory*        GetDirectory() const;//returns pointer to directory where data are stored. 
170     TObject*           GetFromDirectory(const char *name) const
171       {return (GetDirectory())?GetDirectory()->Get(name):0x0;}    
172    protected:
173     
174     virtual Int_t      AddToBoard(TObject* obj) = 0;//add to white board - board can be TTask or TFolder
175     virtual void       RemoveFromBoard(TObject* obj) = 0;
176     
177     AliDataLoader*     GetDataLoader() const;
178     Int_t              GetDebug() const;
179
180     Bool_t             fIsLoaded;    //!  flag indicating if data are loaded
181     Bool_t             fStoreInTopOfFile;// if true, data are stored in top of file ->Indicates fDoNotReload == kTRUE
182
183    private:
184     Bool_t             fDoNotReload; // if this flag is on object is not reloaded while GetEvent is called.
185                                      //Specially important for tasks. Task loops over events while producing data, 
186                          //and has a base loader which writes it to file every processed event.
187                          //If this flag is not on, while taking next event, loader deletes task
188                          // and tries to get new one from file
189     AliDataLoader*     fDataLoader;  //! pointer to Data Loader this Base Loader belongs to
190
191  ClassDef(AliBaseLoader,1)    
192 };
193
194 //__________________________________________
195 ////////////////////////////////////////////
196 //                                        //
197 //  class AliObjectLoader                 //
198 //                                        //
199 //                                        //
200 ////////////////////////////////////////////
201
202 class AliObjectLoader: public AliBaseLoader
203  {
204    public:
205      AliObjectLoader(){};
206      AliObjectLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop = kFALSE);
207      AliObjectLoader(const AliObjectLoader& source);
208      AliObjectLoader& operator=(const AliObjectLoader& source);
209      virtual          ~AliObjectLoader(){};
210      TObject*          Get() const;
211
212    protected:
213      TFolder*          GetFolder() const;
214      Int_t             AddToBoard(TObject* obj);
215      void              RemoveFromBoard(TObject* obj);
216
217  ClassDef(AliObjectLoader,1)    
218   
219  };
220
221 //__________________________________________
222 ////////////////////////////////////////////
223 //                                        //
224 //  class AliTreeLoader                   //
225 //                                        //
226 //                                        //
227 ////////////////////////////////////////////
228
229 class AliTreeLoader: public AliObjectLoader
230  {
231    public:
232      AliTreeLoader(){};
233      AliTreeLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop = kFALSE);
234      AliTreeLoader(const AliTreeLoader& source);
235      AliTreeLoader& operator=(const AliTreeLoader& source);
236      virtual ~AliTreeLoader(){};
237      
238      virtual TTree*     Tree() const {return dynamic_cast<TTree*>(Get());}
239      virtual void       MakeTree();
240      virtual Int_t      WriteData(Option_t* opt="");
241
242    ClassDef(AliTreeLoader,1)    
243  };
244
245 //__________________________________________
246 ////////////////////////////////////////////
247 //                                        //
248 //  class AliTaskLoader                   //
249 //                                        //
250 //                                        //
251 ////////////////////////////////////////////
252  
253 class AliTaskLoader: public AliBaseLoader
254  {
255   public:
256     AliTaskLoader():fParentalTask(0x0){};
257     AliTaskLoader(const TString& name, AliDataLoader* dl, TTask* parentaltask, Bool_t storeontop = kFALSE);
258     AliTaskLoader(const AliTaskLoader& source);
259     AliTaskLoader& operator=(const AliTaskLoader& source);
260     virtual ~AliTaskLoader(){};
261     
262     TObject*           Get() const; 
263     virtual TTask*     Task() const {return dynamic_cast<TTask*>(Get());}
264     virtual void       Clean();
265
266   protected:
267     Int_t              AddToBoard(TObject* obj);
268     void               RemoveFromBoard(TObject* obj);
269     TTask*             GetParentalTask() const;
270
271   private:
272     TTask*             fParentalTask; // Parental task
273
274   ClassDef(AliTaskLoader,1)    
275  };
276
277 #endif
278
279