Skip to content
Snippets Groups Projects
Commit 6e43b725 authored by Scott Snyder's avatar Scott Snyder Committed by Adam Edward Barton
Browse files

LArRecConditions: Clean up LArFebConfig.

Remove mutable cache in LArFebConfig --- it can't really be making
any significant difference.  But add a method to retrieve both upper
and lower thresholds in one go.  Thus can also remove the locking.
Convert the map to an unordered_map.  Add a method to fill the map,
allowing the removal of the friend declaration.
parent 47128512
No related branches found
No related tags found
No related merge requests found
......@@ -44,8 +44,10 @@ StatusCode LArGainThresholds2Ntuple::stop() {
std::vector<HWIdentifier>::const_iterator itOnIdEnd = m_onlineId->channel_end();
for(; itOnId!=itOnIdEnd;++itOnId){
const HWIdentifier hwid = *itOnId;
lower=febConfig->lowerGainThreshold(hwid);
upper=febConfig->upperGainThreshold(hwid);
short lower_v, upper_v;
febConfig->thresholds (hwid, lower_v, upper_v);
lower = lower_v;
upper = upper_v;
fillFromIdentifier(hwid);
......
......@@ -9,43 +9,51 @@
#include "Identifier/HWIdentifier.h"
#include "CoralBase/AttributeList.h"
#include "LArElecCalib/LArCalibErrorCode.h"
#include <vector>
#include <mutex>
#include <unordered_map>
class LArOnlineID;
class LArFebConfig: public AthMessaging {
friend class LArFEBConfigCondAlg; //The conditions alg filling this object
public:
LArFebConfig()=delete;
LArFebConfig(const LArOnlineID* onlineId); // we do not own this pointer
void add (HWIdentifier febid,
const coral::AttributeList* attrList);
//Accessor methods from ILArFEBConfigReader
short lowerGainThreshold(const HWIdentifier& id) const;
short upperGainThreshold(const HWIdentifier& id) const;
void thresholds (const HWIdentifier& chid, short& lower, short& upper) const;
private:
const LArOnlineID* m_onlineID;
std::map<HWIdentifier,const coral::AttributeList*> m_attrPerFeb;
mutable std::map<HWIdentifier,const coral::AttributeList*>::const_iterator m_lastIt;
mutable std::mutex m_itMtx;
std::unordered_map<HWIdentifier::value_type,const coral::AttributeList*> m_attrPerFeb;
const coral::AttributeList* getAttrList (const HWIdentifier& chid,
int& channel) const;
short
getThresholdFromAttrList(const std::string& MedLow,
const coral::AttributeList* attrList,
const std::string& chanstr) const;
short getThreshold(const std::string& MedLow, const HWIdentifier& chid) const;
short getThreshold(const char* MedLow, const HWIdentifier& chid) const;
static const std::string s_lower;
static const std::string s_upper;
enum {ERRORCODE = LArElecCalib::ERRORCODE};
};
inline short LArFebConfig::lowerGainThreshold(const HWIdentifier& chid) const {
return getThreshold("lower",chid);
return getThreshold(s_lower, chid);
}
inline short LArFebConfig::upperGainThreshold(const HWIdentifier& chid) const {
return getThreshold("upper",chid);
return getThreshold(s_upper,chid);
}
......
......@@ -8,32 +8,78 @@
#include "GaudiKernel/IMessageSvc.h"
#include "CoralBase/Attribute.h"
const std::string LArFebConfig::s_lower = "lower";
const std::string LArFebConfig::s_upper = "upper";
LArFebConfig::LArFebConfig(const LArOnlineID* onlineId) :
AthMessaging(Gaudi::svcLocator()->service< IMessageSvc >( "MessageSvc" ),"LArFebConfig"),
m_onlineID(onlineId)
{ }
short LArFebConfig::getThreshold(const char* MedLow, const HWIdentifier& chid) const {
if (m_attrPerFeb.size()==0) {
ATH_MSG_WARNING("FEB treshold cache is empty. Callback not fired?");
return ERRORCODE;
void LArFebConfig::add (HWIdentifier febid,
const coral::AttributeList* attrList)
{
m_attrPerFeb[febid.get_compact()] = attrList;
}
void LArFebConfig::thresholds (const HWIdentifier& chid,
short& lower,
short& upper) const
{
int channel = 0;
const coral::AttributeList* attrList = getAttrList (chid, channel);
if (attrList == nullptr) {
lower = ERRORCODE;
upper = ERRORCODE;
return;
}
std::string chanstr = std::to_string(channel+1);
lower = getThresholdFromAttrList (s_lower, attrList, chanstr);
upper = getThresholdFromAttrList (s_upper, attrList, chanstr);
}
std::lock_guard<std::mutex> lock(m_itMtx); //Makes sure the following isn't executed concurently
const HWIdentifier fid=m_onlineID->feb_Id(chid);
const int channel=m_onlineID->channel(chid);
if (m_lastIt==m_attrPerFeb.end() || m_lastIt->first!=fid)
m_lastIt=m_attrPerFeb.find(fid);
const coral::AttributeList*
LArFebConfig::getAttrList (const HWIdentifier& chid,
int& channel) const
{
if (m_attrPerFeb.empty()) {
ATH_MSG_WARNING("FEB threshold cache is empty");
return nullptr;
}
if (m_lastIt==m_attrPerFeb.end()) {
const HWIdentifier fid=m_onlineID->feb_Id(chid);
channel = m_onlineID->channel(chid);
auto it = m_attrPerFeb.find(fid.get_compact());
if (it == m_attrPerFeb.end()) {
ATH_MSG_DEBUG("Such FEB was not found !");
return nullptr;
}
return it->second;
}
short
LArFebConfig::getThresholdFromAttrList(const std::string& MedLow,
const coral::AttributeList* attrList,
const std::string& chanstr) const
{
std::string channame = MedLow + chanstr;
return (short)(*attrList)[channame].data<int32_t>(); //Will throw and exception if channel does not exist
}
short LArFebConfig::getThreshold(const std::string& MedLow,
const HWIdentifier& chid) const
{
int channel = 0;
const coral::AttributeList* attrList = getAttrList (chid, channel);
if (attrList == nullptr) {
return ERRORCODE;
}else {
std::string channame(MedLow,5);
channame += std::to_string(channel+1);
return (short)(*(m_lastIt->second))[channame].data<int32_t>(); //Will throw and exception if channel does not exist
}
}
std::string chanstr = std::to_string(channel+1);
return getThresholdFromAttrList (MedLow, attrList, chanstr);
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include "LArFEBConfigCondAlg.h"
......@@ -89,10 +89,9 @@ StatusCode LArFEBConfigCondAlg::execute(const EventContext& ctx) const {
const HWIdentifier fid(chanit->first); //COOL channel number == FEB identifier
//const coral::AttributeList& attr = chanit->second;
ATH_MSG_DEBUG("Working on FEB 0x" << std::hex << fid.get_compact() << std::dec << " " << m_onlineID->channel_name(fid));
p_febConfig->m_attrPerFeb[fid]=std::move(&(chanit->second));
p_febConfig->add (fid, &chanit->second);
++nFebs;
}//End loop over COOL channels
p_febConfig->m_lastIt = p_febConfig->m_attrPerFeb.end();
}
ATH_MSG_INFO("Read gain thresholds for " << nFebs << " Febs from " << m_listOfFolders.size() << " database folders.");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment