#include "AliCDBEntry.h"
#include "AliCDBManager.h"
#include "AliCodeTimer.h"
+#include "AliDCSValue.h"
#include "AliLog.h"
+#include "AliMpDCSNamer.h"
+#include "AliMUONConstants.h"
+#include "AliMUONGlobalCrateConfig.h"
+#include "AliMUONRegionalTriggerConfig.h"
#include "AliMUONRejectList.h"
#include "AliMUONTriggerEfficiencyCells.h"
#include "AliMUONTriggerLut.h"
+#include "AliMUONVCalibParam.h"
#include "AliMUONVStore.h"
#include "AliMUONVStore.h"
-#include "AliMUONVCalibParam.h"
-#include "AliMUONGlobalCrateConfig.h"
-#include "AliMUONRegionalTriggerConfig.h"
#include <Riostream.h>
#include <TClass.h>
ClassImp(AliMUONCalibrationData)
/// \endcond
-AliMUONVStore* AliMUONCalibrationData::fBypassPedestals(0x0);
-AliMUONVStore* AliMUONCalibrationData::fBypassGains(0x0);
+AliMUONVStore* AliMUONCalibrationData::fgBypassPedestals(0x0);
+AliMUONVStore* AliMUONCalibrationData::fgBypassGains(0x0);
//_____________________________________________________________________________
AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber,
fCapacitances(0x0),
fNeighbours(0x0),
fOccupancyMap(0x0),
-fRejectList(0x0)
+fRejectList(0x0),
+fConfig(0x0)
{
/// Default ctor.
TriggerEfficiency();
Capacitances();
Neighbours();
+ Config();
}
}
//_____________________________________________________________________________
AliMUONCalibrationData::~AliMUONCalibrationData()
{
- /// Destructor. Note that we're the owner of our pointers.
- //PH The owner of the objects is CDB, do not delete them!
- // Reset();
+ /// Destructor. Note that we're the owner of our pointers if the OCDB cache
+ /// is not set. Otherwise the cache is supposed to take care of them...
+ if (!(AliCDBManager::Instance()->GetCacheFlag())) Reset();
}
//_____________________________________________________________________________
}
+//______________________________________________________________________________
+void AliMUONCalibrationData::PatchHVValues(TObjArray& values,
+ Int_t& nbelowready,
+ Int_t& noff,
+ Int_t& ntrips,
+ Int_t& neor,
+ TString* msg)
+{
+ /// We do here a little bit of massaging of the HV values, if needed.
+ ///
+ /// The main point is to "gather" the values near the end of the run (the last XX seconds)
+ /// to avoid the ramp-down before end-of-run syndrom...
+ ///
+ /// The rest is more of a debug/expert tool to have closer look at trends
+ ///
+
+ Double_t HVBEAMTUNING(1300);
+
+ Bool_t eorProblem(kFALSE);
+
+ UInt_t mergeDelay(300); // in seconds
+
+ // First start by removing values within the last mergeDelay seconds, keeping only
+ // the last one
+
+ AliDCSValue* last = static_cast<AliDCSValue*>(values.At(values.GetLast()));
+
+ Int_t* toberemoved = new Int_t[values.GetLast()+1];
+
+ memset(toberemoved,0,(values.GetLast()+1)*sizeof(Int_t));
+
+ Int_t ntoberemoved(0);
+
+ for ( Int_t i = values.GetLast()-1; i > 0; --i )
+ {
+ AliDCSValue* val = static_cast<AliDCSValue*>(values.At(i));
+
+ if ( last->GetTimeStamp() - val->GetTimeStamp() < mergeDelay )
+ {
+ toberemoved[i]=1;
+ ++ntoberemoved;
+ }
+ }
+
+ if (ntoberemoved)
+ {
+ // ok, we have some values within the same mergeDelay seconds
+ // we'll "merge" them by taking the last one, except if
+ // the last one is below HVBEAMTUNING, in which case we
+ // remove that one too (meaning the ramp-down was requesting
+ // before the end-of-run)
+
+ if ( last->GetFloat() < HVBEAMTUNING )
+ {
+ eorProblem=kTRUE;
+ if (msg) *msg = "ERROR RAMP-DOWN BEFORE EOR";
+ toberemoved[values.GetLast()]=1;
+ }
+
+ for ( Int_t i = 0; i <= values.GetLast(); ++i )
+ {
+ if ( toberemoved[i] ) values.RemoveAt(i);
+ }
+
+ values.Compress();
+
+ }
+
+ delete[] toberemoved;
+
+ if (eorProblem)
+ {
+ ++neor;
+ return;
+ }
+
+ // now for the rest of the diagnosis
+
+ Int_t ntmpoff(0);
+ Int_t ntmpready(0);
+
+ for ( Int_t i = 0; i <= values.GetLast(); ++i )
+ {
+ AliDCSValue* val = static_cast<AliDCSValue*>(values.At(i));
+
+ if ( val->GetFloat() < AliMpDCSNamer::TrackerHVOFF() )
+ {
+ ++ntmpoff;
+ }
+ else if ( val->GetFloat() < HVBEAMTUNING )
+ {
+ ++ntmpready;
+ }
+ }
+
+ if ( ntmpoff )
+ {
+ if ( ntmpoff == values.GetLast()+1 )
+ {
+ if (msg) *msg = "ERROR HV OFF";
+ ++noff;
+ }
+ else
+ {
+ if (msg) *msg = "ERROR TRIP";
+ ++ntrips;
+ }
+ }
+
+ if ( ntmpready == values.GetLast()+1 )
+ {
+ if (msg) *msg = "ERROR BELOW READY";
+ }
+
+ if (ntmpready) ++nbelowready;
+}
//_____________________________________________________________________________
TMap*
-AliMUONCalibrationData::CreateHV(Int_t runNumber, Int_t* startOfValidity)
+AliMUONCalibrationData::CreateHV(Int_t runNumber, Int_t* startOfValidity, Bool_t patched)
{
/// Create a new HV map from the OCDB for a given run
- return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
+ TMap* hvMap = dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
+ if (patched)
+ {
+ TIter next(hvMap);
+ TObjString* hvChannelName;
+
+ while ( ( hvChannelName = static_cast<TObjString*>(next()) ) )
+ {
+ TString name(hvChannelName->String());
+
+ if ( name.Contains("sw") ) continue; // skip switches
+
+ TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(name.Data()));
+ TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
+ if (!values)
+ {
+ AliErrorClass(Form("Could not get values for alias %s",name.Data()));
+ }
+ else
+ {
+ int nbelowready(0);
+ int noff(0);
+ int ntrips(0);
+ int neor(0);
+
+ PatchHVValues(*values,nbelowready,noff,ntrips,neor,0x0);
+ if (neor)
+ {
+ nbelowready=noff=ntrips=neor=0;
+ PatchHVValues(*values,nbelowready,noff,ntrips,neor,0x0);
+ if (neor)
+ {
+ AliErrorClass("neor is not null after PatchHVValue ! This is serious !");
+ }
+ }
+ }
+ }
+
+ }
+ return hvMap;
}
//_____________________________________________________________________________
/// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
/// and return the corresponding TObject.
- AliCodeTimerAutoClass(Form("%d : %s",runNumber,path));
+ AliCodeTimerAutoClass(Form("%d : %s",runNumber,path),0);
AliCDBManager* man = AliCDBManager::Instance();
if ( startOfValidity ) *startOfValidity = entry->GetId().GetFirstRun();
TObject* object = entry->GetObject();
- entry->SetOwner(kFALSE);
- if (!(man->GetCacheFlag())) delete entry;
+ if (!(man->GetCacheFlag()))
+ {
+ entry->SetOwner(kFALSE);
+ delete entry;
+ }
return object;
}
else
{
- AliCodeTimerAutoClass(Form("Failed to get %s for run %d",path,runNumber));
+ AliCodeTimerAutoClass(Form("Failed to get %s for run %d",path,runNumber),1);
}
return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals",startOfValidity));
}
+//_____________________________________________________________________________
+AliMUONVStore*
+AliMUONCalibrationData::CreateConfig(Int_t runNumber, Int_t* startOfValidity)
+{
+ /// Create a new config store from the OCDB for a given run
+ return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Config",startOfValidity));
+}
+
//_____________________________________________________________________________
AliMUONRegionalTriggerConfig*
AliMUONCalibrationData::Gains() const
{
/// Create (if needed) and return the internal store for gains.
- if (fBypassGains) return fBypassGains;
+ if (fgBypassGains) return fgBypassGains;
if (!fGains)
{
//_____________________________________________________________________________
TMap*
-AliMUONCalibrationData::HV() const
+AliMUONCalibrationData::HV(Bool_t patched) const
{
/// Return the calibration for a given (detElemId, manuId) pair
if (!fHV)
{
- fHV = CreateHV(fRunNumber);
+ fHV = CreateHV(fRunNumber,0,patched);
}
return fHV;
}
AliMUONCalibrationData::BypassStores(AliMUONVStore* ped, AliMUONVStore* gain)
{
/// Force the use of those pedestals and gains
- fBypassPedestals = ped;
- fBypassGains = gain;
+ fgBypassPedestals = ped;
+ fgBypassGains = gain;
}
{
/// Return pedestals
- if (fBypassPedestals) return fBypassPedestals;
+ if (fgBypassPedestals) return fgBypassPedestals;
if (!fPedestals)
{
return fPedestals;
}
+//_____________________________________________________________________________
+AliMUONVStore*
+AliMUONCalibrationData::Config() const
+{
+ /// Return config
+
+ if (!fConfig)
+ {
+ fConfig = CreateConfig(fRunNumber);
+ }
+ return fConfig;
+}
+
//_____________________________________________________________________________
AliMUONVCalibParam*
AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
cout << "RunNumber " << RunNumber()
<< " fGains=" << fGains
<< " fPedestals=" << fPedestals
+ << " fConfig=" << fConfig
<< " fHV=" << fHV
<< " fTriggerDCS=" << fTriggerDCS
<< " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
{
/// Reset all data
+ AliCodeTimerAuto("",0);
+
+ delete fConfig;
+ fConfig = 0x0;
delete fPedestals;
fPedestals = 0x0;
delete fGains;
{
AliInfoClass("Pedestals read OK");
}
+
+ if ( ! CreateConfig(runNumber) )
+ {
+ AliErrorClass("Could not read config");
+ }
+ else
+ {
+ AliInfoClass("Config read OK");
+ }
if ( ! CreateRegionalTriggerConfig(runNumber) )
{