AliPhysics  96f6795 (96f6795)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CorrExtractor.C
Go to the documentation of this file.
1 #include <TFile.h>
2 #include <TList.h>
3 #include <TParameter.h>
4 #include <TError.h>
6 
12 {
19  : fFile(0),
20  fTop(0),
21  fOut(""),
22  fRunNo(0),
23  fSys(0),
24  fSNN(0),
25  fField(999),
26  fMC(false),
27  fSatellite(false),
28  fManager(manager)
29  {}
31  const TString& name)
32  {
33  TObject* o = 0;
34  if (p == 0) {
35  o = fFile->Get(name);
36  if (!o) {
37  Warning("CorrExtractor", "Object %s not found in file", name.Data());
38  return 0;
39  }
40  }
41  else {
42  o = p->FindObject(name);
43  if (!o) {
44  Warning("CorrExtractor", "Object %s not found in %s",
45  name.Data(), p->GetName());
46  return 0;
47  }
48  }
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());
52  return 0;
53  }
54  return static_cast<TCollection*>(o);
55  }
64  {
65  if (path.IsNull()) return 0;
66  TObjArray* tokens = path.Tokenize("/");
67  TIter next(tokens);
68  TObjString* token = 0;
69  TCollection* p = 0;
70  while ((token = static_cast<TObjString*>(next()))) {
71  const TString& t = token->String();
72  if (t.IsNull()) continue;
73  p = GetCollection(p, t);
74  if (!p) break;
75  }
76  tokens->Delete();
77  return p;
78 
79  }
88  TObject* FindObject(const TString& path,
89  const TString& name)
90  {
91  if (path.IsNull()) {
92  TObject* o = fFile->Get(name);
93  if (!o) {
94  Warning("CorrExtractor", "Object %s not found in file",
95  name.Data());
96  return 0;
97  }
98  return o;
99  }
100  TCollection* p = FindCollection(path);
101  if (!p) {
102  Warning("CorrExtractor", "Path %s invalid", path.Data());
103  return 0;
104  }
105  return p->FindObject(name);
106  }
117  const TString& sumFolder,
118  const TString& out)
119  {
120  fOut = out;
121  Clear();
122 
123  fFile = TFile::Open(fileName, "READ");
124  if (!fFile) {
125  Error("CorrExtractor", "Failed to open \"%s\"", fileName.Data());
126  Clear();
127  return false;
128  }
129  TCollection* c = FindCollection(Form("%s/fmdEventInspector",
130  sumFolder.Data()));
131  if (!c) {
132  // sumFolder = "forwardQAResults";
133  c = FindCollection(Form("%s/fmdEventInspector",
134  "forwardQAResults"));
135  if (!c) {
136  Error("CorrExtractor", "Couldn't get event inspector list from %s",
137  fileName.Data());
138  Clear();
139  return false;
140  }
141  }
142  TObject* oSys = c->FindObject("sys");
143  TObject* oSNN = c->FindObject("sNN");
144  TObject* oFld = c->FindObject("field");
145  TObject* oRun = c->FindObject("runNo");
146  TObject* oSat = c->FindObject("satellite");
147  if (oSys && fSys <= 0) fSys = oSys->GetUniqueID();
148  if (oSNN && fSNN <= 0) fSNN = oSNN->GetUniqueID();
149  if (oFld && fField >= 999) fField = oFld->GetUniqueID();
150  if (oRun && fRunNo <= 0) fRunNo = oRun->GetUniqueID();
151  if (oSat) fSatellite = oSat->GetUniqueID();
152 
153  if (fSys <= 0 || fSys > 3 || fSNN <= 0 || fField >= 999 || fRunNo <= 0 ){
154  Error("CorrExtractor", "Failed to get settings\n"
155  " sys=%d sNN=%d field=%d run=%ld", fSys, fSNN, fField, fRunNo);
156  Clear();
157  return false;
158  }
159  return true;
160  }
166  void SetMC(Bool_t mc=true) { fMC = mc; }
175  Bool_t Extract(const TClass* cls, const TString& parent)
176  {
177  return Extract(cls->GetName(), parent);
178  }
187  Bool_t Extract(const TString& objName,
188  const TString& parent="")
189  {
190  if (!fFile) {
191  Warning("Extract", "No file opened");
192  return false;
193  }
194  TObject* o = FindObject(parent, objName);
195  if (!o) {
196  Warning("Extract", "Object %s not found in collection %s",
197  objName.Data(), parent.Data());
198  return false;
199  }
200  if (o->TestBit(1<<15) && !o->TestBit(1<<16)) {
201  Warning("Extract", "Object %s is not good", objName.Data());
202  TFile* bad = TFile::Open("bad.root", "RECREATE");
203  (new TNamed("bad","BadCorrection"))->Write();
204  bad->Write();
205  bad->Close();
206  return false;
207  }
208  return fManager->Store(o,
209  fRunNo,
210  fSys,
211  fSNN,
212  fField,
213  fMC,
214  fSatellite,
215  fOut.Data());
216  }
221  void Clear()
222  {
223  if (!fFile) return;
224  fFile->Close();
225  fFile = 0;
226  fTop = 0;
227  fRunNo = 0;
228  fSys = 0;
229  fSNN = 0;
230  fField = 999;
231  fMC = false;
232  fSatellite = false;
233  }
234  TFile* fFile; // Our file
235  TList* fTop; // Top list
236  TString fOut; // Output
237  ULong_t fRunNo; // Run number
238  UShort_t fSys; // System
239  UShort_t fSNN; // Collision energy in GeV
240  Short_t fField; // L3 field in kG
241  Bool_t fMC; // Simulation flag
242  Bool_t fSatellite; // Satellite interaction flag
243  AliCorrectionManagerBase* fManager; // Correction manager to use
244 };
245 
246 //
247 // EOF
248 //
249 
250 
Base class for correction managers.
TCollection * GetCollection(TCollection *p, const TString &name)
Definition: CorrExtractor.C:30
TString fileName
TObject * FindObject(const TString &path, const TString &name)
Definition: CorrExtractor.C:88
Bool_t Init(const TString &fileName, const TString &sumFolder, const TString &out)
TCanvas * c
Definition: TestFitELoss.C:172
Bool_t Extract(const TString &objName, const TString &parent="")
AliCorrectionManagerBase * fManager
virtual Bool_t Store(TObject *o, ULong_t runNo, UShort_t sys, UShort_t sNN, Short_t field, Bool_t mc, Bool_t sat, const char *file, const char *meth="NEAR") const
unsigned long ULong_t
Definition: External.C:38
Bool_t Extract(const TClass *cls, const TString &parent)
short Short_t
Definition: External.C:23
TCollection * FindCollection(const TString &path)
Definition: CorrExtractor.C:63
CorrExtractor(AliCorrectionManagerBase *manager)
Definition: CorrExtractor.C:18
void SetMC(Bool_t mc=true)
unsigned short UShort_t
Definition: External.C:28
bool Bool_t
Definition: External.C:53