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 AliBaseLoader::AliBaseLoader(const AliBaseLoader& source) :
69 fIsLoaded(source.fIsLoaded),
70 fStoreInTopOfFile(source.fStoreInTopOfFile),
71 fDoNotReload(source.fDoNotReload),
72 fDataLoader(source.fDataLoader)
77 AliFatal("Copy constructor not implemented");
80 //______________________________________________________________________________
81 AliBaseLoader& AliBaseLoader::operator=(const AliBaseLoader& /*source*/)
84 // Assignment operator
86 AliFatal("Assignment operator not implemented");
90 //______________________________________________________________________________
91 Int_t AliBaseLoader::Load(Option_t* opt)
94 // Loads and posts the data
96 AliDebug(1, Form("data type = %s, option = %s",GetName(),opt));
100 AliDebug(1,Form("Data <<%s>> are already loaded. Use ReloadData to force reload. Nothing done",GetName()));
106 if (GetDataLoader()->IsFileOpen() == kTRUE)
108 if (GetDataLoader()->IsOptionContrary(opt) == kTRUE)
110 AliError(Form("Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName()));
111 AliError("File was already opened in READ-ONLY mode, while now WRITEABLE access is requested.");
112 AliError("Use AliDataLoader::SetOption to enforce change of access mode OR");
113 AliError("Load previosly loaded data with coherent option.");
119 retval = GetDataLoader()->OpenFile(opt);
122 AliError(Form("Error occured while opening <<%s>> file",GetName()));
126 //if file is recreated there is no sense to search for data to post and get Error message
127 if (AliLoader::TestFileOption(opt) == kFALSE)
129 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(this);
130 if (tl) tl->MakeTree();
138 AliError(Form("Error occured while posting %s from file to folder.",GetName()));
146 //______________________________________________________________________________
147 Int_t AliBaseLoader::Post()
150 // Posts data container to proper folders
153 if ( GetDirectory() == 0x0)
155 AliError(Form("%s directory is NULL. Load before.",GetDataLoader()->GetName()));
159 TObject* data = GetFromDirectory(fName);
162 //if such an obejct already exists - remove it first
167 //check if file is in update mode
168 Int_t fileupdate = GetDataLoader()->GetFileOption().CompareTo("update",TString::kIgnoreCase);
169 if ( fileupdate == 0)
170 { //if it is, it is normal that there is no data yet
171 AliDebug(1, Form("Can not find %s in file %s (file is opened in UPDATE mode).",
172 GetName(),GetDataLoader()->GetFile()->GetName()));
176 AliError(Form("Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName()));
183 //______________________________________________________________________________
184 Int_t AliBaseLoader::Post(TObject* data)
187 // Posts data container to proper folders
191 AliError("Pointer to object is NULL");
195 if ( fName.CompareTo(data->GetName()) != 0)
197 AliFatal(Form("Object name is <<%s>> while <<%s>> expected",data->GetName(),GetName()));
198 return -1;//pro forma
201 TObject* obj = Get();
204 AliWarning("This object was already posted.");
209 AliWarning(Form("Object named %s already exitsts in data folder. Removing it",GetName()));
212 return AddToBoard(data);
215 //______________________________________________________________________________
216 Int_t AliBaseLoader::WriteData(Option_t* opt)
219 // Writes data defined by di object
220 // opt might be "OVERWRITE" in case of forcing overwriting
222 AliDebug(1, Form("Writing %s container for %s data. Option is %s.",
223 GetName(),GetDataLoader()->GetName(),opt));
225 TObject *data = Get();
227 {//did not get, nothing to write
228 AliWarning(Form("Tree named %s not found in folder. Nothing to write.",GetName()));
232 //check if file is opened
233 if (GetDirectory() == 0x0)
236 GetDataLoader()->SetFileOption("UPDATE");
237 if (GetDataLoader()->OpenFile("UPDATE"))
239 //oops, can not open the file, give an error message and return error code
240 AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName()));
245 if (GetDataLoader()->IsFileWritable() == kFALSE)
247 AliError(Form("File %s is not writable",GetDataLoader()->GetFileName().Data()));
251 GetDirectory()->cd(); //set the proper directory active
253 //see if hits container already exists in this (root) directory
254 TObject* obj = GetFromDirectory(GetName());
256 { //if they exist, see if option OVERWRITE is used
257 const char *oOverWrite = strstr(opt,"OVERWRITE");
259 {//if it is not used - give an error message and return an error code
260 AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
265 AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s",
266 GetName(),opt,data->GetName()));
267 AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s",
268 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
269 GetDirectory()->GetFile()->GetName()));
271 AliDebug(1, "Writing data");
272 data->Write(0,TObject::kOverwrite);
274 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
280 //______________________________________________________________________________
281 Int_t AliBaseLoader::Reload()
284 // Unloads and loads datat again - if loaded before
289 return Load(GetDataLoader()->GetFileOption());
294 //______________________________________________________________________________
295 void AliBaseLoader::Clean()
298 // Removes objects from folder/task
300 AliDebug(1, Form("%s %s",GetName(),GetDataLoader()->GetName()));
301 TObject* obj = Get();
304 AliDebug(1, Form("cleaning %s.",GetName()));
305 RemoveFromBoard(obj);
310 //______________________________________________________________________________
311 void AliBaseLoader::Unload()
313 // Unloads data and closes the files
316 GetDataLoader()->CloseFile();
319 //______________________________________________________________________________
320 AliDataLoader* AliBaseLoader::GetDataLoader() const
323 // Returns pointer to the data loader
325 if (fDataLoader == 0x0)
327 AliFatal("Pointer to Data Loader is NULL");
332 //______________________________________________________________________________
333 TDirectory* AliBaseLoader::GetDirectory() const
336 // returnd TDirectory where data are to be saved
337 // if fStoreInTopOfFile flag is true - returns pointer to file
339 return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory();