1 /////////////////////////////////////////////////////////////////////////////////////////////
3 // class AliTreeLoader //
5 // Container of all data needed for full //
6 // description of each data type //
7 // (Hits, Kine, ...) //
9 // Each data loader has a basic standard setup of BaseLoaders //
10 // which can be identuified by indexes (defined by EStdBasicLoaders) //
11 // Data managed by these standard base loaders has fixed naming convention //
12 // e.g. - tree with hits is always named TreeH //
13 // (defined in AliLoader::fgkDefaultHitsContainerName) //
14 // - task DtectorName+Name defined //
16 // EStdBasicLoaders idx Object Type Description //
17 // kData 0 TTree or TObject main data itself (hits,digits,...) //
18 // kTask 1 TTask object producing main data //
19 // kQA 2 TTree quality assurance tree //
20 // kQATask 3 TTask task producing QA object //
23 // User can define and add more basic loaders even Run Time. //
24 // Caution: in order to save information about added base loader //
25 // user must rewrite Run Loader to galice.file, overwriting old setup //
27 /////////////////////////////////////////////////////////////////////////////////////////////
32 #include "AliTreeLoader.h"
34 #include "AliRunLoader.h"
37 ClassImp(AliTreeLoader)
39 //______________________________________________________________________________
40 AliTreeLoader::AliTreeLoader(const TString& name, AliDataLoader* dl,Bool_t storeontop):
41 AliObjectLoader(name,dl,storeontop)
48 //______________________________________________________________________________
49 AliTreeLoader::AliTreeLoader(const AliTreeLoader& source):
50 AliObjectLoader(source)
55 AliFatal("Copy constructor not implemented");
58 //______________________________________________________________________________
59 AliTreeLoader& AliTreeLoader::operator=(const AliTreeLoader& /*source*/)
62 // Assignment operator
64 AliFatal("Assignment operator not implemented");
68 //______________________________________________________________________________
69 Int_t AliTreeLoader::WriteData(Option_t* opt)
72 // Writes data defined by di object
73 // opt might be "OVERWRITE" in case of forcing overwriting
75 AliDebug(1, Form("Writing %s container for %s data. Option is %s.",
76 GetName(),GetDataLoader()->GetName(),opt));
78 TObject *data = Get();
80 {//did not get, nothing to write
81 AliWarning(Form("Tree named %s not found in folder. Nothing to write.",GetName()));
85 //check if file is opened
86 if (GetDirectory() == 0x0)
89 GetDataLoader()->SetFileOption("UPDATE");
90 if (GetDataLoader()->OpenFile("UPDATE"))
92 //oops, can not open the file, give an error message and return error code
93 AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName()));
98 if (GetDataLoader()->IsFileWritable() == kFALSE)
100 AliError(Form("File %s is not writable",GetDataLoader()->GetFileName().Data()));
104 GetDirectory()->cd(); //set the proper directory active
106 //see if hits container already exists in this (root) directory
107 TObject* obj = GetFromDirectory(GetName());
109 { //if they exist, see if option OVERWRITE is used
110 const char *oOverWrite = strstr(opt,"OVERWRITE");
112 {//if it is not used - give an error message and return an error code
113 AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
118 AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s",
119 GetName(),opt,data->GetName()));
120 AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s",
121 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
122 GetDirectory()->GetFile()->GetName()));
124 //if a data object is a tree set the directory
125 TTree* tree = dynamic_cast<TTree*>(data);
126 if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above)
128 AliDebug(1, "Writing tree");
129 data->Write(0,TObject::kOverwrite);
131 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
137 //______________________________________________________________________________
138 void AliTreeLoader::MakeTree()
141 // This virtual method creates the tree in the file
145 AliDebug(1, Form("name = %s, Data Name = %s Tree already exists.",
146 GetName(),GetDataLoader()->GetName()));
147 return;//tree already made
149 AliDebug(1, Form("Making Tree named %s.",GetName()));
151 TString dtypename(GetDataLoader()->GetName());
152 TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree
155 AliError(Form("Can not create %s tree.",GetName()));
158 tree->SetAutoSave(1000000000); //no autosave
159 GetFolder()->Add(tree);
160 WriteData("OVERWRITE");//write tree to the file