#include <TBrowser.h>
#include <TParameter.h>
#include <TFileMerger.h>
+#include <TBits.h>
+#include <TTree.h>
//____________________________________________________________________
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();
-
}
//____________________________________________________________________
}
if (destination.BeginsWith("$OADB_PATH") ||
destination.BeginsWith("$ALICE_ROOT"))
- AliInfoF("Now commit %s to subversion", destination.Data());
+ AliInfoF("Now commit %s to git", destination.Data());
+ return true;
+}
+//____________________________________________________________________
+Bool_t
+AliCorrectionManagerBase::CleanUp(const TString& destination, Bool_t verb) const
+{
+ AliOADBForward* db = fDB;
+ if (!db) db = new AliOADBForward;
+
+ for (Int_t i = 0; i < 32; i++) {
+ const Correction* c = GetCorrection(i);
+ if (!c) continue;
+
+ if (!c->fEnabled) {
+ Info("CleanUp", "Table %s not enabled", c->GetName());
+ continue;
+ }
+ Info("CleanUp", "Will clean up table %s", c->GetName());
+ c->CleanIt(db, destination, verb);
+ }
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)
return *this;
}
+//____________________________________________________________________
+void
+AliCorrectionManagerBase::Correction::MassageFields(ULong_t& run,
+ UShort_t& sys,
+ UShort_t& sNN,
+ Short_t & fld,
+ Bool_t& mc,
+ Bool_t& sat) const
+{
+ // Massage fields according to settings
+ if (!(fQueryFields & kRun)) run = kIgnoreValue;
+ if (!(fQueryFields & kSys)) sys = kIgnoreValue;
+ if (!(fQueryFields & kSNN)) sNN = kIgnoreValue;
+ if (!(fQueryFields & kField)) fld = AliOADBForward::kInvalidField;
+ if (!(fQueryFields & kMC)) mc = false;
+ if (!(fQueryFields & kSatellite)) sat = false;
+}
+
+//____________________________________________________________________
+Bool_t
+AliCorrectionManagerBase::Correction::OpenIt(AliOADBForward* db,
+ Bool_t vrb,
+ Bool_t fallback) const
+{
+ if (!db) {
+ Warning("OpenIt", "No DB passed");
+ return false;
+ }
+
+ // Check if table is open
+ if (db->FindTable(fName, true)) return true;
+
+ // if not try to open it
+ if (db->Open(fTitle, fName, false, vrb, fallback)) return true;
+
+ // Give warning
+ AliWarningF("Failed to open table %s from %s", GetName(), GetTitle());
+ AliWarningF("content of %s for %s:",
+ gSystem->WorkingDirectory(), GetName());
+ gSystem->Exec("pwd; ls -l");
+ return false;
+}
+
//____________________________________________________________________
Bool_t
AliCorrectionManagerBase::Correction::ReadIt(AliOADBForward* db,
fObject = 0;
// Massage fields according to settings
- if (!(fQueryFields & kRun)) run = kIgnoreValue;
- if (!(fQueryFields & kSys)) sys = kIgnoreValue;
- if (!(fQueryFields & kSNN)) sNN = kIgnoreValue;
- if (!(fQueryFields & kField)) fld = AliOADBForward::kInvalidField; // kIgnoreField;
- if (!(fQueryFields & kMC)) mc = false;
- if (!(fQueryFields & kSatellite)) sat = false;
+ MassageFields(run, sys, sNN, fld, mc, sat);
+
+ if (!OpenIt(db, vrb, fallback)) return 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, fallback)) {
- AliWarningF("Failed to open table %s from %s", GetName(), GetTitle());
- AliWarningF("content of %s for %s:",
- gSystem->WorkingDirectory(), GetName());
- gSystem->Exec("pwd; ls -l");
- return false;
- }
- }
-
// Query database
AliOADBForward::Entry* e = db->Get(fName, run, AliOADBForward::kDefault,
sys, sNN, fld, mc, sat);
AliOADBForward* tdb = (local ? new AliOADBForward : db);
// Try to open the table read/write
- if (!tdb->Open(fileName, Form("%s/%s", GetName(), meth), true, true)) {
+ if (!tdb->Open(fileName, Form("%s/%s", GetName(), meth), true, false)) {
AliWarningF("Failed to open table %s in %s", GetName(), fileName.Data());
return false;
}
// Massage fields according to settings
- if (!(fQueryFields & kRun)) run = kIgnoreValue;
- if (!(fQueryFields & kSys)) sys = kIgnoreValue;
- if (!(fQueryFields & kSNN)) sNN = kIgnoreValue;
- if (!(fQueryFields & kField)) fld = AliOADBForward::kInvalidField; // kIgnoreField;
- if (!(fQueryFields & kMC)) mc = false;
- if (!(fQueryFields & kSatellite)) sat = false;
+ MassageFields(run, sys, sNN, fld, mc, sat);
// Try to insert the object
if (!tdb->Insert(fName, obj, run, sys, sNN, fld, mc, sat)) {
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");
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") || !fObject) return;
-
- gROOT->IncreaseDirLevel();
- fObject->Print();
+ if (opt.Contains("D") && fObject) {
+ gROOT->IncreaseDirLevel();
+ fObject->Print();
+ gROOT->DecreaseDirLevel();
+ }
gROOT->DecreaseDirLevel();
}
b->Add(new TObjString(fLastEntry), "Entry");
if (fObject) b->Add(fObject);
}
+//____________________________________________________________________
+Bool_t
+AliCorrectionManagerBase::Correction::CleanIt(AliOADBForward* db,
+ const TString& dest,
+ Bool_t verb) const
+{
+ // Open the table for this correction
+ if (!OpenIt(db, verb , false)) {
+ Warning("CleanIt", "Failed to open table for %s", GetName());
+ return false;
+ }
+
+ // Get our table - should be here if the above succeeded
+ AliOADBForward::Table* t = db->FindTable(fName, !verb);
+ if (!t) {
+ Warning("CleanIt", "Failed to get table for %s", GetName());
+ return false;
+ }
+
+ // Get some pointers and make a bit mask of entries to copy
+ TTree* tree = t->fTree;
+ Int_t nEnt = tree->GetEntries();
+ TBits copy(nEnt);
+ copy.ResetAllBits(false);
+ // TString runs;
+
+ // Loop over all entries
+ Info("CleanIt", "Looping over %d entries in tree", nEnt);
+ for (Int_t i = 0; i < nEnt; i++) {
+ // Read in next entry
+ tree->GetEntry(i);
+
+ // Check if we got an object
+ AliOADBForward::Entry* e = t->fEntry;
+ if (!e) continue;
+
+ // Let's see it
+ // if (verb) e->Print();
+
+ // Now query the DB with this entry's fields
+ ULong_t run = e->fRunNo;
+ UShort_t sys = e->fSys;
+ UShort_t sNN = e->fSNN;
+ Short_t fld = e->fField;
+ Bool_t mc = e->fMC;
+ Bool_t sat = e->fSatellite;
+ TString txt = e->GetTitle();
+ MassageFields(run, sys, sNN, fld, mc, sat);
+
+
+ Int_t r = t->GetEntry(run, AliOADBForward::kDefault,
+ sys, sNN, fld, mc, sat);
+ if (r < 0) {
+ Warning("CleanIt","Uh! didn't get an entry for %s (%d)",
+ txt.Data(), i);
+ r = i;
+ // continue;
+ }
+#if 0
+ // Here, we hard-code some fixes to remove bad entries
+ if (fld != AliOADBForward::kInvalidField) {
+ switch (sys) {
+ case 1:
+ if (sNN == 900 && fld <= 0) r = -1;
+ else if (sNN == 7000 && fld >= 0) r = -1;
+ else if (sNN == 2760 && fld >= 0) r = -1;
+ break;
+ case 2:
+ if (fld >= 0) r = -1;
+ break;
+ }
+ }
+#endif
+
+ Printf("%-10s (%3d %3d): %s %s",
+ (i==r ? "copied" : "ignored"), i, r, txt.Data(), GetName());
+
+ if (r != i) continue;
+
+ // If the entry found by the query and this entry is the same,
+ // then we should keep it
+ copy.SetBitNumber(i,true);
+ // runs.Append(Form("%7lu", run));
+ }
+
+ // Now loop over the entries of the tree again, this time
+ // checking if we should copy or not.
+ // Loop over all entries
+ for (Int_t i = 0; i < nEnt; i++) {
+ // If not marked for copy, continue to the next.
+ if (!copy.TestBitNumber(i)) continue;
+
+ // Read in next entry
+ tree->GetEntry(i);
+
+ // Check if we got an object
+ AliOADBForward::Entry* e = t->fEntry;
+ if (!e) continue;
+
+ // Let's get the entry data and store that in a new correction
+ // table
+ ULong_t run = e->fRunNo;
+ UShort_t sys = e->fSys;
+ UShort_t sNN = e->fSNN;
+ Short_t fld = e->fField;
+ Bool_t mc = e->fMC;
+ Bool_t sat = e->fSatellite;
+ TObject* obj = e->fData;
+ TString txt = e->GetTitle();
+ Printf("Storing %3d: %s %s", i, txt.Data(), GetName());
+ if (!StoreIt(0, obj, run, sys, sNN, fld, mc, sat, dest.Data(),
+ AliOADBForward::Mode2String(t->fMode))) {
+ Warning("CleanIt", "Failed to write new entry to %s", dest.Data());
+ continue;
+ }
+ }
+ // Printf("Runs: %s", runs.Data());
+ return true;
+}
+
//
// EOF
//