1 /////////////////////////////////////////////////////////////////////////////////////////////
3 // class AliBaseLoader //
5 // Container of all data needed for full //
6 // description of each data type //
7 // (Hits, Kine, ...) //
9 // Each data loader has a basic standard setup of BaseLoaders //
10 // which can be identuified by indexes (defined by EStdBasicLoaders) //
11 // Data managed by these standard base loaders has fixed naming convention //
12 // e.g. - tree with hits is always named TreeH //
13 // (defined in AliLoader::fgkDefaultHitsContainerName) //
14 // - task DtectorName+Name defined //
16 // EStdBasicLoaders idx Object Type Description //
17 // kData 0 TTree or TObject main data itself (hits,digits,...) //
18 // kTask 1 TTask object producing main data //
19 // kQA 2 TTree quality assurance tree //
20 // kQATask 3 TTask task producing QA object //
23 // User can define and add more basic loaders even Run Time. //
24 // Caution: in order to save information about added base loader //
25 // user must rewrite Run Loader to galice.file, overwriting old setup //
27 /////////////////////////////////////////////////////////////////////////////////////////////
34 #include "AliBaseLoader.h"
36 #include "AliTreeLoader.h"
37 #include "AliRunLoader.h"
39 ClassImp(AliBaseLoader)
41 //______________________________________________________________________________
42 AliBaseLoader::AliBaseLoader():
44 fStoreInTopOfFile(kFALSE),
49 // default constructor
53 //______________________________________________________________________________
54 AliBaseLoader::AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
55 TNamed(name,name+" Base Loader"),
57 fStoreInTopOfFile(storeontop),
58 fDoNotReload(storeontop),//if stored on top of file - this object is loaded ones pe
66 //______________________________________________________________________________
67 Int_t AliBaseLoader::Load(Option_t* opt)
70 // Loads and posts the data
72 AliDebug(1, Form("data type = %s, option = %s",GetName(),opt));
76 AliDebug(1,Form("Data <<%s>> are already loaded. Use ReloadData to force reload. Nothing done",GetName()));
82 if (GetDataLoader()->IsFileOpen() == kTRUE)
84 if (GetDataLoader()->IsOptionContrary(opt) == kTRUE)
86 AliError(Form("Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName()));
87 AliError("File was already opened in READ-ONLY mode, while now WRITEABLE access is requested.");
88 AliError("Use AliDataLoader::SetOption to enforce change of access mode OR");
89 AliError("Load previosly loaded data with coherent option.");
95 retval = GetDataLoader()->OpenFile(opt);
98 AliError(Form("Error occured while opening <<%s>> file",GetName()));
102 //if file is recreated there is no sense to search for data to post and get Error message
103 if (AliLoader::TestFileOption(opt) == kFALSE)
105 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(this);
106 if (tl) tl->MakeTree();
114 AliError(Form("Error occured while posting %s from file to folder.",GetName()));
122 //______________________________________________________________________________
123 Int_t AliBaseLoader::Post()
126 // Posts data container to proper folders
129 if ( GetDirectory() == 0x0)
131 AliError(Form("%s directory is NULL. Load before.",GetDataLoader()->GetName()));
135 TObject* data = GetFromDirectory(fName);
138 //if such an obejct already exists - remove it first
143 //check if file is in update mode
144 Int_t fileupdate = GetDataLoader()->GetFileOption().CompareTo("update",TString::kIgnoreCase);
145 if ( fileupdate == 0)
146 { //if it is, it is normal that there is no data yet
147 AliDebug(1, Form("Can not find %s in file %s (file is opened in UPDATE mode).",
148 GetName(),GetDataLoader()->GetFile()->GetName()));
152 AliError(Form("Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName()));
159 //______________________________________________________________________________
160 Int_t AliBaseLoader::Post(TObject* data)
163 // Posts data container to proper folders
167 AliError("Pointer to object is NULL");
171 if ( fName.CompareTo(data->GetName()) != 0)
173 AliFatal(Form("Object name is <<%s>> while <<%s>> expected",data->GetName(),GetName()));
174 return -1;//pro forma
177 TObject* obj = Get();
180 AliWarning("This object was already posted.");
185 AliWarning(Form("Object named %s already exitsts in data folder. Removing it",GetName()));
188 return AddToBoard(data);
191 //______________________________________________________________________________
192 Int_t AliBaseLoader::WriteData(Option_t* opt)
195 // Writes data defined by di object
196 // opt might be "OVERWRITE" in case of forcing overwriting
198 AliDebug(1, Form("Writing %s container for %s data. Option is %s.",
199 GetName(),GetDataLoader()->GetName(),opt));
201 TObject *data = Get();
203 {//did not get, nothing to write
204 AliWarning(Form("Tree named %s not found in folder. Nothing to write.",GetName()));
208 //check if file is opened
209 if (GetDirectory() == 0x0)
212 GetDataLoader()->SetFileOption("UPDATE");
213 if (GetDataLoader()->OpenFile("UPDATE"))
215 //oops, can not open the file, give an error message and return error code
216 AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName()));
221 if (GetDataLoader()->IsFileWritable() == kFALSE)
223 AliError(Form("File %s is not writable",GetDataLoader()->GetFileName().Data()));
227 GetDirectory()->cd(); //set the proper directory active
229 //see if hits container already exists in this (root) directory
230 TObject* obj = GetFromDirectory(GetName());
232 { //if they exist, see if option OVERWRITE is used
233 const char *oOverWrite = strstr(opt,"OVERWRITE");
235 {//if it is not used - give an error message and return an error code
236 AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
241 AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s",
242 GetName(),opt,data->GetName()));
243 AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s",
244 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
245 GetDirectory()->GetFile()->GetName()));
247 AliDebug(1, "Writing data");
248 data->Write(0,TObject::kOverwrite);
250 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
256 //______________________________________________________________________________
257 Int_t AliBaseLoader::Reload()
260 // Unloads and loads datat again - if loaded before
265 return Load(GetDataLoader()->GetFileOption());
270 //______________________________________________________________________________
271 void AliBaseLoader::Clean()
274 // Removes objects from folder/task
276 AliDebug(1, Form("%s %s",GetName(),GetDataLoader()->GetName()));
277 TObject* obj = Get();
280 AliDebug(1, Form("cleaning %s.",GetName()));
281 RemoveFromBoard(obj);
286 //______________________________________________________________________________
287 void AliBaseLoader::Unload()
289 // Unloads data and closes the files
292 GetDataLoader()->CloseFile();
295 //______________________________________________________________________________
296 AliDataLoader* AliBaseLoader::GetDataLoader() const
299 // Returns pointer to the data loader
301 if (fDataLoader == 0x0)
303 AliFatal("Pointer to Data Loader is NULL");
308 //______________________________________________________________________________
309 TDirectory* AliBaseLoader::GetDirectory() const
312 // returnd TDirectory where data are to be saved
313 // if fStoreInTopOfFile flag is true - returns pointer to file
315 return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory();