]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGLF/FORWARD/analysis2/AliCorrectionManagerBase.cxx
Minor fixes
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliCorrectionManagerBase.cxx
index 35e80273df9a7b97295ff8b088d424edab847949..6e71b9f6097258dbf1f421aa1ee3ad13836ab30a 100644 (file)
@@ -21,7 +21,8 @@ AliCorrectionManagerBase::AliCorrectionManagerBase()
     fMC(false), 
     fSatellite(false), 
     fDB(0),
-    fDebug(false)
+    fDebug(false),
+    fFallBack(false)
 {
 }
 
@@ -36,7 +37,8 @@ AliCorrectionManagerBase::AliCorrectionManagerBase(Bool_t)
     fMC(false), 
     fSatellite(false), 
     fDB(0),
-    fDebug(false)
+    fDebug(false),
+    fFallBack(false)
 {
   fCorrections.SetOwner(false);
   fCorrections.SetName("corrections");
@@ -54,7 +56,8 @@ AliCorrectionManagerBase::AliCorrectionManagerBase(const
     fMC(o.fMC), 
     fSatellite(o.fSatellite), 
     fDB(o.fDB),
-    fDebug(o.fDebug)
+    fDebug(o.fDebug),
+    fFallBack(o.fFallBack)
 {
   fCorrections.SetOwner(false);
   Int_t n = o.fCorrections.GetEntriesFast();
@@ -77,6 +80,7 @@ AliCorrectionManagerBase::operator=(const AliCorrectionManagerBase& o)
   fSatellite   = o.fSatellite;
   fDB          = o.fDB;
   fDebug        = o.fDebug;
+  fFallBack     = o.fFallBack;
 
   fCorrections.Clear();
   Int_t n = o.fCorrections.GetEntriesFast();
@@ -92,41 +96,45 @@ AliCorrectionManagerBase::~AliCorrectionManagerBase()
   // fCorrections.Delete();
 }
 
+#define PF(N,V,...)                                    \
+  AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
+#define PFB(N,FLAG)                            \
+  do {                                                                 \
+    AliForwardUtil::PrintName(N);                                      \
+    std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
+  } while(false)
+#define PFV(N,VALUE)                                   \
+  do {                                                 \
+    AliForwardUtil::PrintName(N);                      \
+    std::cout << (VALUE) << std::endl; } while(false)
+
 //____________________________________________________________________
 void
 AliCorrectionManagerBase::Print(Option_t* option) const
 {
-  char ind[gROOT->GetDirLevel()+1];
-  for (Int_t i = 0; i < gROOT->GetDirLevel(); i++) ind[i] = ' ';
-  ind[gROOT->GetDirLevel()] = '\0';
-
-  std::cout << ind << GetName() << ":\n"
-           << ind << "  Initialised:      " 
-           << (fIsInit ? "yes" : "no") << std::endl;
-  if (fIsInit) 
-    std::cout << ind << "  Run number:       " << fRun << "\n"
-             << ind << "  Collision system: " 
-             << AliForwardUtil::CollisionSystemString(fSys) << "\n"
-             << ind << "  Sqrt(s_NN):       "
-             << AliForwardUtil::CenterOfMassEnergyString(fSNN) << "\n"
-             << ind << "  Magnetic field:   " 
-             << AliForwardUtil::MagneticFieldString(fField) << "\n"
-             << ind << "  For simulations:  " << (fMC ? "yes" : "no") << "\n"
-             << ind << "  For satellites:   " 
-             << (fSatellite ? "yes" : "no") << std::endl;
-
+  AliForwardUtil::PrintTask(*this);
+  gROOT->IncreaseDirLevel();
+  PFB("Initialized", fIsInit);
+  if (fIsInit) {
+    PFV("Run number", fRun);
+    PFV("Collision system", AliForwardUtil::CollisionSystemString(fSys));
+    PFV("Sqrt(s_NN)",AliForwardUtil::CenterOfMassEnergyString(fSNN));
+    PFV("Magnetic field", AliForwardUtil::MagneticFieldString(fField));
+    PFB("For simulations", fMC);
+    PFB("For satellites", fSatellite);
+  }
   TString opt(option);
   opt.ToUpper();
-  if (!opt.Contains("R")) return;
-  
-  gROOT->IncreaseDirLevel();
-  Int_t n = fCorrections.GetEntriesFast();
-  for (Int_t id = 0; id < n; id++) { 
-    const Correction* c = GetCorrection(id);
-    c->Print(option);
+  if (opt.Contains("R")) {
+    // gROOT->IncreaseDirLevel();
+    Int_t n = fCorrections.GetEntriesFast();
+    for (Int_t id = 0; id < n; id++) { 
+      const Correction* c = GetCorrection(id);
+      c->Print(option);
+    }
+    // gROOT->DecreaseDirLevel();  
   }
   gROOT->DecreaseDirLevel();  
-  
 }
 
 //____________________________________________________________________
@@ -201,6 +209,41 @@ AliCorrectionManagerBase::Append(const TString& addition,
   return true;
 }
   
+//____________________________________________________________________
+void
+AliCorrectionManagerBase::EnableCorrections(UInt_t what)
+{
+  for (Int_t i = 0; i < 32; i++) {
+    if (!GetCorrection(i)) continue;
+    EnableCorrection(i, (1 << i) & what);
+  }
+}
+//____________________________________________________________________
+Bool_t
+AliCorrectionManagerBase::CheckCorrections(UInt_t what, Bool_t verbose) const
+{
+  Bool_t ret = true;
+  for (Int_t i = 0; i < 32; i++) {
+    Bool_t enabled = (1 << i) & what;
+    if (!enabled) continue;
+    const Correction* c = GetCorrection(i);
+    if (!c) {
+      ret = false;
+      if (verbose) 
+       AliWarningF("No correction registered for bit %d", i);
+      continue;
+    }
+    const TObject* o = c->Get();
+    if (!o) { 
+      ret = false;
+      if (verbose) 
+       AliWarningF("Correction %s (bit %d) not initialized!", c->GetName(), i);
+      continue;
+    }
+  }
+  return ret;
+}
+
 //____________________________________________________________________
 void
 AliCorrectionManagerBase::RegisterCorrection(Int_t id, Correction* corr)
@@ -406,7 +449,7 @@ AliCorrectionManagerBase::ReadCorrection(Int_t      id,
 
   Correction* c = GetCorrection(id);
   if (!c->fEnabled) return true;
-  return c->ReadIt(fDB, run, sys, sNN, fld, mc, sat, fDebug);
+  return c->ReadIt(fDB, run, sys, sNN, fld, mc, sat, fDebug, fFallBack);
 }
 
 //____________________________________________________________________
@@ -510,7 +553,8 @@ AliCorrectionManagerBase::Correction::ReadIt(AliOADBForward* db,
                                             Short_t         fld, 
                                             Bool_t          mc, 
                                             Bool_t          sat,
-                                            Bool_t          vrb)
+                                            Bool_t          vrb,
+                                            Bool_t          fallback)
 {
   if (!fEnabled) {
     AliWarningF("Correction %s not enabled", GetName());
@@ -524,13 +568,13 @@ AliCorrectionManagerBase::Correction::ReadIt(AliOADBForward* db,
   if (!(fQueryFields & kRun))       run = kIgnoreValue;
   if (!(fQueryFields & kSys))       sys = kIgnoreValue;
   if (!(fQueryFields & kSNN))       sNN = kIgnoreValue;
-  if (!(fQueryFields & kField))     fld = kIgnoreField;
+  if (!(fQueryFields & kField))     fld = AliOADBForward::kInvalidField; // kIgnoreField;
   if (!(fQueryFields & kMC))        mc  = false;
   if (!(fQueryFields & kSatellite)) sat = false;
 
   // Check if table is open, and if not try to open it 
   if (!db->FindTable(fName, true)) {
-    if (!db->Open(fTitle, fName, false, vrb)) {
+    if (!db->Open(fTitle, fName, false, vrb, fallback)) {
       AliWarningF("Failed to open table %s from %s", GetName(), GetTitle());
       AliWarningF("content of %s for %s:", 
                  gSystem->WorkingDirectory(), GetName());
@@ -607,7 +651,7 @@ AliCorrectionManagerBase::Correction::StoreIt(AliOADBForward* db,
   if (!(fQueryFields & kRun))       run = kIgnoreValue;
   if (!(fQueryFields & kSys))       sys = kIgnoreValue;
   if (!(fQueryFields & kSNN))       sNN = kIgnoreValue;
-  if (!(fQueryFields & kField))     fld = kIgnoreField;
+  if (!(fQueryFields & kField))     fld = AliOADBForward::kInvalidField; // kIgnoreField;
   if (!(fQueryFields & kMC))        mc  = false;
   if (!(fQueryFields & kSatellite)) sat = false;
   
@@ -675,13 +719,13 @@ AliCorrectionManagerBase::Correction::TheClass() const
 void
 AliCorrectionManagerBase::Correction::Print(Option_t* option) const
 {
-  char ind[gROOT->GetDirLevel()+1];
-  for (Int_t i = 0; i < gROOT->GetDirLevel(); i++) ind[i] = ' ';
-  ind[gROOT->GetDirLevel()] = '\0';
-
-  std::cout << ind << GetName() << ":  " << (fEnabled ? "en" : "dis") 
-           << "abled" << std::endl;
-  if (!fEnabled) return;
+  AliForwardUtil::PrintTask(*this);
+  gROOT->IncreaseDirLevel();
+  PFB("Enabled", fEnabled);
+  if (!fEnabled) {
+    gROOT->DecreaseDirLevel();
+    return;
+  }
 
   TString flds;
   if (fQueryFields & kRun)       flds.Append("run");
@@ -694,19 +738,19 @@ AliCorrectionManagerBase::Correction::Print(Option_t* option) const
 
   const TClass* cl = TheClass();
 
-  std::cout << "   Path:            " << GetTitle() << "\n"
-           << "   Data class:      " << cl->GetName() << "\n"
-           << "   Query fields:    " << flds << std::endl;
+  PFV("Path",GetTitle());
+  PFV("Data class", cl->GetName());
+  PFV("Query fields", flds);
   
-  if (fObject && !fLastEntry.IsNull()) 
-    std::cout << "   Entry:           " << fLastEntry << std::endl;
+  if (fObject && !fLastEntry.IsNull())  PF("Entry", fLastEntry);
   
   TString opt(option);
   opt.ToUpper();
-  if (!opt.Contains("D")) return;
-
-  gROOT->IncreaseDirLevel();
-  fObject->Print();
+  if (opt.Contains("D") && fObject) {
+    gROOT->IncreaseDirLevel();
+    fObject->Print();
+    gROOT->DecreaseDirLevel();
+  }
   gROOT->DecreaseDirLevel();
 }