AliPhysics  97344c9 (97344c9)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliCorrectionManagerBase.cxx
Go to the documentation of this file.
2 #include "AliOADBForward.h"
3 #include "AliForwardUtil.h"
4 #include <AliLog.h>
5 #include <TMath.h>
6 #include <iostream>
7 #include <TROOT.h>
8 #include <TSystem.h>
9 #include <TBrowser.h>
10 #include <TParameter.h>
11 #include <TFileMerger.h>
12 #include <TBits.h>
13 #include <TTree.h>
14 
15 //____________________________________________________________________
17  : fCorrections(),
18  fIsInit(false),
19  fRun(kIgnoreValue),
20  fSys(kIgnoreValue),
21  fSNN(kIgnoreValue),
22  fField(kIgnoreField),
23  fMC(false),
24  fSatellite(false),
25  fDB(0),
26  fDebug(false),
27  fFallBack(false)
28 {
29 }
30 
31 //____________________________________________________________________
33  : fCorrections(16),
34  fIsInit(false),
35  fRun(kIgnoreValue),
36  fSys(kIgnoreValue),
37  fSNN(kIgnoreValue),
38  fField(kIgnoreField),
39  fMC(false),
40  fSatellite(false),
41  fDB(0),
42  fDebug(false),
43  fFallBack(false)
44 {
45  fCorrections.SetOwner(false);
46  fCorrections.SetName("corrections");
47 }
48 //____________________________________________________________________
51  : TObject(o),
52  fCorrections(),
53  fIsInit(o.fIsInit),
54  fRun(o.fRun),
55  fSys(o.fSys),
56  fSNN(o.fSNN),
57  fField(o.fField),
58  fMC(o.fMC),
59  fSatellite(o.fSatellite),
60  fDB(o.fDB),
61  fDebug(o.fDebug),
62  fFallBack(o.fFallBack)
63 {
64  fCorrections.SetOwner(false);
65  Int_t n = o.fCorrections.GetEntriesFast();
66  for (Int_t i = 0; i < n; i++) {
67  fCorrections.AddAt(o.fCorrections.At(i), i);
68  }
69 }
70 //____________________________________________________________________
73 {
74  if (&o == this) return *this;
75 
76  fIsInit = o.fIsInit;
77  fRun = o.fRun;
78  fSys = o.fSys;
79  fSNN = o.fSNN;
80  fField = o.fField;
81  fMC = o.fMC;
83  fDB = o.fDB;
84  fDebug = o.fDebug;
85  fFallBack = o.fFallBack;
86 
87  fCorrections.Clear();
88  Int_t n = o.fCorrections.GetEntriesFast();
89  for (Int_t i = 0; i < n; i++) {
90  fCorrections.AddAt(o.fCorrections.At(i), i);
91  }
92  return *this;
93 }
94 
95 //____________________________________________________________________
97 {
98  // fCorrections.Delete();
99 }
100 
101 #define PF(N,V,...) \
102  AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
103 #define PFB(N,FLAG) \
104  do { \
105  AliForwardUtil::PrintName(N); \
106  std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
107  } while(false)
108 #define PFV(N,VALUE) \
109  do { \
110  AliForwardUtil::PrintName(N); \
111  std::cout << (VALUE) << std::endl; } while(false)
112 
113 //____________________________________________________________________
114 void
116 {
118  gROOT->IncreaseDirLevel();
119  PFB("Initialized", fIsInit);
120  if (fIsInit) {
121  PFV("Run number", fRun);
122  PFV("Collision system", AliForwardUtil::CollisionSystemString(fSys));
124  PFV("Magnetic field", AliForwardUtil::MagneticFieldString(fField));
125  PFB("For simulations", fMC);
126  PFB("For satellites", fSatellite);
127  }
128  TString opt(option);
129  opt.ToUpper();
130  if (opt.Contains("R")) {
131  // gROOT->IncreaseDirLevel();
132  Int_t n = fCorrections.GetEntriesFast();
133  for (Int_t id = 0; id < n; id++) {
134  const Correction* c = GetCorrection(id);
135  c->Print(option);
136  }
137  // gROOT->DecreaseDirLevel();
138  }
139  gROOT->DecreaseDirLevel();
140 }
141 
142 //____________________________________________________________________
143 void
145 {
146  b->Add(&fCorrections);
147 }
148 
149 //____________________________________________________________________
150 void
152 {
153  Int_t n = fCorrections.GetEntriesFast();
154  for (Int_t id = 0; id < n; id++) {
155  Correction* c = GetCorrection(id);
156  const char* old = c->GetTitle();
157  TString oldf(gSystem->BaseName(old));
158  c->SetFile(gSystem->ConcatFileName(prefix, oldf));
159  }
160 }
161 
162 //____________________________________________________________________
163 Bool_t
165  ULong_t runNo,
166  UShort_t sys,
167  UShort_t sNN,
168  Short_t field,
169  Bool_t mc,
170  Bool_t sat,
171  const char* file,
172  const char* meth) const
173 {
174  Bool_t ret = false;
175  Int_t n = fCorrections.GetEntriesFast();
176  for (Int_t id = 0; id < n; id++) {
177  const Correction* c = GetCorrection(id);
178  if (!o->IsA()->InheritsFrom(c->fCls)) continue;
179 
180  ret = c->StoreIt(fDB, o, runNo, sys, sNN, field, mc, sat, file, meth);
181  break;
182  }
183  return ret;
184 }
185 
186 //____________________________________________________________________
187 Bool_t
189  const TString& destination) const
190 {
191  if (addition.IsNull()) {
192  AliWarning("No addition specified");
193  return false;
194  }
195  if (destination.IsNull()) {
196  AliWarning("No destination storage specified");
197  return false;
198  }
199  TFileMerger merger;
200  merger.SetPrintLevel(1);
201  merger.OutputFile(destination, "UPDATE");
202  merger.AddFile(addition);
203  if (!merger.PartialMerge()) {
204  AliInfoF("Failed to merge %s with %s",
205  addition.Data(), destination.Data());
206  return false;
207  }
208  if (destination.BeginsWith("$OADB_PATH") ||
209  destination.BeginsWith("$ALICE_PHYSICS"))
210  AliInfoF("Now commit %s to git", destination.Data());
211  return true;
212 }
213 //____________________________________________________________________
214 Bool_t
216  Bool_t verb,
217  Bool_t all) const
218 {
219  AliOADBForward* db = fDB;
220  if (!db) db = new AliOADBForward;
221 
222  for (Int_t i = 0; i < 32; i++) {
223  const Correction* c = GetCorrection(i);
224  if (!c) continue;
225 
226  if (!c->fEnabled) {
227  Info("CleanUp", "Table %s not enabled", c->GetName());
228  continue;
229  }
230  Info("CleanUp", "Will clean up table %s", c->GetName());
231  c->CleanIt(db, destination, verb, all);
232  }
233  return true;
234 }
235 
236 
237 //____________________________________________________________________
238 void
240 {
241  for (Int_t i = 0; i < 32; i++) {
242  if (!GetCorrection(i)) continue;
243  EnableCorrection(i, (1 << i) & what);
244  }
245 }
246 //____________________________________________________________________
247 Bool_t
249 {
250  Bool_t ret = true;
251  for (Int_t i = 0; i < 32; i++) {
252  Bool_t enabled = (1 << i) & what;
253  if (!enabled) continue;
254  const Correction* c = GetCorrection(i);
255  if (!c) {
256  ret = false;
257  if (verbose)
258  AliWarningF("No correction registered for bit %d", i);
259  continue;
260  }
261  const TObject* o = c->Get();
262  if (!o) {
263  ret = false;
264  if (verbose)
265  AliWarningF("Correction %s (bit %d) not initialized!", c->GetName(), i);
266  continue;
267  }
268  }
269  return ret;
270 }
271 
272 //____________________________________________________________________
273 const char*
275 {
276  const Correction* c = GetCorrection(what);
277  if (!c) return 0;
278  const TClass* cls = c->TheClass();
279  if (!cls) return 0;
280  return cls->GetName();
281 }
282 
283 //____________________________________________________________________
284 void
286 {
287  fCorrections.AddAtAndExpand(corr, id);
288 }
289 
290 //____________________________________________________________________
291 void
293  const TString& tableName,
294  const TString& fileName,
295  TClass* cls,
296  UShort_t fields,
297  Bool_t enabled)
298 {
299  RegisterCorrection(id,new Correction(tableName,fileName,cls,fields,enabled));
300 }
301 
302 //____________________________________________________________________
305 {
306  if (id < 0 || id > fCorrections.GetEntriesFast()) return 0;
307  return static_cast<Correction*>(fCorrections.At(id));
308 }
309 
310 //____________________________________________________________________
313 {
314  if (id < 0 || id > fCorrections.GetEntriesFast()) return 0;
315  return static_cast<Correction*>(fCorrections.At(id));
316 }
317 
318 //____________________________________________________________________
319 void
321 {
322  Correction* c = GetCorrection(id);
323  if (!c) return;
324  c->SetFile(fileName);
325 }
326 
327 //____________________________________________________________________
328 Int_t
330 {
331  Int_t n = fCorrections.GetEntriesFast();
332  for (Int_t id = 0; id < n; id++) {
333  const Correction* c = GetCorrection(id);
334  if (what.EqualTo(c->GetName(), TString::kIgnoreCase)) return id;
335  }
336  return -1;
337 }
338 
339 //____________________________________________________________________
340 void
342 {
343  Correction* c = GetCorrection(id);
344  if (!c) {
345  AliWarningF("Cannot enable non-existing correction at %d", id);
346  return;
347  }
348  c->fEnabled = enable;
349 }
350 
351 //____________________________________________________________________
352 Int_t
354 {
355  Int_t n = fCorrections.GetEntriesFast();
356  TClass* ocl = obj->IsA();
357  for (Int_t id = 0; id < n; id++) {
358  const Correction* c = GetCorrection(id);
359  if (ocl->InheritsFrom(c->fCls)) return id;
360  }
361  return -1;
362 }
363 //____________________________________________________________________
364 TObject*
366 {
367  Correction* c = GetCorrection(id);
368  if (!c) {
369  AliWarningF("Cannot find correction with id %d", id);
370  return 0;
371  }
372  return c->Get();
373 }
374 //____________________________________________________________________
375 const TObject*
377 {
378  const Correction* c = GetCorrection(id);
379  if (!c) {
380  AliWarningF("Cannot find correction with id %d", id);
381  return 0;
382  }
383  return c->Get();
384 }
385 
386 //____________________________________________________________________
387 Bool_t
389  UShort_t sys,
390  UShort_t sNN,
391  Short_t fld,
392  Bool_t mc,
393  Bool_t sat,
394  Bool_t force)
395 {
396  if (force) fIsInit = false;
397  if (!CheckConditions(run, sys, sNN, fld, mc, sat)) return false;
398  if (!ReadCorrections(run, sys, sNN, fld, mc, sat)) return false;
399  fIsInit = true;
400 
401  if (fDB) {
402  delete fDB;
403  fDB = 0;
404  }
405 
406  return true;
407 }
408 
409 //____________________________________________________________________
410 Bool_t
412  UShort_t sys,
413  UShort_t sNN,
414  Short_t fld,
415  Bool_t mc,
416  Bool_t sat)
417 {
418  if (!fIsInit) return true;
419 
420  AliInfo("We are already initialised - checking settings...");
421  Bool_t same = true;
422  if (fRun != run) {
423  same = false;
424  }
425  if (fSys != sys) {
426  AliWarningF("Initialised collision system %s (%d) and "
427  "passed same %s (%d) does not match",
430  same = false;
431  }
432  if (TMath::Abs(fSNN - sNN) >= 10) {
433  AliWarningF("Initialised center of mass energy per nuclean "
434  "%s (%d) and passed same %s (%d) does not match",
437  same = false;
438  }
439  if (fField != fld) {
440  AliWarningF("Initialied L3 magnetic field %s (%d) and passed "
441  "same %s (%d) does not match",
444  same = false;
445  }
446  if (fMC != mc) {
447  AliWarningF("Initialied data type (%s) and passed "
448  "same (%s) does not match",
449  (fMC ? "MC" : "real"), (mc ? "MC" : "real"));
450  same = false;
451  }
452  if (fSatellite != sat) {
453  AliWarningF("Initialied collision ip type (%s) and passed "
454  "same (%s) does not match",
455  (fSatellite ? "satellite" : "nominal"),
456  (sat ? "satellite" : "nominal"));
457  same = false;
458  }
459  if (!same) {
460  AliWarning("Intialised parameters and these are not the same "
461  "- PROCEED WITH CAUTION!");
462  }
463  else
464  AliInfo("Initialized values consistent with data");
465 
466  return true;
467 
468 }
469 
470 //____________________________________________________________________
471 Bool_t
473  ULong_t run,
474  UShort_t sys,
475  UShort_t sNN,
476  Short_t fld,
477  Bool_t mc,
478  Bool_t sat)
479 {
480  if (!fDB) {
481  // We should always open the database, since we're not
482  // streamingthat object to disk.
483  fDB = new AliOADBForward;
484  }
485 
486  Correction* c = GetCorrection(id);
487  if (!c->fEnabled) return true;
488  return c->ReadIt(fDB, run, sys, sNN, fld, mc, sat, fDebug, fFallBack);
489 }
490 
491 //____________________________________________________________________
492 Bool_t
494  UShort_t sys,
495  UShort_t sNN,
496  Short_t fld,
497  Bool_t mc,
498  Bool_t sat)
499 {
500  if (fIsInit) return true;
501  if (fRun == run &&
502  fSys == sys &&
503  fField == fld &&
504  fMC == mc &&
505  fSatellite == sat &&
506  TMath::Abs(fSNN - sNN) < 11) {
507  // Already initialized for this - return
508  fIsInit = true;
509  return true;
510  }
511  if (!fDB) {
512  // We should always open the database, since we're not
513  // streamingthat object to disk.
514  fDB = new AliOADBForward;
515  }
516 
517  fRun = run;
518  fSys = sys;
519  fSNN = sNN;
520  fField = fld;
521  fMC = mc;
522  fSatellite = sat;
523  Int_t n = fCorrections.GetEntriesFast();
524  Bool_t ret = true;
525  for (Int_t id = 0; id < n; id++)
526  if (!ReadCorrection(id, run, sys, sNN, fld, mc, sat)) ret = false;
527  return ret;
528 }
529 
530 //====================================================================
532  : TNamed(),
533  fCls(0),
534  fClientCls(""),
535  fQueryFields(0),
536  fEnabled(false),
537  fLastEntry(),
538  fObject(0)
539 {}
540 
541 //____________________________________________________________________
543  const TString& fileName,
544  TClass* cls,
545  UShort_t fields,
546  Bool_t enabled)
547  : TNamed(tableName, fileName),
548  fCls(cls),
549  fClientCls(cls->GetName()),
550  fQueryFields(fields),
551  fEnabled(enabled),
552  fLastEntry(""),
553  fObject(0)
554 {}
555 
556 //____________________________________________________________________
558  : TNamed(o),
559  fCls(o.fCls),
560  fClientCls(o.fClientCls),
561  fQueryFields(o.fQueryFields),
562  fEnabled(o.fEnabled),
563  fLastEntry(o.fLastEntry),
564  fObject(o.fObject)
565 {}
566 
567 //____________________________________________________________________
570 {
571  if (&o == this) return *this;
572  SetName(o.GetName());
573  SetTitle(o.GetTitle());
574  fCls = o.fCls;
575  //fClientCls = o.fClientCls;
576  fQueryFields = o.fQueryFields;
577  fEnabled = o.fEnabled;
578  fLastEntry = o.fLastEntry;
579  fObject = o.fObject;
580  return *this;
581 }
582 
583 //____________________________________________________________________
584 void
586  UShort_t& sys,
587  UShort_t& sNN,
588  Short_t & fld,
589  Bool_t& mc,
590  Bool_t& sat) const
591 {
592  // Massage fields according to settings
593  if (!(fQueryFields & kRun)) run = kIgnoreValue;
594  if (!(fQueryFields & kSys)) sys = kIgnoreValue;
595  if (!(fQueryFields & kSNN)) sNN = kIgnoreValue;
596  if (!(fQueryFields & kField)) fld = AliOADBForward::kInvalidField;
597  if (!(fQueryFields & kMC)) mc = false;
598  if (!(fQueryFields & kSatellite)) sat = false;
599 }
600 //____________________________________________________________________
601 void
603  UShort_t& sys,
604  UShort_t& sNN,
605  Short_t & fld,
606  Bool_t& mc,
607  Bool_t& sat) const
608 {
609  // Massage fields according to settings
610  if (run <= 197388 && run >= 196433) {
611  // These are Pb-p runs
612  sys = 4; // AliAODForwardMult::kPbp;
613  }
614  if (sNN == 27615) sNN = 2760;
615 }
616 
617 //____________________________________________________________________
618 Bool_t
620  Bool_t vrb,
621  Bool_t fallback) const
622 {
623  if (!db) {
624  Warning("OpenIt", "No DB passed");
625  return false;
626  }
627 
628  // Check if table is open
629  if (db->FindTable(fName, true)) return true;
630 
631  // if not try to open it
632  if (db->Open(fTitle, fName, false, vrb, fallback)) return true;
633 
634  // Give warning
635  AliWarningF("Failed to open table %s from %s", GetName(), GetTitle());
636  AliWarningF("content of %s for %s:",
637  gSystem->WorkingDirectory(), GetName());
638  gSystem->Exec("pwd; ls -l");
639  return false;
640 }
641 
642 //____________________________________________________________________
643 Bool_t
645  ULong_t run,
646  UShort_t sys,
647  UShort_t sNN,
648  Short_t fld,
649  Bool_t mc,
650  Bool_t sat,
651  Bool_t vrb,
652  Bool_t fallback)
653 {
654  if (!fEnabled) {
655  AliWarningF("Correction %s not enabled", GetName());
656  return 0;
657  }
658 
659  // Assume failure
660  fObject = 0;
661 
662  // Massage fields according to settings
663  MassageFields(run, sys, sNN, fld, mc, sat);
664 
665  if (!OpenIt(db, vrb, fallback)) return false;
666 
667  // Query database
668  AliOADBForward::Entry* e = db->Get(fName, run, AliOADBForward::kDefault,
669  sys, sNN, fld, mc, sat);
670  // Check return value
671  if (!e || !e->fData) {
672  AliWarningF("Failed to get %s from database in %s with "
673  "run=%lu sys=%hu sNN=%hu fld=%hd %s %s",
674  GetName(), GetTitle(), run, sys, sNN, fld,
675  (mc ? "MC" : "real"), (sat ? "satellite" : "nominal"));
676  return false;
677  }
678 
679  // Ge the returned data
680  TObject* o = e->fData;
681  if (!o) {
682  AliWarningF("Entry %p \"%s\" has no data! (%p)", e, e->GetTitle(), o);
683  return false;
684  }
685  const TClass* cl = TheClass();
686  // Check return class
687  if (!o->IsA()->InheritsFrom(cl)) {
688  AliWarningF("%p is not pointer to a %s object but a %s",
689  o, fCls->GetName(), o->ClassName());
690  return false;
691  }
692 
693  // Success
694  fObject = o;
695  fLastEntry = e->GetTitle();
696 
697  return true;
698 }
699 
700 //____________________________________________________________________
701 Bool_t
703  TObject* obj,
704  ULong_t run,
705  UShort_t sys,
706  UShort_t sNN,
707  Short_t fld,
708  Bool_t mc,
709  Bool_t sat,
710  const char* file,
711  const char* meth) const
712 {
713  // Info("StoreIt", "Storing run=%lu sys=%hy sNN=%d fld=%d mc=%d sat=%d",
714  // run, sys, sNN, fld, mc, sat);
715  const TClass* cl = TheClass();
716 
717  // Check value class
718  if (!obj->IsA()->InheritsFrom(cl)) {
719  AliWarningF("%p is not pointer to a %s object but a %s",
720  obj, cl->GetName(), obj->ClassName());
721  return false;
722  }
723 
724  Bool_t local = file || !db;
725  TString fileName = (local ? file : fTitle.Data());
726  AliOADBForward* tdb = (local ? new AliOADBForward : db);
727 
728  // Try to open the table read/write
729  if (!tdb->Open(fileName, Form("%s/%s", GetName(), meth), true, false)) {
730  AliWarningF("Failed to open table %s in %s", GetName(), fileName.Data());
731  return false;
732  }
733 
734  // Massage fields according to settings
735  MassageFields(run, sys, sNN, fld, mc, sat);
736 
737  // Try to insert the object
738  if (!tdb->Insert(fName, obj, run, sys, sNN, fld, mc, sat)) {
739  AliWarningF("Failed to insert into %s off database in %s with "
740  "run=%lu sys=%hu sNN=%hu fld=%hd %s %s",
741  GetName(), GetTitle(), run, sys, sNN, fld,
742  (mc ? "MC" : "real"), (sat ? "satellite" : "nominal"));
743  return false;
744  }
745 
746  if (local) {
747  tdb->Close();
748  delete tdb;
749 
750  AliInfoF("Correction object %s written to DB in %s - merge this with "
751  "%s to store for good", obj->GetName(), fileName.Data(),
752  GetTitle());
753  }
754 
755  // Success
756  return true;
757 }
758 //____________________________________________________________________
759 TObject*
761 {
762  if (!fEnabled) {
763  AliWarningF("Correction %s not enabled", GetName());
764  return 0;
765  }
766  return fObject;
767 }
768 //____________________________________________________________________
769 const TObject*
771 {
772  if (!fEnabled) {
773  AliWarningF("Correction %s not enabled", GetName());
774  return 0;
775  }
776  return fObject;
777 }
778 
779 //____________________________________________________________________
780 const TClass*
782 {
783  if (fCls) return fCls;
784  if (fClientCls.IsNull()) {
785  AliErrorF("No class name set for correction %s", GetName());
786  return 0;
787  }
788  fCls = gROOT->GetClass(fClientCls);
789  if (!fCls) {
790  AliErrorF("Couldn't get class %s for correction %s",
791  fClientCls.Data(), GetName());
792  return 0;
793  }
794  return fCls;
795 }
796 
797 //____________________________________________________________________
798 void
800 {
802  gROOT->IncreaseDirLevel();
803  PFB("Enabled", fEnabled);
804  if (!fEnabled) {
805  gROOT->DecreaseDirLevel();
806  return;
807  }
808 
809  TString flds;
810  if (fQueryFields & kRun) flds.Append("run");
811  if (fQueryFields & kSys) flds.Append("|sys");
812  if (fQueryFields & kSNN) flds.Append("|sNN");
813  if (fQueryFields & kField) flds.Append("|field");
814  if (fQueryFields & kMC) flds.Append("|MC");
815  if (fQueryFields & kSatellite) flds.Append("|Satellite");
816  if (flds.BeginsWith("|")) flds.Remove(0,1);
817 
818  const TClass* cl = TheClass();
819 
820  PFV("Path",GetTitle());
821  PFV("Data class", cl->GetName());
822  PFV("Query fields", flds);
823 
824  if (fObject && !fLastEntry.IsNull()) PF("Entry", fLastEntry);
825 
826  TString opt(option);
827  opt.ToUpper();
828  if (opt.Contains("D") && fObject) {
829  gROOT->IncreaseDirLevel();
830  fObject->Print();
831  gROOT->DecreaseDirLevel();
832  }
833  gROOT->DecreaseDirLevel();
834 }
835 
836 //____________________________________________________________________
837 void
839 {
840  b->Add(const_cast<TClass*>(fCls), "Class");
841  TString flds;
842  if (fQueryFields & kRun) flds.Append("run");
843  if (fQueryFields & kSys) flds.Append("|sys");
844  if (fQueryFields & kSNN) flds.Append("|sNN");
845  if (fQueryFields & kField) flds.Append("|field");
846  if (fQueryFields & kMC) flds.Append("|MC");
847  if (fQueryFields & kSatellite) flds.Append("|Satellite");
848  if (flds.BeginsWith("|")) flds.Remove(0,1);
849 
850  b->Add(new TObjString(flds), "Query fields");
851  b->Add(new TParameter<bool>("Enabled", fEnabled));
852  b->Add(new TObjString(fLastEntry), "Entry");
853  if (fObject) b->Add(fObject);
854 }
855 //____________________________________________________________________
856 Bool_t
858  const TString& dest,
859  Bool_t verb,
860  Bool_t all) const
861 {
862  // Open the table for this correction
863  if (!OpenIt(db, verb , false)) {
864  Warning("CleanIt", "Failed to open table for %s", GetName());
865  return false;
866  }
867 
868  // Get our table - should be here if the above succeeded
869  AliOADBForward::Table* t = db->FindTable(fName, !verb);
870  if (!t) {
871  Warning("CleanIt", "Failed to get table for %s", GetName());
872  return false;
873  }
874 
875  // Get some pointers and make a bit mask of entries to copy
876  TTree* tree = t->fTree;
877  Int_t nEnt = tree->GetEntries();
878  Int_t nCpy = 0;
879  TBits copy(nEnt);
880  copy.ResetAllBits();
881 
882  // Loop over all entries
883  Info("CleanIt", "Looping over %d entries in tree", nEnt);
884  for (Int_t i = 0; i < nEnt; i++) {
885  if (all) {
886  copy.SetBitNumber(i, true);
887  continue;
888  }
889 
890  // Read in next entry
891  tree->GetEntry(i);
892 
893  // Check if we got an object
894  AliOADBForward::Entry* e = t->fEntry;
895  if (!e) continue;
896 
897  // Let's see it
898  // if (verb) e->Print();
899 
900  // Now query the DB with this entry's fields
901  ULong_t run = e->fRunNo;
902  UShort_t sys = e->fSys;
903  UShort_t sNN = e->fSNN;
904  Short_t fld = e->fField;
905  Bool_t mc = e->fMC;
906  Bool_t sat = e->fSatellite;
907  TString txt = e->GetTitle();
908  MassageFields(run, sys, sNN, fld, mc, sat);
909  CorrectFields(run, sys, sNN, fld, mc, sat);
910 
912  sys, sNN, fld, mc, sat);
913  if (r < 0) {
914  Warning("CleanIt","Uh! didn't get an entry for %s (%d)",
915  txt.Data(), i);
916  r = i;
917  // continue;
918  }
919 #if 0
920  // Here, we hard-code some fixes to remove bad entries
921  if (fld != AliOADBForward::kInvalidField) {
922  switch (sys) {
923  case 1:
924  if (sNN == 900 && fld <= 0) r = -1;
925  else if (sNN == 7000 && fld >= 0) r = -1;
926  else if (sNN == 2760 && fld >= 0) r = -1;
927  break;
928  case 2:
929  if (fld >= 0) r = -1;
930  break;
931  }
932  }
933 #endif
934 
935  Printf("%-10s (%3d %3d): %s %s",
936  (i==r ? "copied" : "ignored"), i, r, txt.Data(), GetName());
937 
938  if (r != i) continue;
939 
940  // If the entry found by the query and this entry is the same,
941  // then we should keep it
942  copy.SetBitNumber(i,true);
943  // runs.Append(Form("%7lu", run));
944  }
945 
946  // Now loop over the entries of the tree again, this time
947  // checking if we should copy or not.
948  // Loop over all entries
949  for (Int_t i = 0; i < nEnt; i++) {
950  // If not marked for copy, continue to the next.
951  if (!copy.TestBitNumber(i)) continue;
952 
953  // Read in next entry
954  tree->GetEntry(i);
955 
956  // Check if we got an object
957  AliOADBForward::Entry* e = t->fEntry;
958  if (!e) continue;
959 
960  // Let's get the entry data and store that in a new correction
961  // table
962  ULong_t run = e->fRunNo;
963  UShort_t sys = e->fSys;
964  UShort_t sNN = e->fSNN;
965  Short_t fld = e->fField;
966  Bool_t mc = e->fMC;
967  Bool_t sat = e->fSatellite;
968  TObject* obj = e->fData;
969  TString txt = e->GetTitle();
970  CorrectFields(run, sys, sNN, fld, mc, sat);
971  Printf("Storing %3d: %s -> %9lu/%d/%05d/%2d/%s/%s %s",
972  i, txt.Data(), run, sys, sNN, fld, (mc?"simu":"real"),
973  (sat?"sat":"nom"), GetName());
974  if (!StoreIt(0, obj, run, sys, sNN, fld, mc, sat, dest.Data(),
976  Warning("CleanIt", "Failed to write new entry to %s", dest.Data());
977  continue;
978  }
979  nCpy++;
980  }
981  // Printf("Runs: %s", runs.Data());
982  Printf("Copied %6d entries of %6d for %s", nCpy, nEnt, fName.Data());
983  return true;
984 }
985 
986 //
987 // EOF
988 //
Base class for correction managers.
static const char * Mode2String(ERunSelectMode mode)
void EnableCorrection(Int_t id, Bool_t enable=true)
static const char * CenterOfMassEnergyString(UShort_t cms)
virtual void SetPrefix(const TString &prefix)
#define PFV(N, VALUE)
UShort_t fSys
UShort_t fSNN
TString fileName
TSystem * gSystem
virtual void EnableCorrections(UInt_t what)
Bool_t ReadCorrection(Int_t id, ULong_t run, UShort_t sys, UShort_t sNN, Short_t fld, Bool_t mc, Bool_t sat)
Bool_t InitCorrections(ULong_t run, UShort_t sys, UShort_t sNN, Short_t fld, Bool_t mc, Bool_t sat, Bool_t force=false)
TCanvas * c
Definition: TestFitELoss.C:172
void Print(Option_t *option="") const
void RegisterCorrection(Int_t id, Correction *corr)
void CorrectFields(ULong_t &run, UShort_t &sys, UShort_t &sNN, Short_t &fld, Bool_t &mc, Bool_t &sat) const
virtual Bool_t CleanUp(const TString &destination, Bool_t verb=false, Bool_t all=false) const
Bool_t ReadIt(AliOADBForward *db, ULong_t run, UShort_t sys, UShort_t sNN, Short_t fld, Bool_t mc, Bool_t sat, Bool_t vrb=false, Bool_t fbk=false)
Table * FindTable(const TString &name, Bool_t quite=false) const
ULong_t fRunNo
static const char * MagneticFieldString(Short_t field)
AliCorrectionManagerBase & operator=(const AliCorrectionManagerBase &o)
int Int_t
Definition: External.C:63
Bool_t fMC
void SetCorrectionFile(Int_t id, const TString &fileName) const
unsigned int UInt_t
Definition: External.C:33
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
Various utilities used in PWGLF/FORWARD.
virtual Bool_t CheckCorrections(UInt_t what, Bool_t verbose=true) const
Bool_t CleanIt(AliOADBForward *db, const TString &dest, Bool_t verb=false, Bool_t all=false) const
const char * GetObjectName(Int_t what) const
unsigned long ULong_t
Definition: External.C:38
Int_t GetId(const TString &what) const
const char * GetTitle() const
Bool_t fSatellite
virtual void Browse(TBrowser *b)
static void PrintTask(const TObject &o)
short Short_t
Definition: External.C:23
Correction * GetCorrection(Int_t id)
Bool_t CheckConditions(ULong_t run, UShort_t sys, UShort_t sNN, Short_t fld, Bool_t mc, Bool_t sat)
Correction & operator=(const Correction &o)
Bool_t ReadCorrections(ULong_t run, UShort_t sys, UShort_t sNN, Short_t fld, Bool_t mc, Bool_t sat)
virtual void Print(Option_t *option="") const
virtual Bool_t Append(const TString &addition, const TString &destination="") const
TFile * file
Bool_t Insert(const TString &table, TObject *o, ULong_t runNo, UShort_t sys, UShort_t sNN, Short_t field, Bool_t mc=false, Bool_t sat=false, ULong_t aliRev=0, const TString &author="")
Entry * Get(const TString &table, ULong_t run=0, ERunSelectMode mode=kNear, UShort_t sys=0, UShort_t sNN=0, Short_t fld=0, Bool_t mc=false, Bool_t sat=false) const
#define PFB(N, FLAG)
unsigned short UShort_t
Definition: External.C:28
const char Option_t
Definition: External.C:48
Bool_t OpenIt(AliOADBForward *db, Bool_t vrb=false, Bool_t fallback=false) const
static const char * CollisionSystemString(UShort_t sys)
ERunSelectMode fMode
Int_t GetEntry(ULong_t run=0, ERunSelectMode mode=kNear, UShort_t sys=0, UShort_t sNN=0, Short_t fld=0, Bool_t mc=false, Bool_t sat=false) const
bool Bool_t
Definition: External.C:53
Short_t fField
Bool_t Open(const TString &fileName, const TString &tables="*", Bool_t rw=false, Bool_t verb=false, Bool_t fallback=false)
Bool_t StoreIt(AliOADBForward *db, TObject *o, ULong_t run, UShort_t sys, UShort_t sNN, Short_t fld, Bool_t mc, Bool_t sat, const char *file=0, const char *meth="NEAR") const
TObject * fData
#define PF(N, V,...)
void MassageFields(ULong_t &run, UShort_t &sys, UShort_t &sNN, Short_t &fld, Bool_t &mc, Bool_t &sat) const