1 #include <AliDataLoader.h>
2 //__________________________________________
3 /////////////////////////////////////////////////////////////////////////////////////////////
5 // class AliDataLoader //
7 // Container of all data needed for full //
8 // description of each data type //
9 // (Hits, Kine, ...) //
11 // Each data loader has a basic standard setup of BaseLoaders //
12 // which can be identuified by indexes (defined by EStdBasicLoaders) //
13 // Data managed by these standard base loaders has fixed naming convention //
14 // e.g. - tree with hits is always named TreeH //
15 // (defined in AliLoader::fgkDefaultHitsContainerName) //
16 // - task DtectorName+Name defined //
18 // EStdBasicLoaders idx Object Type Description //
19 // kData 0 TTree or TObject main data itself (hits,digits,...) //
20 // kTask 1 TTask object producing main data //
21 // kQA 2 TTree quality assurance tree //
22 // kQATask 3 TTask task producing QA object //
25 // User can define and add more basic loaders even Run Time. //
26 // Caution: in order to save information about added base loader //
27 // user must rewrite Run Loader to galice.file, overwriting old setup //
29 /////////////////////////////////////////////////////////////////////////////////////////////
37 #include "AliRunLoader.h"
39 ClassImp(AliDataLoader)
41 AliDataLoader::AliDataLoader():
57 /*****************************************************************************/
59 AliDataLoader::AliDataLoader(const char* filename, const char* contname, const char* name, Option_t* opt):
67 fBaseLoaders(new TObjArray(4)),
75 // creates a 0 loader, depending on option, default "T" is specialized loader for trees
76 // else standard object loader
77 // trees needs special care, becouse we need to set dir before writing
78 AliDebug(1, Form("File name is %s",fFileName.Data()));
82 if (option.CompareTo("T",TString::kIgnoreCase) == 0)
83 bl = new AliTreeLoader(contname,this);
85 bl = new AliObjectLoader(contname,this);
86 fBaseLoaders->AddAt(bl,kData);
89 /*****************************************************************************/
90 AliDataLoader::AliDataLoader(const AliDataLoader& source):TNamed(source) {
92 AliFatal("Copy constructor not implemented");
94 /*****************************************************************************/
95 AliDataLoader& AliDataLoader::operator=(const AliDataLoader& /*source*/) {
96 // Assignment operator
97 AliFatal("Assignment operator not implemented");
100 /*****************************************************************************/
102 AliDataLoader::~AliDataLoader()
107 /*****************************************************************************/
109 Int_t AliDataLoader::SetEvent()
111 //basically the same that GetEvent but do not post data to folders
112 AliRunLoader* rl = GetRunLoader();
115 AliError("Can not get RunGettr");
119 Int_t evno = rl->GetEventNumber();
121 TIter next(fBaseLoaders);
123 while ((bl = (AliBaseLoader*)next()))
125 if (bl->DoNotReload() == kFALSE) bl->Clean();
134 AliDebug(1, Form("Reloading new file. File opt is %s",fFileOption.Data()));
135 OpenFile(fFileOption);
138 fDirectory = AliLoader::ChangeDir(fFile,evno);
139 if (fDirectory == 0x0)
141 AliError(Form("Can not chage directory in file %s",fFile->GetName()));
147 /*****************************************************************************/
149 Int_t AliDataLoader::GetEvent()
151 // posts all loaded data from files to White Board
152 // event number is defined in RunLoader
155 // 0 - in case of no error
156 // 1 - event not found
158 //for each base laoder post, if was loaded before GetEvent
160 //call set event to switch to new directory in file
163 //post all data that were loaded before
164 // ->SetEvent does not call Unload, but only cleans White Board
165 // such IsLoaded flag stays untached
167 if ( AliLoader::TestFileOption(fFileOption) == kTRUE ) //if file is read or update mode try to post
168 { //in other case there is no sense to post: file is new
169 TIter nextbl(fBaseLoaders);
171 while ((bl = (AliBaseLoader*)nextbl()))
175 if (bl->DoNotReload() == kFALSE) bl->Post();
181 /*****************************************************************************/
183 Int_t AliDataLoader::OpenFile(Option_t* opt)
185 //Opens file named 'filename', and assigns pointer to it to 'file'
186 //jumps to fDirectoryectory corresponding to current event and stores the pointer to it in 'fDirectory'
187 //option 'opt' is passed to TFile::Open
190 if(fFile->IsOpen() == kTRUE)
192 AliWarning(Form(" File %s already opened. First close it.",fFile->GetName()));
197 AliWarning(Form("Pointer to file %s is not null, but file is not opened",
204 TString fname(SetFileOffset(fFileName));
206 fFile = (TFile *)(gROOT->GetListOfFiles()->FindObject(fname));
209 if(fFile->IsOpen() == kTRUE)
211 AliWarning(Form("File %s already opened by sombody else. First close it.",
218 fFile = TFile::Open(fname,fFileOption);//open the file
221 AliError(Form("Can not open file %s",fname.Data()));
224 if (fFile->IsOpen() == kFALSE)
226 AliError(Form("Can not open file %s",fname.Data()));
230 fFile->SetCompressionLevel(fCompressionLevel);
232 AliRunLoader* rg = GetRunLoader();
235 AliError("Can not find Run-Loader in folder.");
238 Int_t evno = rg->GetEventNumber();
240 fDirectory = AliLoader::ChangeDir(fFile,evno);
241 if (fDirectory == 0x0)
243 AliError(Form("Can not chage fDirectory in file %s.",fFile->GetName()));
248 /*****************************************************************************/
250 void AliDataLoader::Unload()
252 //unloads main data - shortcut method
253 GetBaseLoader(0)->Unload();
255 /*****************************************************************************/
257 void AliDataLoader::UnloadAll()
259 //Unloads all data and tasks
260 if ( fFile == 0x0 ) return; //nothing loaded
262 TIter next(fBaseLoaders);
264 while ((bl = (AliBaseLoader*)next()))
269 /*****************************************************************************/
271 Int_t AliDataLoader::Reload()
273 //Unloads and loads data again
274 if ( fFile == 0x0 ) return 0;
276 TBits loaded(fBaseLoaders->GetEntries());
277 TIter next(fBaseLoaders);
281 while ((bl = (AliBaseLoader*)next()))
285 loaded.SetBitNumber(i++,kTRUE);
293 while ((bl = (AliBaseLoader*)next()))
295 if (loaded.TestBitNumber(i++))
297 retval = bl->Load(fFileOption);
300 AliError(Form("Error occur while loading %s",bl->GetName()));
309 /*****************************************************************************/
310 Int_t AliDataLoader::WriteData(Option_t* opt)
312 //Writes primary data == first BaseLoader
313 AliDebug(1, Form("Writing %s container for %s data. Option is %s.",
314 GetBaseLoader(0)->GetName(),GetName(),opt));
315 return GetBaseLoader(0)->WriteData(opt);
317 /*****************************************************************************/
319 Int_t AliDataLoader::Load(Option_t* opt)
321 //Writes primary data == first BaseLoader
322 return GetBaseLoader(0)->Load(opt);
324 /*****************************************************************************/
326 Int_t AliDataLoader::SetEventFolder(TFolder* eventfolder)
328 //sets the event folder
329 if (eventfolder == 0x0)
331 AliError("Stupid joke. Argument is NULL");
334 AliDebug(1, Form("name = %s Setting Event Folder named %s.",
335 GetName(),eventfolder->GetName()));
337 fEventFolder = eventfolder;
340 /*****************************************************************************/
342 Int_t AliDataLoader::SetFolder(TFolder* folder)
344 // Sets the folder and the data loaders
347 AliError("Stupid joke. Argument is NULL");
351 AliDebug(1, Form("name = %s Setting folder named %s.",GetName(),folder->GetName()));
354 TIter next(fBaseLoaders);
357 while ((bl = (AliBaseLoader*)next()))
359 bl->SetDataLoader(this);
364 /******************************************************************/
366 TFolder* AliDataLoader::GetEventFolder()
368 //get EVENT folder (data that are changing from event to event, even in single run)
369 AliDebug(1, "EF = %#x");
372 /*****************************************************************************/
374 AliRunLoader* AliDataLoader::GetRunLoader()
376 //gets the run-loader from event folder
377 AliRunLoader* rg = 0x0;
378 TFolder* ef = GetEventFolder();
381 AliError("Can not get event folder.");
384 rg = dynamic_cast<AliRunLoader*>(ef->FindObject(AliRunLoader::GetRunLoaderName()));
388 /*****************************************************************************/
389 void AliDataLoader::CloseFile()
392 TIter next(fBaseLoaders);
394 while ((bl = (AliBaseLoader*)next()))
396 if (bl->IsLoaded()) return;
399 AliDebug(1, "Closing and deleting (object) file.");
405 /*****************************************************************************/
407 void AliDataLoader::Clean()
410 GetBaseLoader(0)->Clean();
412 /*****************************************************************************/
414 void AliDataLoader::CleanAll()
416 //Cleans all folders and tasks
417 TIter next(fBaseLoaders);
419 while ((bl = (AliBaseLoader*)next()))
424 /*****************************************************************************/
426 void AliDataLoader::SetFileNameSuffix(const TString& suffix)
428 //adds the suffix before ".root",
429 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
430 //made on Jiri Chudoba demand
431 AliDebug(1, Form("suffix=%s",suffix.Data()));
432 AliDebug(1, Form(" Digits File Name before: %s",fFileName.Data()));
434 static TString dotroot(".root");
435 const TString& suffixdotroot = suffix + dotroot;
436 fFileName = fFileName.ReplaceAll(dotroot,suffixdotroot);
438 AliDebug(1, Form(" after : %s",fFileName.Data()));
440 /*****************************************************************************/
442 Bool_t AliDataLoader::CheckReload()
444 //checks if we have to reload given file
445 if (fFile == 0x0) return kFALSE;
446 TString tmp = SetFileOffset(fFileName);
447 if (tmp.CompareTo(fFile->GetName())) return kTRUE; //file must be reloaded
450 /*****************************************************************************/
452 const TString AliDataLoader::SetFileOffset(const TString& fname)
456 Long_t offset = (Long_t)GetRunLoader()->GetFileOffset();
457 if (fNEventsPerFile > 0) {
458 offset = GetRunLoader()->GetEventNumber()/fNEventsPerFile;
460 if (offset < 1) return fname;
463 soffset += offset;//automatic conversion to string
464 TString dotroot(".root");
465 const TString& offfsetdotroot = offset + dotroot;
467 out = out.ReplaceAll(dotroot,offfsetdotroot);
468 AliDebug(1, Form("in=%s out=%s.",fname.Data(),out.Data()));
472 /*****************************************************************************/
474 void AliDataLoader::SetFileOption(Option_t* newopt)
477 if (fFileOption.CompareTo(newopt) == 0) return;
478 fFileOption = newopt;
481 /*****************************************************************************/
483 void AliDataLoader::SetCompressionLevel(Int_t cl)
485 //sets comression level for data defined by di
486 fCompressionLevel = cl;
487 if (fFile) fFile->SetCompressionLevel(cl);
489 /*****************************************************************************/
491 void AliDataLoader::MakeTree()
493 // Makes tree for the current data loader
494 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(fBaseLoaders->At(0));
497 AliError("Can not make a tree because main base loader is not a tree loader");
502 /*****************************************************************************/
504 Bool_t AliDataLoader::IsFileWritable() const
506 //returns true if file is writable
507 return (fFile)?fFile->IsWritable():kFALSE;
509 /*****************************************************************************/
511 Bool_t AliDataLoader::IsFileOpen() const
513 //returns true if file is writable
514 return (fFile)?fFile->IsOpen():kFALSE;
516 /*****************************************************************************/
518 Bool_t AliDataLoader::IsOptionContrary(const TString& option) const
520 //Checks if passed option is contrary with file open option
521 //which is passed option "writable" and existing option not wriable
522 //in reverse case it is no harm so it is NOT contrary
523 if (fFile == 0x0) return kFALSE; //file is not opened - no problem
525 if ( ( AliLoader::IsOptionWritable(option) == kTRUE ) && // passed option is writable and
526 ( AliLoader::IsOptionWritable(fFileOption) == kFALSE ) ) // existing one is not writable
533 /*****************************************************************************/
534 void AliDataLoader::AddBaseLoader(AliBaseLoader* bl)
536 //Adds a base loader to lits of base loaders managed by this data loader
537 //Managed data/task will be stored in proper root directory,
539 // - in case of tree/object - data folder connected with detector associated with this data loader
540 // - in case of task - parental task which defined in this AliTaskLoader
544 AliWarning("Pointer is null.");
548 TObject* obj = fBaseLoaders->FindObject(bl->GetName());
551 AliError("Can not add this base loader.");
552 AliError(Form("There exists already base loader which manages data named %s for this detector.",obj->GetName()));
557 fBaseLoaders->Add(bl);
560 /*****************************************************************************/
562 AliBaseLoader* AliDataLoader::GetBaseLoader(const TString& name) const
564 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->FindObject(name));
566 /*****************************************************************************/
568 AliBaseLoader* AliDataLoader::GetBaseLoader(Int_t n) const
570 // Gets the n-th base loader (what is n?)
571 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->At(n));
573 /*****************************************************************************/
575 TTree* AliDataLoader::Tree() const
577 //returns tree from the main base loader
578 //it is just shortcut method for comfort of user
579 //main storage object does not have to be Tree -
580 //that is why first we need to check if it is a TreeLoader
581 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(GetBaseLoader(0));
582 if (tl == 0x0) return 0x0;
585 /*****************************************************************************/
587 void AliDataLoader::SetDirName(TString& dirname)
589 // Sets the directory name where the files will be stored
590 AliDebug(10, Form("FileName before %s",fFileName.Data()));
592 Int_t n = fFileName.Last('/');
594 AliDebug(10, Form("Slash found on pos %d",n));
596 if (n > 0) fFileName = fFileName.Remove(0,n+1);
598 AliDebug(10, Form("Core FileName %s",fFileName.Data()));
600 fFileName = dirname + "/" + fFileName;
602 AliDebug(10, Form("FileName after %s",fFileName.Data()));
604 /*****************************************************************************/
605 AliObjectLoader* AliDataLoader::GetBaseDataLoader()
607 // Gets the base data loader
608 return dynamic_cast<AliObjectLoader*>(GetBaseLoader(kData));
610 /*****************************************************************************/
611 AliTaskLoader* AliDataLoader::GetBaseTaskLoader()
613 // Gets the base task loader
614 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kTask));
616 /*****************************************************************************/
617 AliBaseLoader* AliDataLoader::GetBaseQALoader()
619 // Gets the base QA loader
620 return GetBaseLoader(kQA);
622 /*****************************************************************************/
623 AliTaskLoader* AliDataLoader::GetBaseQATaskLoader()
625 //returns pointer to QA base loader
626 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kQATask));
628 /*****************************************************************************/
629 void AliDataLoader::SetBaseDataLoader(AliBaseLoader* bl)
631 //sets data base loader
634 AliError("Parameter is null");
637 if (GetBaseDataLoader()) delete GetBaseDataLoader();
638 fBaseLoaders->AddAt(bl,kData);
640 /*****************************************************************************/
641 void AliDataLoader::SetBaseTaskLoader(AliTaskLoader* bl)
643 //sets Task base loader
646 AliError("Parameter is null");
649 if (GetBaseTaskLoader()) delete GetBaseTaskLoader();
650 fBaseLoaders->AddAt(bl,kTask);
652 /*****************************************************************************/
653 void AliDataLoader::SetBaseQALoader(AliBaseLoader* bl)
655 //sets QA base loader
658 AliError("Parameter is null");
661 if (GetBaseQALoader()) delete GetBaseQALoader();
662 fBaseLoaders->AddAt(bl,kQA);
664 /*****************************************************************************/
665 void AliDataLoader::SetBaseQATaskLoader(AliTaskLoader* bl)
667 //sets QA Task base loader
670 AliError("Parameter is null");
673 if (GetBaseQATaskLoader()) delete GetBaseQATaskLoader();
674 fBaseLoaders->AddAt(bl,kQATask);
676 void AliDataLoader::Synchronize()
678 //synchrinizes all writtable files
679 if ( fFile ) fFile->Flush();
682 /*****************************************************************************/
683 /*****************************************************************************/
684 /*****************************************************************************/
685 //__________________________________________
686 ///////////////////////////////////////////////////////////////////////////////
688 // class AliBaseLoader //
691 ///////////////////////////////////////////////////////////////////////////////
692 ClassImp(AliBaseLoader)
694 AliBaseLoader::AliBaseLoader():
696 fStoreInTopOfFile(kFALSE),
697 fDoNotReload(kFALSE),
700 //default constructor
702 /*****************************************************************************/
704 AliBaseLoader::AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
705 TNamed(name,name+" Base Loader"),
707 fStoreInTopOfFile(storeontop),
708 fDoNotReload(storeontop),//if stored on top of file - this object is loaded ones pe
714 /*****************************************************************************/
715 AliBaseLoader::AliBaseLoader(const AliBaseLoader& source):TNamed(source) {
717 AliFatal("Copy constructor not implemented");
719 /*****************************************************************************/
720 AliBaseLoader& AliBaseLoader::operator=(const AliBaseLoader& /*source*/) {
721 // Assignment operator
722 AliFatal("Assignment operator not implemented");
725 /*****************************************************************************/
727 Int_t AliBaseLoader::Load(Option_t* opt)
729 // Loads and posts the data
730 AliDebug(1, Form("data type = %s, option = %s",GetName(),opt));
734 AliWarning(Form("Data <<%s>> are already loaded. Use ReloadData to force reload. Nothing done",GetName()));
740 if (GetDataLoader()->IsFileOpen() == kTRUE)
742 if (GetDataLoader()->IsOptionContrary(opt) == kTRUE)
744 AliError(Form("Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName()));
745 AliError("File was already opened in READ-ONLY mode, while now WRITEABLE access is requested.");
746 AliError("Use AliDataLoader::SetOption to enforce change of access mode OR");
747 AliError("Load previosly loaded data with coherent option.");
753 retval = GetDataLoader()->OpenFile(opt);
756 AliError(Form("Error occured while opening <<%s>> file",GetName()));
760 //if file is recreated there is no sense to search for data to post and get Error message
761 if (AliLoader::TestFileOption(opt) == kFALSE)
763 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(this);
764 if (tl) tl->MakeTree();
772 AliError(Form("Error occured while posting %s from file to folder.",GetName()));
779 /*****************************************************************************/
781 Int_t AliBaseLoader::Post()
783 //Posts data container to proper folders
785 if ( GetDirectory() == 0x0)
787 AliError(Form("%s directory is NULL. Load before.",GetDataLoader()->GetName()));
791 TObject* data = GetFromDirectory(fName);
794 //if such an obejct already exists - remove it first
799 //check if file is in update mode
800 Int_t fileupdate = GetDataLoader()->GetFileOption().CompareTo("update",TString::kIgnoreCase);
801 if ( fileupdate == 0)
802 { //if it is, it is normal that there is no data yet
803 AliDebug(1, Form("Can not find %s in file %s (file is opened in UPDATE mode).",
804 GetName(),GetDataLoader()->GetFile()->GetName()));
808 AliError(Form("Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName()));
814 /*****************************************************************************/
816 Int_t AliBaseLoader::Post(TObject* data)
818 //Posts data container to proper folders
821 AliError("Pointer to object is NULL");
825 if ( fName.CompareTo(data->GetName()) != 0)
827 AliFatal(Form("Object name is <<%s>> while <<%s>> expected",data->GetName(),GetName()));
828 return -1;//pro forma
831 TObject* obj = Get();
834 AliWarning("This object was already posted.");
839 AliWarning(Form("Object named %s already exitsts in data folder. Removing it",GetName()));
842 return AddToBoard(data);
844 /*****************************************************************************/
846 Int_t AliBaseLoader::WriteData(Option_t* opt)
848 //Writes data defined by di object
849 //opt might be "OVERWRITE" in case of forcing overwriting
850 AliDebug(1, Form("Writing %s container for %s data. Option is %s.",
851 GetName(),GetDataLoader()->GetName(),opt));
853 TObject *data = Get();
855 {//did not get, nothing to write
856 AliWarning(Form("Tree named %s not found in folder. Nothing to write.",GetName()));
860 //check if file is opened
861 if (GetDirectory() == 0x0)
864 GetDataLoader()->SetFileOption("UPDATE");
865 if (GetDataLoader()->OpenFile("UPDATE"))
867 //oops, can not open the file, give an error message and return error code
868 AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName()));
873 if (GetDataLoader()->IsFileWritable() == kFALSE)
875 AliError(Form("File %s is not writable",GetDataLoader()->GetFileName().Data()));
879 GetDirectory()->cd(); //set the proper directory active
881 //see if hits container already exists in this (root) directory
882 TObject* obj = GetFromDirectory(GetName());
884 { //if they exist, see if option OVERWRITE is used
885 const char *oOverWrite = strstr(opt,"OVERWRITE");
887 {//if it is not used - give an error message and return an error code
888 AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
893 AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s",
894 GetName(),opt,data->GetName()));
895 AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s",
896 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
897 GetDirectory()->GetFile()->GetName()));
899 AliDebug(1, "Writing data");
900 data->Write(0,TObject::kOverwrite);
902 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
907 /*****************************************************************************/
909 Int_t AliBaseLoader::Reload()
911 //Unloads and loads datat again - if loaded before
915 return Load(GetDataLoader()->GetFileOption());
919 /*****************************************************************************/
921 void AliBaseLoader::Clean()
923 //removes objects from folder/task
924 AliDebug(1, Form("%s %s",GetName(),GetDataLoader()->GetName()));
925 TObject* obj = Get();
928 AliDebug(1, Form("cleaning %s.",GetName()));
929 RemoveFromBoard(obj);
933 /*****************************************************************************/
935 void AliBaseLoader::Unload()
937 // Unloads data and closes the files
940 GetDataLoader()->CloseFile();
942 /*****************************************************************************/
943 AliDataLoader* AliBaseLoader::GetDataLoader() const
945 // Returns pointer to the data loader
946 if (fDataLoader == 0x0)
948 AliFatal("Pointer to Data Loader is NULL");
952 /*****************************************************************************/
954 TDirectory* AliBaseLoader::GetDirectory() const
956 // returnd TDirectory where data are to be saved
957 //if fStoreInTopOfFile flag is true - returns pointer to file
958 return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory();
960 /*****************************************************************************/
961 /*****************************************************************************/
962 /*****************************************************************************/
963 //__________________________________________
964 ///////////////////////////////////////////////////////////////////////////////
966 // class AliObjectLoader //
969 ///////////////////////////////////////////////////////////////////////////////
971 ClassImp(AliObjectLoader)
973 AliObjectLoader::AliObjectLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
974 AliBaseLoader(name,dl,storeontop)
978 /*****************************************************************************/
980 TFolder* AliObjectLoader::GetFolder() const
982 // Returns pointer to the object folder
983 TFolder* df = GetDataLoader()->GetFolder();
986 AliFatal("Data Folder is NULL");
990 /*****************************************************************************/
991 AliObjectLoader::AliObjectLoader(const AliObjectLoader& source):
992 AliBaseLoader(source) {
994 AliFatal("Copy constructor not implemented");
996 /*****************************************************************************/
997 AliObjectLoader& AliObjectLoader::operator=(const AliObjectLoader& /*source*/) {
998 // Assignment operator
999 AliFatal("Assignment operator not implemented");
1002 /*****************************************************************************/
1004 void AliObjectLoader::RemoveFromBoard(TObject* obj)
1006 // Removes "obj" from the board
1007 GetFolder()->Remove(obj);
1009 /*****************************************************************************/
1010 Int_t AliObjectLoader::AddToBoard(TObject* obj)
1012 // Adds "obj" to the board
1013 GetFolder()->Add(obj);
1016 /*****************************************************************************/
1018 TObject* AliObjectLoader::Get() const
1020 // Returns pointer to the object loader
1021 return (GetFolder()) ? GetFolder()->FindObject(GetName()) : 0x0;
1024 /*****************************************************************************/
1025 /*****************************************************************************/
1026 /*****************************************************************************/
1027 //__________________________________________
1028 ///////////////////////////////////////////////////////////////////////////////
1030 // class AliTreeLoader //
1033 ///////////////////////////////////////////////////////////////////////////////
1035 ClassImp(AliTreeLoader)
1037 AliTreeLoader::AliTreeLoader(const TString& name, AliDataLoader* dl,Bool_t storeontop):
1038 AliObjectLoader(name,dl,storeontop)
1042 /*****************************************************************************/
1043 AliTreeLoader::AliTreeLoader(const AliTreeLoader& source):
1044 AliObjectLoader(source) {
1046 AliFatal("Copy constructor not implemented");
1048 /*****************************************************************************/
1049 AliTreeLoader& AliTreeLoader::operator=(const AliTreeLoader& /*source*/) {
1050 // Assignment operator
1051 AliFatal("Assignment operator not implemented");
1055 /*****************************************************************************/
1057 Int_t AliTreeLoader::WriteData(Option_t* opt)
1059 //Writes data defined by di object
1060 //opt might be "OVERWRITE" in case of forcing overwriting
1062 AliDebug(1, Form("Writing %s container for %s data. Option is %s.",
1063 GetName(),GetDataLoader()->GetName(),opt));
1065 TObject *data = Get();
1067 {//did not get, nothing to write
1068 AliWarning(Form("Tree named %s not found in folder. Nothing to write.",GetName()));
1072 //check if file is opened
1073 if (GetDirectory() == 0x0)
1075 //if not try to open
1076 GetDataLoader()->SetFileOption("UPDATE");
1077 if (GetDataLoader()->OpenFile("UPDATE"))
1079 //oops, can not open the file, give an error message and return error code
1080 AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName()));
1085 if (GetDataLoader()->IsFileWritable() == kFALSE)
1087 AliError(Form("File %s is not writable",GetDataLoader()->GetFileName().Data()));
1091 GetDirectory()->cd(); //set the proper directory active
1093 //see if hits container already exists in this (root) directory
1094 TObject* obj = GetFromDirectory(GetName());
1096 { //if they exist, see if option OVERWRITE is used
1097 const char *oOverWrite = strstr(opt,"OVERWRITE");
1099 {//if it is not used - give an error message and return an error code
1100 AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
1105 AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s",
1106 GetName(),opt,data->GetName()));
1107 AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s",
1108 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
1109 GetDirectory()->GetFile()->GetName()));
1111 //if a data object is a tree set the directory
1112 TTree* tree = dynamic_cast<TTree*>(data);
1113 if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above)
1115 AliDebug(1, "Writing tree");
1116 data->Write(0,TObject::kOverwrite);
1118 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
1123 /*****************************************************************************/
1125 void AliTreeLoader::MakeTree()
1127 //this virtual method creates the tree in the file
1130 AliDebug(1, Form("name = %s, Data Name = %s Tree already exists.",
1131 GetName(),GetDataLoader()->GetName()));
1132 return;//tree already made
1134 AliDebug(1, Form("Making Tree named %s.",GetName()));
1136 TString dtypename(GetDataLoader()->GetName());
1137 TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree
1140 AliError(Form("Can not create %s tree.",GetName()));
1143 tree->SetAutoSave(1000000000); //no autosave
1144 GetFolder()->Add(tree);
1145 WriteData("OVERWRITE");//write tree to the file
1149 /*****************************************************************************/
1150 /*****************************************************************************/
1151 /*****************************************************************************/
1152 //__________________________________________
1153 ///////////////////////////////////////////////////////////////////////////////
1155 // class AliTaskLoader //
1158 ///////////////////////////////////////////////////////////////////////////////
1160 ClassImp(AliTaskLoader)
1162 AliTaskLoader::AliTaskLoader(const TString& name, AliDataLoader* dl, TTask* parentaltask, Bool_t storeontop):
1163 AliBaseLoader(name,dl,storeontop),
1164 fParentalTask(parentaltask)
1169 /*****************************************************************************/
1170 AliTaskLoader::AliTaskLoader(const AliTaskLoader& source):
1171 AliBaseLoader(source) {
1173 AliFatal("Copy constructor not implemented");
1175 /*****************************************************************************/
1176 AliTaskLoader& AliTaskLoader::operator=(const AliTaskLoader& /*source*/) {
1177 // Assignment operator
1178 AliFatal("Assignment operator not implemented");
1181 /*****************************************************************************/
1182 void AliTaskLoader::Clean()
1184 //removes tasl from parental task
1185 // DO NOT DELETE OBJECT contrary to BaseLoader
1187 AliDebug(1, Form("Clean","%s %s",GetName(),GetDataLoader()->GetName()));
1188 TObject* obj = Get();
1191 AliDebug(1, Form("cleaning %s.",GetName()));
1192 RemoveFromBoard(obj);
1195 /*****************************************************************************/
1197 void AliTaskLoader::RemoveFromBoard(TObject* obj)
1199 // Removes the task "obj" from the board
1200 GetParentalTask()->GetListOfTasks()->Remove(obj);
1202 /*****************************************************************************/
1204 Int_t AliTaskLoader::AddToBoard(TObject* obj)
1206 // Adds task "obj" to the board
1207 TTask* task = dynamic_cast<TTask*>(obj);
1210 AliError("To TTask board can be added only tasks.");
1213 GetParentalTask()->Add(task);
1216 /*****************************************************************************/
1218 TObject* AliTaskLoader::Get() const
1220 // Returns pointer to the current task
1221 return (GetParentalTask()) ? GetParentalTask()->GetListOfTasks()->FindObject(GetName()) : 0x0;
1223 /*****************************************************************************/
1225 TTask* AliTaskLoader::GetParentalTask() const
1227 //returns parental tasks for this task
1228 return fParentalTask;
1231 /*****************************************************************************/
1233 /*****************************************************************************/
1234 /*****************************************************************************/
1235 /*****************************************************************************/