AliPhysics  239578e (239578e)
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  Bool_t ret = true;
154  if (fSys <= 0 || fSys > 5) {
155  Error("CorrExtractor", "Invalid collision energy: %d", fSys);
156  ret = false;
157  }
158  if (fSNN <= 0) {
159  Error("CorrExtractor", "Invalid collision energy: %d", fSNN);
160  ret = false;
161  }
162  if (fField >= 999) {
163  Error("CorrExtractor", "Invalid field value: %d", fField);
164  ret = false;
165  }
166  if (fRunNo <= 0 ){
167  Error("CorrExtractor", "Invalid run number: %d", fRunNo);
168  ret = false;
169  }
170  if (!ret) Clear();
171  return ret;
172  }
178  void SetMC(Bool_t mc=true) { fMC = mc; }
187  Bool_t Extract(const TClass* cls, const TString& parent)
188  {
189  return Extract(cls->GetName(), parent);
190  }
199  Bool_t Extract(const TString& objName,
200  const TString& parent="")
201  {
202  if (!fFile) {
203  Warning("Extract", "No file opened");
204  return false;
205  }
206  TObject* o = FindObject(parent, objName);
207  if (!o) {
208  Warning("Extract", "Object %s not found in collection %s",
209  objName.Data(), parent.Data());
210  return false;
211  }
212  if (o->TestBit(1<<15) && !o->TestBit(1<<16)) {
213  Warning("Extract", "Object %s is not good", objName.Data());
214  TFile* bad = TFile::Open("bad.root", "RECREATE");
215  (new TNamed("bad","BadCorrection"))->Write();
216  bad->Write();
217  bad->Close();
218  return false;
219  }
220  return fManager->Store(o,
221  fRunNo,
222  fSys,
223  fSNN,
224  fField,
225  fMC,
226  fSatellite,
227  fOut.Data());
228  }
233  void Clear()
234  {
235  if (!fFile) return;
236  fFile->Close();
237  fFile = 0;
238  fTop = 0;
239  fRunNo = 0;
240  fSys = 0;
241  fSNN = 0;
242  fField = 999;
243  fMC = false;
244  fSatellite = false;
245  }
246  TFile* fFile; // Our file
247  TList* fTop; // Top list
248  TString fOut; // Output
249  ULong_t fRunNo; // Run number
250  UShort_t fSys; // System
251  UShort_t fSNN; // Collision energy in GeV
252  Short_t fField; // L3 field in kG
253  Bool_t fMC; // Simulation flag
254  Bool_t fSatellite; // Satellite interaction flag
255  AliCorrectionManagerBase* fManager; // Correction manager to use
256 };
257 
258 //
259 // EOF
260 //
261 
262 
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