ATLAS Offline Software
LArCaliWaveSelector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "GaudiKernel/MsgStream.h"
8 
10 
14 
16 
18 
19 
21 using CaliWaveIt = LArCaliWaveContainer::LArCaliWaves::const_iterator;
22 
23 LArCaliWaveSelector::LArCaliWaveSelector(const std::string& name, ISvcLocator* pSvcLocator)
24  : AthAlgorithm(name, pSvcLocator),
25  m_cellID(nullptr),
26  m_gmask(0),
27  m_groupingType("ExtendedFeedThrough")
28 {
29  declareProperty("SelectionList", m_selectionList); // Vector of strings of det/lay/gain/DAC -> "EMB/0/0/200"
30  // Known detectors EMB, EMEC, HEC, FCAL
31  // Available layers 0-3, gains 0-2, DAC 0-65000
32  declareProperty("KeyList", m_keyList);
33  declareProperty("KeyOutput", m_outputKey);
34  declareProperty("GroupingType", m_groupingType);
35 }
36 
38 = default;
39 
41 {
42  ATH_MSG_INFO ( " in initialize.." );
43 
44  // Default list
45  if (m_keyList.empty()) { m_keyList.emplace_back("LArCaliWave"); }
47 
48  ATH_CHECK( detStore()->retrieve (m_cellID, "CaloCell_ID") );
49  if (!m_cellID) {
50  ATH_MSG_ERROR ( "Could not access CaloCell_ID helper" );
51  return StatusCode::FAILURE;
52  }
53 
55 
56  return StatusCode::SUCCESS;
57 }
58 
59 
61 {
62  ATH_MSG_INFO ( " in stop.." );
63 
65  const LArOnOffIdMapping* cabling{*cablingHdl};
66  if(!cabling){
67  ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key() );
68  return StatusCode::FAILURE;
69  }
70 
71  // create empty LArCaliWaveContainer to store DAC selected LArCaliWave
72  // make it view container
73 // LArCaliWaveContainer* selectedCaliWaveContainer = new LArCaliWaveContainer(SG::VIEW_ELEMENTS);
74  auto selectedCaliWaveContainer = std::make_unique<LArCaliWaveContainer>();
75  CHECK( selectedCaliWaveContainer->setGroupingType(m_groupingType,msg()));
76  CHECK( selectedCaliWaveContainer->initialize());
77 
78  std::vector<std::string>::const_iterator key_it = m_keyList.begin();
79  std::vector<std::string>::const_iterator key_it_e = m_keyList.end();
80 
81  for (;key_it!=key_it_e; ++key_it) {
82  const LArCaliWaveContainer* larCaliWaveContainer;
83  StatusCode sc = detStore()->retrieve(larCaliWaveContainer,*key_it);
84  if (sc.isFailure()) {
85  ATH_MSG_WARNING ( "No LArCaliWaveContainer in StoreGate with key = " << *key_it );
86  continue;
87  } else {
88  ATH_MSG_INFO ( "Reading LArCaliWaveContainer with key = " << *key_it );
89  }
90 
91  int det, lay;
92  for ( unsigned gain = CaloGain::LARHIGHGAIN ; gain < CaloGain::LARNGAIN ; ++gain ) {
93  if(!( (0x1<<gain) & m_gmask) ) continue;
94 
95  CaliMapIt cali_it = larCaliWaveContainer->begin(gain) ;
96  CaliMapIt cali_it_e = larCaliWaveContainer->end(gain) ;
97 
98  if ( cali_it == cali_it_e ) {
99  ATH_MSG_DEBUG ( "No wave with gain = " << gain << " in container with key = " << *key_it );
100  continue;
101  } else {
102  ATH_MSG_DEBUG ( "processing gain = " << gain );
103  }
104  for ( ; cali_it != cali_it_e; ++cali_it) {
105 
106  CaliWaveIt wave_it = cali_it->begin();
107  CaliWaveIt wave_it_e = cali_it->end();
108  if ( wave_it == wave_it_e ) {
109  ATH_MSG_DEBUG ( "Empty channel found..." );
110  continue;
111  }
112 
113  HWIdentifier chid = cali_it.channelId();
114  Identifier cell_id = cabling->cnvToIdentifier(chid);
115  if(m_cellID->is_em_barrel(cell_id)){ det = 0;
116  } else if(m_cellID->is_em_endcap(cell_id)) { det = 1;
117  } else if(m_cellID->is_hec(cell_id)) { det = 2;
118  } else if(m_cellID->is_fcal(cell_id)) { det = 3;
119  } else {
120  ATH_MSG_ERROR ( "Wrong ID in LArCaliWaveContainer: "<<m_cellID->print_to_string(cell_id));
121  continue;
122  }
123  lay = m_cellID->sampling(cell_id);
124  DetGain dg = std::make_pair( std::make_pair(det,lay), gain);
125  if( m_mapDAC.find(dg) == m_mapDAC.end() ) continue;
126 
127  for ( ; wave_it != wave_it_e; ++wave_it) {
128  if(wave_it->getDAC() == m_mapDAC[dg]) {
129  (selectedCaliWaveContainer->get(chid,gain)).push_back(*wave_it);
130  break;
131  }
132  }
133  }
134  }
135  }
136 
137  ATH_CHECK( detStore()->record(std::move(selectedCaliWaveContainer),m_outputKey) );
138  return StatusCode::SUCCESS;
139 }
140 
142 {
143  int det,lay,gain,DAC;
144  std::string selstr;
145  for(unsigned i=0; i<m_selectionList.size(); ++i) {
146  std::string::size_type det_delimiter( m_selectionList[i].find('/') );
147  if( std::string::npos == det_delimiter ){
148  ATH_MSG_WARNING ( "Bad selection string: "<< m_selectionList[i] << " skipped...." );
149  continue;
150  }
151  std::string det_string = m_selectionList[i].substr(0, det_delimiter);
152  if(det_string=="EMB") {
153  det = 0;
154  } else if (det_string == "EMEC") {
155  det = 1;
156  } else if (det_string == "HEC") {
157  det = 2;
158  } else if (det_string == "FCAL") {
159  det = 3;
160  } else {
161  ATH_MSG_WARNING ( "Bad detector substring: " << det_string << " skipped ... " );
162  continue;
163  }
164  std::string::size_type lay_delimiter( m_selectionList[i].find('/',det_delimiter+1) );
165  lay = atoi(m_selectionList[i].substr(det_delimiter+1, lay_delimiter).c_str());
166  if(lay < 0 || lay > 3) {
167  ATH_MSG_WARNING ( "Bad layer: " << lay << " skipped..." );
168  continue;
169  }
170  std::string::size_type gain_delimiter( m_selectionList[i].find('/',lay_delimiter+1) );
171  gain = atoi(m_selectionList[i].substr(lay_delimiter+1, gain_delimiter).c_str());
172  if(gain < 0 || gain > 2) {
173  ATH_MSG_WARNING ( "Bad gain: " << gain << " skipped..." );
174  continue;
175  }
176  DAC = atoi(m_selectionList[i].substr(gain_delimiter+1).c_str());
177  if(DAC < 0 || DAC > 65000) {
178  ATH_MSG_WARNING ( "Bad DAC: " << DAC << " skipped..." );
179  continue;
180  }
181 
182  // Now we have all numbers
183  m_mapDAC[std::make_pair( std::make_pair(det,lay), gain)] = DAC;
184  m_gmask |= (0x1<<gain);
185  }
186 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArConditionsContainer< LArCaliWaveVec >::ConstConditionsMapIterator
ConditionsMap::const_iterator ConstConditionsMapIterator
Definition: LArConditionsContainer.h:86
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
LArConditionsContainerDB::iteratorT::channelId
HWIdentifier channelId() const
checkCoolLatestUpdate.dg
dg
Definition: checkCoolLatestUpdate.py:9
LArCaliWaveContainer.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
LArCaliWaveSelector::m_selectionList
std::vector< std::string > m_selectionList
Definition: LArCaliWaveSelector.h:51
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloCell_Base_ID::is_em_endcap
bool is_em_endcap(const Identifier id) const
test if the id belongs to the EM Endcap
LArConditionsContainerDB::iteratorT
Declaration of const iterator.
Definition: LArConditionsContainerDB.h:72
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
LArCaliWaveSelector::stop
StatusCode stop()
Definition: LArCaliWaveSelector.cxx:60
LArCaliWaveSelector::m_outputKey
std::string m_outputKey
Definition: LArCaliWaveSelector.h:52
LArCaliWaveSelector::m_groupingType
std::string m_groupingType
Definition: LArCaliWaveSelector.h:53
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
HWIdentifier
Definition: HWIdentifier.h:13
CaloGain::LARNGAIN
@ LARNGAIN
Definition: CaloGain.h:19
LArCaliWaveSelector::initialize
StatusCode initialize()
Definition: LArCaliWaveSelector.cxx:40
CaloCell_Base_ID::is_hec
bool is_hec(const Identifier id) const
test if the id belongs to the HEC
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
CaloCell_ID.h
LArCaliWaveContainer
Liquid Argon Cumulative Wave Container.
Definition: LArCaliWaveContainer.h:33
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
LArCaliWaveSelector::m_cellID
const CaloCell_ID * m_cellID
Definition: LArCaliWaveSelector.h:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArConditionsContainer::end
ConstConditionsMapIterator end(unsigned int gain) const
end of all channels for this gain
lumiFormat.i
int i
Definition: lumiFormat.py:92
CaloCell_Base_ID::is_fcal
bool is_fcal(const Identifier id) const
test if the id belongs to the FCAL - true also for MiniFCAL
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
CaloCell_Base_ID::sampling
int sampling(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
WritePulseShapeToCool.det
det
Definition: WritePulseShapeToCool.py:204
LArCaliWaveSelector::~LArCaliWaveSelector
~LArCaliWaveSelector()
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
LArCaliWaveSelector.h
CaliWaveIt
LArCaliWaveContainer::LArCaliWaves::const_iterator CaliWaveIt
Definition: LArCaliWaveSelector.cxx:21
AthAlgorithm
Definition: AthAlgorithm.h:47
CaloCell_Base_ID::is_em_barrel
bool is_em_barrel(const Identifier id) const
test if the id belongs to the EM barrel
AtlasDetectorID::print_to_string
std::string print_to_string(Identifier id, const IdContext *context=0) const
or provide the printout in string form
Definition: AtlasDetectorID.cxx:655
LArCaliWaveSelector::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArCaliWaveSelector.h:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArCaliWaveSelector::m_gmask
unsigned short m_gmask
Definition: LArCaliWaveSelector.h:48
LArCaliWaveSelector::LArCaliWaveSelector
LArCaliWaveSelector(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArCaliWaveSelector.cxx:23
errorcheck.h
Helpers for checking error return status codes and reporting errors.
LArCaliWaveSelector::m_mapDAC
std::map< DetGain, int > m_mapDAC
Definition: LArCaliWaveSelector.h:47
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloGain::LARHIGHGAIN
@ LARHIGHGAIN
Definition: CaloGain.h:18
DetGain
std::pair< std::pair< int, int >, int > DetGain
Definition: LArCaliWaveSelector.h:23
LArWaveHelper.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArConditionsContainer::begin
ConstConditionsMapIterator begin(unsigned int gain) const
get iterator for all channels for a gain
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
LArCaliWaveSelector::m_keyList
std::vector< std::string > m_keyList
Definition: LArCaliWaveSelector.h:50
CaloGain.h
LArCaliWaveSelector::parseSelection
void parseSelection()
Definition: LArCaliWaveSelector.cxx:141
LArOnlineID.h
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20