1//Dear emacs, this is -*- c++ -*-
4 Copyright (C) 2002-2022 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_CHECK ( do_symLink(m_dataclass) );
119 ATH_MSG_INFO ( "Object " << classname << " symLinked to its abstract interface" );
121 ATH_MSG_INFO ( "finished!" );
122 return StatusCode::SUCCESS;
127StatusCode LArReadParamsFromFile<DATA>::readFile() {
129 // for online ID: barrel_ec posneg FT slot channel parameters...
130 // for offline ID: det subdet barrel_ec layer region eta phi parameters...
131 int det, subdet, barrel_ec, posneg, ft, slot, channel, region, layer, eta, phi ;
132 std::vector<float> pRead ;
135 SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{m_cablingKey};
136 const LArOnOffIdMapping* cabling{*cablingHdl};
138 ATH_MSG_ERROR( "Do not have cabling from key " << m_cablingKey.key() );
139 return StatusCode::FAILURE;
142 std::ifstream f(m_file) ; // open input file
144 ATH_MSG_ERROR ( "Could not open file " << m_file << ", are you sure it exists??" );
145 return StatusCode::FAILURE ;
147 ATH_MSG_DEBUG ( "File " << m_file << " opened" );
150 unsigned npar = LArParamsProperties::numberOfParams(m_dataclass) ;
151 ATH_MSG_DEBUG ( "The file should contain " << npar << " parameters per record" );
153 while (1) { // read through the file records
155 if ( f.eof() ) break ;
158 std::istringstream buffer(s) ;
159 ATH_MSG_VERBOSE ( "*** Record: '" << s << "'" );
161 if ( s == std::string("") ) continue ; // skip empty records
163 bool good_chID = true ;
165 if ( m_useOfflineIdentifier ) { // get HWIdentifier from offline "coordinates"
168 if ( buffer.fail() ) {
169 ATH_MSG_WARNING ( "Could not read 'det' field for offline identifier" );
170 continue ; // skip and go to next record
173 if ( buffer.fail() ) {
174 ATH_MSG_WARNING ( "Could not read 'subdet' field for offline identifier" );
175 continue ; // skip and go to next record
177 buffer >> barrel_ec ;
178 if ( buffer.fail() ) {
179 ATH_MSG_WARNING ( "Could not read 'barrel_ec' field for offline identifier" );
180 continue ; // skip and go to next record
183 if ( buffer.fail() ) {
184 ATH_MSG_WARNING ( "Could not read 'layer' field for offline identifier" );
185 continue ; // skip and go to next record
188 if ( buffer.fail() ) {
189 ATH_MSG_WARNING ( "Could not read 'region' field for offline identifier" );
190 continue ; // skip and go to next record
193 if ( buffer.fail() ) {
194 ATH_MSG_WARNING ( "Could not read 'eta' field for offline identifier" );
195 continue ; // skip and go to next record
198 if ( buffer.fail() ) {
199 ATH_MSG_WARNING ( "Could not read 'phi' field for offline identifier" );
200 continue ; // skip and go to next record
202 ATH_MSG_VERBOSE ( "Det=" << det << " SubDet=" << subdet << " BarrelEC=" << barrel_ec
203 << " Sampling=" << layer << " Region=" << region << " Eta=" << eta << " Phi=" << phi );
206 ATH_MSG_WARNING ( "Det=" << det << " is not LArCalorimeter -- cannot handle it!" );
210 if ( subdet == 1 ) { // LArEM
211 id = m_emId->channel_id(barrel_ec,layer,region,eta,phi) ;
212 ATH_MSG_VERBOSE ( "LAr EM Identifier=" << id );
213 } else if ( subdet == 2 ) { // LArHEC
214 id = m_hecId->channel_id(barrel_ec,layer,region,eta,phi) ;
215 ATH_MSG_VERBOSE ( "LAr HEC Identifier=" << id );
216 } else if ( subdet == 3 ) { // LArFCAL
217 // id = m_fcalId->channel_id(det,layer,region,eta,phi) ;
218 // log << MSG::VERBOSE << "LAr FCAL Identifier=" << id << endmsg ;
219 ATH_MSG_WARNING ( "Subdet=" << subdet
220 << " is LArFCAL -- conversion to online channel not implemented yet!" );
223 ATH_MSG_WARNING ( "Subdet=" << subdet << " is unknown -- cannot handle it!" );
228 chID = cabling->createSignalChannelID(id) ;
229 } catch ( LArID_Exception & except ) {
230 ATH_MSG_WARNING ( "Could not get HWId for offline Id " << id );
235 if ( ! good_chID ) continue ; // skip and go to next record
237 } else { // get HWIdentifier from online "coordinates"
239 buffer >> barrel_ec ;
240 if ( buffer.fail() ) {
241 ATH_MSG_WARNING ( "Could not read 'barrel_ec' field for online identifier" );
242 continue ; // skip and go to next record
245 if ( buffer.fail() ) {
246 ATH_MSG_WARNING ( "Could not read 'posneg' field for online identifier" );
247 continue ; // skip and go to next record
250 if ( buffer.fail() ) {
251 ATH_MSG_WARNING ( "Could not read 'feedthrough' field for online identifier" );
252 continue ; // skip and go to next record
255 if ( buffer.fail() ) {
256 ATH_MSG_WARNING ( "Could not read 'slot' field for online identifier" );
257 continue ; // skip and go to next record
260 if ( buffer.fail() ) {
261 ATH_MSG_WARNING ( "Could not read 'channel' field for online identifier" );
262 continue ; // skip and go to next record
264 if ( m_useCalibLines ) {
265 chID = m_onlineHelper->calib_channel_Id(barrel_ec,posneg,ft,slot,channel) ;
267 chID = m_onlineHelper->channel_Id(barrel_ec,posneg,ft,slot,channel) ;
270 } // here the HWIdentifier is obtained!
272 if ( ! good_chID ) continue ; // skip and go to next record
278 const float defaultValue = -999 ;
279 for ( unsigned i=0 ; i<npar ; i++ ) pRead[i] = defaultValue ;
280 for ( unsigned i=0 ; i<npar ; i++ ) {
281 //if ( buffer.eof() ) {
282 //log << MSG::DEBUG << "end-of-record reached when reading parameter " << i << " of channel " << chID.get_compact() << endmsg ;
286 if ( buffer.fail() ) {
287 ATH_MSG_WARNING ( "failure when reading parameter " << i << " of channel " << chID.get_compact() );
291 // store into parameters vector
292 msg() << MSG::VERBOSE << "read ch=" << chID.get_compact() ;
293 for ( unsigned i=0 ; i<npar ; i++ ) msg() << " par[" << i << "]=" << pRead[i] ;
295 for ( unsigned gain=0 ; gain<3 ; gain++ ) {
297 StatusCode sc = set(m_dataclass,chID,gain,pRead) ;
298 if ( sc.isFailure() ) {
299 ATH_MSG_WARNING ( "Could not set parameters for ch=" << chID.get_compact() << " gain=" << gain );
301 } catch ( LArID_Exception & except ) {
302 ATH_MSG_WARNING ( "Bad HWId " << chID );
309 } // end of while(1) i.e. the loop through all file records
311 ATH_MSG_DEBUG ( "end of file reached, read " << nrec << " records" );
312 return StatusCode::SUCCESS ;