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