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