Setting of aliases to rawReader done only once. Base decision on cosmic or calib...
[u/mrichter/AliRoot.git] / STEER / STEER / AliTreeLoader.cxx
CommitLineData
a9bbb414 1/////////////////////////////////////////////////////////////////////////////////////////////
2// //
3// class AliTreeLoader //
4// //
5// Container of all data needed for full //
6// description of each data type //
7// (Hits, Kine, ...) //
8// //
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 //
15// //
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 //
21// //
22// //
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 //
26// //
27/////////////////////////////////////////////////////////////////////////////////////////////
28
29/* $Id$ */
30
31#include "AliTreeLoader.h"
a9bbb414 32#include "AliRunLoader.h"
c93255fe 33#include "AliLog.h"
a9bbb414 34
c93255fe 35#include <TFile.h>
36#include <TFolder.h>
a9bbb414 37
38ClassImp(AliTreeLoader)
39
40//______________________________________________________________________________
41AliTreeLoader::AliTreeLoader(const TString& name, AliDataLoader* dl,Bool_t storeontop):
42 AliObjectLoader(name,dl,storeontop)
43{
44 //
45 // Constructor
46 //
47}
48
49//______________________________________________________________________________
a9bbb414 50Int_t AliTreeLoader::WriteData(Option_t* opt)
51{
52 //
53 // Writes data defined by di object
54 // opt might be "OVERWRITE" in case of forcing overwriting
55 //
56 AliDebug(1, Form("Writing %s container for %s data. Option is %s.",
57 GetName(),GetDataLoader()->GetName(),opt));
58
59 TObject *data = Get();
60 if(data == 0x0)
61 {//did not get, nothing to write
62 AliWarning(Form("Tree named %s not found in folder. Nothing to write.",GetName()));
63 return 0;
64 }
65
66 //check if file is opened
67 if (GetDirectory() == 0x0)
68 {
69 //if not try to open
70 GetDataLoader()->SetFileOption("UPDATE");
71 if (GetDataLoader()->OpenFile("UPDATE"))
72 {
73 //oops, can not open the file, give an error message and return error code
74 AliError(Form("Can not open hits file. %s ARE NOT WRITTEN",GetName()));
75 return 1;
76 }
77 }
78
79 if (GetDataLoader()->IsFileWritable() == kFALSE)
80 {
81 AliError(Form("File %s is not writable",GetDataLoader()->GetFileName().Data()));
82 return 2;
83 }
84
85 GetDirectory()->cd(); //set the proper directory active
86
87 //see if hits container already exists in this (root) directory
88 TObject* obj = GetFromDirectory(GetName());
89 if (obj)
90 { //if they exist, see if option OVERWRITE is used
91 const char *oOverWrite = strstr(opt,"OVERWRITE");
92 if(!oOverWrite)
93 {//if it is not used - give an error message and return an error code
94 AliError("Tree already exisists. Use option \"OVERWRITE\" to overwrite previous data");
95 return 3;
96 }
97 }
98
99 AliDebug(1, Form("DataName = %s, opt = %s, data object name = %s",
100 GetName(),opt,data->GetName()));
101 AliDebug(1, Form("File Name = %s, Directory Name = %s Directory's File Name = %s",
102 GetDataLoader()->GetFile()->GetName(),GetDirectory()->GetName(),
103 GetDirectory()->GetFile()->GetName()));
104
105 //if a data object is a tree set the directory
106 TTree* tree = dynamic_cast<TTree*>(data);
107 if (tree) tree->SetDirectory(GetDirectory()); //forces setting the directory to this directory (we changed dir few lines above)
108
109 AliDebug(1, "Writing tree");
110 data->Write(0,TObject::kOverwrite);
111
112 fIsLoaded = kTRUE; // Just to ensure flag is on. Object can be posted manually to folder structure, not using loader.
113
114 return 0;
115
116}
117
118//______________________________________________________________________________
119void AliTreeLoader::MakeTree()
120{
121 //
122 // This virtual method creates the tree in the file
123 //
124 if (Tree())
125 {
126 AliDebug(1, Form("name = %s, Data Name = %s Tree already exists.",
127 GetName(),GetDataLoader()->GetName()));
128 return;//tree already made
129 }
130 AliDebug(1, Form("Making Tree named %s.",GetName()));
131
132 TString dtypename(GetDataLoader()->GetName());
133 TTree* tree = new TTree(GetName(), dtypename + " Container"); //make a tree
134 if (tree == 0x0)
135 {
136 AliError(Form("Can not create %s tree.",GetName()));
137 return;
138 }
139 tree->SetAutoSave(1000000000); //no autosave
140 GetFolder()->Add(tree);
141 WriteData("OVERWRITE");//write tree to the file
142}
143
144