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