+//____________________________________________________________________
+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;
+}
+