X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=blobdiff_plain;f=MUON%2FAliMUONPedestalSubprocessor.cxx;h=4ac64a9d394f6d3c26a2a49f361e7de630060bd0;hp=0f97201682900dcf6042b02ade673facff249afe;hb=a5c69d361383388f5a8031c4ee3174d382fe8148;hpb=8d8e920c928f291455f3e6ee6b1825694c46eb40 diff --git a/MUON/AliMUONPedestalSubprocessor.cxx b/MUON/AliMUONPedestalSubprocessor.cxx index 0f972016829..4ac64a9d394 100644 --- a/MUON/AliMUONPedestalSubprocessor.cxx +++ b/MUON/AliMUONPedestalSubprocessor.cxx @@ -18,11 +18,14 @@ #include "AliMUONPedestalSubprocessor.h" #include "AliCDBMetaData.h" +#include "AliCDBEntry.h" +#include "AliDAQ.h" #include "AliLog.h" #include "AliMUON2DMap.h" #include "AliMUON2DStoreValidator.h" #include "AliMUONCalibParamNF.h" #include "AliMUONPreprocessor.h" +#include "AliMUONTrackerIO.h" #include "AliMpConstants.h" #include "AliMpDDLStore.h" #include "TObjString.h" @@ -32,7 +35,7 @@ #include #include -/// +//----------------------------------------------------------------------------- /// \class AliMUONPedestalSubprocessor /// /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK pedestals. @@ -43,7 +46,7 @@ ///---------------------------------------------------------------------------\n /// /// \author L. Aphecetche -/// +//----------------------------------------------------------------------------- /// \cond CLASSIMP ClassImp(AliMUONPedestalSubprocessor) @@ -54,7 +57,10 @@ AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* ma : AliMUONVSubprocessor(master, "Pedestals", "Upload MUON Tracker pedestals to OCDB"), -fPedestals(0x0) +fPedestals(0x0), +fConfig(0x0), +fConfigChanged(kFALSE), +fTooFewEvents(kFALSE) { /// default ctor } @@ -64,10 +70,56 @@ AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor() { /// dtor delete fPedestals; + delete fConfig; } //_____________________________________________________________________________ -void +Bool_t +AliMUONPedestalSubprocessor::HasConfigChanged(const AliMUONVStore& newConfig) const +{ + /// Check whether the config changed. + /// Any error will return kTRUE to trig a config upload (safer way). + + AliCDBEntry* entry = Master()->GetFromOCDB("Calib","Config"); + if (!entry) + { + AliError("Could not get MUON/Calib/Config entry for current run ! That's not OK !"); + return kTRUE; + } + AliMUONVStore* oldConfig = dynamic_cast(entry->GetObject()); + if (!oldConfig) + { + AliError("Could not get MUON/Calib/Config object for current run (wrong type ?) ! That's not OK !"); + return kTRUE; + } + + if ( oldConfig->GetSize() != newConfig.GetSize() ) + { + return kTRUE; + } + + TIter next(oldConfig->CreateIterator()); + AliMUONVCalibParam* old; + + while ( ( old = static_cast(next()) ) ) + { + Int_t detElemId = old->ID0(); + Int_t manuId = old->ID1(); + + if ( ! newConfig.FindObject(detElemId,manuId) ) + { + // not found in new. Configurations are different. Return right now. + return kTRUE; + } + } + + // all tests OK. Configuration has not changed. + return kFALSE; +} + + +//_____________________________________________________________________________ +Bool_t AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime) { /// When starting a new run, reads in the pedestals ASCII files. @@ -78,35 +130,91 @@ AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endT delete fPedestals; fPedestals = new AliMUON2DMap(kTRUE); - Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld", + delete fConfig; + fConfig = new AliMUON2DMap(kTRUE); + + fTooFewEvents = kFALSE; + + Master()->Log(Form("Reading pedestal files for Run %d startTime %u endTime %u", run,startTime,endTime)); TList* sources = Master()->GetFileSources(kSystem,kId); TIter next(sources); TObjString* o(0x0); Int_t n(0); + Int_t npedFiles(0); while ( ( o = static_cast(next()) ) ) { TString fileName(Master()->GetFile(kSystem,kId,o->GetName())); - Int_t ok = ReadFile(fileName.Data()); - if (!ok) - { - Master()->Log(Form("Could not read file %s",fileName.Data())); - } - else + Int_t ok = ReadPedestalFile(fileName.Data()); + if (ok>0) { n += ok; + ++npedFiles; } } + + delete sources; if (!n) { Master()->Log("Failed to read any pedestals"); + delete fPedestals; fPedestals = 0; + delete fConfig; + fConfig = 0; + + // OK, we did not get our pedestals. Check if the ped run itself + // was bad, i.e. too few events + TString nevents(Master()->GetRunParameter("totalEvents")); + + if ( nevents.Atoi() < 50 ) + { + Master()->Log(Form("The run had only %d events, so the failure to read pedestals is normal",nevents.Atoi())); + // too few events, failure is normal, returns OK. + fTooFewEvents = kTRUE; + return kTRUE; + } + + // no ped, but run looks clean, that's an error + return kFALSE; + } + + const char* kIdConf = "CONFIG"; + + sources = Master()->GetFileSources(kSystem,kIdConf); + TIter nextConf(sources); + Int_t nconf(0); + Int_t nconfFiles(0); + + while ( ( o = static_cast(nextConf()) ) ) + { + TString fileName(Master()->GetFile(kSystem,kIdConf,o->GetName())); + Int_t ok = ReadConfigFile(fileName.Data()); + if (ok>0) + { + nconf += ok; + ++nconfFiles; + } } + delete sources; + + if ( npedFiles != nconfFiles ) + { + Master()->Log(Form("ERROR : Number of config files (%d) different from number of pedestal files (%d)",nconfFiles,npedFiles)); + delete fPedestals; + fPedestals = 0; + delete fConfig; + fConfig = 0; + return kFALSE; + } + + fConfigChanged = HasConfigChanged(*fConfig); + + return kTRUE; } //_____________________________________________________________________________ @@ -115,18 +223,27 @@ AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/) { /// Store the pedestals into the CDB - if (!fPedestals) + if (!fPedestals || !fConfig) { - // this is the only reason to fail for the moment : getting no pedestal - // at all. - return 1; + if ( fTooFewEvents ) + { + // ped run was too short, no reason to complain about that, it's "normal" + // not to have pedestals in that case. + return 0; + } + else + { + // this is the only reason to fail for the moment : getting no pedestal or no config + // at all. + return 1; + } } AliMUON2DStoreValidator validator; Master()->Log("Validating"); - TObjArray* chambers = validator.Validate(*fPedestals); + TObjArray* chambers = validator.Validate(*fPedestals,fConfig); if (chambers) { @@ -146,22 +263,31 @@ AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/) } } - Master()->Log("Storing pedestals"); + Master()->Log("Storing pedestals..."); + if ( fConfigChanged ) + { + Master()->Log("...and configuration, as it has changed"); + } AliCDBMetaData metaData; metaData.SetBeamPeriod(0); metaData.SetResponsible("MUON TRK"); - metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$"); + TString comment("Computed by AliMUONPedestalSubprocessor $Id$"); + comment.ReplaceAll("$",""); + metaData.SetComment(comment.Data()); Bool_t validToInfinity = kTRUE; Bool_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity); - + if ( fConfigChanged ) + { + result = result && Master()->Store("Calib", "Config", fConfig, &metaData, 0, validToInfinity); + } return ( result != kTRUE ); // return 0 if everything is ok. } //_____________________________________________________________________________ Int_t -AliMUONPedestalSubprocessor::ReadFile(const char* filename) +AliMUONPedestalSubprocessor::ReadPedestalFile(const char* filename) { /// Read the pedestals from an ASCII file. \n /// Format of that file is one line per channel : \n @@ -176,41 +302,41 @@ AliMUONPedestalSubprocessor::ReadFile(const char* filename) Master()->Log(Form("Reading %s",sFilename.Data())); - std::ifstream in(sFilename.Data()); - if (!in.good()) + Int_t n = AliMUONTrackerIO::ReadPedestals(sFilename.Data(),*fPedestals); + + switch (n) { - return 0; + case -1: + Master()->Log(Form("Could not open %s",sFilename.Data())); + break; } - char line[80]; - Int_t busPatchID, manuID, manuChannel; - Float_t pedMean, pedSigma; - static const Int_t kNchannels(AliMpConstants::ManuNofChannels()); - Int_t n(0); - while ( in.getline(line,80) ) + return n; +} + +//_____________________________________________________________________________ +Int_t +AliMUONPedestalSubprocessor::ReadConfigFile(const char* filename) +{ + /// Read the configuration from an ASCII file. + /// Format of that file is one line per manu : + /// BUS_PATCH MANU_ADDR + /// Return kFALSE if reading was not successfull. + /// + + TString sFilename(gSystem->ExpandPathName(filename)); + + Master()->Log(Form("Reading %s",sFilename.Data())); + + Int_t n = AliMUONTrackerIO::ReadConfig(sFilename.Data(),*fConfig); + + switch (n) { - if ( line[0] == '/' && line[1] == '/' ) continue; - std::istringstream sin(line); - sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma; - Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID); - AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f", - busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma)); - - AliMUONVCalibParam* ped = - static_cast(fPedestals->FindObject(detElemID,manuID)); - - if (!ped) - { - ped = new AliMUONCalibParamNF(2,kNchannels, - detElemID,manuID, - AliMUONVCalibParam::InvalidFloatValue()); - fPedestals->Add(ped); - } - ped->SetValueAsFloat(manuChannel,0,pedMean); - ped->SetValueAsFloat(manuChannel,1,pedSigma); - ++n; + case -1: + Master()->Log(Form("Could not open %s",sFilename.Data())); + break; } - in.close(); + return n; } @@ -221,4 +347,6 @@ AliMUONPedestalSubprocessor::Print(Option_t* opt) const { /// ouput to screen if (fPedestals) fPedestals->Print("",opt); + if (fConfig) fConfig->Print("",opt); } +