ATLAS Offline Software
Loading...
Searching...
No Matches
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
21using CaliWaveIt = LArCaliWaveContainer::LArCaliWaves::const_iterator;
22
23LArCaliWaveSelector::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
54 ATH_CHECK( m_cablingKey.initialize() );
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
LArCaliWaveContainer::LArCaliWaves::const_iterator CaliWaveIt
LArCaliWaveContainer::ConstConditionsMapIterator CaliMapIt
std::pair< std::pair< int, int >, int > DetGain
static Double_t sc
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
Liquid Argon Cumulative Wave Container.
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
std::map< DetGain, int > m_mapDAC
std::vector< std::string > m_keyList
std::vector< std::string > m_selectionList
const CaloCell_ID * m_cellID
LArCaliWaveSelector(const std::string &name, ISvcLocator *pSvcLocator)
ConditionsMap::const_iterator ConstConditionsMapIterator
ConstConditionsMapIterator begin(unsigned int gain) const
get iterator for all channels for a gain
ConstConditionsMapIterator end(unsigned int gain) const
end of all channels for this gain
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
@ LARNGAIN
Definition CaloGain.h:19
@ LARHIGHGAIN
Definition CaloGain.h:18