1//Dear emacs, this is -*- c++ -*-
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
8#include "LArRawConditions/LArConditionsContainerBase.h"
15LArReadParamsFromFile<DATA>::~LArReadParamsFromFile() = default;
18StatusCode LArReadParamsFromFile<DATA>::initialize() {
19 ATH_MSG_DEBUG ( "in initialize" );
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 ;
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 ;
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();
45 ATH_MSG_ERROR ( "Could not access lar EM ID helper" );
46 return StatusCode::FAILURE;
49 ATH_MSG_ERROR ( "Could not access lar HEC ID helper" );
50 return StatusCode::FAILURE;
53 ATH_MSG_ERROR ( "Could not access lar FCAL ID helper" );
54 return StatusCode::FAILURE;
57 ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
59 ATH_CHECK( m_cablingKey.initialize() );
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 ;
75 ATH_MSG_ERROR ( "ChannelIdType=" << m_chIdType << " is not valid!" );
76 ATH_MSG_ERROR ( "Allowed options are: OfflineID, OnlineID, OnlineCalibID" );
77 return StatusCode::FAILURE ;
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 ***" );
85 ATH_MSG_INFO ( "Reading parameters using *** online identifiers ***" );
88 return StatusCode::SUCCESS;
93StatusCode LArReadParamsFromFile<DATA>::stop ATLAS_NOT_THREAD_SAFE ()
95 ATH_MSG_DEBUG ( "in stop" );
97 if ( m_file == std::string("") ) {
98 ATH_MSG_ERROR ( "Input file name was not specified!" );
99 return StatusCode::FAILURE ;
102 m_dataclass = new DATA ;
103 if ( m_groupingType != LArConditionsContainerBase::Unknown ) {
104 m_dataclass->setGroupingType( static_cast<LArConditionsContainerBase::GroupingType>(m_groupingType) ) ;
106 ATH_CHECK( m_dataclass->initialize() );
108 std::string classname = LArParamsProperties::getClassName(m_dataclass) ;
109 std::string key = LArParamsProperties::keyword( classname ) ;
110 if ( m_customKey != "") key = m_customKey;
112 ATH_CHECK( readFile() );
113 ATH_MSG_INFO ( "Object " << classname << " successfully uploaded from file " << m_file );
115 ATH_CHECK( detStore()->record(m_dataclass,key) );
116 ATH_MSG_INFO ( "Object " << classname << " recorded into detStore with key " << key );
118 ATH_MSG_INFO ( "finished!" );
119 return StatusCode::SUCCESS;
124StatusCode LArReadParamsFromFile<DATA>::readFile() {
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 ;
132 SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{m_cablingKey};
133 const LArOnOffIdMapping* cabling{*cablingHdl};
135 ATH_MSG_ERROR( "Do not have cabling from key " << m_cablingKey.key() );
136 return StatusCode::FAILURE;
139 std::ifstream f(m_file) ; // open input file
141 ATH_MSG_ERROR ( "Could not open file " << m_file << ", are you sure it exists??" );
142 return StatusCode::FAILURE ;
144 ATH_MSG_DEBUG ( "File " << m_file << " opened" );
147 unsigned npar = LArParamsProperties::numberOfParams(m_dataclass) ;
148 ATH_MSG_DEBUG ( "The file should contain " << npar << " parameters per record" );
150 while (1) { // read through the file records
152 if ( f.eof() ) break ;
155 std::istringstream buffer(s) ;
156 ATH_MSG_VERBOSE ( "*** Record: '" << s << "'" );
158 if ( s == std::string("") ) continue ; // skip empty records
160 bool good_chID = true ;
162 if ( m_useOfflineIdentifier ) { // get HWIdentifier from offline "coordinates"
165 if ( buffer.fail() ) {
166 ATH_MSG_WARNING ( "Could not read 'det' field for offline identifier" );
167 continue ; // skip and go to next record
170 if ( buffer.fail() ) {
171 ATH_MSG_WARNING ( "Could not read 'subdet' field for offline identifier" );
172 continue ; // skip and go to next record
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
180 if ( buffer.fail() ) {
181 ATH_MSG_WARNING ( "Could not read 'layer' field for offline identifier" );
182 continue ; // skip and go to next record
185 if ( buffer.fail() ) {
186 ATH_MSG_WARNING ( "Could not read 'region' field for offline identifier" );
187 continue ; // skip and go to next record
190 if ( buffer.fail() ) {
191 ATH_MSG_WARNING ( "Could not read 'eta' field for offline identifier" );
192 continue ; // skip and go to next record
195 if ( buffer.fail() ) {
196 ATH_MSG_WARNING ( "Could not read 'phi' field for offline identifier" );
197 continue ; // skip and go to next record
199 ATH_MSG_VERBOSE ( "Det=" << det << " SubDet=" << subdet << " BarrelEC=" << barrel_ec
200 << " Sampling=" << layer << " Region=" << region << " Eta=" << eta << " Phi=" << phi );
203 ATH_MSG_WARNING ( "Det=" << det << " is not LArCalorimeter -- cannot handle it!" );
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!" );
220 ATH_MSG_WARNING ( "Subdet=" << subdet << " is unknown -- cannot handle it!" );
225 chID = cabling->createSignalChannelID(id) ;
226 } catch ( LArID_Exception & except ) {
227 ATH_MSG_WARNING ( "Could not get HWId for offline Id " << id );
232 if ( ! good_chID ) continue ; // skip and go to next record
234 } else { // get HWIdentifier from online "coordinates"
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
242 if ( buffer.fail() ) {
243 ATH_MSG_WARNING ( "Could not read 'posneg' field for online identifier" );
244 continue ; // skip and go to next record
247 if ( buffer.fail() ) {
248 ATH_MSG_WARNING ( "Could not read 'feedthrough' field for online identifier" );
249 continue ; // skip and go to next record
252 if ( buffer.fail() ) {
253 ATH_MSG_WARNING ( "Could not read 'slot' field for online identifier" );
254 continue ; // skip and go to next record
257 if ( buffer.fail() ) {
258 ATH_MSG_WARNING ( "Could not read 'channel' field for online identifier" );
259 continue ; // skip and go to next record
261 if ( m_useCalibLines ) {
262 chID = m_onlineHelper->calib_channel_Id(barrel_ec,posneg,ft,slot,channel) ;
264 chID = m_onlineHelper->channel_Id(barrel_ec,posneg,ft,slot,channel) ;
267 } // here the HWIdentifier is obtained!
269 if ( ! good_chID ) continue ; // skip and go to next record
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 ;
283 if ( buffer.fail() ) {
284 ATH_MSG_WARNING ( "failure when reading parameter " << i << " of channel " << chID.get_compact() );
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] ;
292 for ( unsigned gain=0 ; gain<3 ; gain++ ) {
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 );
298 } catch ( LArID_Exception & except ) {
299 ATH_MSG_WARNING ( "Bad HWId " << chID );
306 } // end of while(1) i.e. the loop through all file records
308 ATH_MSG_DEBUG ( "end of file reached, read " << nrec << " records" );
309 return StatusCode::SUCCESS ;