ATLAS Offline Software
Loading...
Searching...
No Matches
LArReadParamsFromFile.icc
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7
8#include "LArRawConditions/LArConditionsContainerBase.h"
9
10#include <iostream>
11#include <sstream>
12#include <string>
13
14template <class DATA>
15LArReadParamsFromFile<DATA>::~LArReadParamsFromFile() = default;
16
17template <class DATA>
18StatusCode LArReadParamsFromFile<DATA>::initialize() {
19 ATH_MSG_DEBUG ( "in initialize" );
20
21 if ( m_groupingName == "Unknown" ) {
22 m_groupingType = LArConditionsContainerBase::Unknown ;
23 } else if ( m_groupingName == "SingleGroup" ) {
24 m_groupingType = LArConditionsContainerBase::SingleGroup ;
25 } else if ( m_groupingName == "SubDetectorGrouping" ) {
26 m_groupingType = LArConditionsContainerBase::SubDetectorGrouping ;
27 } else if ( m_groupingName == "FeedThroughGrouping" ) {
28 m_groupingType = LArConditionsContainerBase::FeedThroughGrouping ;
29 } else if ( m_groupingName == "ExtendedFThGrouping" ) {
30 m_groupingType = LArConditionsContainerBase::ExtendedFTGrouping ;
31 } else if ( m_groupingName == "ExtendedSubDetGrouping" ) {
32 m_groupingType = LArConditionsContainerBase::ExtendedSubDetGrouping ;
33 } else {
34 ATH_MSG_ERROR ( "Grouping type " << m_groupingName << " is not foreseen!" );
35 ATH_MSG_ERROR ( "Only \"Unknown\", \"SingleGroup\", \"SubDetectorGrouping\", \"FeedThroughGrouping\" are allowed" );
36 return StatusCode::FAILURE ;
37 }
38
39 const CaloCell_ID* idHelper = nullptr;
40 ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
41 m_emId = idHelper->em_idHelper();
42 m_hecId = idHelper->hec_idHelper();
43 m_fcalId = idHelper->fcal_idHelper();
44 if (!m_emId) {
45 ATH_MSG_ERROR ( "Could not access lar EM ID helper" );
46 return StatusCode::FAILURE;
47 }
48 if (!m_hecId) {
49 ATH_MSG_ERROR ( "Could not access lar HEC ID helper" );
50 return StatusCode::FAILURE;
51 }
52 if (!m_fcalId) {
53 ATH_MSG_ERROR ( "Could not access lar FCAL ID helper" );
54 return StatusCode::FAILURE;
55 }
56
57 ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
58
59 ATH_CHECK( m_cablingKey.initialize() );
60
61 if ( m_chIdType == std::string("UNKNOWN") ) {
62 // use jO specification (default=false) for m_useOfflineIdentifier
63 // and default=false for m_useCalibLines
64 m_useCalibLines = false ;
65 } else if ( m_chIdType == std::string("OfflineID") ) {
66 m_useOfflineIdentifier = true ;
67 m_useCalibLines = false ;
68 } else if ( m_chIdType == std::string("OnlineID") ) {
69 m_useOfflineIdentifier = false ;
70 m_useCalibLines = false ;
71 } else if ( m_chIdType == std::string("OnlineCalibID") ) {
72 m_useOfflineIdentifier = false ;
73 m_useCalibLines = true ;
74 } else {
75 ATH_MSG_ERROR ( "ChannelIdType=" << m_chIdType << " is not valid!" );
76 ATH_MSG_ERROR ( "Allowed options are: OfflineID, OnlineID, OnlineCalibID" );
77 return StatusCode::FAILURE ;
78 }
79
80 if( m_useOfflineIdentifier ) {
81 ATH_MSG_INFO ( "Reading parameters using *** offline identifiers ***" );
82 } else if ( m_useCalibLines ) {
83 ATH_MSG_INFO ( "Reading parameters for *** calibration lines ***" );
84 } else {
85 ATH_MSG_INFO ( "Reading parameters using *** online identifiers ***" );
86 }
87
88 return StatusCode::SUCCESS;
89}
90
91
92template <class DATA>
93StatusCode LArReadParamsFromFile<DATA>::stop ATLAS_NOT_THREAD_SAFE ()
94{
95 ATH_MSG_DEBUG ( "in stop" );
96
97 if ( m_file == std::string("") ) {
98 ATH_MSG_ERROR ( "Input file name was not specified!" );
99 return StatusCode::FAILURE ;
100 }
101
102 m_dataclass = new DATA ;
103 if ( m_groupingType != LArConditionsContainerBase::Unknown ) {
104 m_dataclass->setGroupingType( static_cast<LArConditionsContainerBase::GroupingType>(m_groupingType) ) ;
105 }
106 ATH_CHECK( m_dataclass->initialize() );
107
108 std::string classname = LArParamsProperties::getClassName(m_dataclass) ;
109 std::string key = LArParamsProperties::keyword( classname ) ;
110 if ( m_customKey != "") key = m_customKey;
111
112 ATH_CHECK( readFile() );
113 ATH_MSG_INFO ( "Object " << classname << " successfully uploaded from file " << m_file );
114
115 ATH_CHECK( detStore()->record(m_dataclass,key) );
116 ATH_MSG_INFO ( "Object " << classname << " recorded into detStore with key " << key );
117
118 ATH_MSG_INFO ( "finished!" );
119 return StatusCode::SUCCESS;
120}// end stop-method.
121
122
123template <class DATA>
124StatusCode LArReadParamsFromFile<DATA>::readFile() {
125 // File format:
126 // for online ID: barrel_ec posneg FT slot channel parameters...
127 // for offline ID: det subdet barrel_ec layer region eta phi parameters...
128 int det, subdet, barrel_ec, posneg, ft, slot, channel, region, layer, eta, phi ;
129 std::vector<float> pRead ;
130 HWIdentifier chID ;
131
132 SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{m_cablingKey};
133 const LArOnOffIdMapping* cabling{*cablingHdl};
134 if(!cabling) {
135 ATH_MSG_ERROR( "Do not have cabling from key " << m_cablingKey.key() );
136 return StatusCode::FAILURE;
137 }
138
139 std::ifstream f(m_file) ; // open input file
140 if ( ! f.good() ) {
141 ATH_MSG_ERROR ( "Could not open file " << m_file << ", are you sure it exists??" );
142 return StatusCode::FAILURE ;
143 }
144 ATH_MSG_DEBUG ( "File " << m_file << " opened" );
145
146 unsigned nrec = 0 ;
147 unsigned npar = LArParamsProperties::numberOfParams(m_dataclass) ;
148 ATH_MSG_DEBUG ( "The file should contain " << npar << " parameters per record" );
149
150 while (1) { // read through the file records
151
152 if ( f.eof() ) break ;
153 std::string s ;
154 getline(f,s) ;
155 std::istringstream buffer(s) ;
156 ATH_MSG_VERBOSE ( "*** Record: '" << s << "'" );
157
158 if ( s == std::string("") ) continue ; // skip empty records
159
160 bool good_chID = true ;
161
162 if ( m_useOfflineIdentifier ) { // get HWIdentifier from offline "coordinates"
163
164 buffer >> det ;
165 if ( buffer.fail() ) {
166 ATH_MSG_WARNING ( "Could not read 'det' field for offline identifier" );
167 continue ; // skip and go to next record
168 }
169 buffer >> subdet ;
170 if ( buffer.fail() ) {
171 ATH_MSG_WARNING ( "Could not read 'subdet' field for offline identifier" );
172 continue ; // skip and go to next record
173 }
174 buffer >> barrel_ec ;
175 if ( buffer.fail() ) {
176 ATH_MSG_WARNING ( "Could not read 'barrel_ec' field for offline identifier" );
177 continue ; // skip and go to next record
178 }
179 buffer >> layer ;
180 if ( buffer.fail() ) {
181 ATH_MSG_WARNING ( "Could not read 'layer' field for offline identifier" );
182 continue ; // skip and go to next record
183 }
184 buffer >> region ;
185 if ( buffer.fail() ) {
186 ATH_MSG_WARNING ( "Could not read 'region' field for offline identifier" );
187 continue ; // skip and go to next record
188 }
189 buffer >> eta ;
190 if ( buffer.fail() ) {
191 ATH_MSG_WARNING ( "Could not read 'eta' field for offline identifier" );
192 continue ; // skip and go to next record
193 }
194 buffer >> phi ;
195 if ( buffer.fail() ) {
196 ATH_MSG_WARNING ( "Could not read 'phi' field for offline identifier" );
197 continue ; // skip and go to next record
198 }
199 ATH_MSG_VERBOSE ( "Det=" << det << " SubDet=" << subdet << " BarrelEC=" << barrel_ec
200 << " Sampling=" << layer << " Region=" << region << " Eta=" << eta << " Phi=" << phi );
201 good_chID = true ;
202 if ( det != 4 ) {
203 ATH_MSG_WARNING ( "Det=" << det << " is not LArCalorimeter -- cannot handle it!" );
204 good_chID = false ;
205 } else {
206 Identifier id ;
207 if ( subdet == 1 ) { // LArEM
208 id = m_emId->channel_id(barrel_ec,layer,region,eta,phi) ;
209 ATH_MSG_VERBOSE ( "LAr EM Identifier=" << id );
210 } else if ( subdet == 2 ) { // LArHEC
211 id = m_hecId->channel_id(barrel_ec,layer,region,eta,phi) ;
212 ATH_MSG_VERBOSE ( "LAr HEC Identifier=" << id );
213 } else if ( subdet == 3 ) { // LArFCAL
214 // id = m_fcalId->channel_id(det,layer,region,eta,phi) ;
215 // log << MSG::VERBOSE << "LAr FCAL Identifier=" << id << endmsg ;
216 ATH_MSG_WARNING ( "Subdet=" << subdet
217 << " is LArFCAL -- conversion to online channel not implemented yet!" );
218 good_chID = false ;
219 } else {
220 ATH_MSG_WARNING ( "Subdet=" << subdet << " is unknown -- cannot handle it!" );
221 good_chID = false ;
222 }
223 if ( good_chID ) {
224 try {
225 chID = cabling->createSignalChannelID(id) ;
226 } catch ( LArID_Exception & except ) {
227 ATH_MSG_WARNING ( "Could not get HWId for offline Id " << id );
228 good_chID = false ;
229 }
230 }
231 }
232 if ( ! good_chID ) continue ; // skip and go to next record
233
234 } else { // get HWIdentifier from online "coordinates"
235
236 buffer >> barrel_ec ;
237 if ( buffer.fail() ) {
238 ATH_MSG_WARNING ( "Could not read 'barrel_ec' field for online identifier" );
239 continue ; // skip and go to next record
240 }
241 buffer >> posneg ;
242 if ( buffer.fail() ) {
243 ATH_MSG_WARNING ( "Could not read 'posneg' field for online identifier" );
244 continue ; // skip and go to next record
245 }
246 buffer >> ft ;
247 if ( buffer.fail() ) {
248 ATH_MSG_WARNING ( "Could not read 'feedthrough' field for online identifier" );
249 continue ; // skip and go to next record
250 }
251 buffer >> slot ;
252 if ( buffer.fail() ) {
253 ATH_MSG_WARNING ( "Could not read 'slot' field for online identifier" );
254 continue ; // skip and go to next record
255 }
256 buffer >> channel ;
257 if ( buffer.fail() ) {
258 ATH_MSG_WARNING ( "Could not read 'channel' field for online identifier" );
259 continue ; // skip and go to next record
260 }
261 if ( m_useCalibLines ) {
262 chID = m_onlineHelper->calib_channel_Id(barrel_ec,posneg,ft,slot,channel) ;
263 } else {
264 chID = m_onlineHelper->channel_Id(barrel_ec,posneg,ft,slot,channel) ;
265 }
266
267 } // here the HWIdentifier is obtained!
268
269 if ( ! good_chID ) continue ; // skip and go to next record
270
271 //
272 // get parameters
273 //
274 pRead.resize(npar) ;
275 const float defaultValue = -999 ;
276 for ( unsigned i=0 ; i<npar ; i++ ) pRead[i] = defaultValue ;
277 for ( unsigned i=0 ; i<npar ; i++ ) {
278 //if ( buffer.eof() ) {
279 //log << MSG::DEBUG << "end-of-record reached when reading parameter " << i << " of channel " << chID.get_compact() << endmsg ;
280 //break ;
281 //}
282 buffer >> pRead[i] ;
283 if ( buffer.fail() ) {
284 ATH_MSG_WARNING ( "failure when reading parameter " << i << " of channel " << chID.get_compact() );
285 break ;
286 }
287 }
288 // store into parameters vector
289 msg() << MSG::VERBOSE << "read ch=" << chID.get_compact() ;
290 for ( unsigned i=0 ; i<npar ; i++ ) msg() << " par[" << i << "]=" << pRead[i] ;
291 msg() << endmsg ;
292 for ( unsigned gain=0 ; gain<3 ; gain++ ) {
293 try {
294 StatusCode sc = set(m_dataclass,chID,gain,pRead) ;
295 if ( sc.isFailure() ) {
296 ATH_MSG_WARNING ( "Could not set parameters for ch=" << chID.get_compact() << " gain=" << gain );
297 }
298 } catch ( LArID_Exception & except ) {
299 ATH_MSG_WARNING ( "Bad HWId " << chID );
300 good_chID = false ;
301 }
302 }
303
304 nrec ++ ;
305
306 } // end of while(1) i.e. the loop through all file records
307
308 ATH_MSG_DEBUG ( "end of file reached, read " << nrec << " records" );
309 return StatusCode::SUCCESS ;
310}