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 /////////////////////////////////////////////////////////////////////////////////////////////
31 #include "AliBaseLoader.h"
32 #include "AliTreeLoader.h"
33 #include "AliDataLoader.h"
34 #include "AliLoader.h"
40 ClassImp(AliBaseLoader)
42 //______________________________________________________________________________
43 AliBaseLoader::AliBaseLoader():
45 fStoreInTopOfFile(kFALSE),
50 // default constructor
54 //______________________________________________________________________________
55 AliBaseLoader::AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
56 TNamed(name,name+" Base Loader"),
58 fStoreInTopOfFile(storeontop),
59 fDoNotReload(storeontop),//if stored on top of file - this object is loaded ones pe
67 //______________________________________________________________________________
68 Int_t AliBaseLoader::Load(Option_t* opt)
71 // Loads and posts the data
73 AliDebug(1, Form("data type = %s, option = %s",GetName(),opt));
77 AliDebug(1,Form("Data <<%s>> are already loaded. Use ReloadData to force reload. Nothing done",GetName()));
83 if (GetDataLoader()->IsFileOpen() == kTRUE)
85 if (GetDataLoader()->IsOptionContrary(opt) == kTRUE)
87 AliError(Form("Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName()));
88 AliError("File was already opened in READ-ONLY mode, while now WRITEABLE access is requested.");
89 AliError("Use AliDataLoader::SetOption to enforce change of access mode OR");
90 AliError("Load previosly loaded data with coherent option.");
96 retval = GetDataLoader()->OpenFile(opt);
99 AliError(Form("Error occured while opening <<%s>> file",GetName()));
103 //if file is recreated there is no sense to search for data to post and get Error message
104 if (AliLoader::TestFileOption(opt) == kFALSE)
106 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(this);
107 if (tl) tl->MakeTree();
115 AliError(Form("Error occured while posting %s from file to folder.",GetName()));
123 //______________________________________________________________________________
124 Int_t AliBaseLoader::Post()
127 // Posts data container to proper folders
130 if ( GetDirectory() == 0x0)
132 AliError(Form("%s directory is NULL. Load before.",GetDataLoader()->GetName()));
136 TObject* data = GetFromDirectory(fName);
139 //if such an obejct already exists - remove it first
144 //check if file is in update mode
145 Int_t fileupdate = GetDataLoader()->GetFileOption().CompareTo("update",TString::kIgnoreCase);
146 if ( fileupdate == 0)
147 { //if it is, it is normal that there is no data yet
148 AliDebug(1, Form("Can not find %s in file %s (file is opened in UPDATE mode).",
149 GetName(),GetDataLoader()->GetFile()->GetName()));
153 AliError(Form("Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName()));
160 //______________________________________________________________________________
161 Int_t AliBaseLoader::Post(TObject* data)
164 // Posts data container to proper folders
168 AliError("Pointer to object is NULL");
172 if ( fName.CompareTo(data->GetName()) != 0)
174 AliFatal(Form("Object name is <<%s>> while <<%s>> expected",data->GetName(),GetName()));
175 return -1;//pro forma
178 TObject* obj = Get();
181 AliWarning("This object was already posted.");
186 AliWarning(Form("Object named %s already exitsts in data folder. Removing it",GetName()));
189 return AddToBoard(data);
192 //______________________________________________________________________________
193 Int_t AliBaseLoader::WriteData(Option_t* opt)
196 // Writes data defined by di object
197 // opt might be "OVERWRITE" in case of forcing overwriting
199 AliDebug(1, Form("Writing %s container for %s data. Option is %s.",
200 GetName(),GetDataLoader()->GetName(),opt));
202 TObject *data = Get();
204 {//did not get, nothing to write
205 AliWarning(Form("Tree named %s not found in folder. Nothing to write.",GetName()));
209 //check if file is opened
210 if (GetDirectory() == 0x0)
213 GetDataLoader()->SetFileOption("UPDATE");
214 if (GetDataLoader()->OpenFile("UPDATE"))
216 //oops, can not open the file, give an error message and return error code
217 AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName()));
222 if (GetDataLoader()->IsFileWritable() == kFALSE)
224 AliError(Form("File %s is not writable",GetDataLoader()->GetFileName().Data()));
228 GetDirectory()->cd(); //set the proper directory active
230 //see if hits container already exists in this (root) directory
231 TObject* obj = GetFromDirectory(GetName());
233 { //if they exist, see if option OVERWRITE is used
234 const char *oOverWrite = strstr(opt,"OVERWRITE");
236 {//if it is not used - give an error message and return an error code
237 AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
242 AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s",
243 GetName(),opt,data->GetName()));
244 AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s",
245 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
246 GetDirectory()->GetFile()->GetName()));
248 AliDebug(1, "Writing data");
249 data->Write(0,TObject::kOverwrite);
251 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
257 //______________________________________________________________________________
258 Int_t AliBaseLoader::Reload()
261 // Unloads and loads datat again - if loaded before
266 return Load(GetDataLoader()->GetFileOption());
271 //______________________________________________________________________________
272 void AliBaseLoader::Clean()
275 // Removes objects from folder/task
277 AliDebug(1, Form("%s %s",GetName(),GetDataLoader()->GetName()));
278 TObject* obj = Get();
281 AliDebug(1, Form("cleaning %s.",GetName()));
282 RemoveFromBoard(obj);
287 //______________________________________________________________________________
288 void AliBaseLoader::Unload()
290 // Unloads data and closes the files
293 GetDataLoader()->CloseFile();
296 //______________________________________________________________________________
297 AliDataLoader* AliBaseLoader::GetDataLoader() const
300 // Returns pointer to the data loader
302 if (fDataLoader == 0x0)
304 AliFatal("Pointer to Data Loader is NULL");
309 //______________________________________________________________________________
310 TDirectory* AliBaseLoader::GetDirectory() const
313 // returnd TDirectory where data are to be saved
314 // if fStoreInTopOfFile flag is true - returns pointer to file
316 return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory();