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():
56 /*****************************************************************************/
58 AliDataLoader::AliDataLoader(const char* filename, const char* contname, const char* name, Option_t* opt):
65 fBaseLoaders(new TObjArray(4)),
73 // creates a 0 loader, depending on option, default "T" is specialized loader for trees
74 // else standard object loader
75 // trees needs special care, becouse we need to set dir before writing
77 Info("AliDataLoader","File name is %s",fFileName.Data());
81 if (option.CompareTo("T",TString::kIgnoreCase) == 0)
82 bl = new AliTreeLoader(contname,this);
84 bl = new AliObjectLoader(contname,this);
85 fBaseLoaders->AddAt(bl,kData);
88 /*****************************************************************************/
90 AliDataLoader::~AliDataLoader()
95 /*****************************************************************************/
97 Int_t AliDataLoader::SetEvent()
99 //basically the same that GetEvent but do not post data to folders
100 AliRunLoader* rl = GetRunLoader();
103 Error("SetEvent","Can not get RunGettr");
107 Int_t evno = rl->GetEventNumber();
109 TIter next(fBaseLoaders);
111 while ((bl = (AliBaseLoader*)next()))
113 if (bl->DoNotReload() == kFALSE) bl->Clean();
122 if (GetDebug()) Info("SetEvent","Reloading new file. File opt is %s",fFileOption.Data());
123 OpenFile(fFileOption);
126 fDirectory = AliLoader::ChangeDir(fFile,evno);
127 if (fDirectory == 0x0)
129 Error("SetEvent","Can not chage directory in file %s",fFile->GetName());
135 /*****************************************************************************/
137 Int_t AliDataLoader::GetEvent()
139 // posts all loaded data from files to White Board
140 // event number is defined in RunLoader
143 // 0 - in case of no error
144 // 1 - event not found
146 //for each base laoder post, if was loaded before GetEvent
148 //call set event to switch to new directory in file
151 //post all data that were loaded before
152 // ->SetEvent does not call Unload, but only cleans White Board
153 // such IsLoaded flag stays untached
155 if ( AliLoader::TestFileOption(fFileOption) == kTRUE ) //if file is read or update mode try to post
156 { //in other case there is no sense to post: file is new
157 TIter nextbl(fBaseLoaders);
159 while ((bl = (AliBaseLoader*)nextbl()))
163 if (bl->DoNotReload() == kFALSE) bl->Post();
169 /*****************************************************************************/
171 Int_t AliDataLoader::OpenFile(Option_t* opt)
173 //Opens file named 'filename', and assigns pointer to it to 'file'
174 //jumps to fDirectoryectory corresponding to current event and stores the pointer to it in 'fDirectory'
175 //option 'opt' is passed to TFile::Open
178 if(fFile->IsOpen() == kTRUE)
180 Warning("OpenFile"," File %s already opened. First close it.",fFile->GetName());
185 Warning("OpenFile","Pointer to file %s is not null, but file is not opened",
192 TString fname(SetFileOffset(fFileName));
194 fFile = (TFile *)(gROOT->GetListOfFiles()->FindObject(fname));
197 if(fFile->IsOpen() == kTRUE)
199 Warning("OpenFile","File %s already opened by sombody else. First close it.",
206 fFile = TFile::Open(fname,fFileOption);//open the file
209 Error("OpenFile","Can not open file %s",fname.Data());
212 if (fFile->IsOpen() == kFALSE)
214 Error("OpenFile","Can not open file %s",fname.Data());
218 fFile->SetCompressionLevel(fCompressionLevel);
220 AliRunLoader* rg = GetRunLoader();
223 Error("OpenFile","Can not find Run-Loader in folder.");
226 Int_t evno = rg->GetEventNumber();
228 fDirectory = AliLoader::ChangeDir(fFile,evno);
229 if (fDirectory == 0x0)
231 Error("OpenFile","Can not chage fDirectory in file %s.",fFile->GetName());
236 /*****************************************************************************/
238 void AliDataLoader::Unload()
240 //unloads main data - shortcut method
241 GetBaseLoader(0)->Unload();
243 /*****************************************************************************/
245 void AliDataLoader::UnloadAll()
247 //Unloads all data and tasks
248 if ( fFile == 0x0 ) return; //nothing loaded
250 TIter next(fBaseLoaders);
252 while ((bl = (AliBaseLoader*)next()))
257 /*****************************************************************************/
259 Int_t AliDataLoader::Reload()
261 //Unloads and loads data again
262 if ( fFile == 0x0 ) return 0;
264 TBits loaded(fBaseLoaders->GetEntries());
265 TIter next(fBaseLoaders);
269 while ((bl = (AliBaseLoader*)next()))
273 loaded.SetBitNumber(i++,kTRUE);
281 while ((bl = (AliBaseLoader*)next()))
283 if (loaded.TestBitNumber(i++))
285 retval = bl->Load(fFileOption);
288 Error("Reload","Error occur while loading %s",bl->GetName());
297 /*****************************************************************************/
298 Int_t AliDataLoader::WriteData(Option_t* opt)
300 //Writes primary data == first BaseLoader
302 Info("WriteData","Writing %s container for %s data. Option is %s.",
303 GetBaseLoader(0)->GetName(),GetName(),opt);
304 return GetBaseLoader(0)->WriteData(opt);
306 /*****************************************************************************/
308 Int_t AliDataLoader::Load(Option_t* opt)
310 //Writes primary data == first BaseLoader
311 return GetBaseLoader(0)->Load(opt);
313 /*****************************************************************************/
315 Int_t AliDataLoader::SetEventFolder(TFolder* eventfolder)
317 //sets the event folder
318 if (eventfolder == 0x0)
320 Error("SetEventFolder","Stupid joke. Argument is NULL");
324 Info("SetFolder","name = %s Setting Event Folder named %s.",
325 GetName(),eventfolder->GetName());
327 fEventFolder = eventfolder;
330 /*****************************************************************************/
332 Int_t AliDataLoader::SetFolder(TFolder* folder)
337 Error("SetFolder","Stupid joke. Argument is NULL");
341 if (GetDebug()) Info("SetFolder","name = %s Setting folder named %s.",GetName(),folder->GetName());
344 TIter next(fBaseLoaders);
347 while ((bl = (AliBaseLoader*)next()))
349 bl->SetDataLoader(this);
354 /******************************************************************/
356 TFolder* AliDataLoader::GetEventFolder()
358 //get EVENT folder (data that are changing from event to event, even in single run)
359 if (GetDebug()) Info("GetEventFolder","EF = %#x");
362 /*****************************************************************************/
364 AliRunLoader* AliDataLoader::GetRunLoader()
366 //gets the run-loader from event folder
367 AliRunLoader* rg = 0x0;
368 TFolder* ef = GetEventFolder();
371 Error("GetRunLoader","Can not get event folder.");
374 rg = dynamic_cast<AliRunLoader*>(ef->FindObject(AliRunLoader::fgkRunLoaderName));
378 /*****************************************************************************/
379 void AliDataLoader::CloseFile()
382 TIter next(fBaseLoaders);
384 while ((bl = (AliBaseLoader*)next()))
386 if (bl->IsLoaded()) return;
390 Info("CloseFile","Closing and deleting (object) file.");
396 /*****************************************************************************/
398 void AliDataLoader::Clean()
401 GetBaseLoader(0)->Clean();
403 /*****************************************************************************/
405 void AliDataLoader::CleanAll()
407 //Cleans all folders and tasks
408 TIter next(fBaseLoaders);
410 while ((bl = (AliBaseLoader*)next()))
415 /*****************************************************************************/
417 void AliDataLoader::SetFileNameSuffix(const TString& suffix)
419 //adds the suffix before ".root",
420 //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
421 //made on Jiri Chudoba demand
424 Info("SetFileNameSuffix","suffix=%s",suffix.Data());
425 Info("SetFileNameSuffix"," Digits File Name before: %s",fFileName.Data());
428 static TString dotroot(".root");
429 const TString& suffixdotroot = suffix + dotroot;
430 fFileName = fFileName.ReplaceAll(dotroot,suffixdotroot);
433 Info("SetDigitsFileNameSuffix"," after : %s",fFileName.Data());
435 /*****************************************************************************/
437 Bool_t AliDataLoader::CheckReload()
439 //checks if we have to reload given file
440 if (fFile == 0x0) return kFALSE;
441 TString tmp = SetFileOffset(fFileName);
442 if (tmp.CompareTo(fFile->GetName())) return kTRUE; //file must be reloaded
445 /*****************************************************************************/
447 const TString AliDataLoader::SetFileOffset(const TString& fname)
451 Long_t offset = (Long_t)GetRunLoader()->GetFileOffset();
452 if (offset < 1) return fname;
455 soffset += offset;//automatic conversion to string
456 TString dotroot(".root");
457 const TString& offfsetdotroot = offset + dotroot;
459 out = out.ReplaceAll(dotroot,offfsetdotroot);
460 if (GetDebug()) Info("SetFileOffset","in=%s out=%s.",fname.Data(),out.Data());
464 /*****************************************************************************/
466 void AliDataLoader::SetFileOption(Option_t* newopt)
469 if (fFileOption.CompareTo(newopt) == 0) return;
470 fFileOption = newopt;
473 /*****************************************************************************/
475 void AliDataLoader::SetCompressionLevel(Int_t cl)
477 //sets comression level for data defined by di
478 fCompressionLevel = cl;
479 if (fFile) fFile->SetCompressionLevel(cl);
481 /*****************************************************************************/
483 Int_t AliDataLoader::GetDebug() const
485 //it is not inline bacause AliLoader.h includes AliDataLoaer.h
486 //and there is circular depenedence
487 return AliLoader::GetDebug();
489 /*****************************************************************************/
491 void AliDataLoader::MakeTree()
493 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(fBaseLoaders->At(0));
496 Error("MakeTree","Can not make a tree because main base loader is not a tree loader");
501 /*****************************************************************************/
503 Bool_t AliDataLoader::IsFileWritable() const
505 //returns true if file is writable
506 return (fFile)?fFile->IsWritable():kFALSE;
508 /*****************************************************************************/
510 Bool_t AliDataLoader::IsFileOpen() const
512 //returns true if file is writable
513 return (fFile)?fFile->IsOpen():kFALSE;
515 /*****************************************************************************/
517 Bool_t AliDataLoader::IsOptionContrary(const TString& option) const
519 //Checks if passed option is contrary with file open option
520 //which is passed option "writable" and existing option not wriable
521 //in reverse case it is no harm so it is NOT contrary
522 if (fFile == 0x0) return kFALSE; //file is not opened - no problem
524 if ( ( AliLoader::IsOptionWritable(option) == kTRUE ) && // passed option is writable and
525 ( AliLoader::IsOptionWritable(fFileOption) == kFALSE ) ) // existing one is not writable
532 /*****************************************************************************/
533 void AliDataLoader::AddBaseLoader(AliBaseLoader* bl)
535 //Adds a base loader to lits of base loaders managed by this data loader
536 //Managed data/task will be stored in proper root directory,
538 // - in case of tree/object - data folder connected with detector associated with this data loader
539 // - in case of task - parental task which defined in this AliTaskLoader
543 Warning("AddBaseLoader","Pointer is null.");
547 TObject* obj = fBaseLoaders->FindObject(bl->GetName());
550 Error("AddBaseLoader","Can not add this base loader.");
551 Error("AddBaseLoader","There exists already base loader which manages data named %s for this detector.");
556 fBaseLoaders->Add(bl);
559 /*****************************************************************************/
561 AliBaseLoader* AliDataLoader::GetBaseLoader(const TString& name) const
563 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->FindObject(name));
565 /*****************************************************************************/
567 AliBaseLoader* AliDataLoader::GetBaseLoader(Int_t n) const
569 return dynamic_cast<AliBaseLoader*>(fBaseLoaders->At(n));
571 /*****************************************************************************/
573 TTree* AliDataLoader::Tree() const
575 //returns tree from the main base loader
576 //it is just shortcut method for comfort of user
577 //main storage object does not have to be Tree -
578 //that is why first we need to check if it is a TreeLoader
579 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(GetBaseLoader(0));
580 if (tl == 0x0) return 0x0;
583 /*****************************************************************************/
585 void AliDataLoader::SetDirName(TString& dirname)
587 if (GetDebug()>9) Info("SetDirName","FileName before %s",fFileName.Data());
589 Int_t n = fFileName.Last('/');
591 if (GetDebug()>9) Info("SetDirName","Slash found on pos %d",n);
593 if (n > 0) fFileName = fFileName.Remove(0,n+1);
595 if (GetDebug()>9) Info("SetDirName","Core FileName %s",fFileName.Data());
597 fFileName = dirname + "/" + fFileName;
599 if (GetDebug()>9) Info("SetDirName","FileName after %s",fFileName.Data());
601 /*****************************************************************************/
602 AliObjectLoader* AliDataLoader::GetBaseDataLoader()
604 return dynamic_cast<AliObjectLoader*>(GetBaseLoader(kData));
606 /*****************************************************************************/
607 AliTaskLoader* AliDataLoader::GetBaseTaskLoader()
609 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kTask));
611 /*****************************************************************************/
612 AliBaseLoader* AliDataLoader::GetBaseQALoader()
614 return GetBaseLoader(kQA);
616 /*****************************************************************************/
617 AliTaskLoader* AliDataLoader::GetBaseQATaskLoader()
619 //returns pointer to QA base loader
620 return dynamic_cast<AliTaskLoader*>(GetBaseLoader(kQATask));
622 /*****************************************************************************/
623 void AliDataLoader::SetBaseDataLoader(AliBaseLoader* bl)
625 //sets data base loader
628 Error("SetBaseDataLoader","Parameter is null");
631 if (GetBaseDataLoader()) delete GetBaseDataLoader();
632 fBaseLoaders->AddAt(bl,kData);
634 /*****************************************************************************/
635 void AliDataLoader::SetBaseTaskLoader(AliTaskLoader* bl)
637 //sets Task base loader
640 Error("SetBaseTaskLoader","Parameter is null");
643 if (GetBaseTaskLoader()) delete GetBaseTaskLoader();
644 fBaseLoaders->AddAt(bl,kTask);
646 /*****************************************************************************/
647 void AliDataLoader::SetBaseQALoader(AliBaseLoader* bl)
649 //sets QA base loader
652 Error("SetBaseQALoader","Parameter is null");
655 if (GetBaseQALoader()) delete GetBaseQALoader();
656 fBaseLoaders->AddAt(bl,kQA);
658 /*****************************************************************************/
659 void AliDataLoader::SetBaseQATaskLoader(AliTaskLoader* bl)
661 //sets QA Task base loader
664 Error("SetBaseQATaskLoader","Parameter is null");
667 if (GetBaseQATaskLoader()) delete GetBaseQATaskLoader();
668 fBaseLoaders->AddAt(bl,kQATask);
670 void AliDataLoader::Synchronize()
672 //synchrinizes all writtable files
673 if ( fFile == 0x0 ) return;
674 if ( fFile->IsWritable() == kFALSE ) return;
675 fFile->Write(0,TObject::kOverwrite);
678 /*****************************************************************************/
679 /*****************************************************************************/
680 /*****************************************************************************/
681 //__________________________________________
682 ///////////////////////////////////////////////////////////////////////////////
684 // class AliBaseLoader //
687 ///////////////////////////////////////////////////////////////////////////////
688 ClassImp(AliBaseLoader)
690 AliBaseLoader::AliBaseLoader():
692 fStoreInTopOfFile(kFALSE),
693 fDoNotReload(kFALSE),
697 /*****************************************************************************/
699 AliBaseLoader::AliBaseLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
700 TNamed(name,name+" Base Loader"),
702 fStoreInTopOfFile(storeontop),
703 fDoNotReload(storeontop),//if stored on top of file - this object is loaded ones pe
708 /*****************************************************************************/
710 Int_t AliBaseLoader::Load(Option_t* opt)
713 Info("Load","data type = %s, option = %s",GetName(),opt);
717 Warning("Load","Data <<%s>> are already loaded. Use ReloadData to force reload. Nothing done",GetName());
723 if (GetDataLoader()->IsFileOpen() == kTRUE)
725 if (GetDataLoader()->IsOptionContrary(opt) == kTRUE)
727 Error("Load","Data Type %s, Container Name %s", GetDataLoader()->GetName(),GetName());
728 Error("Load","File was already opened in READ-ONLY mode, while now WRITEABLE access is requested.");
729 Error("Load","Use AliDataLoader::SetOption to enforce change of access mode OR");
730 Error("Load","Load previosly loaded data with coherent option.");
736 retval = GetDataLoader()->OpenFile(opt);
739 Error("Load","Error occured while opening <<%s>> file",GetName());
743 //if file is recreated there is no sense to search for data to post and get Error message
744 if (AliLoader::TestFileOption(opt) == kFALSE)
746 AliTreeLoader* tl = dynamic_cast<AliTreeLoader*>(this);
747 if (tl) tl->MakeTree();
755 Error("Load","Error occured while posting %s from file to folder.",GetName());
762 /*****************************************************************************/
764 Int_t AliBaseLoader::Post()
766 //Posts data container to proper folders
768 if ( GetDirectory() == 0x0)
770 Error("Post","%s directory is NULL. Load before.",GetDataLoader()->GetName());
774 TObject* data = GetFromDirectory(fName);
777 //if such an obejct already exists - remove it first
782 //check if file is in update mode
783 Int_t fileupdate = GetDataLoader()->GetFileOption().CompareTo("update",TString::kIgnoreCase);
784 if ( fileupdate == 0)
785 { //if it is, it is normal that there is no data yet
788 Info("Post","Can not find %s in file %s (file is opened in UPDATE mode).",
789 GetName(),GetDataLoader()->GetFile()->GetName());
794 Warning("Post","Can not find %s in file %s", GetName(),GetDataLoader()->GetFile()->GetName());
799 /*****************************************************************************/
801 Int_t AliBaseLoader::Post(TObject* data)
803 //Posts data container to proper folders
806 Error("Post","Pointer to object is NULL");
809 TObject* obj = Get();
812 if (GetDebug()) Warning("Post","This object was already posted.");
817 Warning("PostData","Object named %s already exitsts in data folder. Removing it",GetName());
820 return AddToBoard(data);
822 /*****************************************************************************/
824 Int_t AliBaseLoader::WriteData(Option_t* opt)
826 //Writes data defined by di object
827 //opt might be "OVERWRITE" in case of forcing overwriting
829 Info("WriteData","Writing %s container for %s data. Option is %s.",
830 GetName(),GetDataLoader()->GetName(),opt);
832 TObject *data = Get();
834 {//did not get, nothing to write
835 Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
839 //check if file is opened
840 if (GetDirectory() == 0x0)
843 GetDataLoader()->SetFileOption("UPDATE");
844 if (GetDataLoader()->OpenFile("UPDATE"))
846 //oops, can not open the file, give an error message and return error code
847 Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
852 if (GetDataLoader()->IsFileWritable() == kFALSE)
854 Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
858 GetDirectory()->cd(); //set the proper directory active
860 //see if hits container already exists in this (root) directory
861 TObject* obj = GetFromDirectory(GetName());
863 { //if they exist, see if option OVERWRITE is used
864 const char *oOverWrite = strstr(opt,"OVERWRITE");
866 {//if it is not used - give an error message and return an error code
867 Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
872 if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
873 GetName(),opt,data->GetName());
874 if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
875 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
876 GetDirectory()->GetFile()->GetName());
878 if (GetDebug()) Info("WriteData","Writing data");
879 data->Write(0,TObject::kOverwrite);
881 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
886 /*****************************************************************************/
888 Int_t AliBaseLoader::Reload()
890 //Unloads and loads datat again - if loaded before
894 return Load(GetDataLoader()->GetFileOption());
898 /*****************************************************************************/
900 void AliBaseLoader::Clean()
902 //removes objects from folder/task
903 if (GetDebug()) Info("Clean","%s %s",GetName(),GetDataLoader()->GetName());
904 TObject* obj = Get();
908 Info("Clean","cleaning %s.",GetName());
909 RemoveFromBoard(obj);
913 /*****************************************************************************/
915 void AliBaseLoader::Unload()
919 GetDataLoader()->CloseFile();
921 /*****************************************************************************/
922 AliDataLoader* AliBaseLoader::GetDataLoader() const
924 if (fDataLoader == 0x0)
926 Fatal("GetDataLoader","Pointer to Data Loader is NULL");
930 /*****************************************************************************/
932 Int_t AliBaseLoader::GetDebug() const
934 return (Int_t)AliLoader::fgDebug;
937 TDirectory* AliBaseLoader::GetDirectory()
939 // returnd TDirectory where data are to be saved
940 //if fStoreInTopOfFile flag is true - returns pointer to file
941 return (fStoreInTopOfFile)?GetDataLoader()->GetFile():GetDataLoader()->GetDirectory();
943 /*****************************************************************************/
944 /*****************************************************************************/
945 /*****************************************************************************/
946 //__________________________________________
947 ///////////////////////////////////////////////////////////////////////////////
949 // class AliObjectLoader //
952 ///////////////////////////////////////////////////////////////////////////////
954 ClassImp(AliObjectLoader)
956 AliObjectLoader::AliObjectLoader(const TString& name, AliDataLoader* dl, Bool_t storeontop):
957 AliBaseLoader(name,dl,storeontop)
961 /*****************************************************************************/
963 TFolder* AliObjectLoader::GetFolder() const
965 TFolder* df = GetDataLoader()->GetFolder();
968 Fatal("GetFolder","Data Folder is NULL");
972 /*****************************************************************************/
974 void AliObjectLoader::RemoveFromBoard(TObject* obj)
976 GetFolder()->Remove(obj);
978 /*****************************************************************************/
979 Int_t AliObjectLoader::AddToBoard(TObject* obj)
981 GetFolder()->Add(obj);
984 /*****************************************************************************/
986 TObject* AliObjectLoader::Get() const
988 return (GetFolder()) ? GetFolder()->FindObject(GetName()) : 0x0;
991 /*****************************************************************************/
992 /*****************************************************************************/
993 /*****************************************************************************/
994 //__________________________________________
995 ///////////////////////////////////////////////////////////////////////////////
997 // class AliTreeLoader //
1000 ///////////////////////////////////////////////////////////////////////////////
1002 ClassImp(AliTreeLoader)
1004 AliTreeLoader::AliTreeLoader(const TString& name, AliDataLoader* dl,Bool_t storeontop):
1005 AliObjectLoader(name,dl,storeontop)
1010 /*****************************************************************************/
1012 Int_t AliTreeLoader::WriteData(Option_t* opt)
1014 //Writes data defined by di object
1015 //opt might be "OVERWRITE" in case of forcing overwriting
1018 Info("WriteData","Writing %s container for %s data. Option is %s.",
1019 GetName(),GetDataLoader()->GetName(),opt);
1021 TObject *data = Get();
1023 {//did not get, nothing to write
1024 Warning("WriteData","Tree named %s not found in folder. Nothing to write.",GetName());
1028 //check if file is opened
1029 if (GetDirectory() == 0x0)
1031 //if not try to open
1032 GetDataLoader()->SetFileOption("UPDATE");
1033 if (GetDataLoader()->OpenFile("UPDATE"))
1035 //oops, can not open the file, give an error message and return error code
1036 Error("WriteData","Can not open hits file. %s ARE NOT WRITTEN",GetName());
1041 if (GetDataLoader()->IsFileWritable() == kFALSE)
1043 Error("WriteData","File %s is not writable",GetDataLoader()->GetFileName().Data());
1047 GetDirectory()->cd(); //set the proper directory active
1049 //see if hits container already exists in this (root) directory
1050 TObject* obj = GetFromDirectory(GetName());
1052 { //if they exist, see if option OVERWRITE is used
1053 const char *oOverWrite = strstr(opt,"OVERWRITE");
1055 {//if it is not used - give an error message and return an error code
1056 Error("WriteData","Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
1061 if (GetDebug()) Info("WriteData","DataName = %s, opt = %s, data object name = %s",
1062 GetName(),opt,data->GetName());
1063 if (GetDebug()) Info("WriteData","File Name = %s, Directory Name = %s Directory's File Name = %s",
1064 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
1065 GetDirectory()->GetFile()->GetName());
1067 //if a data object is a tree set the directory
1068 TTree* tree = dynamic_cast<TTree*>(data);
1069 if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above)
1071 if (GetDebug()) Info("WriteData","Writing tree");
1072 data->Write(0,TObject::kOverwrite);
1074 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
1079 /*****************************************************************************/
1081 void AliTreeLoader::MakeTree()
1083 //this virtual method creates the tree in the file
1087 Info("MakeTree","name = %s, Data Name = %s Tree already exists.",
1088 GetName(),GetDataLoader()->GetName());
1089 return;//tree already made
1092 Info("MakeTree","Making Tree named %s.",GetName());
1094 TString dtypename(GetDataLoader()->GetName());
1095 TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree
1098 Error("MakeTree","Can not create %s tree.",GetName());
1101 tree->SetAutoSave(1000000000); //no autosave
1102 GetFolder()->Add(tree);
1103 WriteData("OVERWRITE");//write tree to the file
1107 /*****************************************************************************/
1108 /*****************************************************************************/
1109 /*****************************************************************************/
1110 //__________________________________________
1111 ///////////////////////////////////////////////////////////////////////////////
1113 // class AliTaskLoader //
1116 ///////////////////////////////////////////////////////////////////////////////
1118 ClassImp(AliTaskLoader)
1120 AliTaskLoader::AliTaskLoader(const TString& name, AliDataLoader* dl, TTask* parentaltask, Bool_t storeontop):
1121 AliBaseLoader(name,dl,storeontop),
1122 fParentalTask(parentaltask)
1127 /*****************************************************************************/
1129 void AliTaskLoader::RemoveFromBoard(TObject* obj)
1131 GetParentalTask()->GetListOfTasks()->Remove(obj);
1133 /*****************************************************************************/
1135 Int_t AliTaskLoader::AddToBoard(TObject* obj)
1137 TTask* task = dynamic_cast<TTask*>(obj);
1140 Error("AddToBoard","To TTask board can be added only tasks.");
1143 GetParentalTask()->Add(task);
1146 /*****************************************************************************/
1148 TObject* AliTaskLoader::Get() const
1150 return (GetParentalTask()) ? GetParentalTask()->GetListOfTasks()->FindObject(GetName()) : 0x0;
1152 /*****************************************************************************/
1154 TTask* AliTaskLoader::GetParentalTask() const
1156 //returns parental tasks for this task
1157 return fParentalTask;
1160 /*****************************************************************************/
1162 /*****************************************************************************/
1163 /*****************************************************************************/
1164 /*****************************************************************************/