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();
99 //____________________________________________________________________
101 AliCorrectionManagerBase::Print(Option_t* option) const
103 char ind[gROOT->GetDirLevel()+1];
104 for (Int_t i = 0; i < gROOT->GetDirLevel(); i++) ind[i] = ' ';
105 ind[gROOT->GetDirLevel()] = '\0';
107 std::cout << ind << GetName() << ":\n"
108 << ind << " Initialised: "
109 << (fIsInit ? "yes" : "no") << std::endl;
111 std::cout << ind << " Run number: " << fRun << "\n"
112 << ind << " Collision system: "
113 << AliForwardUtil::CollisionSystemString(fSys) << "\n"
114 << ind << " Sqrt(s_NN): "
115 << AliForwardUtil::CenterOfMassEnergyString(fSNN) << "\n"
116 << ind << " Magnetic field: "
117 << AliForwardUtil::MagneticFieldString(fField) << "\n"
118 << ind << " For simulations: " << (fMC ? "yes" : "no") << "\n"
119 << ind << " For satellites: "
120 << (fSatellite ? "yes" : "no") << std::endl;
124 if (!opt.Contains("R")) return;
126 gROOT->IncreaseDirLevel();
127 Int_t n = fCorrections.GetEntriesFast();
128 for (Int_t id = 0; id < n; id++) {
129 const Correction* c = GetCorrection(id);
132 gROOT->DecreaseDirLevel();
136 //____________________________________________________________________
138 AliCorrectionManagerBase::Browse(TBrowser* b)
140 b->Add(&fCorrections);
143 //____________________________________________________________________
145 AliCorrectionManagerBase::SetPrefix(const TString& prefix)
147 Int_t n = fCorrections.GetEntriesFast();
148 for (Int_t id = 0; id < n; id++) {
149 Correction* c = GetCorrection(id);
150 const char* old = c->GetTitle();
151 TString oldf(gSystem->BaseName(old));
152 c->SetFile(gSystem->ConcatFileName(prefix, oldf));
156 //____________________________________________________________________
158 AliCorrectionManagerBase::Store(TObject* o,
166 const char* meth) const
169 Int_t n = fCorrections.GetEntriesFast();
170 for (Int_t id = 0; id < n; id++) {
171 const Correction* c = GetCorrection(id);
172 if (!o->IsA()->InheritsFrom(c->fCls)) continue;
174 ret = c->StoreIt(fDB, o, runNo, sys, sNN, field, mc, sat, file, meth);
180 //____________________________________________________________________
182 AliCorrectionManagerBase::Append(const TString& addition,
183 const TString& destination) const
185 if (addition.IsNull()) {
186 AliWarning("No addition specified");
189 if (destination.IsNull()) {
190 AliWarning("No destination storage specified");
194 merger.SetPrintLevel(1);
195 merger.OutputFile(destination, "UPDATE");
196 merger.AddFile(addition);
197 if (!merger.PartialMerge()) {
198 AliInfoF("Failed to merge %s with %s",
199 addition.Data(), destination.Data());
202 if (destination.BeginsWith("$OADB_PATH") ||
203 destination.BeginsWith("$ALICE_ROOT"))
204 AliInfoF("Now commit %s to subversion", destination.Data());
208 //____________________________________________________________________
210 AliCorrectionManagerBase::RegisterCorrection(Int_t id, Correction* corr)
212 fCorrections.AddAtAndExpand(corr, id);
215 //____________________________________________________________________
217 AliCorrectionManagerBase::RegisterCorrection(Int_t id,
218 const TString& tableName,
219 const TString& fileName,
224 RegisterCorrection(id,new Correction(tableName,fileName,cls,fields,enabled));
227 //____________________________________________________________________
228 AliCorrectionManagerBase::Correction*
229 AliCorrectionManagerBase::GetCorrection(Int_t id)
231 if (id < 0 || id > fCorrections.GetEntriesFast()) return 0;
232 return static_cast<Correction*>(fCorrections.At(id));
235 //____________________________________________________________________
236 const AliCorrectionManagerBase::Correction*
237 AliCorrectionManagerBase::GetCorrection(Int_t id) const
239 if (id < 0 || id > fCorrections.GetEntriesFast()) return 0;
240 return static_cast<Correction*>(fCorrections.At(id));
243 //____________________________________________________________________
245 AliCorrectionManagerBase::SetCorrectionFile(Int_t id, const TString& fileName)
247 Correction* c = GetCorrection(id);
249 c->SetFile(fileName);
252 //____________________________________________________________________
254 AliCorrectionManagerBase::GetId(const TString& what) const
256 Int_t n = fCorrections.GetEntriesFast();
257 for (Int_t id = 0; id < n; id++) {
258 const Correction* c = GetCorrection(id);
259 if (what.EqualTo(c->GetName(), TString::kIgnoreCase)) return id;
264 //____________________________________________________________________
266 AliCorrectionManagerBase::EnableCorrection(Int_t id, Bool_t enable)
268 Correction* c = GetCorrection(id);
270 AliWarningF("Cannot enable non-existing correction at %d", id);
273 c->fEnabled = enable;
276 //____________________________________________________________________
278 AliCorrectionManagerBase::GetId(const TObject* obj) const
280 Int_t n = fCorrections.GetEntriesFast();
281 TClass* ocl = obj->IsA();
282 for (Int_t id = 0; id < n; id++) {
283 const Correction* c = GetCorrection(id);
284 if (ocl->InheritsFrom(c->fCls)) return id;
288 //____________________________________________________________________
290 AliCorrectionManagerBase::Get(Int_t id)
292 Correction* c = GetCorrection(id);
294 AliWarningF("Cannot find correction with id %d", id);
299 //____________________________________________________________________
301 AliCorrectionManagerBase::Get(Int_t id) const
303 const Correction* c = GetCorrection(id);
305 AliWarningF("Cannot find correction with id %d", id);
311 //____________________________________________________________________
313 AliCorrectionManagerBase::InitCorrections(ULong_t run,
321 if (force) fIsInit = false;
322 if (!CheckConditions(run, sys, sNN, fld, mc, sat)) return false;
323 if (!ReadCorrections(run, sys, sNN, fld, mc, sat)) return false;
334 //____________________________________________________________________
336 AliCorrectionManagerBase::CheckConditions(ULong_t run,
343 if (!fIsInit) return true;
345 AliInfo("We are already initialised - checking settings...");
351 AliWarningF("Initialised collision system %s (%d) and "
352 "passed same %s (%d) does not match",
353 AliForwardUtil::CollisionSystemString(fSys), fSys,
354 AliForwardUtil::CollisionSystemString(sys), sys);
357 if (TMath::Abs(fSNN - sNN) >= 10) {
358 AliWarningF("Initialised center of mass energy per nuclean "
359 "%s (%d) and passed same %s (%d) does not match",
360 AliForwardUtil::CenterOfMassEnergyString(fSNN), fSNN,
361 AliForwardUtil::CenterOfMassEnergyString(sNN), sNN);
365 AliWarningF("Initialied L3 magnetic field %s (%d) and passed "
366 "same %s (%d) does not match",
367 AliForwardUtil::MagneticFieldString(fField), fField,
368 AliForwardUtil::MagneticFieldString(fld), fld);
372 AliWarningF("Initialied data type (%s) and passed "
373 "same (%s) does not match",
374 (fMC ? "MC" : "real"), (mc ? "MC" : "real"));
377 if (fSatellite != sat) {
378 AliWarningF("Initialied collision ip type (%s) and passed "
379 "same (%s) does not match",
380 (fSatellite ? "satellite" : "nominal"),
381 (sat ? "satellite" : "nominal"));
385 AliWarning("Intialised parameters and these are not the same "
386 "- PROCEED WITH CAUTION!");
389 AliInfo("Initialized values consistent with data");
395 //____________________________________________________________________
397 AliCorrectionManagerBase::ReadCorrection(Int_t id,
406 // We should always open the database, since we're not
407 // streamingthat object to disk.
408 fDB = new AliOADBForward;
411 Correction* c = GetCorrection(id);
412 if (!c->fEnabled) return true;
413 return c->ReadIt(fDB, run, sys, sNN, fld, mc, sat, fDebug, fFallBack);
416 //____________________________________________________________________
418 AliCorrectionManagerBase::ReadCorrections(ULong_t run,
425 if (fIsInit) return true;
431 TMath::Abs(fSNN - sNN) < 11) {
432 // Already initialized for this - return
437 // We should always open the database, since we're not
438 // streamingthat object to disk.
439 fDB = new AliOADBForward;
448 Int_t n = fCorrections.GetEntriesFast();
450 for (Int_t id = 0; id < n; id++)
451 if (!ReadCorrection(id, run, sys, sNN, fld, mc, sat)) ret = false;
455 //====================================================================
456 AliCorrectionManagerBase::Correction::Correction()
466 //____________________________________________________________________
467 AliCorrectionManagerBase::Correction::Correction(const TString& tableName,
468 const TString& fileName,
472 : TNamed(tableName, fileName),
474 fClientCls(cls->GetName()),
475 fQueryFields(fields),
481 //____________________________________________________________________
482 AliCorrectionManagerBase::Correction::Correction(const Correction& o)
485 fClientCls(o.fClientCls),
486 fQueryFields(o.fQueryFields),
487 fEnabled(o.fEnabled),
488 fLastEntry(o.fLastEntry),
492 //____________________________________________________________________
493 AliCorrectionManagerBase::Correction&
494 AliCorrectionManagerBase::Correction::operator=(const Correction& o)
496 if (&o == this) return *this;
497 SetName(o.GetName());
498 SetTitle(o.GetTitle());
500 //fClientCls = o.fClientCls;
501 fQueryFields = o.fQueryFields;
502 fEnabled = o.fEnabled;
503 fLastEntry = o.fLastEntry;
508 //____________________________________________________________________
510 AliCorrectionManagerBase::Correction::ReadIt(AliOADBForward* db,
521 AliWarningF("Correction %s not enabled", GetName());
528 // Massage fields according to settings
529 if (!(fQueryFields & kRun)) run = kIgnoreValue;
530 if (!(fQueryFields & kSys)) sys = kIgnoreValue;
531 if (!(fQueryFields & kSNN)) sNN = kIgnoreValue;
532 if (!(fQueryFields & kField)) fld = AliOADBForward::kInvalidField; // kIgnoreField;
533 if (!(fQueryFields & kMC)) mc = false;
534 if (!(fQueryFields & kSatellite)) sat = false;
536 // Check if table is open, and if not try to open it
537 if (!db->FindTable(fName, true)) {
538 if (!db->Open(fTitle, fName, false, vrb, fallback)) {
539 AliWarningF("Failed to open table %s from %s", GetName(), GetTitle());
540 AliWarningF("content of %s for %s:",
541 gSystem->WorkingDirectory(), GetName());
542 gSystem->Exec("pwd; ls -l");
548 AliOADBForward::Entry* e = db->Get(fName, run, AliOADBForward::kDefault,
549 sys, sNN, fld, mc, sat);
550 // Check return value
551 if (!e || !e->fData) {
552 AliWarningF("Failed to get %s from database in %s with "
553 "run=%lu sys=%hu sNN=%hu fld=%hd %s %s",
554 GetName(), GetTitle(), run, sys, sNN, fld,
555 (mc ? "MC" : "real"), (sat ? "satellite" : "nominal"));
559 // Ge the returned data
560 TObject* o = e->fData;
562 const TClass* cl = TheClass();
563 // Check return class
564 if (!o->IsA()->InheritsFrom(cl)) {
565 AliWarningF("%p is not pointer to a %s object but a %s",
566 o, fCls->GetName(), o->ClassName());
572 fLastEntry = e->GetTitle();
577 //____________________________________________________________________
579 AliCorrectionManagerBase::Correction::StoreIt(AliOADBForward* db,
588 const char* meth) const
590 // Info("StoreIt", "Storing run=%lu sys=%hy sNN=%d fld=%d mc=%d sat=%d",
591 // run, sys, sNN, fld, mc, sat);
592 const TClass* cl = TheClass();
595 if (!obj->IsA()->InheritsFrom(cl)) {
596 AliWarningF("%p is not pointer to a %s object but a %s",
597 obj, cl->GetName(), obj->ClassName());
601 Bool_t local = file || !db;
602 TString fileName = (local ? file : fTitle.Data());
603 AliOADBForward* tdb = (local ? new AliOADBForward : db);
605 // Try to open the table read/write
606 if (!tdb->Open(fileName, Form("%s/%s", GetName(), meth), true, true)) {
607 AliWarningF("Failed to open table %s in %s", GetName(), fileName.Data());
611 // Massage fields according to settings
612 if (!(fQueryFields & kRun)) run = kIgnoreValue;
613 if (!(fQueryFields & kSys)) sys = kIgnoreValue;
614 if (!(fQueryFields & kSNN)) sNN = kIgnoreValue;
615 if (!(fQueryFields & kField)) fld = AliOADBForward::kInvalidField; // kIgnoreField;
616 if (!(fQueryFields & kMC)) mc = false;
617 if (!(fQueryFields & kSatellite)) sat = false;
619 // Try to insert the object
620 if (!tdb->Insert(fName, obj, run, sys, sNN, fld, mc, sat)) {
621 AliWarningF("Failed to insert into %s off database in %s with "
622 "run=%lu sys=%hu sNN=%hu fld=%hd %s %s",
623 GetName(), GetTitle(), run, sys, sNN, fld,
624 (mc ? "MC" : "real"), (sat ? "satellite" : "nominal"));
632 AliInfoF("Correction object %s written to DB in %s - merge this with "
633 "%s to store for good", obj->GetName(), fileName.Data(),
640 //____________________________________________________________________
642 AliCorrectionManagerBase::Correction::Get()
645 AliWarningF("Correction %s not enabled", GetName());
650 //____________________________________________________________________
652 AliCorrectionManagerBase::Correction::Get() const
655 AliWarningF("Correction %s not enabled", GetName());
661 //____________________________________________________________________
663 AliCorrectionManagerBase::Correction::TheClass() const
665 if (fCls) return fCls;
666 if (fClientCls.IsNull()) {
667 AliErrorF("No class name set for correction %s", GetName());
670 fCls = gROOT->GetClass(fClientCls);
672 AliErrorF("Couldn't get class %s for correction %s",
673 fClientCls.Data(), GetName());
679 //____________________________________________________________________
681 AliCorrectionManagerBase::Correction::Print(Option_t* option) const
683 char ind[gROOT->GetDirLevel()+1];
684 for (Int_t i = 0; i < gROOT->GetDirLevel(); i++) ind[i] = ' ';
685 ind[gROOT->GetDirLevel()] = '\0';
687 std::cout << ind << GetName() << ": " << (fEnabled ? "en" : "dis")
688 << "abled" << std::endl;
689 if (!fEnabled) return;
692 if (fQueryFields & kRun) flds.Append("run");
693 if (fQueryFields & kSys) flds.Append("|sys");
694 if (fQueryFields & kSNN) flds.Append("|sNN");
695 if (fQueryFields & kField) flds.Append("|field");
696 if (fQueryFields & kMC) flds.Append("|MC");
697 if (fQueryFields & kSatellite) flds.Append("|Satellite");
698 if (flds.BeginsWith("|")) flds.Remove(0,1);
700 const TClass* cl = TheClass();
702 std::cout << " Path: " << GetTitle() << "\n"
703 << " Data class: " << cl->GetName() << "\n"
704 << " Query fields: " << flds << std::endl;
706 if (fObject && !fLastEntry.IsNull())
707 std::cout << " Entry: " << fLastEntry << std::endl;
711 if (!opt.Contains("D") || !fObject) return;
713 gROOT->IncreaseDirLevel();
715 gROOT->DecreaseDirLevel();
718 //____________________________________________________________________
720 AliCorrectionManagerBase::Correction::Browse(TBrowser* b)
722 b->Add(const_cast<TClass*>(fCls), "Class");
724 if (fQueryFields & kRun) flds.Append("run");
725 if (fQueryFields & kSys) flds.Append("|sys");
726 if (fQueryFields & kSNN) flds.Append("|sNN");
727 if (fQueryFields & kField) flds.Append("|field");
728 if (fQueryFields & kMC) flds.Append("|MC");
729 if (fQueryFields & kSatellite) flds.Append("|Satellite");
730 if (flds.BeginsWith("|")) flds.Remove(0,1);
732 b->Add(new TObjString(flds), "Query fields");
733 b->Add(new TParameter<bool>("Enabled", fEnabled));
734 b->Add(new TObjString(fLastEntry), "Entry");
735 if (fObject) b->Add(fObject);