From a9bbb4147c2d444bf73e90f39d12640452ab8847 Mon Sep 17 00:00:00 2001 From: alibrary Date: Wed, 13 Apr 2005 08:41:26 +0000 Subject: [PATCH] Splitting loader class to have proper debug messages --- EMCAL/AliEMCALLoader.cxx | 7 +- PHOS/AliPHOSLoader.cxx | 1 + START/AliSTARTLoader.h | 1 + STEER/AliBaseLoader.cxx | 342 ++++++++++ STEER/AliBaseLoader.h | 89 +++ STEER/AliDataLoader.cxx | 1301 ++++++++++++------------------------- STEER/AliDataLoader.h | 144 +--- STEER/AliLoader.cxx | 17 +- STEER/AliLoader.h | 19 +- STEER/AliObjectLoader.cxx | 106 +++ STEER/AliObjectLoader.h | 37 ++ STEER/AliPID.cxx | 68 +- STEER/AliPID.h | 5 +- STEER/AliRunLoader.cxx | 1 - STEER/AliTaskLoader.cxx | 131 ++++ STEER/AliTaskLoader.h | 43 ++ STEER/AliTreeLoader.cxx | 162 +++++ STEER/AliTreeLoader.h | 46 ++ STEER/libSTEER.pkg | 1 + 19 files changed, 1442 insertions(+), 1079 deletions(-) create mode 100644 STEER/AliBaseLoader.cxx create mode 100644 STEER/AliBaseLoader.h create mode 100644 STEER/AliObjectLoader.cxx create mode 100644 STEER/AliObjectLoader.h create mode 100644 STEER/AliTaskLoader.cxx create mode 100644 STEER/AliTaskLoader.h create mode 100644 STEER/AliTreeLoader.cxx create mode 100644 STEER/AliTreeLoader.h diff --git a/EMCAL/AliEMCALLoader.cxx b/EMCAL/AliEMCALLoader.cxx index 16681949f4a..17be32b29c1 100644 --- a/EMCAL/AliEMCALLoader.cxx +++ b/EMCAL/AliEMCALLoader.cxx @@ -45,11 +45,12 @@ // --- Standard library --- // --- AliRoot header files --- -#include "AliLog.h" -#include "AliEMCALLoader.h" #include "AliEMCAL.h" -#include "AliEMCALHit.h" #include "AliEMCALGetter.h" +#include "AliEMCALHit.h" +#include "AliEMCALLoader.h" +#include "AliLog.h" +#include "AliObjectLoader.h" ClassImp(AliEMCALLoader) diff --git a/PHOS/AliPHOSLoader.cxx b/PHOS/AliPHOSLoader.cxx index 16c248860da..c8e8bd105fc 100644 --- a/PHOS/AliPHOSLoader.cxx +++ b/PHOS/AliPHOSLoader.cxx @@ -47,6 +47,7 @@ // --- Standard library --- // --- AliRoot header files --- +#include "AliObjectLoader.h" #include "AliLog.h" #include "AliPHOSLoader.h" #include "AliPHOS.h" diff --git a/START/AliSTARTLoader.h b/START/AliSTARTLoader.h index 6c649676cc3..a75f98c15e4 100644 --- a/START/AliSTARTLoader.h +++ b/START/AliSTARTLoader.h @@ -2,6 +2,7 @@ #define ALISTARTLOADER_H #include "AliLoader.h" +#include "AliObjectLoader.h" class AliSTARTdigit; diff --git a/STEER/AliBaseLoader.cxx b/STEER/AliBaseLoader.cxx new file mode 100644 index 00000000000..4e4746d9889 --- /dev/null +++ b/STEER/AliBaseLoader.cxx @@ -0,0 +1,342 @@ +///////////////////////////////////////////////////////////////////////////////////////////// +// // +// class AliBaseLoader // +// // +// Container of all data needed for full // +// description of each data type // +// (Hits, Kine, ...) // +// // +// Each data loader has a basic standard setup of BaseLoaders // +// which can be identuified by indexes (defined by EStdBasicLoaders) // +// Data managed by these standard base loaders has fixed naming convention // +// e.g. - tree with hits is always named TreeH // +// (defined in AliLoader::fgkDefaultHitsContainerName) // +// - task DtectorName+Name defined // +// // +// EStdBasicLoaders idx Object Type Description // +// kData 0 TTree or TObject main data itself (hits,digits,...) // +// kTask 1 TTask object producing main data // +// kQA 2 TTree quality assurance tree // +// kQATask 3 TTask task producing QA object // +// // +// // +// User can define and add more basic loaders even Run Time. // +// Caution: in order to save information about added base loader // +// user must rewrite Run Loader to galice.file, overwriting old setup // +// // +///////////////////////////////////////////////////////////////////////////////////////////// + +/* $Id$ */ + +#include + +#include "AliBaseLoader.h" +#include "AliLog.h" +#include "AliTreeLoader.h" +#include "AliRunLoader.h" + +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), + fIsLoaded(source.fIsLoaded), + fStoreInTopOfFile(source.fStoreInTopOfFile), + fDoNotReload(source.fDoNotReload), + fDataLoader(source.fDataLoader) +{ + // + // copy constructor + // + AliFatal("Copy constructor not implemented"); +} + +//______________________________________________________________________________ +AliBaseLoader& AliBaseLoader::operator=(const AliBaseLoader& /*source*/) +{ + // + // Assignment operator + // + AliFatal("Assignment operator not implemented"); + return *this; +} + +//______________________________________________________________________________ +Int_t AliBaseLoader::Load(Option_t* opt) +{ + // + // Loads and posts the data + // + AliDebug(1, Form("data type = %s, option = %s",GetName(),opt)); + + if (Get()) + { + AliWarning(Form("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) + { + AliError(Form("Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName())); + AliError("File was already opened in READ-ONLY mode, while now WRITEABLE access is requested."); + AliError("Use AliDataLoader::SetOption to enforce change of access mode OR"); + AliError("Load previosly loaded data with coherent option."); + return 10; + } + } + else + { + retval = GetDataLoader()->OpenFile(opt); + if (retval) + { + AliError(Form("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(this); + if (tl) tl->MakeTree(); + fIsLoaded = kTRUE; + return 0; + } + + retval = Post(); + if (retval) + { + AliError(Form("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) + { + AliError(Form("%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 + AliDebug(1, Form("Can not find %s in file %s (file is opened in UPDATE mode).", + GetName(),GetDataLoader()->GetFile()->GetName())); + } + else + { + AliError(Form("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) + { + AliError("Pointer to object is NULL"); + return 1; + } + + if ( fName.CompareTo(data->GetName()) != 0) + { + AliFatal(Form("Object name is <<%s>> while <<%s>> expected",data->GetName(),GetName())); + return -1;//pro forma + } + + TObject* obj = Get(); + if (data == obj) + { + AliWarning("This object was already posted."); + return 0; + } + if (obj) + { + AliWarning(Form("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 + // + AliDebug(1, Form("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 + AliWarning(Form("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 + AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName())); + return 1; + } + } + + if (GetDataLoader()->IsFileWritable() == kFALSE) + { + AliError(Form("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 + AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data"); + return 3; + } + } + + AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s", + GetName(),opt,data->GetName())); + AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s", + GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(), + GetDirectory()->GetFile()->GetName())); + + AliDebug(1, "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 + // + AliDebug(1, Form("%s %s",GetName(),GetDataLoader()->GetName())); + TObject* obj = Get(); + if(obj) + { + AliDebug(1, Form("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) + { + AliFatal("Pointer to Data Loader is NULL"); + } + return fDataLoader; +} + +//______________________________________________________________________________ +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(); +} + + + diff --git a/STEER/AliBaseLoader.h b/STEER/AliBaseLoader.h new file mode 100644 index 00000000000..929829cee0b --- /dev/null +++ b/STEER/AliBaseLoader.h @@ -0,0 +1,89 @@ +#ifndef ALIBASELOADER_H +#define ALIBASELOADER_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +//__________________________________________ +//////////////////////////////////////////// +// // +// class AliBaseLoader // +// // +// Loader responsible for one data type // +// i.e. Hits, Kine, etc. // +// many objects type can be assciated // +// with one data type: storing object // +// (usually tree), task producing it, // +// Quality Assurance(QA), QA Task, and // +// others. // +// // +// // +//////////////////////////////////////////// + +#include +#include +#include +#include +#include +class TFile; +class TFolder; + +class AliLoader; +class AliDataLoader; +class AliObjectLoader; +class AliRunLoader; +class AliTaskLoader; +class AliTreeLoader; + +class AliBaseLoader: public TNamed +{ + public: + AliBaseLoader(); + AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop = kFALSE); + AliBaseLoader(const AliBaseLoader& source); + AliBaseLoader& operator=(const AliBaseLoader& source); + + virtual ~AliBaseLoader(){}; + + virtual Int_t Load(Option_t* opt=""); + virtual void Unload(); + virtual Int_t Reload(); + virtual Int_t WriteData(Option_t* opt=""); + virtual void Clean(); + virtual Int_t Post();//Takes from file and sends to proper TFolder (Data Folder) + virtual Int_t Post(TObject* data);//Sends to proper TFolder (Data Folder) + virtual TObject* Get() const = 0; + Bool_t IsLoaded()const{return fIsLoaded;} + void SetDataLoader(AliDataLoader* dl){fDataLoader = dl;} + void SetEventFolder(TFolder* /*ef*/){;} + void SetDoNotReload(Bool_t flag){fDoNotReload = flag;} + Bool_t DoNotReload() const {return fDoNotReload;} + TDirectory* GetDirectory() const;//returns pointer to directory where data are stored. + TObject* GetFromDirectory(const char *name) const + {return (GetDirectory())?GetDirectory()->Get(name):0x0;} + protected: + + virtual Int_t AddToBoard(TObject* obj) = 0;//add to white board - board can be TTask or TFolder + virtual void RemoveFromBoard(TObject* obj) = 0; + + AliDataLoader* GetDataLoader() const; + + Bool_t fIsLoaded; //! flag indicating if data are loaded + Bool_t fStoreInTopOfFile;// if true, data are stored in top of file ->Indicates fDoNotReload == kTRUE + + private: + Bool_t fDoNotReload; // if this flag is on object is not reloaded while GetEvent is called. + //Specially important for tasks. Task loops over events while producing data, + //and has a base loader which writes it to file every processed event. + //If this flag is not on, while taking next event, loader deletes task + // and tries to get new one from file + AliDataLoader* fDataLoader; //! pointer to Data Loader this Base Loader belongs to + + ClassDef(AliBaseLoader,1) +}; + + +#endif + + diff --git a/STEER/AliDataLoader.cxx b/STEER/AliDataLoader.cxx index a6790bd732d..347ef76d044 100644 --- a/STEER/AliDataLoader.cxx +++ b/STEER/AliDataLoader.cxx @@ -1,5 +1,3 @@ -#include -//__________________________________________ ///////////////////////////////////////////////////////////////////////////////////////////// // // // class AliDataLoader // @@ -28,16 +26,22 @@ // // ///////////////////////////////////////////////////////////////////////////////////////////// -#include +/* $Id$ */ + +#include #include +#include #include -#include +#include "AliDataLoader.h" #include "AliLog.h" +#include "AliObjectLoader.h" #include "AliRunLoader.h" +#include "AliTreeLoader.h" ClassImp(AliDataLoader) +//______________________________________________________________________________ AliDataLoader::AliDataLoader(): fFileName(0), fFile(0x0), @@ -54,9 +58,10 @@ AliDataLoader::AliDataLoader(): { } -/*****************************************************************************/ -AliDataLoader::AliDataLoader(const char* filename, const char* contname, const char* name, Option_t* opt): +//______________________________________________________________________________ +AliDataLoader::AliDataLoader(const char* filename, const char* contname, + const char* name, Option_t* opt): TNamed(name,name), fFileName(filename), fFile(0x0), @@ -71,12 +76,12 @@ AliDataLoader::AliDataLoader(const char* filename, const char* contname, const c fEventFolder(0x0), fFolder(0x0) { -//constructor -// creates a 0 loader, depending on option, default "T" is specialized loader for trees -// else standard object loader -// trees needs special care, becouse we need to set dir before writing + //constructor + // creates a 0 loader, depending on option, default "T" is specialized loader for trees + // else standard object loader + // trees needs special care, becouse we need to set dir before writing AliDebug(1, Form("File name is %s",fFileName.Data())); - + TString option(opt); AliBaseLoader* bl; if (option.CompareTo("T",TString::kIgnoreCase) == 0) @@ -86,7 +91,8 @@ AliDataLoader::AliDataLoader(const char* filename, const char* contname, const c fBaseLoaders->AddAt(bl,kData); } -/*****************************************************************************/ + +//______________________________________________________________________________ AliDataLoader::AliDataLoader(const AliDataLoader& source) : TNamed(source), fFileName(source.fFileName), @@ -102,292 +108,323 @@ AliDataLoader::AliDataLoader(const AliDataLoader& source) : fEventFolder(source.fEventFolder), fFolder(source.fFolder) { + // // copy constructor + // AliFatal("Copy constructor not implemented"); } -/*****************************************************************************/ -AliDataLoader& AliDataLoader::operator=(const AliDataLoader& /*source*/) { + + +//______________________________________________________________________________ +AliDataLoader& AliDataLoader::operator=(const AliDataLoader& /*source*/) +{ + // // Assignment operator + // AliFatal("Assignment operator not implemented"); return *this; } -/*****************************************************************************/ + +//______________________________________________________________________________ AliDataLoader::~AliDataLoader() { -//dtor - UnloadAll(); + // + //dtor + // + UnloadAll(); } -/*****************************************************************************/ +//______________________________________________________________________________ Int_t AliDataLoader::SetEvent() { -//basically the same that GetEvent but do not post data to folders - AliRunLoader* rl = GetRunLoader(); - if (rl == 0x0) - { - AliError("Can not get RunGettr"); - return 1; - } - - Int_t evno = rl->GetEventNumber(); - - TIter next(fBaseLoaders); - AliBaseLoader* bl; - while ((bl = (AliBaseLoader*)next())) - { - if (bl->DoNotReload() == kFALSE) bl->Clean(); - } - - if(fFile) - { - if (CheckReload()) - { - delete fFile; - fFile = 0x0; - AliDebug(1, Form("Reloading new file. File opt is %s",fFileOption.Data())); - OpenFile(fFileOption); - } - - fDirectory = AliLoader::ChangeDir(fFile,evno); - if (fDirectory == 0x0) - { - AliError(Form("Can not chage directory in file %s",fFile->GetName())); - return 1; - } - } - return 0; + // + // The same that GetEvent but do not post data to folders + // + AliRunLoader* rl = GetRunLoader(); + if (rl == 0x0) + { + AliError("Can not get RunGettr"); + return 1; + } + + Int_t evno = rl->GetEventNumber(); + + TIter next(fBaseLoaders); + AliBaseLoader* bl; + while ((bl = (AliBaseLoader*)next())) + { + if (bl->DoNotReload() == kFALSE) bl->Clean(); + } + + if(fFile) + { + if (CheckReload()) + { + delete fFile; + fFile = 0x0; + AliDebug(1, Form("Reloading new file. File opt is %s",fFileOption.Data())); + OpenFile(fFileOption); + } + + fDirectory = AliLoader::ChangeDir(fFile,evno); + if (fDirectory == 0x0) + { + AliError(Form("Can not chage directory in file %s",fFile->GetName())); + return 1; + } + } + return 0; } -/*****************************************************************************/ +//______________________________________________________________________________ Int_t AliDataLoader::GetEvent() { - // posts all loaded data from files to White Board - // event number is defined in RunLoader - // - //returns: - // 0 - in case of no error - // 1 - event not found - // - //for each base laoder post, if was loaded before GetEvent - - //call set event to switch to new directory in file - - - //post all data that were loaded before - // ->SetEvent does not call Unload, but only cleans White Board - // such IsLoaded flag stays untached - - if ( AliLoader::TestFileOption(fFileOption) == kTRUE ) //if file is read or update mode try to post - { //in other case there is no sense to post: file is new - TIter nextbl(fBaseLoaders); - AliBaseLoader* bl; - while ((bl = (AliBaseLoader*)nextbl())) - { - if (bl->IsLoaded()) - { - if (bl->DoNotReload() == kFALSE) bl->Post(); - } - } - } - return 0; + // posts all loaded data from files to White Board + // event number is defined in RunLoader + // + //returns: + // 0 - in case of no error + // 1 - event not found + // + //for each base laoder post, if was loaded before GetEvent + + //call set event to switch to new directory in file + + + //post all data that were loaded before + // ->SetEvent does not call Unload, but only cleans White Board + // such IsLoaded flag stays untached + + if ( AliLoader::TestFileOption(fFileOption) == kTRUE ) //if file is read or update mode try to post + { //in other case there is no sense to post: file is new + TIter nextbl(fBaseLoaders); + AliBaseLoader* bl; + while ((bl = (AliBaseLoader*)nextbl())) + { + if (bl->IsLoaded()) + { + if (bl->DoNotReload() == kFALSE) bl->Post(); + } + } + } + return 0; } -/*****************************************************************************/ +//______________________________________________________________________________ Int_t AliDataLoader::OpenFile(Option_t* opt) { -//Opens file named 'filename', and assigns pointer to it to 'file' -//jumps to fDirectoryectory corresponding to current event and stores the pointer to it in 'fDirectory' -//option 'opt' is passed to TFile::Open + //Opens file named 'filename', and assigns pointer to it to 'file' + //jumps to fDirectoryectory corresponding to current event and stores the pointer to it in 'fDirectory' + //option 'opt' is passed to TFile::Open if (fFile) - { - if(fFile->IsOpen() == kTRUE) - { - AliWarning(Form(" File %s already opened. First close it.",fFile->GetName())); - return 0; - } - else - { - AliWarning(Form("Pointer to file %s is not null, but file is not opened", - fFile->GetName())); - delete fFile; - fFile = 0x0; - } - } + { + if(fFile->IsOpen() == kTRUE) + { + AliWarning(Form(" File %s already opened. First close it.",fFile->GetName())); + return 0; + } + else + { + AliWarning(Form("Pointer to file %s is not null, but file is not opened", + fFile->GetName())); + delete fFile; + fFile = 0x0; + } + } TString fname(SetFileOffset(fFileName)); fFile = (TFile *)(gROOT->GetListOfFiles()->FindObject(fname)); if (fFile) - { - if(fFile->IsOpen() == kTRUE) - { - AliWarning(Form("File %s already opened by sombody else. First close it.", - fFile->GetName())); - return 0; - } - } + { + if(fFile->IsOpen() == kTRUE) + { + AliWarning(Form("File %s already opened by sombody else. First close it.", + fFile->GetName())); + return 0; + } + } fFileOption = opt; fFile = TFile::Open(fname,fFileOption);//open the file if (fFile == 0x0) - {//file is null - AliError(Form("Can not open file %s",fname.Data())); - return 1; - } + {//file is null + AliError(Form("Can not open file %s",fname.Data())); + return 1; + } if (fFile->IsOpen() == kFALSE) - {//file is null - AliError(Form("Can not open file %s",fname.Data())); - return 1; - } - + {//file is null + AliError(Form("Can not open file %s",fname.Data())); + return 1; + } + fFile->SetCompressionLevel(fCompressionLevel); AliRunLoader* rg = GetRunLoader(); if (rg == 0x0) - { - AliError("Can not find Run-Loader in folder."); - return 2; - } + { + AliError("Can not find Run-Loader in folder."); + return 2; + } Int_t evno = rg->GetEventNumber(); fDirectory = AliLoader::ChangeDir(fFile,evno); if (fDirectory == 0x0) - { - AliError(Form("Can not chage fDirectory in file %s.",fFile->GetName())); - return 3; - } + { + AliError(Form("Can not chage fDirectory in file %s.",fFile->GetName())); + return 3; + } return 0; } -/*****************************************************************************/ +//______________________________________________________________________________ void AliDataLoader::Unload() { - //unloads main data - shortcut method + // + //unloads main data - shortcut method + // GetBaseLoader(0)->Unload(); } -/*****************************************************************************/ +//______________________________________________________________________________ void AliDataLoader::UnloadAll() { -//Unloads all data and tasks - if ( fFile == 0x0 ) return; //nothing loaded - - TIter next(fBaseLoaders); - AliBaseLoader* bl; - while ((bl = (AliBaseLoader*)next())) - { - bl->Unload(); - } + // + // Unloads all data and tasks + // + if ( fFile == 0x0 ) return; //nothing loaded + + TIter next(fBaseLoaders); + AliBaseLoader* bl; + while ((bl = (AliBaseLoader*)next())) + { + bl->Unload(); + } } -/*****************************************************************************/ + +//______________________________________________________________________________ Int_t AliDataLoader::Reload() { - //Unloads and loads data again - if ( fFile == 0x0 ) return 0; - - TBits loaded(fBaseLoaders->GetEntries()); - TIter next(fBaseLoaders); - AliBaseLoader* bl; + // + // Unloads and loads data again + // + if ( fFile == 0x0 ) return 0; + + TBits loaded(fBaseLoaders->GetEntries()); + TIter next(fBaseLoaders); + AliBaseLoader* bl; + + Int_t i = 0; + while ((bl = (AliBaseLoader*)next())) + { + if (bl->IsLoaded()) + { + loaded.SetBitNumber(i++,kTRUE); + bl->Unload(); + } + } + + Int_t retval; + i = 0; + next.Reset(); + while ((bl = (AliBaseLoader*)next())) + { + if (loaded.TestBitNumber(i++)) + { + retval = bl->Load(fFileOption); + if (retval) + { + AliError(Form("Error occur while loading %s",bl->GetName())); + return retval; + } + } + } + return 0; +} - Int_t i = 0; - while ((bl = (AliBaseLoader*)next())) - { - if (bl->IsLoaded()) - { - loaded.SetBitNumber(i++,kTRUE); - bl->Unload(); - } - } - - Int_t retval; - i = 0; - next.Reset(); - while ((bl = (AliBaseLoader*)next())) - { - if (loaded.TestBitNumber(i++)) - { - retval = bl->Load(fFileOption); - if (retval) - { - AliError(Form("Error occur while loading %s",bl->GetName())); - return retval; - } - } - } - - return 0; - } -/*****************************************************************************/ +//______________________________________________________________________________ Int_t AliDataLoader::WriteData(Option_t* opt) { -//Writes primary data == first BaseLoader + // + // Writes primary data == first BaseLoader + // AliDebug(1, Form("Writing %s container for %s data. Option is %s.", GetBaseLoader(0)->GetName(),GetName(),opt)); return GetBaseLoader(0)->WriteData(opt); } -/*****************************************************************************/ +//______________________________________________________________________________ Int_t AliDataLoader::Load(Option_t* opt) { -//Writes primary data == first BaseLoader + // + // Writes primary data == first BaseLoader + // return GetBaseLoader(0)->Load(opt); } -/*****************************************************************************/ +//______________________________________________________________________________ Int_t AliDataLoader::SetEventFolder(TFolder* eventfolder) { - //sets the event folder - if (eventfolder == 0x0) - { - AliError("Stupid joke. Argument is NULL"); - return 1; - } - AliDebug(1, Form("name = %s Setting Event Folder named %s.", - GetName(),eventfolder->GetName())); - - fEventFolder = eventfolder; - return 0; + // + // Sets the event folder + // + if (eventfolder == 0x0) + { + AliError("Stupid joke. Argument is NULL"); + return 1; + } + AliDebug(1, Form("name = %s Setting Event Folder named %s.", + GetName(),eventfolder->GetName())); + + fEventFolder = eventfolder; + return 0; } -/*****************************************************************************/ + +//______________________________________________________________________________ Int_t AliDataLoader::SetFolder(TFolder* folder) { // Sets the folder and the data loaders - if (folder == 0x0) - { - AliError("Stupid joke. Argument is NULL"); + if (folder == 0x0) + { + AliError("Stupid joke. Argument is NULL"); return 1; - } - - AliDebug(1, Form("name = %s Setting folder named %s.",GetName(),folder->GetName())); - - fFolder = folder; - TIter next(fBaseLoaders); - AliBaseLoader* bl; - - while ((bl = (AliBaseLoader*)next())) - { - bl->SetDataLoader(this); - } - - return 0; + } + + AliDebug(1, Form("name = %s Setting folder named %s.",GetName(),folder->GetName())); + + fFolder = folder; + TIter next(fBaseLoaders); + AliBaseLoader* bl; + + while ((bl = (AliBaseLoader*)next())) + { + bl->SetDataLoader(this); + } + + return 0; } -/******************************************************************/ +//______________________________________________________________________________ TFolder* AliDataLoader::GetEventFolder() { -//get EVENT folder (data that are changing from event to event, even in single run) + // + // Get EVENT folder + // Data that are changing from event to event, even in single run + // AliDebug(1, "EF = %#x"); return fEventFolder; } -/*****************************************************************************/ +//______________________________________________________________________________ AliRunLoader* AliDataLoader::GetRunLoader() { -//gets the run-loader from event folder + // + // Gets the run-loader from event folder + // AliRunLoader* rg = 0x0; TFolder* ef = GetEventFolder(); if (ef == 0x0) @@ -399,80 +436,92 @@ AliRunLoader* AliDataLoader::GetRunLoader() return rg; } -/*****************************************************************************/ +//______________________________________________________________________________ void AliDataLoader::CloseFile() { - //closes file + // + // Closes file + // TIter next(fBaseLoaders); AliBaseLoader* bl; while ((bl = (AliBaseLoader*)next())) - { - if (bl->IsLoaded()) return; - } + { + if (bl->IsLoaded()) return; + } AliDebug(1, "Closing and deleting (object) file."); - + delete fFile; fFile = 0x0; fDirectory = 0x0; } -/*****************************************************************************/ + +//______________________________________________________________________________ void AliDataLoader::Clean() { - //Cleans main data + // + // Cleans main data + // GetBaseLoader(0)->Clean(); -} -/*****************************************************************************/ +} +//______________________________________________________________________________ void AliDataLoader::CleanAll() { - //Cleans all folders and tasks + // + // Cleans all folders and tasks + // TIter next(fBaseLoaders); AliBaseLoader* bl; while ((bl = (AliBaseLoader*)next())) - { + { bl->Clean(); - } + } } -/*****************************************************************************/ +//______________________________________________________________________________ void AliDataLoader::SetFileNameSuffix(const TString& suffix) { - //adds the suffix before ".root", - //e.g. TPC.Digits.root -> TPC.DigitsMerged.root - //made on Jiri Chudoba demand + // + // adds the suffix before ".root", + // e.g. TPC.Digits.root -> TPC.DigitsMerged.root + // made on Jiri Chudoba demand + // AliDebug(1, Form("suffix=%s",suffix.Data())); AliDebug(1, Form(" Digits File Name before: %s",fFileName.Data())); - + static TString dotroot(".root"); const TString& suffixdotroot = suffix + dotroot; fFileName = fFileName.ReplaceAll(dotroot,suffixdotroot); - + AliDebug(1, Form(" after : %s",fFileName.Data())); } -/*****************************************************************************/ +//______________________________________________________________________________ Bool_t AliDataLoader::CheckReload() { -//checks if we have to reload given file - if (fFile == 0x0) return kFALSE; - TString tmp = SetFileOffset(fFileName); - if (tmp.CompareTo(fFile->GetName())) return kTRUE; //file must be reloaded - return kFALSE; + // + // Checks if we have to reload given file + // + if (fFile == 0x0) return kFALSE; + TString tmp = SetFileOffset(fFileName); + if (tmp.CompareTo(fFile->GetName())) return kTRUE; //file must be reloaded + return kFALSE; } -/*****************************************************************************/ +//______________________________________________________________________________ const TString AliDataLoader::SetFileOffset(const TString& fname) { - -//return fname; + // + // Return fname + // Long_t offset = (Long_t)GetRunLoader()->GetFileOffset(); if (fNEventsPerFile > 0) { offset = GetRunLoader()->GetEventNumber()/fNEventsPerFile; } if (offset < 1) return fname; - + TString soffset; soffset += offset;//automatic conversion to string TString dotroot(".root"); @@ -481,30 +530,35 @@ const TString AliDataLoader::SetFileOffset(const TString& fname) out = out.ReplaceAll(dotroot,offfsetdotroot); AliDebug(1, Form("in=%s out=%s.",fname.Data(),out.Data())); return out; - } -/*****************************************************************************/ +//______________________________________________________________________________ void AliDataLoader::SetFileOption(Option_t* newopt) { - //sets file option + // + // Sets file option + // if (fFileOption.CompareTo(newopt) == 0) return; fFileOption = newopt; Reload(); } -/*****************************************************************************/ +//______________________________________________________________________________ void AliDataLoader::SetCompressionLevel(Int_t cl) { -//sets comression level for data defined by di + // + // Sets comression level for data defined by di + // fCompressionLevel = cl; if (fFile) fFile->SetCompressionLevel(cl); } -/*****************************************************************************/ +//______________________________________________________________________________ void AliDataLoader::MakeTree() { + // // Makes tree for the current data loader + // AliTreeLoader* tl = dynamic_cast(fBaseLoaders->At(0)); if (tl == 0x0) { @@ -513,27 +567,31 @@ void AliDataLoader::MakeTree() } tl->MakeTree(); } -/*****************************************************************************/ +//______________________________________________________________________________ Bool_t AliDataLoader::IsFileWritable() const { -//returns true if file is writable - return (fFile)?fFile->IsWritable():kFALSE; + // + // Returns true if file is writable + // + return (fFile)?fFile->IsWritable():kFALSE; } -/*****************************************************************************/ +//______________________________________________________________________________ Bool_t AliDataLoader::IsFileOpen() const { -//returns true if file is writable - return (fFile)?fFile->IsOpen():kFALSE; + // + // Returns true if file is writable + // + return (fFile)?fFile->IsOpen():kFALSE; } -/*****************************************************************************/ +//______________________________________________________________________________ Bool_t AliDataLoader::IsOptionContrary(const TString& option) const { -//Checks if passed option is contrary with file open option -//which is passed option "writable" and existing option not wriable -//in reverse case it is no harm so it is NOT contrary + // Checks if passed option is contrary with file open option + // which is passed option "writable" and existing option not wriable + // in reverse case it is no harm so it is NOT contrary if (fFile == 0x0) return kFALSE; //file is not opened - no problem if ( ( AliLoader::IsOptionWritable(option) == kTRUE ) && // passed option is writable and @@ -541,120 +599,139 @@ Bool_t AliDataLoader::IsOptionContrary(const TString& option) const { return kTRUE; } - + return kFALSE; } -/*****************************************************************************/ + + +//______________________________________________________________________________ void AliDataLoader::AddBaseLoader(AliBaseLoader* bl) { -//Adds a base loader to lits of base loaders managed by this data loader -//Managed data/task will be stored in proper root directory, -//and posted to -// - in case of tree/object - data folder connected with detector associated with this data loader -// - in case of task - parental task which defined in this AliTaskLoader - - if (bl == 0x0) - { - AliWarning("Pointer is null."); - return; - } - - TObject* obj = fBaseLoaders->FindObject(bl->GetName()); - if (obj) - { - AliError("Can not add this base loader."); - AliError(Form("There exists already base loader which manages data named %s for this detector.",obj->GetName())); - return; - } - + //Adds a base loader to lits of base loaders managed by this data loader + //Managed data/task will be stored in proper root directory, + //and posted to + // - in case of tree/object - data folder connected with detector associated with this data loader + // - in case of task - parental task which defined in this AliTaskLoader + + if (bl == 0x0) + { + AliWarning("Pointer is null."); + return; + } + + TObject* obj = fBaseLoaders->FindObject(bl->GetName()); + if (obj) + { + AliError("Can not add this base loader."); + AliError(Form("There exists already base loader which manages data named %s for this detector.",obj->GetName())); + return; + } - fBaseLoaders->Add(bl); + fBaseLoaders->Add(bl); } -/*****************************************************************************/ - +//______________________________________________________________________________ AliBaseLoader* AliDataLoader::GetBaseLoader(const TString& name) const { + // + // Return pointer to base loader + // return dynamic_cast(fBaseLoaders->FindObject(name)); } -/*****************************************************************************/ +//______________________________________________________________________________ AliBaseLoader* AliDataLoader::GetBaseLoader(Int_t n) const { + // // Gets the n-th base loader (what is n?) - return dynamic_cast(fBaseLoaders->At(n)); + // + return dynamic_cast(fBaseLoaders->At(n)); } -/*****************************************************************************/ +//______________________________________________________________________________ TTree* AliDataLoader::Tree() const { -//returns tree from the main base loader -//it is just shortcut method for comfort of user -//main storage object does not have to be Tree - -//that is why first we need to check if it is a TreeLoader - AliTreeLoader* tl = dynamic_cast(GetBaseLoader(0)); - if (tl == 0x0) return 0x0; - return tl->Tree(); + // Returns tree from the main base loader + // it is just shortcut method for comfort of user + // main storage object does not have to be Tree - + // that is why first we need to check if it is a TreeLoader + AliTreeLoader* tl = dynamic_cast(GetBaseLoader(0)); + if (tl == 0x0) return 0x0; + return tl->Tree(); } -/*****************************************************************************/ +//______________________________________________________________________________ void AliDataLoader::SetDirName(TString& dirname) { + // // Sets the directory name where the files will be stored + // AliDebug(10, Form("FileName before %s",fFileName.Data())); - Int_t n = fFileName.Last('/'); - AliDebug(10, Form("Slash found on pos %d",n)); - if (n > 0) fFileName = fFileName.Remove(0,n+1); - AliDebug(10, Form("Core FileName %s",fFileName.Data())); - fFileName = dirname + "/" + fFileName; - AliDebug(10, Form("FileName after %s",fFileName.Data())); } -/*****************************************************************************/ + +//______________________________________________________________________________ AliObjectLoader* AliDataLoader::GetBaseDataLoader() { + // // Gets the base data loader - return dynamic_cast(GetBaseLoader(kData)); + // + return dynamic_cast(GetBaseLoader(kData)); } -/*****************************************************************************/ + +//______________________________________________________________________________ AliTaskLoader* AliDataLoader::GetBaseTaskLoader() { + // // Gets the base task loader - return dynamic_cast(GetBaseLoader(kTask)); + // + return dynamic_cast(GetBaseLoader(kTask)); } -/*****************************************************************************/ + +//______________________________________________________________________________ AliBaseLoader* AliDataLoader::GetBaseQALoader() { + // // Gets the base QA loader + // return GetBaseLoader(kQA); } -/*****************************************************************************/ + +//______________________________________________________________________________ AliTaskLoader* AliDataLoader::GetBaseQATaskLoader() { -//returns pointer to QA base loader - return dynamic_cast(GetBaseLoader(kQATask)); + // + // Returns pointer to QA base loader + // + return dynamic_cast(GetBaseLoader(kQATask)); } -/*****************************************************************************/ + +//______________________________________________________________________________ void AliDataLoader::SetBaseDataLoader(AliBaseLoader* bl) { -//sets data base loader + // + // Sets data base loader + // if (bl == 0x0) - { - AliError("Parameter is null"); - return; - } + { + AliError("Parameter is null"); + return; + } if (GetBaseDataLoader()) delete GetBaseDataLoader(); fBaseLoaders->AddAt(bl,kData); } -/*****************************************************************************/ + +//______________________________________________________________________________ void AliDataLoader::SetBaseTaskLoader(AliTaskLoader* bl) { -//sets Task base loader + // + // Sets Task base loader + // if (bl == 0x0) { AliError("Parameter is null"); @@ -663,597 +740,45 @@ void AliDataLoader::SetBaseTaskLoader(AliTaskLoader* bl) if (GetBaseTaskLoader()) delete GetBaseTaskLoader(); fBaseLoaders->AddAt(bl,kTask); } -/*****************************************************************************/ + +//______________________________________________________________________________ void AliDataLoader::SetBaseQALoader(AliBaseLoader* bl) { -//sets QA base loader + // + // Sets QA base loader + // if (bl == 0x0) - { - AliError("Parameter is null"); - return; - } + { + AliError("Parameter is null"); + return; + } if (GetBaseQALoader()) delete GetBaseQALoader(); fBaseLoaders->AddAt(bl,kQA); } -/*****************************************************************************/ + +//______________________________________________________________________________ void AliDataLoader::SetBaseQATaskLoader(AliTaskLoader* bl) { -//sets QA Task base loader + // + // Sets QA Task base loader + // if (bl == 0x0) - { - AliError("Parameter is null"); - return; + { + AliError("Parameter is null"); + return; } if (GetBaseQATaskLoader()) delete GetBaseQATaskLoader(); fBaseLoaders->AddAt(bl,kQATask); } + +//______________________________________________________________________________ void AliDataLoader::Synchronize() { - //synchrinizes all writtable files + // + // Synchronizes all writable files + // if ( fFile ) fFile->Flush(); } -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ -//__________________________________________ -/////////////////////////////////////////////////////////////////////////////// -// // -// 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), - fIsLoaded(source.fIsLoaded), - fStoreInTopOfFile(source.fStoreInTopOfFile), - fDoNotReload(source.fDoNotReload), - fDataLoader(source.fDataLoader) -{ - // copy constructor - AliFatal("Copy constructor not implemented"); -} -/*****************************************************************************/ -AliBaseLoader& AliBaseLoader::operator=(const AliBaseLoader& /*source*/) { - // Assignment operator - AliFatal("Assignment operator not implemented"); - return *this; -} -/*****************************************************************************/ - -Int_t AliBaseLoader::Load(Option_t* opt) -{ - // Loads and posts the data - AliDebug(1, Form("data type = %s, option = %s",GetName(),opt)); - - if (Get()) - { - AliWarning(Form("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) - { - AliError(Form("Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName())); - AliError("File was already opened in READ-ONLY mode, while now WRITEABLE access is requested."); - AliError("Use AliDataLoader::SetOption to enforce change of access mode OR"); - AliError("Load previosly loaded data with coherent option."); - return 10; - } - } - else - { - retval = GetDataLoader()->OpenFile(opt); - if (retval) - { - AliError(Form("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(this); - if (tl) tl->MakeTree(); - fIsLoaded = kTRUE; - return 0; - } - - retval = Post(); - if (retval) - { - AliError(Form("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) - { - AliError(Form("%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 - AliDebug(1, Form("Can not find %s in file %s (file is opened in UPDATE mode).", - GetName(),GetDataLoader()->GetFile()->GetName())); - } - else - { - AliError(Form("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) - { - AliError("Pointer to object is NULL"); - return 1; - } - - if ( fName.CompareTo(data->GetName()) != 0) - { - AliFatal(Form("Object name is <<%s>> while <<%s>> expected",data->GetName(),GetName())); - return -1;//pro forma - } - - TObject* obj = Get(); - if (data == obj) - { - AliWarning("This object was already posted."); - return 0; - } - if (obj) - { - AliWarning(Form("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 - AliDebug(1, Form("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 - AliWarning(Form("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 - AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName())); - return 1; - } - } - - if (GetDataLoader()->IsFileWritable() == kFALSE) - { - AliError(Form("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 - AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data"); - return 3; - } - } - - AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s", - GetName(),opt,data->GetName())); - AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s", - GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(), - GetDirectory()->GetFile()->GetName())); - - AliDebug(1, "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 - AliDebug(1, Form("%s %s",GetName(),GetDataLoader()->GetName())); - TObject* obj = Get(); - if(obj) - { - AliDebug(1, Form("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) - { - AliFatal("Pointer to Data Loader is NULL"); - } - return fDataLoader; -} -/*****************************************************************************/ - -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) - { - AliFatal("Data Folder is NULL"); - } - return df; -} -/*****************************************************************************/ -AliObjectLoader::AliObjectLoader(const AliObjectLoader& source): - AliBaseLoader(source) { - // copy constructor - AliFatal("Copy constructor not implemented"); -} -/*****************************************************************************/ -AliObjectLoader& AliObjectLoader::operator=(const AliObjectLoader& /*source*/) { - // Assignment operator - AliFatal("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 - AliFatal("Copy constructor not implemented"); -} -/*****************************************************************************/ -AliTreeLoader& AliTreeLoader::operator=(const AliTreeLoader& /*source*/) { - // Assignment operator - AliFatal("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 - - AliDebug(1, Form("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 - AliWarning(Form("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 - AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName())); - return 1; - } - } - - if (GetDataLoader()->IsFileWritable() == kFALSE) - { - AliError(Form("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 - AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data"); - return 3; - } - } - - AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s", - GetName(),opt,data->GetName())); - AliDebug(1, Form("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(data); - if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above) - - AliDebug(1, "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()) - { - AliDebug(1, Form("name = %s, Data Name = %s Tree already exists.", - GetName(),GetDataLoader()->GetName())); - return;//tree already made - } - AliDebug(1, Form("Making Tree named %s.",GetName())); - - TString dtypename(GetDataLoader()->GetName()); - TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree - if (tree == 0x0) - { - AliError(Form("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), - fParentalTask(source.fParentalTask) -{ - // copy constructor - AliFatal("Copy constructor not implemented"); -} -/*****************************************************************************/ -AliTaskLoader& AliTaskLoader::operator=(const AliTaskLoader& /*source*/) { - // Assignment operator - AliFatal("Assignment operator not implemented"); - return *this; -} -/*****************************************************************************/ -void AliTaskLoader::Clean() -{ -//removes tasl from parental task -// DO NOT DELETE OBJECT contrary to BaseLoader -// - AliDebug(1, Form("Clean","%s %s",GetName(),GetDataLoader()->GetName())); - TObject* obj = Get(); - if(obj) - { - AliDebug(1, Form("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(obj); - if (task == 0x0) - { - AliError("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; -} - -/*****************************************************************************/ - -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ diff --git a/STEER/AliDataLoader.h b/STEER/AliDataLoader.h index a54c9655cc1..84b90e822df 100644 --- a/STEER/AliDataLoader.h +++ b/STEER/AliDataLoader.h @@ -24,8 +24,8 @@ #include #include #include -#include -#include +class TTask; +class TTree; class TFile; class TFolder; @@ -132,146 +132,6 @@ class AliDataLoader: public TNamed ClassDef(AliDataLoader,2) }; - -//__________________________________________ -//////////////////////////////////////////// -// // -// class AliBaseLoader // -// // -// // -//////////////////////////////////////////// - - -class AliBaseLoader: public TNamed -{ - public: - AliBaseLoader(); - AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop = kFALSE); - AliBaseLoader(const AliBaseLoader& source); - AliBaseLoader& operator=(const AliBaseLoader& source); - - virtual ~AliBaseLoader(){}; - - virtual Int_t Load(Option_t* opt=""); - virtual void Unload(); - virtual Int_t Reload(); - virtual Int_t WriteData(Option_t* opt=""); - virtual void Clean(); - virtual Int_t Post();//Takes from file and sends to proper TFolder (Data Folder) - virtual Int_t Post(TObject* data);//Sends to proper TFolder (Data Folder) - virtual TObject* Get() const = 0; - Bool_t IsLoaded()const{return fIsLoaded;} - void SetDataLoader(AliDataLoader* dl){fDataLoader = dl;} - void SetEventFolder(TFolder* /*ef*/){;} - void SetDoNotReload(Bool_t flag){fDoNotReload = flag;} - Bool_t DoNotReload() const {return fDoNotReload;} - TDirectory* GetDirectory() const;//returns pointer to directory where data are stored. - TObject* GetFromDirectory(const char *name) const - {return (GetDirectory())?GetDirectory()->Get(name):0x0;} - protected: - - virtual Int_t AddToBoard(TObject* obj) = 0;//add to white board - board can be TTask or TFolder - virtual void RemoveFromBoard(TObject* obj) = 0; - - AliDataLoader* GetDataLoader() const; - - Bool_t fIsLoaded; //! flag indicating if data are loaded - Bool_t fStoreInTopOfFile;// if true, data are stored in top of file ->Indicates fDoNotReload == kTRUE - - private: - Bool_t fDoNotReload; // if this flag is on object is not reloaded while GetEvent is called. - //Specially important for tasks. Task loops over events while producing data, - //and has a base loader which writes it to file every processed event. - //If this flag is not on, while taking next event, loader deletes task - // and tries to get new one from file - AliDataLoader* fDataLoader; //! pointer to Data Loader this Base Loader belongs to - - ClassDef(AliBaseLoader,1) -}; - -//__________________________________________ -//////////////////////////////////////////// -// // -// class AliObjectLoader // -// // -// // -//////////////////////////////////////////// - -class AliObjectLoader: public AliBaseLoader - { - public: - AliObjectLoader(){}; - AliObjectLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop = kFALSE); - AliObjectLoader(const AliObjectLoader& source); - AliObjectLoader& operator=(const AliObjectLoader& source); - virtual ~AliObjectLoader(){}; - TObject* Get() const; - - protected: - TFolder* GetFolder() const; - Int_t AddToBoard(TObject* obj); - void RemoveFromBoard(TObject* obj); - - ClassDef(AliObjectLoader,1) - - }; - -//__________________________________________ -//////////////////////////////////////////// -// // -// class AliTreeLoader // -// // -// // -//////////////////////////////////////////// - -class AliTreeLoader: public AliObjectLoader - { - public: - AliTreeLoader(){}; - AliTreeLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop = kFALSE); - AliTreeLoader(const AliTreeLoader& source); - AliTreeLoader& operator=(const AliTreeLoader& source); - virtual ~AliTreeLoader(){}; - - virtual TTree* Tree() const {return dynamic_cast(Get());} - virtual void MakeTree(); - virtual Int_t WriteData(Option_t* opt=""); - - ClassDef(AliTreeLoader,1) - }; - -//__________________________________________ -//////////////////////////////////////////// -// // -// class AliTaskLoader // -// // -// // -//////////////////////////////////////////// - -class AliTaskLoader: public AliBaseLoader - { - public: - AliTaskLoader():fParentalTask(0x0){}; - AliTaskLoader(const TString& name, AliDataLoader* dl, TTask* parentaltask, Bool_t storeontop = kFALSE); - AliTaskLoader(const AliTaskLoader& source); - AliTaskLoader& operator=(const AliTaskLoader& source); - virtual ~AliTaskLoader(){}; - - TObject* Get() const; - virtual TTask* Task() const {return dynamic_cast(Get());} - virtual void Clean(); - - protected: - Int_t AddToBoard(TObject* obj); - void RemoveFromBoard(TObject* obj); - TTask* GetParentalTask() const; - - private: - TTask* fParentalTask; // Parental task - - ClassDef(AliTaskLoader,1) - }; - #endif diff --git a/STEER/AliLoader.cxx b/STEER/AliLoader.cxx index 47925c54100..daf6734c621 100644 --- a/STEER/AliLoader.cxx +++ b/STEER/AliLoader.cxx @@ -11,21 +11,18 @@ //Root includes #include -#include #include -#include -#include +#include #include -#include +#include //AliRoot includes -#include -#include -#include -#include -#include -#include #include "AliConfig.h" +#include "AliDetector.h" +#include "AliDigitizer.h" +#include "AliLog.h" +#include "AliRun.h" +#include "AliRunLoader.h" const TString AliLoader::fgkDefaultHitsContainerName("TreeH"); const TString AliLoader::fgkDefaultDigitsContainerName = "TreeD"; diff --git a/STEER/AliLoader.h b/STEER/AliLoader.h index 32f2dc3e62a..c200b8056cc 100644 --- a/STEER/AliLoader.h +++ b/STEER/AliLoader.h @@ -1,19 +1,20 @@ #ifndef ALILOADER_H #define ALILOADER_H +class TDirectory; +class TFile; +class TString; +class TTask; +class TTree; + #include #include -//#include -#include "AliDataLoader.h" - -class TString; -class TFile; -class TTree; -class TTask; -class AliRunLoader; class AliDigitizer; -class TDirectory; +class AliRunLoader; + +#include "AliDataLoader.h" +#include "AliTaskLoader.h" //___________________________________________________________________ diff --git a/STEER/AliObjectLoader.cxx b/STEER/AliObjectLoader.cxx new file mode 100644 index 00000000000..33e3a07b9e2 --- /dev/null +++ b/STEER/AliObjectLoader.cxx @@ -0,0 +1,106 @@ +///////////////////////////////////////////////////////////////////////////////////////////// +// // +// class AliObjectLoader // +// // +// Container of all data needed for full // +// description of each data type // +// (Hits, Kine, ...) // +// // +// Each data loader has a basic standard setup of BaseLoaders // +// which can be identuified by indexes (defined by EStdBasicLoaders) // +// Data managed by these standard base loaders has fixed naming convention // +// e.g. - tree with hits is always named TreeH // +// (defined in AliLoader::fgkDefaultHitsContainerName) // +// - task DtectorName+Name defined // +// // +// EStdBasicLoaders idx Object Type Description // +// kData 0 TTree or TObject main data itself (hits,digits,...) // +// kTask 1 TTask object producing main data // +// kQA 2 TTree quality assurance tree // +// kQATask 3 TTask task producing QA object // +// // +// // +// User can define and add more basic loaders even Run Time. // +// Caution: in order to save information about added base loader // +// user must rewrite Run Loader to galice.file, overwriting old setup // +// // +///////////////////////////////////////////////////////////////////////////////////////////// + +#include "AliLog.h" +#include "AliObjectLoader.h" +#include "AliRunLoader.h" + +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) + { + AliFatal("Data Folder is NULL"); + } + return df; +} + +//______________________________________________________________________________ +AliObjectLoader::AliObjectLoader(const AliObjectLoader& source): + AliBaseLoader(source) { + // + // copy constructor + // + AliFatal("Copy constructor not implemented"); +} + +//______________________________________________________________________________ +AliObjectLoader& AliObjectLoader::operator=(const AliObjectLoader& /*source*/) +{ + // + // Assignment operator + // + AliFatal("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; +} + + + diff --git a/STEER/AliObjectLoader.h b/STEER/AliObjectLoader.h new file mode 100644 index 00000000000..a11cf2dd59d --- /dev/null +++ b/STEER/AliObjectLoader.h @@ -0,0 +1,37 @@ +#ifndef ALIOBJECTLOADER_H +#define ALIOBJECTLOADER_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +//////////////////////////////////////////// +// // +// class AliObjectLoader // +// // +// // +//////////////////////////////////////////// + +#include "AliBaseLoader.h" + +class AliObjectLoader: public AliBaseLoader + { + public: + AliObjectLoader(){}; + AliObjectLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop = kFALSE); + AliObjectLoader(const AliObjectLoader& source); + AliObjectLoader& operator=(const AliObjectLoader& source); + virtual ~AliObjectLoader(){}; + TObject* Get() const; + + protected: + TFolder* GetFolder() const; + Int_t AddToBoard(TObject* obj); + void RemoveFromBoard(TObject* obj); + + ClassDef(AliObjectLoader,1) + +}; +#endif + + diff --git a/STEER/AliPID.cxx b/STEER/AliPID.cxx index 1f34a86334c..50bd0de35db 100644 --- a/STEER/AliPID.cxx +++ b/STEER/AliPID.cxx @@ -38,18 +38,17 @@ // // /////////////////////////////////////////////////////////////////////////////// +#include +#include +#include -#include "AliPID.h" #include "AliLog.h" -#include -#include -#include +#include "AliPID.h" #define M(PID) TDatabasePDG::Instance()->GetParticle(fgkParticleCode[(PID)])->Mass() ClassImp(AliPID) - const char* AliPID::fgkParticleName[AliPID::kSPECIESN+1] = { "electron", "muon", @@ -78,7 +77,9 @@ const Int_t AliPID::fgkParticleCode[AliPID::kSPECIESN+1] = { 0 }; -const Float_t AliPID::fgkParticleMass[AliPID::kSPECIESN+1] = { +/*const*/ Float_t AliPID::fgkParticleMass[AliPID::kSPECIESN+1] = { + 0,0,0,0,0,0,0,0,0,0,0 + /* M(kElectron), // electron M(kMuon), // muon M(kPion), // pion @@ -90,6 +91,7 @@ const Float_t AliPID::fgkParticleMass[AliPID::kSPECIESN+1] = { M(kKaon0), // kaon0 M(kEleCon), // electron conversion 0.00000 // unknown + */ }; Double_t AliPID::fgPrior[kSPECIESN] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -100,11 +102,13 @@ AliPID::AliPID() : TObject(), fCharged(0) { -// set default values (= equal probabilities) - - for (Int_t i = 0; i < kSPECIESN; i++) { + // + // Default constructor + // + Init(); + // set default values (= equal probabilities) + for (Int_t i = 0; i < kSPECIESN; i++) fProbDensity[i] = 1./kSPECIESN; - } } //_______________________________________________________________________ @@ -113,14 +117,15 @@ AliPID::AliPID(const Double_t* probDensity, Bool_t charged) : fCharged(charged) { // - // set given probability densities + // Standard constructor // - for (Int_t i = 0; i < kSPECIES; i++) { + Init(); + // set given probability densities + for (Int_t i = 0; i < kSPECIES; i++) fProbDensity[i] = probDensity[i]; - } - for (Int_t i = kSPECIES; i < kSPECIESN; i++) { + + for (Int_t i = kSPECIES; i < kSPECIESN; i++) fProbDensity[i] = ((charged) ? 0 : probDensity[i]); - } } //_______________________________________________________________________ @@ -129,14 +134,15 @@ AliPID::AliPID(const Float_t* probDensity, Bool_t charged) : fCharged(charged) { // - // set given probability densities + // Standard constructor // - for (Int_t i = 0; i < kSPECIES; i++) { + Init(); + // set given probability densities + for (Int_t i = 0; i < kSPECIES; i++) fProbDensity[i] = probDensity[i]; - } - for (Int_t i = kSPECIES; i < kSPECIESN; i++) { + + for (Int_t i = kSPECIES; i < kSPECIESN; i++) fProbDensity[i] = ((charged) ? 0 : probDensity[i]); - } } //_______________________________________________________________________ @@ -147,9 +153,9 @@ AliPID::AliPID(const AliPID& pid) : // // copy constructor // - for (Int_t i = 0; i < kSPECIESN; i++) { + // We do not call init here, MUST already be done + for (Int_t i = 0; i < kSPECIESN; i++) fProbDensity[i] = pid.fProbDensity[i]; - } } //_______________________________________________________________________ @@ -164,14 +170,26 @@ AliPID& AliPID::operator = (const AliPID& pid) return *this; } +//_______________________________________________________________________ +void AliPID::Init() +{ + // + // Initialise the masses + // + // Initialise only once... + if(!fgkParticleMass[0]) + for (Int_t i = 0; i < kSPECIESN; i++) + fgkParticleMass[i] = M(fgkParticleCode[i]); +} //_____________________________________________________________________________ Double_t AliPID::GetProbability(EParticleType iType, const Double_t* prior) const { -// get the probability to be a particle of type "iType" -// assuming the a priori probabilities "prior" - + // + // Get the probability to be a particle of type "iType" + // assuming the a priori probabilities "prior" + // Double_t sum = 0.; Int_t nSpecies = ((fCharged) ? kSPECIES : kSPECIESN); for (Int_t i = 0; i < nSpecies; i++) { diff --git a/STEER/AliPID.h b/STEER/AliPID.h index 7c2f5169703..9c9494e4dfe 100644 --- a/STEER/AliPID.h +++ b/STEER/AliPID.h @@ -64,11 +64,14 @@ class AliPID : public TObject { AliPID& operator *= (const AliPID& pid); private: + + void Init(); + Bool_t fCharged; // flag for charged/neutral Double_t fProbDensity[kSPECIESN]; // probability densities static Double_t fgPrior[kSPECIESN]; // a priori probabilities - static const Float_t fgkParticleMass[kSPECIESN+1]; // particle masses + static /*const*/ Float_t fgkParticleMass[kSPECIESN+1]; // particle masses static const char* fgkParticleName[kSPECIESN+1]; // particle names static const Int_t fgkParticleCode[kSPECIESN+1]; // particle codes diff --git a/STEER/AliRunLoader.cxx b/STEER/AliRunLoader.cxx index 8c5b82311d0..d5199aa02c5 100644 --- a/STEER/AliRunLoader.cxx +++ b/STEER/AliRunLoader.cxx @@ -64,7 +64,6 @@ class TTask; #include "AliDetector.h" #include "AliRunDataStorage.h" #include "AliRunDataFile.h" -#include "AliRunLoader.h" ClassImp(AliRunLoader) diff --git a/STEER/AliTaskLoader.cxx b/STEER/AliTaskLoader.cxx new file mode 100644 index 00000000000..bda5cf997c5 --- /dev/null +++ b/STEER/AliTaskLoader.cxx @@ -0,0 +1,131 @@ + +///////////////////////////////////////////////////////////////////////////////////////////// +// // +// class AliTaskLoader // +// // +// Container of all data needed for full // +// description of each data type // +// (Hits, Kine, ...) // +// // +// Each data loader has a basic standard setup of BaseLoaders // +// which can be identuified by indexes (defined by EStdBasicLoaders) // +// Data managed by these standard base loaders has fixed naming convention // +// e.g. - tree with hits is always named TreeH // +// (defined in AliLoader::fgkDefaultHitsContainerName) // +// - task DtectorName+Name defined // +// // +// EStdBasicLoaders idx Object Type Description // +// kData 0 TTree or TObject main data itself (hits,digits,...) // +// kTask 1 TTask object producing main data // +// kQA 2 TTree quality assurance tree // +// kQATask 3 TTask task producing QA object // +// // +// // +// User can define and add more basic loaders even Run Time. // +// Caution: in order to save information about added base loader // +// user must rewrite Run Loader to galice.file, overwriting old setup // +// // +///////////////////////////////////////////////////////////////////////////////////////////// + +/* $Id$ */ + +#include "AliLog.h" +#include "AliRunLoader.h" +#include "AliTaskLoader.h" + +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), + fParentalTask(source.fParentalTask) +{ + // + // copy constructor + // + AliFatal("Copy constructor not implemented"); +} + +//______________________________________________________________________________ +AliTaskLoader& AliTaskLoader::operator=(const AliTaskLoader& /*source*/) +{ + // + // Assignment operator + // + AliFatal("Assignment operator not implemented"); + return *this; +} + +//______________________________________________________________________________ +void AliTaskLoader::Clean() +{ + // + // Removes tasl from parental task + // DO NOT DELETE OBJECT contrary to BaseLoader + // + AliDebug(1, Form("Clean","%s %s",GetName(),GetDataLoader()->GetName())); + TObject* obj = Get(); + if(obj) + { + AliDebug(1, Form("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(obj); + if (task == 0x0) + { + AliError("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; +} + + + diff --git a/STEER/AliTaskLoader.h b/STEER/AliTaskLoader.h new file mode 100644 index 00000000000..691d0dedc73 --- /dev/null +++ b/STEER/AliTaskLoader.h @@ -0,0 +1,43 @@ +#ifndef ALITASKLOADER_H +#define ALITASKLOADER_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +//////////////////////////////////////////// +// // +// class AliTaskLoader // +// // +// // +//////////////////////////////////////////// + +/* $Id$ */ + +#include "AliBaseLoader.h" + +class AliTaskLoader: public AliBaseLoader + { + public: + AliTaskLoader():fParentalTask(0x0){}; + AliTaskLoader(const TString& name, AliDataLoader* dl, TTask* parentaltask, Bool_t storeontop = kFALSE); + AliTaskLoader(const AliTaskLoader& source); + AliTaskLoader& operator=(const AliTaskLoader& source); + virtual ~AliTaskLoader(){}; + + TObject* Get() const; + virtual TTask* Task() const {return dynamic_cast(Get());} + virtual void Clean(); + + protected: + Int_t AddToBoard(TObject* obj); + void RemoveFromBoard(TObject* obj); + TTask* GetParentalTask() const; + + private: + TTask* fParentalTask; // Parental task + + ClassDef(AliTaskLoader,1) + }; + +#endif + + diff --git a/STEER/AliTreeLoader.cxx b/STEER/AliTreeLoader.cxx new file mode 100644 index 00000000000..6f39cca379e --- /dev/null +++ b/STEER/AliTreeLoader.cxx @@ -0,0 +1,162 @@ +///////////////////////////////////////////////////////////////////////////////////////////// +// // +// class AliTreeLoader // +// // +// Container of all data needed for full // +// description of each data type // +// (Hits, Kine, ...) // +// // +// Each data loader has a basic standard setup of BaseLoaders // +// which can be identuified by indexes (defined by EStdBasicLoaders) // +// Data managed by these standard base loaders has fixed naming convention // +// e.g. - tree with hits is always named TreeH // +// (defined in AliLoader::fgkDefaultHitsContainerName) // +// - task DtectorName+Name defined // +// // +// EStdBasicLoaders idx Object Type Description // +// kData 0 TTree or TObject main data itself (hits,digits,...) // +// kTask 1 TTask object producing main data // +// kQA 2 TTree quality assurance tree // +// kQATask 3 TTask task producing QA object // +// // +// // +// User can define and add more basic loaders even Run Time. // +// Caution: in order to save information about added base loader // +// user must rewrite Run Loader to galice.file, overwriting old setup // +// // +///////////////////////////////////////////////////////////////////////////////////////////// + +/* $Id$ */ + +#include "AliTreeLoader.h" +#include "AliLog.h" +#include "AliRunLoader.h" + + +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 + // + AliFatal("Copy constructor not implemented"); +} + +//______________________________________________________________________________ +AliTreeLoader& AliTreeLoader::operator=(const AliTreeLoader& /*source*/) +{ + // + // Assignment operator + // + AliFatal("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 + // + AliDebug(1, Form("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 + AliWarning(Form("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 + AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName())); + return 1; + } + } + + if (GetDataLoader()->IsFileWritable() == kFALSE) + { + AliError(Form("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 + AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data"); + return 3; + } + } + + AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s", + GetName(),opt,data->GetName())); + AliDebug(1, Form("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(data); + if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above) + + AliDebug(1, "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()) + { + AliDebug(1, Form("name = %s, Data Name = %s Tree already exists.", + GetName(),GetDataLoader()->GetName())); + return;//tree already made + } + AliDebug(1, Form("Making Tree named %s.",GetName())); + + TString dtypename(GetDataLoader()->GetName()); + TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree + if (tree == 0x0) + { + AliError(Form("Can not create %s tree.",GetName())); + return; + } + tree->SetAutoSave(1000000000); //no autosave + GetFolder()->Add(tree); + WriteData("OVERWRITE");//write tree to the file +} + + diff --git a/STEER/AliTreeLoader.h b/STEER/AliTreeLoader.h new file mode 100644 index 00000000000..72475ae6217 --- /dev/null +++ b/STEER/AliTreeLoader.h @@ -0,0 +1,46 @@ +#ifndef ALITREELOADER_H +#define ALITREELOADER_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +//////////////////////////////////////////// +// // +// class AliTreeLoader // +// // +// Loader responsible for one data type // +// i.e. Hits, Kine, etc. // +// many objects type can be assciated // +// with one data type: storing object // +// (usually tree), task producing it, // +// Quality Assurance(QA), QA Task, and // +// others. // +// // +// // +//////////////////////////////////////////// + +class TString; +class TTree; + +#include "AliObjectLoader.h" + +class AliTreeLoader: public AliObjectLoader + { + public: + AliTreeLoader(){}; + AliTreeLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop = kFALSE); + AliTreeLoader(const AliTreeLoader& source); + AliTreeLoader& operator=(const AliTreeLoader& source); + virtual ~AliTreeLoader(){}; + + virtual TTree* Tree() const {return dynamic_cast(Get());} + virtual void MakeTree(); + virtual Int_t WriteData(Option_t* opt=""); + + ClassDef(AliTreeLoader,1) + }; + +#endif + + diff --git a/STEER/libSTEER.pkg b/STEER/libSTEER.pkg index 3e1f36f6082..a441563689f 100644 --- a/STEER/libSTEER.pkg +++ b/STEER/libSTEER.pkg @@ -1,4 +1,5 @@ SRCS = AliRunLoader.cxx AliLoader.cxx AliDataLoader.cxx \ +AliObjectLoader.cxx AliBaseLoader.cxx AliTreeLoader.cxx AliTaskLoader.cxx \ AliDetector.cxx AliHeader.cxx AliMagF.cxx \ AliDigit.cxx AliHit.cxx AliPoints.cxx \ AliDisplay.cxx AliRun.cxx AliGenerator.cxx AliVertexGenerator.cxx \ -- 2.43.0