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 /////////////////////////////////////////////////////////////////////////////////////////////
33 #include "AliBaseLoader.h"
35 #include "AliTreeLoader.h"
36 #include "AliRunLoader.h"
38 ClassImp(AliBaseLoader)
40 //______________________________________________________________________________
41 AliBaseLoader::AliBaseLoader():
43 fStoreInTopOfFile(kFALSE),
48 // default constructor
52 //______________________________________________________________________________
53 AliBaseLoader::AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
54 TNamed(name,name+" Base Loader"),
56 fStoreInTopOfFile(storeontop),
57 fDoNotReload(storeontop),//if stored on top of file - this object is loaded ones pe
65 //______________________________________________________________________________
66 AliBaseLoader::AliBaseLoader(const AliBaseLoader& source) :
68 fIsLoaded(source.fIsLoaded),
69 fStoreInTopOfFile(source.fStoreInTopOfFile),
70 fDoNotReload(source.fDoNotReload),
71 fDataLoader(source.fDataLoader)
76 AliFatal("Copy constructor not implemented");
79 //______________________________________________________________________________
80 AliBaseLoader& AliBaseLoader::operator=(const AliBaseLoader& /*source*/)
83 // Assignment operator
85 AliFatal("Assignment operator not implemented");
89 //______________________________________________________________________________
90 Int_t AliBaseLoader::Load(Option_t* opt)
93 // Loads and posts the data
95 AliDebug(1, Form("data type = %s, option = %s",GetName(),opt));
99 AliWarning(Form("Data <<%s>> are already loaded. Use ReloadData to force reload. Nothing done",GetName()));
105 if (GetDataLoader()->IsFileOpen() == kTRUE)
107 if (GetDataLoader()->IsOptionContrary(opt) == kTRUE)
109 AliError(Form("Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName()));
110 AliError("File was already opened in READ-ONLY mode, while now WRITEABLE access is requested.");
111 AliError("Use AliDataLoader::SetOption to enforce change of access mode OR");
112 AliError("Load previosly loaded data with coherent option.");
118 retval = GetDataLoader()->OpenFile(opt);
121 AliError(Form("Error occured while opening <<%s>> file",GetName()));
125 //if file is recreated there is no sense to search for data to post and get Error message
126 if (AliLoader::TestFileOption(opt) == kFALSE)
128 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(this);
129 if (tl) tl->MakeTree();
137 AliError(Form("Error occured while posting %s from file to folder.",GetName()));
145 //______________________________________________________________________________
146 Int_t AliBaseLoader::Post()
149 // Posts data container to proper folders
152 if ( GetDirectory() == 0x0)
154 AliError(Form("%s directory is NULL. Load before.",GetDataLoader()->GetName()));
158 TObject* data = GetFromDirectory(fName);
161 //if such an obejct already exists - remove it first
166 //check if file is in update mode
167 Int_t fileupdate = GetDataLoader()->GetFileOption().CompareTo("update",TString::kIgnoreCase);
168 if ( fileupdate == 0)
169 { //if it is, it is normal that there is no data yet
170 AliDebug(1, Form("Can not find %s in file %s (file is opened in UPDATE mode).",
171 GetName(),GetDataLoader()->GetFile()->GetName()));
175 AliError(Form("Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName()));
182 //______________________________________________________________________________
183 Int_t AliBaseLoader::Post(TObject* data)
186 // Posts data container to proper folders
190 AliError("Pointer to object is NULL");
194 if ( fName.CompareTo(data->GetName()) != 0)
196 AliFatal(Form("Object name is <<%s>> while <<%s>> expected",data->GetName(),GetName()));
197 return -1;//pro forma
200 TObject* obj = Get();
203 AliWarning("This object was already posted.");
208 AliWarning(Form("Object named %s already exitsts in data folder. Removing it",GetName()));
211 return AddToBoard(data);
214 //______________________________________________________________________________
215 Int_t AliBaseLoader::WriteData(Option_t* opt)
218 // Writes data defined by di object
219 // opt might be "OVERWRITE" in case of forcing overwriting
221 AliDebug(1, Form("Writing %s container for %s data. Option is %s.",
222 GetName(),GetDataLoader()->GetName(),opt));
224 TObject *data = Get();
226 {//did not get, nothing to write
227 AliWarning(Form("Tree named %s not found in folder. Nothing to write.",GetName()));
231 //check if file is opened
232 if (GetDirectory() == 0x0)
235 GetDataLoader()->SetFileOption("UPDATE");
236 if (GetDataLoader()->OpenFile("UPDATE"))
238 //oops, can not open the file, give an error message and return error code
239 AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName()));
244 if (GetDataLoader()->IsFileWritable() == kFALSE)
246 AliError(Form("File %s is not writable",GetDataLoader()->GetFileName().Data()));
250 GetDirectory()->cd(); //set the proper directory active
252 //see if hits container already exists in this (root) directory
253 TObject* obj = GetFromDirectory(GetName());
255 { //if they exist, see if option OVERWRITE is used
256 const char *oOverWrite = strstr(opt,"OVERWRITE");
258 {//if it is not used - give an error message and return an error code
259 AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
264 AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s",
265 GetName(),opt,data->GetName()));
266 AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s",
267 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
268 GetDirectory()->GetFile()->GetName()));
270 AliDebug(1, "Writing data");
271 data->Write(0,TObject::kOverwrite);
273 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
279 //______________________________________________________________________________
280 Int_t AliBaseLoader::Reload()
283 // Unloads and loads datat again - if loaded before
288 return Load(GetDataLoader()->GetFileOption());
293 //______________________________________________________________________________
294 void AliBaseLoader::Clean()
297 // Removes objects from folder/task
299 AliDebug(1, Form("%s %s",GetName(),GetDataLoader()->GetName()));
300 TObject* obj = Get();
303 AliDebug(1, Form("cleaning %s.",GetName()));
304 RemoveFromBoard(obj);
309 //______________________________________________________________________________
310 void AliBaseLoader::Unload()
312 // Unloads data and closes the files
315 GetDataLoader()->CloseFile();
318 //______________________________________________________________________________
319 AliDataLoader* AliBaseLoader::GetDataLoader() const
322 // Returns pointer to the data loader
324 if (fDataLoader == 0x0)
326 AliFatal("Pointer to Data Loader is NULL");
331 //______________________________________________________________________________
332 TDirectory* AliBaseLoader::GetDirectory() const
335 // returnd TDirectory where data are to be saved
336 // if fStoreInTopOfFile flag is true - returns pointer to file
338 return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory();