From dc02d468695d1ad35c7f7e6f852f3486eeac9d8a Mon Sep 17 00:00:00 2001 From: cholm Date: Sun, 4 Nov 2007 10:07:53 +0000 Subject: [PATCH] Fixed AliFMDPreprocessor to use GetFromOCDB. It is still AliFMDParameters that get the stuff, but it uses the AliFMDPreprocessor object to do so. In this way, we're sure that we use the same data in all steps of the preprocessor. Updated test script. --- FMD/AliFMDParameters.cxx | 130 ++++++++++++++++-------------- FMD/AliFMDParameters.h | 32 ++++++-- FMD/AliFMDPreprocessor.cxx | 142 ++++++++++++++++++++++++++++++--- FMD/AliFMDPreprocessor.h | 26 ++++++ FMD/scripts/TestPreprocessor.C | 52 ++++++++---- 5 files changed, 292 insertions(+), 90 deletions(-) diff --git a/FMD/AliFMDParameters.cxx b/FMD/AliFMDParameters.cxx index f324faf3bdb..a0d58609cee 100644 --- a/FMD/AliFMDParameters.cxx +++ b/FMD/AliFMDParameters.cxx @@ -40,8 +40,11 @@ #include "AliFMDAltroMapping.h" // ALIFMDALTROMAPPING_H #include // ALICDBMANAGER_H #include // ALICDBMANAGER_H +#include +#include #include #include +#include #include #include @@ -126,7 +129,22 @@ AliFMDParameters::Init(Bool_t forceReInit, UInt_t what) if (what & kZeroSuppression) InitZeroSuppression(); if (what & kAltroMap) InitAltroMap(); fIsInit = kTRUE; - +} +//__________________________________________________________________ +void +AliFMDParameters::Init(AliFMDPreprocessor* pp, Bool_t forceReInit, UInt_t what) +{ + // Initialize the parameters manager. We need to get stuff from the + // CDB here. + if (forceReInit) fIsInit = kFALSE; + if (fIsInit) return; + if (what & kPulseGain) InitPulseGain(pp); + if (what & kPedestal) InitPedestal(pp); + if (what & kDeadMap) InitDeadMap(pp); + if (what & kSampleRate) InitSampleRate(pp); + if (what & kZeroSuppression) InitZeroSuppression(pp); + if (what & kAltroMap) InitAltroMap(pp); + fIsInit = kTRUE; } //__________________________________________________________________ @@ -434,18 +452,42 @@ AliFMDParameters::SetStripRange(UShort_t min, UShort_t max) fFixedMaxStrip = max; } +//__________________________________________________________________ +AliCDBEntry* +AliFMDParameters::GetEntry(const char* path, AliFMDPreprocessor* pp, + Bool_t fatal) const +{ + // Get an entry from the CDB or via preprocessor + AliCDBEntry* entry = 0; + if (!pp) { + AliCDBManager* cdb = AliCDBManager::Instance(); + entry = cdb->Get(path); + } + else { + const char* third = gSystem->BaseName(path); + const char* second = gSystem->BaseName(gSystem->DirName(path)); + entry = pp->GetFromCDB(second, third); + } + if (!entry) { + TString msg(Form("No %s found in CDB, perhaps you need to " + "use AliFMDCalibFaker?", path)); + if (fatal) { AliFatal(msg.Data()); } + else AliLog::Message(AliLog::kWarning, msg.Data(), "FMD", + "AliFMDParameters", "GetEntry", __FILE__, + __LINE__); + return 0; + } + return entry; +} + + //__________________________________________________________________ void -AliFMDParameters::InitPulseGain() +AliFMDParameters::InitPulseGain(AliFMDPreprocessor* pp) { // Get pulse gain from CDB or used fixed - AliCDBManager* cdb = AliCDBManager::Instance(); - AliCDBEntry* gain = cdb->Get(fgkPulseGain); - if (!gain) { - AliFatal(Form("No %s found in CDB, perhaps you need to " - "use AliFMDCalibFaker?", fgkPulseGain)); - return; - } + AliCDBEntry* gain = GetEntry(fgkPulseGain, pp); + if (!gain) return; AliFMDDebug(1, ("Got gain from CDB")); fPulseGain = dynamic_cast(gain->GetObject()); @@ -453,16 +495,12 @@ AliFMDParameters::InitPulseGain() } //__________________________________________________________________ void -AliFMDParameters::InitPedestal() +AliFMDParameters::InitPedestal(AliFMDPreprocessor* pp) { // Initialize the pedestals from CDB - AliCDBManager* cdb = AliCDBManager::Instance(); - AliCDBEntry* pedestal = cdb->Get(fgkPedestal); - if (!pedestal) { - AliFatal(Form("No %s found in CDB, perhaps you need to " - "use AliFMDCalibFaker?", fgkPedestal)); - return; - } + AliCDBEntry* pedestal = GetEntry(fgkPedestal, pp); + if (!pedestal) return; + AliFMDDebug(1, ("Got pedestal from CDB")); fPedestal = dynamic_cast(pedestal->GetObject()); if (!fPedestal) AliFatal("Invalid pedestal object from CDB"); @@ -470,16 +508,12 @@ AliFMDParameters::InitPedestal() //__________________________________________________________________ void -AliFMDParameters::InitDeadMap() +AliFMDParameters::InitDeadMap(AliFMDPreprocessor* pp) { // Get Dead-channel-map from CDB - AliCDBManager* cdb = AliCDBManager::Instance(); - AliCDBEntry* deadMap = cdb->Get(fgkDead); - if (!deadMap) { - AliFatal(Form("No %s found in CDB, perhaps you need to " - "use AliFMDCalibFaker?", fgkDead)); - return; - } + AliCDBEntry* deadMap = GetEntry(fgkDead, pp); + if (!deadMap) return; + AliFMDDebug(1, ("Got dead map from CDB")); fDeadMap = dynamic_cast(deadMap->GetObject()); if (!fDeadMap) AliFatal("Invalid dead map object from CDB"); @@ -487,16 +521,11 @@ AliFMDParameters::InitDeadMap() //__________________________________________________________________ void -AliFMDParameters::InitZeroSuppression() +AliFMDParameters::InitZeroSuppression(AliFMDPreprocessor* pp) { // Get 0-suppression from CDB - AliCDBManager* cdb = AliCDBManager::Instance(); - AliCDBEntry* zeroSup = cdb->Get(fgkZeroSuppression); - if (!zeroSup) { - AliFatal(Form("No %s found in CDB, perhaps you need to " - "use AliFMDCalibFaker?", fgkZeroSuppression)); - return; - } + AliCDBEntry* zeroSup = GetEntry(fgkZeroSuppression, pp); + if (!zeroSup) return; AliFMDDebug(1, ("Got zero suppression from CDB")); fZeroSuppression = dynamic_cast(zeroSup->GetObject()); @@ -505,16 +534,11 @@ AliFMDParameters::InitZeroSuppression() //__________________________________________________________________ void -AliFMDParameters::InitSampleRate() +AliFMDParameters::InitSampleRate(AliFMDPreprocessor* pp) { // get Sample rate from CDB - AliCDBManager* cdb = AliCDBManager::Instance(); - AliCDBEntry* sampRat = cdb->Get(fgkSampleRate); - if (!sampRat) { - AliFatal(Form("No %s found in CDB, perhaps you need to " - "use AliFMDCalibFaker?", fgkSampleRate)); - return; - } + AliCDBEntry* sampRat = GetEntry(fgkSampleRate, pp); + if (!sampRat) return; AliFMDDebug(1, ("Got zero suppression from CDB")); fSampleRate = dynamic_cast(sampRat->GetObject()); if (!fSampleRate) AliFatal("Invalid zero suppression object from CDB"); @@ -522,17 +546,12 @@ AliFMDParameters::InitSampleRate() //__________________________________________________________________ void -AliFMDParameters::InitAltroMap() +AliFMDParameters::InitAltroMap(AliFMDPreprocessor* pp) { // Get hardware mapping from CDB - AliCDBManager* cdb = AliCDBManager::Instance(); - AliCDBEntry* hwMap = cdb->Get(fgkAltroMap); - if (!hwMap) { - AliFatal(Form("No %s found in CDB, perhaps you need to " - "use AliFMDCalibFaker?", fgkAltroMap)); - fAltroMap = new AliFMDAltroMapping; - return; - } + AliCDBEntry* hwMap = GetEntry(fgkAltroMap, pp); + if (!hwMap) return; + AliFMDDebug(1, ("Got ALTRO map from CDB")); fAltroMap = dynamic_cast(hwMap->GetObject()); if (!fAltroMap) { @@ -543,16 +562,11 @@ AliFMDParameters::InitAltroMap() //__________________________________________________________________ void -AliFMDParameters::InitStripRange() +AliFMDParameters::InitStripRange(AliFMDPreprocessor* pp) { // Get strips read-out from CDB - AliCDBManager* cdb = AliCDBManager::Instance(); - AliCDBEntry* range = cdb->Get(fgkStripRange); - if (!range) { - AliFatal(Form("No %s found in CDB, perhaps you need to " - "use AliFMDCalibFaker?", fgkStripRange)); - return; - } + AliCDBEntry* range = GetEntry(fgkStripRange, pp); + if (!range) return; AliFMDDebug(1, ("Got strip range from CDB")); fStripRange = dynamic_cast(range->GetObject()); if (!fStripRange) AliFatal("Invalid strip range object from CDB"); diff --git a/FMD/AliFMDParameters.h b/FMD/AliFMDParameters.h index b8e68912ba8..84222a900b7 100644 --- a/FMD/AliFMDParameters.h +++ b/FMD/AliFMDParameters.h @@ -37,6 +37,9 @@ class AliFMDCalibGain; class AliFMDCalibSampleRate; class AliFMDCalibStripRange; class AliFMDAltroMapping; +class AliCDBEntry; +class AliFMDPreprocessor; + //____________________________________________________________________ // // Singleton class to handle various parameters (not geometry) of the @@ -101,6 +104,13 @@ public: void Init(Bool_t forceReInit=kFALSE, UInt_t what = (kPulseGain|kPedestal|kDeadMap|kSampleRate| kZeroSuppression|kAltroMap)); + /** Initialize the manager. This tries to read the parameters from + CDB. If that fails, the class uses the hard-coded parameters. + */ + void Init(AliFMDPreprocessor* pp, + Bool_t forceReInit=kFALSE, + UInt_t what = (kPulseGain|kPedestal|kDeadMap|kSampleRate| + kZeroSuppression|kAltroMap)); /** Print all parameters. @param option Option string */ void Print(Option_t* option="A") const; @@ -349,20 +359,28 @@ protected: virtual ~AliFMDParameters() {} /** Singleton instance */ static AliFMDParameters* fgInstance; // Static singleton instance + /** Get an entry from either global AliCDBManager or passed + AliFMDPreprocessor. + @param path Path to CDB object. + @param pp AliFMDPreprocessor + @param fatal If true, raise a fatal flag if we didn't get the entry. + @return AliCDBEntry if found */ + AliCDBEntry* GetEntry(const char* path, AliFMDPreprocessor* pp, + Bool_t fatal=kTRUE) const; /** Initialize gains. Try to get them from CDB */ - void InitPulseGain(); + void InitPulseGain(AliFMDPreprocessor* pp=0); /** Initialize pedestals. Try to get them from CDB */ - void InitPedestal(); + void InitPedestal(AliFMDPreprocessor* pp=0); /** Initialize dead map. Try to get it from CDB */ - void InitDeadMap(); + void InitDeadMap(AliFMDPreprocessor* pp=0); /** Initialize sample rates. Try to get them from CDB */ - void InitSampleRate(); + void InitSampleRate(AliFMDPreprocessor* pp=0); /** Initialize zero suppression thresholds. Try to get them from CDB */ - void InitZeroSuppression(); + void InitZeroSuppression(AliFMDPreprocessor* pp=0); /** Initialize hardware map. Try to get it from CDB */ - void InitAltroMap(); + void InitAltroMap(AliFMDPreprocessor* pp=0); /** Initialize strip range. Try to get it from CDB */ - void InitStripRange(); + void InitStripRange(AliFMDPreprocessor* pp=0); Bool_t fIsInit; // Whether we've been initialised diff --git a/FMD/AliFMDPreprocessor.cxx b/FMD/AliFMDPreprocessor.cxx index 6c5df9dc1bc..9af16077039 100644 --- a/FMD/AliFMDPreprocessor.cxx +++ b/FMD/AliFMDPreprocessor.cxx @@ -60,6 +60,8 @@ #include "AliFMDPreprocessor.h" #include "AliFMDCalibPedestal.h" #include "AliFMDCalibGain.h" +#include "AliFMDCalibStripRange.h" +#include "AliFMDCalibSampleRate.h" #include "AliFMDParameters.h" #include "AliCDBMetaData.h" #include "AliCDBManager.h" @@ -77,6 +79,40 @@ ClassImp(AliFMDPreprocessor) ; #endif +//____________________________________________________ +Bool_t AliFMDPreprocessor::GetAndCheckFileSources(TList*& list, + Int_t system, + const char* id) +{ + // Convinience function + // Parameters: + // list On return, list of files. + // system Alice system (DAQ, DCS, ...) + // id File id + // Return: + // kTRUE on success. + list = GetFileSources(system, id); + if (!list) { + TString sys; + switch (system) { + case kDAQ: sys = "DAQ"; break; + case kDCS: sys = "DCS"; break; + default: sys = "unknown"; break; + } + Log(Form("Failed to get file sources for %s/%s", sys.Data(), system)); + return kFALSE; + } + return kTRUE; +} + +//____________________________________________________ +AliCDBEntry* +AliFMDPreprocessor::GetFromCDB(const char* second, const char* third) +{ + return GetFromOCDB(second, third); +} + + //____________________________________________________ UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */) { @@ -94,13 +130,32 @@ UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */) // cdb->SetDefaultStorage("local://$ALICE_ROOT"); // cdb->SetRun(0); AliFMDParameters* pars = AliFMDParameters::Instance(); - pars->Init(false, AliFMDParameters::kAltroMap); + pars->Init(this, false, AliFMDParameters::kAltroMap); + + // This is if the SOR contains Fee parameters, and we run a DA to + // extract these parameters. The same code could work if we get + // the information from DCS via the FXS + TList* files = 0; + GetAndCheckFileSources(files, kDAQ,"info"); + // if (!ifiles) return 1; + AliFMDCalibSampleRate* calibRate = 0; + AliFMDCalibStripRange* calibRange = 0; + AliFMDCalibZeroSuppression* calibZero = 0; + GetInfoCalibration(files, calibRate, calibRange, calibZero); + // Gt the run type + TString runType(GetRunType()); + //Creating calibration objects - TList* pedFiles = GetFileSources(kDAQ,"pedestal"); - TList* gainFiles = GetFileSources(kDAQ, "gain"); - AliFMDCalibPedestal* calibPed = GetPedestalCalibration(pedFiles); - AliFMDCalibGain* calibGain = GetGainCalibration(gainFiles); + AliFMDCalibPedestal* calibPed = 0; + AliFMDCalibGain* calibGain = 0; + if (runType.Contains("PEDESTAL", TString::kIgnoreCase) && + GetAndCheckFileSources(files, kDAQ, "pedestal")) + calibPed = GetPedestalCalibration(files); + if (runType.Contains("PULSER", TString::kIgnoreCase) && + GetAndCheckFileSources(files, kDAQ, "gain")) + calibGain = GetGainCalibration(files); + //Storing Calibration objects @@ -109,15 +164,82 @@ UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */) metaData.SetResponsible("Hans H. Dalsgaard"); metaData.SetComment("Preprocessor stores pedestals and gains for the FMD."); - Bool_t resultPed = kFALSE, resultGain = kFALSE; - if(calibPed) resultPed = Store("Calib","Pedestal", calibPed, &metaData); - if(calibGain) resultGain = Store("Calib","PulseGain", calibGain, &metaData); - if (calibPed) delete calibPed; - if (calibGain) delete calibGain; + Bool_t resultPed = kFALSE; + Bool_t resultGain = kFALSE; + Bool_t resultRange = kFALSE; + Bool_t resultRate = kFALSE; + Bool_t resultZero = kFALSE; + if(calibPed) { + resultPed = Store("Calib","Pedestal", calibPed, &metaData); + delete calibPed; + } + if(calibGain) { + resultGain = Store("Calib","PulseGain", calibGain, &metaData); + delete calibGain; + } + if(calibRange) { + resultRange = Store("Calib","StripRange", calibRange, &metaData); + delete calibRange; + } + if(calibRate) { + resultRate = Store("Calib","SampleRate", calibRate, &metaData); + delete calibRate; + } + if(calibZero) { + resultZero = Store("Calib","ZeroSuppression", calibZero, &metaData); + delete calibZero; + } return (resultPed && resultGain ? 0 : 1); +#if 0 + // Disabled until we implement GetInfoCalibration properly + return (resultPed && + resultGain && + resultRange && + resultRate && + resultZero + ? 0 : 1); +#endif +} + +//____________________________________________________________________ +Bool_t +AliFMDPreprocessor::GetInfoCalibration(TList* files, + AliFMDCalibSampleRate*& s, + AliFMDCalibStripRange*& r, + AliFMDCalibZeroSuppression*& z) +{ + // Get info calibrations. + // Parameters: + // files List of files. + // s On return, newly allocated object + // r On return, newly allocated object + // z On return, newly allocated object + // Return: + // kTRUE on success + if (!files) return kTRUE; // Should really be false + if (files->GetEntries() <= 0) return kTRUE; + + s = new AliFMDCalibSampleRate(); + r = new AliFMDCalibStripRange(); + z = new AliFMDCalibZeroSuppression(); + + // AliFMDParameters* pars = AliFMDParameters::Instance(); + TIter iter(files); + TObjString* fileSource; + + while((fileSource = dynamic_cast(iter.Next()))) { + const Char_t* filename = GetFile(kDAQ, "info", fileSource->GetName()); + std::ifstream in(filename); + if(!in) { + AliError(Form("File %s not found!", filename)); + continue; + } + } + return kTRUE; } + //____________________________________________________________________ AliFMDCalibPedestal* AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles) diff --git a/FMD/AliFMDPreprocessor.h b/FMD/AliFMDPreprocessor.h index 3662282ce91..5d9142306eb 100644 --- a/FMD/AliFMDPreprocessor.h +++ b/FMD/AliFMDPreprocessor.h @@ -12,8 +12,15 @@ #include "AliPreprocessor.h" +#ifndef ALIFMDUSHORTMAP_H +# include +#endif +typedef AliFMDUShortMap AliFMDCalibZeroSuppression; class AliFMDCalibPedestal; class AliFMDCalibGain; +class AliFMDCalibSampleRate; +class AliFMDCalibStripRange; +class AliCDBEntry; class TList; //___________________________________________________________________ @@ -60,6 +67,8 @@ public: {} /** Destructor */ virtual ~AliFMDPreprocessor() {} + /** Get an entry from OCDB */ + AliCDBEntry* GetFromCDB(const char* second, const char* third); protected: /** Get the pedestal calibrations @param list List of files */ @@ -67,6 +76,23 @@ protected: /** Get the gain calibrations @param list List of files */ AliFMDCalibGain* GetGainCalibration(TList*); + /** Get info calibrations. + @param files List of files. + @param s On return, newly allocated object + @param r On return, newly allocated object + @param z On return, newly allocated object + @return kTRUE on success */ + Bool_t GetInfoCalibration(TList* files, + AliFMDCalibSampleRate*& s, + AliFMDCalibStripRange*& r, + AliFMDCalibZeroSuppression*& z); + /** Convinience function + @param list On return, list of files. + @param system Alice system (DAQ, DCS, ...) + @param id File id + @return kTRUE on success. */ + Bool_t GetAndCheckFileSources(TList*& list, Int_t system, const char* id); + /** Entry method @param dcsAliasMap Map of DCS data points */ virtual UInt_t Process(TMap* dcsAliasMap); diff --git a/FMD/scripts/TestPreprocessor.C b/FMD/scripts/TestPreprocessor.C index 08885eb32f2..b0a3afc837b 100644 --- a/FMD/scripts/TestPreprocessor.C +++ b/FMD/scripts/TestPreprocessor.C @@ -9,7 +9,7 @@ #ifndef __CINT__ # include # include -# include <../FMD/AliFMDPreprocessor.h> +# include # include # include # include @@ -20,13 +20,14 @@ # include // # include <../FMD/AliFMDCalibZeroSuppression.h> // # include <../FMD/AliFMDCalibDeadMap.h> -# include <../FMD/AliFMDParameters.h> -# include <../SHUTTLE/TestShuttle/AliTestShuttle.h> +# include +# include # include # include # include # include # include +# include #endif namespace { @@ -185,7 +186,7 @@ namespace { // void ReadBack(const char* dbBase="local://$ALICE_ROOT/FMD/") { - AliLog::SetModuleDebugLevel("FMD", 1); + // AliLog::SetModuleDebugLevel("FMD", 1); // Set specific storage of FMD ALTRO map AliCDBManager::Instance()->SetDefaultStorage(Form("%s/TestCDB", dbBase)); AliCDBManager::Instance()->SetSpecificStorage("FMD/Calib/AltroMap", @@ -270,16 +271,8 @@ void TestPreprocessor(Bool_t createDummies=kTRUE, // create AliTestShuttle instance // The parameters are run, startTime, endTime AliTestShuttle* shuttle = new AliTestShuttle(0, 0, 1); - - // Set specific storage of FMD ALTRO map - AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT"); - AliCDBManager::Instance()->SetSpecificStorage("FMD/Calib/AltroMap", - "local://$ALICE_ROOT"); - AliCDBManager::Instance()->SetRun(0); - // TODO if needed, change location of OCDB and Reference test - // folders by default they are set to - // $ALICE_ROOT/TestCDB and TestReference - AliTestShuttle::SetMainCDB(Form("%s/TestCDB", dbBase)); + AliTestShuttle::SetMainCDB("local://$ALICE_ROOT"); + AliTestShuttle::SetLocalCDB(Form("%s/TestCDB", dbBase)); AliTestShuttle::SetMainRefStorage(Form("%s/TestReference", dbBase)); std::cout << "Test OCDB storage URI: " << AliShuttleInterface::GetMainCDB() @@ -292,7 +285,7 @@ void TestPreprocessor(Bool_t createDummies=kTRUE, "source1", "peds.csv"); shuttle->AddInputFile(AliShuttleInterface::kDAQ, "FMD", "gain", "source2", "gains.csv"); - shuttle->SetInputRunType("PHYSICS"); + shuttle->SetInputRunType("PEDESTAL PULSER PHYSICS"); new AliFMDPreprocessor(shuttle); // Test the preprocessor @@ -379,6 +372,35 @@ void WriteDCSAliasMap() ->Put(dcsAliasMap, id, &metaData); } +#ifndef __CINT__ +int +main(int argc, char** argv) +{ + Bool_t createDummies = kTRUE; + TString dbBase = "local://$ALICE_ROOT/FMD/"; + for (int i = 1; i < argc; i++) { + if (argv[i][0] == '-') { + switch (argv[i][1]) { + case 'h': + std::cout << "Usage: " << argv[0] << " [OPTIONS]\n\n" + << "Options:\n" + << "\t-h\tThis help\n" + << "\t-d\tToggle dummies\n" + << "\t-b DIR\tSet database dir\n" + << std::endl; + return 0; + case 'd': createDummies = !createDummies; break; + case 'b': dbBase = argv[++i]; break; + } + } + } + + TestPreprocessor(createDummies, dbBase); + return 0; +} + +#endif + //____________________________________________________________________ // // EOF -- 2.43.0