3 #include <TParameter.h>
5 #include "AliCorrectionManagerBase.h"
8 * Extract corrections from result file
16 * @param manager Correction manager
18 CorrExtractor(AliCorrectionManagerBase* manager)
30 TCollection* GetCollection(TCollection* p,
37 Warning("CorrExtractor", "Object %s not found in file", name.Data());
42 o = p->FindObject(name);
44 Warning("CorrExtractor", "Object %s not found in %s",
45 name.Data(), p->GetName());
49 if (!o->IsA()->InheritsFrom(TCollection::Class())) {
50 Warning("CorrExtractor", "%s in %s is not a collection, but a %s",
51 name.Data(), (p ? p->GetName() : "file"), o->ClassName());
54 return static_cast<TCollection*>(o);
57 * Find a collection in a file
59 * @param path Path to collection
61 * @return Found collection or null
63 TCollection* FindCollection(const TString& path)
65 if (path.IsNull()) return 0;
66 TObjArray* tokens = path.Tokenize("/");
68 TObjString* token = 0;
70 while ((token = static_cast<TObjString*>(next()))) {
71 const TString& t = token->String();
72 if (t.IsNull()) continue;
73 p = GetCollection(p, t);
83 * @param path Path to object
84 * @param name Name of object
86 * @return Found object or null
88 TObject* FindObject(const TString& path,
92 TObject* o = fFile->Get(name);
94 Warning("CorrExtractor", "Object %s not found in file",
100 TCollection* p = FindCollection(path);
102 Warning("CorrExtractor", "Path %s invalid", path.Data());
105 return p->FindObject(name);
108 * Initialize this extactor
110 * @param fileName File to extract from
111 * @param sumFolder The summed folder
112 * @param out The result folder
114 * @return true on success
116 Bool_t Init(const TString& fileName,
117 const TString& sumFolder,
123 fFile = TFile::Open(fileName, "READ");
125 Error("CorrExtractor", "Failed to open \"%s\"", fileName.Data());
129 TCollection* c = FindCollection(Form("%s/fmdEventInspector",
132 Error("CorrExtractor", "Couldn't get event inspector list from %s",
137 TObject* oSys = c->FindObject("sys");
138 TObject* oSNN = c->FindObject("sNN");
139 TObject* oFld = c->FindObject("field");
140 TObject* oRun = c->FindObject("runNo");
141 TObject* oSat = c->FindObject("satellite");
142 if (oSys && fSys <= 0) fSys = oSys->GetUniqueID();
143 if (oSNN && fSNN <= 0) fSNN = oSNN->GetUniqueID();
144 if (oFld && fField >= 999) fField = oFld->GetUniqueID();
145 if (oRun && fRunNo <= 0) fRunNo = oRun->GetUniqueID();
146 if (oSat) fSatellite = oSat->GetUniqueID();
148 if (fSys <= 0 || fSys > 3 || fSNN <= 0 || fField >= 999 || fRunNo <= 0 ){
149 Error("CorrExtractor", "Failed to get settings");
156 * Set whether this is MC or not
158 * @param mc If true, consider this MC
160 void SetMC(Bool_t mc=true) { fMC = mc; }
164 * @param cls Class of object
165 * @param parent Parent folder
169 Bool_t Extract(const TClass* cls, const TString& parent)
171 return Extract(cls->GetName(), parent);
176 * @param objName Object name
177 * @param parent Parent folder
181 Bool_t Extract(const TString& objName,
182 const TString& parent="")
185 Warning("Extract", "No file opened");
188 TObject* o = FindObject(parent, objName);
190 Warning("Extract", "Object %s not found in collection %s",
191 objName.Data(), parent.Data());
194 return fManager->Store(o,
204 * Clear this extractor
220 TFile* fFile; // Our file
221 TList* fTop; // Top list
222 TString fOut; // Output
223 ULong_t fRunNo; // Run number
224 UShort_t fSys; // System
225 UShort_t fSNN; // Collision energy in GeV
226 Short_t fField; // L3 field in kG
227 Bool_t fMC; // Simulation flag
228 Bool_t fSatellite; // Satellite interaction flag
229 AliCorrectionManagerBase* fManager; // Correction manager to use