10 #include <TParameter.h>
11 #include <TFileMerger.h>
59 fSatellite(o.fSatellite),
62 fFallBack(o.fFallBack)
66 for (
Int_t i = 0; i < n; i++) {
74 if (&o ==
this)
return *
this;
89 for (
Int_t i = 0; i < n; i++) {
101 #define PF(N,V,...) \
102 AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
103 #define PFB(N,FLAG) \
105 AliForwardUtil::PrintName(N); \
106 std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
108 #define PFV(N,VALUE) \
110 AliForwardUtil::PrintName(N); \
111 std::cout << (VALUE) << std::endl; } while(false)
118 gROOT->IncreaseDirLevel();
125 PFB(
"For simulations",
fMC);
130 if (opt.Contains(
"R")) {
133 for (
Int_t id = 0;
id < n;
id++) {
139 gROOT->DecreaseDirLevel();
154 for (
Int_t id = 0;
id < n;
id++) {
156 const char* old = c->GetTitle();
172 const char* meth)
const
176 for (
Int_t id = 0;
id < n;
id++) {
178 if (!o->IsA()->InheritsFrom(c->
fCls))
continue;
180 ret = c->
StoreIt(
fDB, o, runNo, sys, sNN, field, mc, sat, file, meth);
189 const TString& destination)
const
191 if (addition.IsNull()) {
192 AliWarning(
"No addition specified");
195 if (destination.IsNull()) {
196 AliWarning(
"No destination storage specified");
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());
208 if (destination.BeginsWith(
"$OADB_PATH") ||
209 destination.BeginsWith(
"$ALICE_PHYSICS"))
210 AliInfoF(
"Now commit %s to git", destination.Data());
222 for (
Int_t i = 0; i < 32; i++) {
227 Info(
"CleanUp",
"Table %s not enabled", c->GetName());
230 Info(
"CleanUp",
"Will clean up table %s", c->GetName());
231 c->
CleanIt(db, destination, verb, all);
241 for (
Int_t i = 0; i < 32; i++) {
251 for (
Int_t i = 0; i < 32; i++) {
252 Bool_t enabled = (1 << i) & what;
253 if (!enabled)
continue;
258 AliWarningF(
"No correction registered for bit %d", i);
265 AliWarningF(
"Correction %s (bit %d) not initialized!", c->GetName(), i);
280 return cls->GetName();
306 if (id < 0 || id >
fCorrections.GetEntriesFast())
return 0;
314 if (id < 0 || id >
fCorrections.GetEntriesFast())
return 0;
332 for (
Int_t id = 0;
id < n;
id++) {
334 if (what.EqualTo(c->GetName(), TString::kIgnoreCase))
return id;
345 AliWarningF(
"Cannot enable non-existing correction at %d",
id);
356 TClass* ocl = obj->IsA();
357 for (
Int_t id = 0;
id < n;
id++) {
359 if (ocl->InheritsFrom(c->
fCls))
return id;
369 AliWarningF(
"Cannot find correction with id %d",
id);
380 AliWarningF(
"Cannot find correction with id %d",
id);
420 AliInfo(
"We are already initialised - checking settings...");
426 AliWarningF(
"Initialised collision system %s (%d) and "
427 "passed same %s (%d) does not match",
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",
440 AliWarningF(
"Initialied L3 magnetic field %s (%d) and passed "
441 "same %s (%d) does not match",
447 AliWarningF(
"Initialied data type (%s) and passed "
448 "same (%s) does not match",
449 (
fMC ?
"MC" :
"real"), (mc ?
"MC" :
"real"));
453 AliWarningF(
"Initialied collision ip type (%s) and passed "
454 "same (%s) does not match",
456 (sat ?
"satellite" :
"nominal"));
460 AliWarning(
"Intialised parameters and these are not the same "
461 "- PROCEED WITH CAUTION!");
464 AliInfo(
"Initialized values consistent with data");
506 TMath::Abs(
fSNN - sNN) < 11) {
525 for (
Int_t id = 0;
id < n;
id++)
526 if (!
ReadCorrection(
id, run, sys, sNN, fld, mc, sat)) ret =
false;
547 :
TNamed(tableName, fileName),
549 fClientCls(cls->GetName()),
550 fQueryFields(fields),
560 fClientCls(o.fClientCls),
561 fQueryFields(o.fQueryFields),
562 fEnabled(o.fEnabled),
563 fLastEntry(o.fLastEntry),
571 if (&o ==
this)
return *
this;
572 SetName(o.GetName());
573 SetTitle(o.GetTitle());
597 if (!(fQueryFields &
kMC)) mc =
false;
598 if (!(fQueryFields &
kSatellite)) sat =
false;
610 if (run <= 197388 && run >= 196433) {
614 if (sNN == 27615) sNN = 2760;
624 Warning(
"OpenIt",
"No DB passed");
629 if (db->
FindTable(fName,
true))
return true;
632 if (db->
Open(fTitle, fName,
false, vrb, fallback))
return true;
635 AliWarningF(
"Failed to open table %s from %s", GetName(), GetTitle());
636 AliWarningF(
"content of %s for %s:",
637 gSystem->WorkingDirectory(), GetName());
655 AliWarningF(
"Correction %s not enabled", GetName());
663 MassageFields(run, sys, sNN, fld, mc, sat);
665 if (!OpenIt(db, vrb, fallback))
return false;
669 sys, sNN, fld, mc, sat);
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"));
682 AliWarningF(
"Entry %p \"%s\" has no data! (%p)", e, e->
GetTitle(), o);
685 const TClass* cl = TheClass();
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());
711 const char* meth)
const
715 const TClass* cl = TheClass();
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());
724 Bool_t local = file || !db;
729 if (!tdb->
Open(fileName, Form(
"%s/%s", GetName(), meth),
true,
false)) {
730 AliWarningF(
"Failed to open table %s in %s", GetName(), fileName.Data());
735 MassageFields(run, sys, sNN, fld, mc, sat);
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"));
750 AliInfoF(
"Correction object %s written to DB in %s - merge this with "
751 "%s to store for good", obj->GetName(), fileName.Data(),
763 AliWarningF(
"Correction %s not enabled", GetName());
773 AliWarningF(
"Correction %s not enabled", GetName());
783 if (fCls)
return fCls;
784 if (fClientCls.IsNull()) {
785 AliErrorF(
"No class name set for correction %s", GetName());
788 fCls = gROOT->GetClass(fClientCls);
790 AliErrorF(
"Couldn't get class %s for correction %s",
791 fClientCls.Data(), GetName());
802 gROOT->IncreaseDirLevel();
803 PFB(
"Enabled", fEnabled);
805 gROOT->DecreaseDirLevel();
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);
818 const TClass* cl = TheClass();
820 PFV(
"Path",GetTitle());
821 PFV(
"Data class", cl->GetName());
822 PFV(
"Query fields", flds);
824 if (fObject && !fLastEntry.IsNull())
PF(
"Entry", fLastEntry);
828 if (opt.Contains(
"D") && fObject) {
829 gROOT->IncreaseDirLevel();
831 gROOT->DecreaseDirLevel();
833 gROOT->DecreaseDirLevel();
840 b->Add(const_cast<TClass*>(fCls),
"Class");
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);
850 b->Add(
new TObjString(flds),
"Query fields");
852 b->Add(
new TObjString(fLastEntry),
"Entry");
853 if (fObject) b->Add(fObject);
863 if (!OpenIt(db, verb ,
false)) {
864 Warning(
"CleanIt",
"Failed to open table for %s", GetName());
871 Warning(
"CleanIt",
"Failed to get table for %s", GetName());
877 Int_t nEnt = tree->GetEntries();
883 Info(
"CleanIt",
"Looping over %d entries in tree", nEnt);
884 for (
Int_t i = 0; i < nEnt; i++) {
886 copy.SetBitNumber(i,
true);
908 MassageFields(run, sys, sNN, fld, mc, sat);
909 CorrectFields(run, sys, sNN, fld, mc, sat);
912 sys, sNN, fld, mc, sat);
914 Warning(
"CleanIt",
"Uh! didn't get an entry for %s (%d)",
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;
929 if (fld >= 0) r = -1;
935 Printf(
"%-10s (%3d %3d): %s %s",
936 (i==r ?
"copied" :
"ignored"), i, r, txt.Data(), GetName());
938 if (r != i)
continue;
942 copy.SetBitNumber(i,
true);
949 for (
Int_t i = 0; i < nEnt; i++) {
951 if (!copy.TestBitNumber(i))
continue;
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());
982 Printf(
"Copied %6d entries of %6d for %s", nCpy, nEnt, fName.Data());
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)
void SetFile(const TString &fileName)
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)
AliCorrectionManagerBase()
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)
Bool_t fDebug
do not store
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
static const char * MagneticFieldString(Short_t field)
AliCorrectionManagerBase & operator=(const AliCorrectionManagerBase &o)
void SetCorrectionFile(Int_t id, const TString &fileName) const
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
Int_t GetId(const TString &what) const
const char * GetTitle() const
virtual void Browse(TBrowser *b)
static void PrintTask(const TObject &o)
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
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="")
const TClass * TheClass() const
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
Bool_t OpenIt(AliOADBForward *db, Bool_t vrb=false, Bool_t fallback=false) const
static const char * CollisionSystemString(UShort_t sys)
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_t Open(const TString &fileName, const TString &tables="*", Bool_t rw=false, Bool_t verb=false, Bool_t fallback=false)
virtual ~AliCorrectionManagerBase()
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
void MassageFields(ULong_t &run, UShort_t &sys, UShort_t &sNN, Short_t &fld, Bool_t &mc, Bool_t &sat) const