1 #include "AliCorrectionManagerBase.h"
2 #include "AliOADBForward.h"
3 #include "AliForwardUtil.h"
10 #include <TParameter.h>
11 #include <TFileMerger.h>
13 //____________________________________________________________________
14 AliCorrectionManagerBase::AliCorrectionManagerBase()
29 //____________________________________________________________________
30 AliCorrectionManagerBase::AliCorrectionManagerBase(Bool_t)
43 fCorrections.SetOwner(false);
44 fCorrections.SetName("corrections");
46 //____________________________________________________________________
47 AliCorrectionManagerBase::AliCorrectionManagerBase(const
48 AliCorrectionManagerBase& o)
57 fSatellite(o.fSatellite),
60 fFallBack(o.fFallBack)
62 fCorrections.SetOwner(false);
63 Int_t n = o.fCorrections.GetEntriesFast();
64 for (Int_t i = 0; i < n; i++) {
65 fCorrections.AddAt(o.fCorrections.At(i), i);
68 //____________________________________________________________________
69 AliCorrectionManagerBase&
70 AliCorrectionManagerBase::operator=(const AliCorrectionManagerBase& o)
72 if (&o == this) return *this;
80 fSatellite = o.fSatellite;
83 fFallBack = o.fFallBack;
86 Int_t n = o.fCorrections.GetEntriesFast();
87 for (Int_t i = 0; i < n; i++) {
88 fCorrections.AddAt(o.fCorrections.At(i), i);
93 //____________________________________________________________________
94 AliCorrectionManagerBase::~AliCorrectionManagerBase()
96 // fCorrections.Delete();
100 AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
101 #define PFB(N,FLAG) \
103 AliForwardUtil::PrintName(N); \
104 std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
106 #define PFV(N,VALUE) \
108 AliForwardUtil::PrintName(N); \
109 std::cout << (VALUE) << std::endl; } while(false)
111 //____________________________________________________________________
113 AliCorrectionManagerBase::Print(Option_t* option) const
115 AliForwardUtil::PrintTask(*this);
116 gROOT->IncreaseDirLevel();
117 PFB("Initialized", fIsInit);
119 PFV("Run number", fRun);
120 PFV("Collision system", AliForwardUtil::CollisionSystemString(fSys));
121 PFV("Sqrt(s_NN)",AliForwardUtil::CenterOfMassEnergyString(fSNN));
122 PFV("Magnetic field", AliForwardUtil::MagneticFieldString(fField));
123 PFB("For simulations", fMC);
124 PFB("For satellites", fSatellite);
128 if (opt.Contains("R")) {
129 // gROOT->IncreaseDirLevel();
130 Int_t n = fCorrections.GetEntriesFast();
131 for (Int_t id = 0; id < n; id++) {
132 const Correction* c = GetCorrection(id);
135 // gROOT->DecreaseDirLevel();
137 gROOT->DecreaseDirLevel();
140 //____________________________________________________________________
142 AliCorrectionManagerBase::Browse(TBrowser* b)
144 b->Add(&fCorrections);
147 //____________________________________________________________________
149 AliCorrectionManagerBase::SetPrefix(const TString& prefix)
151 Int_t n = fCorrections.GetEntriesFast();
152 for (Int_t id = 0; id < n; id++) {
153 Correction* c = GetCorrection(id);
154 const char* old = c->GetTitle();
155 TString oldf(gSystem->BaseName(old));
156 c->SetFile(gSystem->ConcatFileName(prefix, oldf));
160 //____________________________________________________________________
162 AliCorrectionManagerBase::Store(TObject* o,
170 const char* meth) const
173 Int_t n = fCorrections.GetEntriesFast();
174 for (Int_t id = 0; id < n; id++) {
175 const Correction* c = GetCorrection(id);
176 if (!o->IsA()->InheritsFrom(c->fCls)) continue;
178 ret = c->StoreIt(fDB, o, runNo, sys, sNN, field, mc, sat, file, meth);
184 //____________________________________________________________________
186 AliCorrectionManagerBase::Append(const TString& addition,
187 const TString& destination) const
189 if (addition.IsNull()) {
190 AliWarning("No addition specified");
193 if (destination.IsNull()) {
194 AliWarning("No destination storage specified");
198 merger.SetPrintLevel(1);
199 merger.OutputFile(destination, "UPDATE");
200 merger.AddFile(addition);
201 if (!merger.PartialMerge()) {
202 AliInfoF("Failed to merge %s with %s",
203 addition.Data(), destination.Data());
206 if (destination.BeginsWith("$OADB_PATH") ||
207 destination.BeginsWith("$ALICE_ROOT"))
208 AliInfoF("Now commit %s to subversion", destination.Data());
212 //____________________________________________________________________
214 AliCorrectionManagerBase::EnableCorrections(UInt_t what)
216 for (Int_t i = 0; i < 32; i++) {
217 if (!GetCorrection(i)) continue;
218 EnableCorrection(i, (1 << i) & what);
221 //____________________________________________________________________
223 AliCorrectionManagerBase::CheckCorrections(UInt_t what, Bool_t verbose) const
226 for (Int_t i = 0; i < 32; i++) {
227 Bool_t enabled = (1 << i) & what;
228 if (!enabled) continue;
229 const Correction* c = GetCorrection(i);
233 AliWarningF("No correction registered for bit %d", i);
236 const TObject* o = c->Get();
240 AliWarningF("Correction %s (bit %d) not initialized!", c->GetName(), i);
247 //____________________________________________________________________
249 AliCorrectionManagerBase::RegisterCorrection(Int_t id, Correction* corr)
251 fCorrections.AddAtAndExpand(corr, id);
254 //____________________________________________________________________
256 AliCorrectionManagerBase::RegisterCorrection(Int_t id,
257 const TString& tableName,
258 const TString& fileName,
263 RegisterCorrection(id,new Correction(tableName,fileName,cls,fields,enabled));
266 //____________________________________________________________________
267 AliCorrectionManagerBase::Correction*
268 AliCorrectionManagerBase::GetCorrection(Int_t id)
270 if (id < 0 || id > fCorrections.GetEntriesFast()) return 0;
271 return static_cast<Correction*>(fCorrections.At(id));
274 //____________________________________________________________________
275 const AliCorrectionManagerBase::Correction*
276 AliCorrectionManagerBase::GetCorrection(Int_t id) const
278 if (id < 0 || id > fCorrections.GetEntriesFast()) return 0;
279 return static_cast<Correction*>(fCorrections.At(id));
282 //____________________________________________________________________
284 AliCorrectionManagerBase::SetCorrectionFile(Int_t id, const TString& fileName)
286 Correction* c = GetCorrection(id);
288 c->SetFile(fileName);
291 //____________________________________________________________________
293 AliCorrectionManagerBase::GetId(const TString& what) const
295 Int_t n = fCorrections.GetEntriesFast();
296 for (Int_t id = 0; id < n; id++) {
297 const Correction* c = GetCorrection(id);
298 if (what.EqualTo(c->GetName(), TString::kIgnoreCase)) return id;
303 //____________________________________________________________________
305 AliCorrectionManagerBase::EnableCorrection(Int_t id, Bool_t enable)
307 Correction* c = GetCorrection(id);
309 AliWarningF("Cannot enable non-existing correction at %d", id);
312 c->fEnabled = enable;
315 //____________________________________________________________________
317 AliCorrectionManagerBase::GetId(const TObject* obj) const
319 Int_t n = fCorrections.GetEntriesFast();
320 TClass* ocl = obj->IsA();
321 for (Int_t id = 0; id < n; id++) {
322 const Correction* c = GetCorrection(id);
323 if (ocl->InheritsFrom(c->fCls)) return id;
327 //____________________________________________________________________
329 AliCorrectionManagerBase::Get(Int_t id)
331 Correction* c = GetCorrection(id);
333 AliWarningF("Cannot find correction with id %d", id);
338 //____________________________________________________________________
340 AliCorrectionManagerBase::Get(Int_t id) const
342 const Correction* c = GetCorrection(id);
344 AliWarningF("Cannot find correction with id %d", id);
350 //____________________________________________________________________
352 AliCorrectionManagerBase::InitCorrections(ULong_t run,
360 if (force) fIsInit = false;
361 if (!CheckConditions(run, sys, sNN, fld, mc, sat)) return false;
362 if (!ReadCorrections(run, sys, sNN, fld, mc, sat)) return false;
373 //____________________________________________________________________
375 AliCorrectionManagerBase::CheckConditions(ULong_t run,
382 if (!fIsInit) return true;
384 AliInfo("We are already initialised - checking settings...");
390 AliWarningF("Initialised collision system %s (%d) and "
391 "passed same %s (%d) does not match",
392 AliForwardUtil::CollisionSystemString(fSys), fSys,
393 AliForwardUtil::CollisionSystemString(sys), sys);
396 if (TMath::Abs(fSNN - sNN) >= 10) {
397 AliWarningF("Initialised center of mass energy per nuclean "
398 "%s (%d) and passed same %s (%d) does not match",
399 AliForwardUtil::CenterOfMassEnergyString(fSNN), fSNN,
400 AliForwardUtil::CenterOfMassEnergyString(sNN), sNN);
404 AliWarningF("Initialied L3 magnetic field %s (%d) and passed "
405 "same %s (%d) does not match",
406 AliForwardUtil::MagneticFieldString(fField), fField,
407 AliForwardUtil::MagneticFieldString(fld), fld);
411 AliWarningF("Initialied data type (%s) and passed "
412 "same (%s) does not match",
413 (fMC ? "MC" : "real"), (mc ? "MC" : "real"));
416 if (fSatellite != sat) {
417 AliWarningF("Initialied collision ip type (%s) and passed "
418 "same (%s) does not match",
419 (fSatellite ? "satellite" : "nominal"),
420 (sat ? "satellite" : "nominal"));
424 AliWarning("Intialised parameters and these are not the same "
425 "- PROCEED WITH CAUTION!");
428 AliInfo("Initialized values consistent with data");
434 //____________________________________________________________________
436 AliCorrectionManagerBase::ReadCorrection(Int_t id,
445 // We should always open the database, since we're not
446 // streamingthat object to disk.
447 fDB = new AliOADBForward;
450 Correction* c = GetCorrection(id);
451 if (!c->fEnabled) return true;
452 return c->ReadIt(fDB, run, sys, sNN, fld, mc, sat, fDebug, fFallBack);
455 //____________________________________________________________________
457 AliCorrectionManagerBase::ReadCorrections(ULong_t run,
464 if (fIsInit) return true;
470 TMath::Abs(fSNN - sNN) < 11) {
471 // Already initialized for this - return
476 // We should always open the database, since we're not
477 // streamingthat object to disk.
478 fDB = new AliOADBForward;
487 Int_t n = fCorrections.GetEntriesFast();
489 for (Int_t id = 0; id < n; id++)
490 if (!ReadCorrection(id, run, sys, sNN, fld, mc, sat)) ret = false;
494 //====================================================================
495 AliCorrectionManagerBase::Correction::Correction()
505 //____________________________________________________________________
506 AliCorrectionManagerBase::Correction::Correction(const TString& tableName,
507 const TString& fileName,
511 : TNamed(tableName, fileName),
513 fClientCls(cls->GetName()),
514 fQueryFields(fields),
520 //____________________________________________________________________
521 AliCorrectionManagerBase::Correction::Correction(const Correction& o)
524 fClientCls(o.fClientCls),
525 fQueryFields(o.fQueryFields),
526 fEnabled(o.fEnabled),
527 fLastEntry(o.fLastEntry),
531 //____________________________________________________________________
532 AliCorrectionManagerBase::Correction&
533 AliCorrectionManagerBase::Correction::operator=(const Correction& o)
535 if (&o == this) return *this;
536 SetName(o.GetName());
537 SetTitle(o.GetTitle());
539 //fClientCls = o.fClientCls;
540 fQueryFields = o.fQueryFields;
541 fEnabled = o.fEnabled;
542 fLastEntry = o.fLastEntry;
547 //____________________________________________________________________
549 AliCorrectionManagerBase::Correction::ReadIt(AliOADBForward* db,
560 AliWarningF("Correction %s not enabled", GetName());
567 // Massage fields according to settings
568 if (!(fQueryFields & kRun)) run = kIgnoreValue;
569 if (!(fQueryFields & kSys)) sys = kIgnoreValue;
570 if (!(fQueryFields & kSNN)) sNN = kIgnoreValue;
571 if (!(fQueryFields & kField)) fld = AliOADBForward::kInvalidField; // kIgnoreField;
572 if (!(fQueryFields & kMC)) mc = false;
573 if (!(fQueryFields & kSatellite)) sat = false;
575 // Check if table is open, and if not try to open it
576 if (!db->FindTable(fName, true)) {
577 if (!db->Open(fTitle, fName, false, vrb, fallback)) {
578 AliWarningF("Failed to open table %s from %s", GetName(), GetTitle());
579 AliWarningF("content of %s for %s:",
580 gSystem->WorkingDirectory(), GetName());
581 gSystem->Exec("pwd; ls -l");
587 AliOADBForward::Entry* e = db->Get(fName, run, AliOADBForward::kDefault,
588 sys, sNN, fld, mc, sat);
589 // Check return value
590 if (!e || !e->fData) {
591 AliWarningF("Failed to get %s from database in %s with "
592 "run=%lu sys=%hu sNN=%hu fld=%hd %s %s",
593 GetName(), GetTitle(), run, sys, sNN, fld,
594 (mc ? "MC" : "real"), (sat ? "satellite" : "nominal"));
598 // Ge the returned data
599 TObject* o = e->fData;
601 const TClass* cl = TheClass();
602 // Check return class
603 if (!o->IsA()->InheritsFrom(cl)) {
604 AliWarningF("%p is not pointer to a %s object but a %s",
605 o, fCls->GetName(), o->ClassName());
611 fLastEntry = e->GetTitle();
616 //____________________________________________________________________
618 AliCorrectionManagerBase::Correction::StoreIt(AliOADBForward* db,
627 const char* meth) const
629 // Info("StoreIt", "Storing run=%lu sys=%hy sNN=%d fld=%d mc=%d sat=%d",
630 // run, sys, sNN, fld, mc, sat);
631 const TClass* cl = TheClass();
634 if (!obj->IsA()->InheritsFrom(cl)) {
635 AliWarningF("%p is not pointer to a %s object but a %s",
636 obj, cl->GetName(), obj->ClassName());
640 Bool_t local = file || !db;
641 TString fileName = (local ? file : fTitle.Data());
642 AliOADBForward* tdb = (local ? new AliOADBForward : db);
644 // Try to open the table read/write
645 if (!tdb->Open(fileName, Form("%s/%s", GetName(), meth), true, true)) {
646 AliWarningF("Failed to open table %s in %s", GetName(), fileName.Data());
650 // Massage fields according to settings
651 if (!(fQueryFields & kRun)) run = kIgnoreValue;
652 if (!(fQueryFields & kSys)) sys = kIgnoreValue;
653 if (!(fQueryFields & kSNN)) sNN = kIgnoreValue;
654 if (!(fQueryFields & kField)) fld = AliOADBForward::kInvalidField; // kIgnoreField;
655 if (!(fQueryFields & kMC)) mc = false;
656 if (!(fQueryFields & kSatellite)) sat = false;
658 // Try to insert the object
659 if (!tdb->Insert(fName, obj, run, sys, sNN, fld, mc, sat)) {
660 AliWarningF("Failed to insert into %s off database in %s with "
661 "run=%lu sys=%hu sNN=%hu fld=%hd %s %s",
662 GetName(), GetTitle(), run, sys, sNN, fld,
663 (mc ? "MC" : "real"), (sat ? "satellite" : "nominal"));
671 AliInfoF("Correction object %s written to DB in %s - merge this with "
672 "%s to store for good", obj->GetName(), fileName.Data(),
679 //____________________________________________________________________
681 AliCorrectionManagerBase::Correction::Get()
684 AliWarningF("Correction %s not enabled", GetName());
689 //____________________________________________________________________
691 AliCorrectionManagerBase::Correction::Get() const
694 AliWarningF("Correction %s not enabled", GetName());
700 //____________________________________________________________________
702 AliCorrectionManagerBase::Correction::TheClass() const
704 if (fCls) return fCls;
705 if (fClientCls.IsNull()) {
706 AliErrorF("No class name set for correction %s", GetName());
709 fCls = gROOT->GetClass(fClientCls);
711 AliErrorF("Couldn't get class %s for correction %s",
712 fClientCls.Data(), GetName());
718 //____________________________________________________________________
720 AliCorrectionManagerBase::Correction::Print(Option_t* option) const
722 AliForwardUtil::PrintTask(*this);
723 gROOT->IncreaseDirLevel();
724 PFB("Enabled", fEnabled);
726 gROOT->DecreaseDirLevel();
731 if (fQueryFields & kRun) flds.Append("run");
732 if (fQueryFields & kSys) flds.Append("|sys");
733 if (fQueryFields & kSNN) flds.Append("|sNN");
734 if (fQueryFields & kField) flds.Append("|field");
735 if (fQueryFields & kMC) flds.Append("|MC");
736 if (fQueryFields & kSatellite) flds.Append("|Satellite");
737 if (flds.BeginsWith("|")) flds.Remove(0,1);
739 const TClass* cl = TheClass();
741 PFV("Path",GetTitle());
742 PFV("Data class", cl->GetName());
743 PFV("Query fields", flds);
745 if (fObject && !fLastEntry.IsNull()) PF("Entry", fLastEntry);
749 if (opt.Contains("D") && fObject) {
750 gROOT->IncreaseDirLevel();
752 gROOT->DecreaseDirLevel();
754 gROOT->DecreaseDirLevel();
757 //____________________________________________________________________
759 AliCorrectionManagerBase::Correction::Browse(TBrowser* b)
761 b->Add(const_cast<TClass*>(fCls), "Class");
763 if (fQueryFields & kRun) flds.Append("run");
764 if (fQueryFields & kSys) flds.Append("|sys");
765 if (fQueryFields & kSNN) flds.Append("|sNN");
766 if (fQueryFields & kField) flds.Append("|field");
767 if (fQueryFields & kMC) flds.Append("|MC");
768 if (fQueryFields & kSatellite) flds.Append("|Satellite");
769 if (flds.BeginsWith("|")) flds.Remove(0,1);
771 b->Add(new TObjString(flds), "Query fields");
772 b->Add(new TParameter<bool>("Enabled", fEnabled));
773 b->Add(new TObjString(fLastEntry), "Entry");
774 if (fObject) b->Add(fObject);