-/*****************************************************************************/
-/*****************************************************************************/
-/*****************************************************************************/
-//__________________________________________
-///////////////////////////////////////////////////////////////////////////////
-// //
-// class AliBaseLoader //
-// //
-// //
-///////////////////////////////////////////////////////////////////////////////
-ClassImp(AliBaseLoader)
-
-AliBaseLoader::AliBaseLoader():
- fIsLoaded(kFALSE),
- fStoreInTopOfFile(kFALSE),
- fDoNotReload(kFALSE),
- fDataLoader(0x0)
-{
- //default constructor
-}
-/*****************************************************************************/
-
-AliBaseLoader::AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
- TNamed(name,name+" Base Loader"),
- fIsLoaded(kFALSE),
- fStoreInTopOfFile(storeontop),
- fDoNotReload(storeontop),//if stored on top of file - this object is loaded ones pe
- fDataLoader(dl)
-{
- //constructor
-}
-
-/*****************************************************************************/
-AliBaseLoader::AliBaseLoader(const AliBaseLoader& source):TNamed(source) {
- // copy constructor
- Fatal("AliBaseLoader","Copy constructor not implemented");
-}
-/*****************************************************************************/
-AliBaseLoader& AliBaseLoader::operator=(const AliBaseLoader& /*source*/) {
- // Assignment operator
- Fatal("AliBaseLoader","Assignment operator not implemented");
- return *this;
-}
-/*****************************************************************************/
-
-Int_t AliBaseLoader::Load(Option_t* opt)
-{
- // Loads and posts the data
- if (GetDebug())
- Info("Load","data type = %s, option = %s",GetName(),opt);
-
- if (Get())
- {
- Warning("Load","Data <<%s>> are already loaded. Use ReloadData to force reload. Nothing done",GetName());
- return 0;
- }
-
- Int_t retval;
-
- if (GetDataLoader()->IsFileOpen() == kTRUE)
- {
- if (GetDataLoader()->IsOptionContrary(opt) == kTRUE)
- {
- Error("Load","Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName());
- Error("Load","File was already opened in READ-ONLY mode, while now WRITEABLE access is requested.");
- Error("Load","Use AliDataLoader::SetOption to enforce change of access mode OR");
- Error("Load","Load previosly loaded data with coherent option.");
- return 10;
- }
- }
- else
- {
- retval = GetDataLoader()->OpenFile(opt);
- if (retval)
- {
- Error("Load","Error occured while opening <<%s>> file",GetName());
- return retval;
- }
- }
- //if file is recreated there is no sense to search for data to post and get Error message
- if (AliLoader::TestFileOption(opt) == kFALSE)
- {
- AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(this);
- if (tl) tl->MakeTree();
- fIsLoaded = kTRUE;
- return 0;
- }
-
- retval = Post();
- if (retval)
- {
- Error("Load","Error occured while posting %s from file to folder.",GetName());
- return retval;
- }
-
- fIsLoaded = kTRUE;
- return 0;
-}
-/*****************************************************************************/
-
-Int_t AliBaseLoader::Post()
-{
-//Posts data container to proper folders
-
- if ( GetDirectory() == 0x0)
- {
- Error("Post","%s directory is NULL. Load before.",GetDataLoader()->GetName());
- return 2;
- }
-
- TObject* data = GetFromDirectory(fName);
- if(data)
- {
- //if such an obejct already exists - remove it first
- return Post(data);
- }
- else
- {
- //check if file is in update mode
- Int_t fileupdate = GetDataLoader()->GetFileOption().CompareTo("update",TString::kIgnoreCase);
- if ( fileupdate == 0)
- { //if it is, it is normal that there is no data yet
- if (GetDebug())
- {
- Info("Post","Can not find %s in file %s (file is opened in UPDATE mode).",
- GetName(),GetDataLoader()->GetFile()->GetName());
- }
- }
- else
- {
- Error("Post","Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName());
- return 5;
- }
- }
- return 0;
-}
-/*****************************************************************************/
-
-Int_t AliBaseLoader::Post(TObject* data)
-{
-//Posts data container to proper folders
- if (data == 0x0)
- {
- Error("Post","Pointer to object is NULL");
- return 1;
- }
-
- if ( fName.CompareTo(data->GetName()) != 0)
- {
- Fatal("Post(TObject*)","Object name is <<%s>> while <<%s>> expected",data->GetName(),GetName());
- return -1;//pro forma
- }
-
- TObject* obj = Get();
- if (data == obj)
- {
- if (GetDebug()) Warning("Post","This object was already posted.");
- return 0;
- }
- if (obj)
- {
- Warning("PostData","Object named %s already exitsts in data folder. Removing it",GetName());
- Clean();
- }
- return AddToBoard(data);
-}
-/*****************************************************************************/
-
-Int_t AliBaseLoader::WriteData(Option_t* opt)
-{
-//Writes data defined by di object
-//opt might be "OVERWRITE" in case of forcing overwriting
- if (GetDebug())
- Info("WriteData","Writing %s container for %s data. Option is %s.",
- GetName(),GetDataLoader()->GetName(),opt);
-
- TObject *data = Get();
- if(data == 0x0)
- {//did not get, nothing to write
- Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
- return 0;
- }
-
- //check if file is opened
- if (GetDirectory() == 0x0)
- {
- //if not try to open
- GetDataLoader()->SetFileOption("UPDATE");
- if (GetDataLoader()->OpenFile("UPDATE"))
- {
- //oops, can not open the file, give an error message and return error code
- Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
- return 1;
- }
- }
-
- if (GetDataLoader()->IsFileWritable() == kFALSE)
- {
- Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
- return 2;
- }
-
- GetDirectory()->cd(); //set the proper directory active
-
- //see if hits container already exists in this (root) directory
- TObject* obj = GetFromDirectory(GetName());
- if (obj)
- { //if they exist, see if option OVERWRITE is used
- const char *oOverWrite = strstr(opt,"OVERWRITE");
- if(!oOverWrite)
- {//if it is not used - give an error message and return an error code
- Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
- return 3;
- }
- }
-
- if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
- GetName(),opt,data->GetName());
- if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
- GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
- GetDirectory()->GetFile()->GetName());
-
- if (GetDebug()) Info("WriteData","Writing data");
- data->Write(0,TObject::kOverwrite);
-
- fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
-
- return 0;
-
-}
-/*****************************************************************************/
-
-Int_t AliBaseLoader::Reload()
-{
-//Unloads and loads datat again - if loaded before
- if (IsLoaded())
- {
- Unload();
- return Load(GetDataLoader()->GetFileOption());
- }
- return 0;
-}
-/*****************************************************************************/
-
-void AliBaseLoader::Clean()
-{
-//removes objects from folder/task
- if (GetDebug()) Info("Clean","%s %s",GetName(),GetDataLoader()->GetName());
- TObject* obj = Get();
- if(obj)
- {
- if (GetDebug())
- Info("Clean","cleaning %s.",GetName());
- RemoveFromBoard(obj);
- delete obj;
- }
-}
-/*****************************************************************************/
-
-void AliBaseLoader::Unload()
-{
- // Unloads data and closes the files
- Clean();
- fIsLoaded = kFALSE;
- GetDataLoader()->CloseFile();
-}
-/*****************************************************************************/
-AliDataLoader* AliBaseLoader::GetDataLoader() const
-{
- // Returns pointer to the data loader
- if (fDataLoader == 0x0)
- {
- Fatal("GetDataLoader","Pointer to Data Loader is NULL");
- }
- return fDataLoader;
-}
-/*****************************************************************************/
-
-Int_t AliBaseLoader::GetDebug() const
-{
- // Returns debug level
- return (Int_t)AliLoader::GetDebug();
-}
-
-TDirectory* AliBaseLoader::GetDirectory() const
-{
- // returnd TDirectory where data are to be saved
- //if fStoreInTopOfFile flag is true - returns pointer to file
- return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory();
-}
-/*****************************************************************************/
-/*****************************************************************************/
-/*****************************************************************************/
-//__________________________________________
-///////////////////////////////////////////////////////////////////////////////
-// //
-// class AliObjectLoader //
-// //
-// //
-///////////////////////////////////////////////////////////////////////////////
-
-ClassImp(AliObjectLoader)
-
-AliObjectLoader::AliObjectLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
- AliBaseLoader(name,dl,storeontop)
-{
-//constructor
-}
-/*****************************************************************************/
-
-TFolder* AliObjectLoader::GetFolder() const
-{
- // Returns pointer to the object folder
- TFolder* df = GetDataLoader()->GetFolder();
- if (df == 0x0)
- {
- Fatal("GetFolder","Data Folder is NULL");
- }
- return df;
-}
-/*****************************************************************************/
-AliObjectLoader::AliObjectLoader(const AliObjectLoader& source):
- AliBaseLoader(source) {
- // copy constructor
- Fatal("AliObjectLoader","Copy constructor not implemented");
-}
-/*****************************************************************************/
-AliObjectLoader& AliObjectLoader::operator=(const AliObjectLoader& /*source*/) {
- // Assignment operator
- Fatal("AliObjectLoader","Assignment operator not implemented");
- return *this;
-}
-/*****************************************************************************/
-
-void AliObjectLoader::RemoveFromBoard(TObject* obj)
-{
- // Removes "obj" from the board
- GetFolder()->Remove(obj);
-}
-/*****************************************************************************/
-Int_t AliObjectLoader::AddToBoard(TObject* obj)
-{
- // Adds "obj" to the board
- GetFolder()->Add(obj);
- return 0;
-}
-/*****************************************************************************/
-
-TObject* AliObjectLoader::Get() const
-{
- // Returns pointer to the object loader
- return (GetFolder()) ? GetFolder()->FindObject(GetName()) : 0x0;
-}
-
-/*****************************************************************************/
-/*****************************************************************************/
-/*****************************************************************************/
-//__________________________________________
-///////////////////////////////////////////////////////////////////////////////
-// //
-// class AliTreeLoader //
-// //
-// //
-///////////////////////////////////////////////////////////////////////////////
-
-ClassImp(AliTreeLoader)
-
-AliTreeLoader::AliTreeLoader(const TString& name, AliDataLoader* dl,Bool_t storeontop):
- AliObjectLoader(name,dl,storeontop)
-{
-//constructor
-}
-/*****************************************************************************/
-AliTreeLoader::AliTreeLoader(const AliTreeLoader& source):
- AliObjectLoader(source) {
- // copy constructor
- Fatal("AliTreeLoader","Copy constructor not implemented");
-}
-/*****************************************************************************/
-AliTreeLoader& AliTreeLoader::operator=(const AliTreeLoader& /*source*/) {
- // Assignment operator
- Fatal("AliTreeLoader","Assignment operator not implemented");
- return *this;
-}
-
-/*****************************************************************************/
-
-Int_t AliTreeLoader::WriteData(Option_t* opt)
-{
-//Writes data defined by di object
-//opt might be "OVERWRITE" in case of forcing overwriting
-
- if (GetDebug())
- Info("WriteData","Writing %s container for %s data. Option is %s.",
- GetName(),GetDataLoader()->GetName(),opt);
-
- TObject *data = Get();
- if(data == 0x0)
- {//did not get, nothing to write
- Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
- return 0;
- }
-
- //check if file is opened
- if (GetDirectory() == 0x0)
- {
- //if not try to open
- GetDataLoader()->SetFileOption("UPDATE");
- if (GetDataLoader()->OpenFile("UPDATE"))
- {
- //oops, can not open the file, give an error message and return error code
- Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
- return 1;
- }
- }
-
- if (GetDataLoader()->IsFileWritable() == kFALSE)
- {
- Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
- return 2;
- }
-
- GetDirectory()->cd(); //set the proper directory active
-
- //see if hits container already exists in this (root) directory
- TObject* obj = GetFromDirectory(GetName());
- if (obj)
- { //if they exist, see if option OVERWRITE is used
- const char *oOverWrite = strstr(opt,"OVERWRITE");
- if(!oOverWrite)
- {//if it is not used - give an error message and return an error code
- Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
- return 3;
- }
- }
-
- if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
- GetName(),opt,data->GetName());
- if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
- GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
- GetDirectory()->GetFile()->GetName());
-
- //if a data object is a tree set the directory
- TTree* tree = dynamic_cast<TTree*>(data);
- if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above)
-
- if (GetDebug()) Info("WriteData","Writing tree");
- data->Write(0,TObject::kOverwrite);
-
- fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
-
- return 0;
-
-}
-/*****************************************************************************/
-
-void AliTreeLoader::MakeTree()
-{
-//this virtual method creates the tree in the file
- if (Tree())
- {
- if (GetDebug())
- Info("MakeTree","name = %s, Data Name = %s Tree already exists.",
- GetName(),GetDataLoader()->GetName());
- return;//tree already made
- }
- if (GetDebug())
- Info("MakeTree","Making Tree named %s.",GetName());
-
- TString dtypename(GetDataLoader()->GetName());
- TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree
- if (tree == 0x0)
- {
- Error("MakeTree","Can not create %s tree.",GetName());
- return;
- }
- tree->SetAutoSave(1000000000); //no autosave
- GetFolder()->Add(tree);
- WriteData("OVERWRITE");//write tree to the file
-}
-
-
-/*****************************************************************************/
-/*****************************************************************************/
-/*****************************************************************************/
-//__________________________________________
-///////////////////////////////////////////////////////////////////////////////
-// //
-// class AliTaskLoader //
-// //
-// //
-///////////////////////////////////////////////////////////////////////////////
-
-ClassImp(AliTaskLoader)
-
-AliTaskLoader::AliTaskLoader(const TString& name, AliDataLoader* dl, TTask* parentaltask, Bool_t storeontop):
- AliBaseLoader(name,dl,storeontop),
- fParentalTask(parentaltask)
-{
-//constructor
-}
-
-/*****************************************************************************/
-AliTaskLoader::AliTaskLoader(const AliTaskLoader& source):
- AliBaseLoader(source) {
- // copy constructor
- Fatal("AliTaskLoader","Copy constructor not implemented");
-}
-/*****************************************************************************/
-AliTaskLoader& AliTaskLoader::operator=(const AliTaskLoader& /*source*/) {
- // Assignment operator
- Fatal("AliTaskLoader","Assignment operator not implemented");
- return *this;
-}
-/*****************************************************************************/
-void AliTaskLoader::Clean()
-{
-//removes tasl from parental task
-// DO NOT DELETE OBJECT contrary to BaseLoader
-//
- if (GetDebug()) Info("Clean","%s %s",GetName(),GetDataLoader()->GetName());
- TObject* obj = Get();
- if(obj)
- {
- if (GetDebug())
- Info("Clean","cleaning %s.",GetName());
- RemoveFromBoard(obj);
- }
-}
-/*****************************************************************************/
-
-void AliTaskLoader::RemoveFromBoard(TObject* obj)
-{
- // Removes the task "obj" from the board
- GetParentalTask()->GetListOfTasks()->Remove(obj);
-}
-/*****************************************************************************/
-
-Int_t AliTaskLoader::AddToBoard(TObject* obj)
-{
- // Adds task "obj" to the board
- TTask* task = dynamic_cast<TTask*>(obj);
- if (task == 0x0)
- {
- Error("AddToBoard","To TTask board can be added only tasks.");
- return 1;
- }
- GetParentalTask()->Add(task);
- return 0;
-}
-/*****************************************************************************/
-
-TObject* AliTaskLoader::Get() const
-{
- // Returns pointer to the current task
- return (GetParentalTask()) ? GetParentalTask()->GetListOfTasks()->FindObject(GetName()) : 0x0;
-}
-/*****************************************************************************/
-
-TTask* AliTaskLoader::GetParentalTask() const
-{
-//returns parental tasks for this task
- return fParentalTask;
-}
-
-/*****************************************************************************/
-
-/*****************************************************************************/
-/*****************************************************************************/
-/*****************************************************************************/