1 //Dear emacs, this is -*- c++ -*-
4 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
8 #include "LArRawConditions/LArConditionsContainerBase.h"
15 LArReadParamsFromFile<DATA>::LArReadParamsFromFile(const std::string& name, ISvcLocator* pSvcLocator):
16 AthAlgorithm(name, pSvcLocator),
21 m_groupingType(LArConditionsContainerBase::SingleGroup),
22 m_useCalibLines(false),
26 // file name to be read
27 declareProperty("File",m_file="") ;
28 // choose whether use offline ID (default is online)
29 declareProperty("UseOfflineIdentifier",m_useOfflineIdentifier=false) ;
30 // assign grouping type (only for LArConditionsContainer-based classes)
31 declareProperty("GroupingType",m_groupingName="Unknown") ;
32 declareProperty("ChannelIdType",m_chIdType="UNKNOWN");
33 declareProperty("CustomKey",m_customKey="");
37 LArReadParamsFromFile<DATA>::~LArReadParamsFromFile()
41 StatusCode LArReadParamsFromFile<DATA>::initialize() {
42 ATH_MSG_DEBUG ( "in initialize" );
44 if ( m_groupingName == "Unknown" ) {
45 m_groupingType = LArConditionsContainerBase::Unknown ;
46 } else if ( m_groupingName == "SingleGroup" ) {
47 m_groupingType = LArConditionsContainerBase::SingleGroup ;
48 } else if ( m_groupingName == "SubDetectorGrouping" ) {
49 m_groupingType = LArConditionsContainerBase::SubDetectorGrouping ;
50 } else if ( m_groupingName == "FeedThroughGrouping" ) {
51 m_groupingType = LArConditionsContainerBase::FeedThroughGrouping ;
52 } else if ( m_groupingName == "ExtendedFThGrouping" ) {
53 m_groupingType = LArConditionsContainerBase::ExtendedFTGrouping ;
54 } else if ( m_groupingName == "ExtendedSubDetGrouping" ) {
55 m_groupingType = LArConditionsContainerBase::ExtendedSubDetGrouping ;
57 ATH_MSG_ERROR ( "Grouping type " << m_groupingName << " is not foreseen!" );
58 ATH_MSG_ERROR ( "Only \"Unknown\", \"SingleGroup\", \"SubDetectorGrouping\", \"FeedThroughGrouping\" are allowed" );
59 return StatusCode::FAILURE ;
62 const CaloCell_ID* idHelper = nullptr;
63 ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
64 m_emId = idHelper->em_idHelper();
65 m_hecId = idHelper->hec_idHelper();
66 m_fcalId = idHelper->fcal_idHelper();
68 ATH_MSG_ERROR ( "Could not access lar EM ID helper" );
69 return StatusCode::FAILURE;
72 ATH_MSG_ERROR ( "Could not access lar HEC ID helper" );
73 return StatusCode::FAILURE;
76 ATH_MSG_ERROR ( "Could not access lar FCAL ID helper" );
77 return StatusCode::FAILURE;
80 ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
82 ATH_CHECK( m_cablingKey.initialize() );
84 if ( m_chIdType == std::string("UNKNOWN") ) {
85 // use jO specification (default=false) for m_useOfflineIdentifier
86 // and default=false for m_useCalibLines
87 m_useCalibLines = false ;
88 } else if ( m_chIdType == std::string("OfflineID") ) {
89 m_useOfflineIdentifier = true ;
90 m_useCalibLines = false ;
91 } else if ( m_chIdType == std::string("OnlineID") ) {
92 m_useOfflineIdentifier = false ;
93 m_useCalibLines = false ;
94 } else if ( m_chIdType == std::string("OnlineCalibID") ) {
95 m_useOfflineIdentifier = false ;
96 m_useCalibLines = true ;
98 ATH_MSG_ERROR ( "ChannelIdType=" << m_chIdType << " is not valid!" );
99 ATH_MSG_ERROR ( "Allowed options are: OfflineID, OnlineID, OnlineCalibID" );
100 return StatusCode::FAILURE ;
103 if( m_useOfflineIdentifier ) {
104 ATH_MSG_INFO ( "Reading parameters using *** offline identifiers ***" );
105 } else if ( m_useCalibLines ) {
106 ATH_MSG_INFO ( "Reading parameters for *** calibration lines ***" );
108 ATH_MSG_INFO ( "Reading parameters using *** online identifiers ***" );
111 return StatusCode::SUCCESS;
115 template <class DATA>
116 StatusCode LArReadParamsFromFile<DATA>::stop ATLAS_NOT_THREAD_SAFE ()
118 ATH_MSG_DEBUG ( "in stop" );
120 if ( m_file == std::string("") ) {
121 ATH_MSG_ERROR ( "Input file name was not specified!" );
122 return StatusCode::FAILURE ;
125 m_dataclass = new DATA ;
126 if ( m_groupingType != LArConditionsContainerBase::Unknown ) {
127 m_dataclass->setGroupingType( static_cast<LArConditionsContainerBase::GroupingType>(m_groupingType) ) ;
129 ATH_CHECK( m_dataclass->initialize() );
131 std::string classname = LArParamsProperties::getClassName(m_dataclass) ;
132 std::string key = LArParamsProperties::keyword( classname ) ;
133 if ( m_customKey != "") key = m_customKey;
135 ATH_CHECK( readFile() );
136 ATH_MSG_INFO ( "Object " << classname << " successfully uploaded from file " << m_file );
138 ATH_CHECK( detStore()->record(m_dataclass,key) );
139 ATH_MSG_INFO ( "Object " << classname << " recorded into detStore with key " << key );
141 ATH_CHECK ( do_symLink(m_dataclass) );
142 ATH_MSG_INFO ( "Object " << classname << " symLinked to its abstract interface" );
144 ATH_MSG_INFO ( "finished!" );
145 return StatusCode::SUCCESS;
149 template <class DATA>
150 StatusCode LArReadParamsFromFile<DATA>::readFile() {
152 // for online ID: barrel_ec posneg FT slot channel parameters...
153 // for offline ID: det subdet barrel_ec layer region eta phi parameters...
154 int det, subdet, barrel_ec, posneg, ft, slot, channel, region, layer, eta, phi ;
155 std::vector<float> pRead ;
158 SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{m_cablingKey};
159 const LArOnOffIdMapping* cabling{*cablingHdl};
161 ATH_MSG_ERROR( "Do not have cabling from key " << m_cablingKey.key() );
162 return StatusCode::FAILURE;
165 std::ifstream f(m_file.c_str()) ; // open input file
167 ATH_MSG_ERROR ( "Could not open file " << m_file << ", are you sure it exists??" );
168 return StatusCode::FAILURE ;
170 ATH_MSG_DEBUG ( "File " << m_file << " opened" );
173 unsigned npar = LArParamsProperties::numberOfParams(m_dataclass) ;
174 ATH_MSG_DEBUG ( "The file should contain " << npar << " parameters per record" );
176 while (1) { // read through the file records
178 if ( f.eof() ) break ;
181 std::istringstream buffer(s) ;
182 ATH_MSG_VERBOSE ( "*** Record: '" << s << "'" );
184 if ( s == std::string("") ) continue ; // skip empty records
186 bool good_chID = true ;
188 if ( m_useOfflineIdentifier ) { // get HWIdentifier from offline "coordinates"
191 if ( buffer.fail() ) {
192 ATH_MSG_WARNING ( "Could not read 'det' field for offline identifier" );
193 continue ; // skip and go to next record
196 if ( buffer.fail() ) {
197 ATH_MSG_WARNING ( "Could not read 'subdet' field for offline identifier" );
198 continue ; // skip and go to next record
200 buffer >> barrel_ec ;
201 if ( buffer.fail() ) {
202 ATH_MSG_WARNING ( "Could not read 'barrel_ec' field for offline identifier" );
203 continue ; // skip and go to next record
206 if ( buffer.fail() ) {
207 ATH_MSG_WARNING ( "Could not read 'layer' field for offline identifier" );
208 continue ; // skip and go to next record
211 if ( buffer.fail() ) {
212 ATH_MSG_WARNING ( "Could not read 'region' field for offline identifier" );
213 continue ; // skip and go to next record
216 if ( buffer.fail() ) {
217 ATH_MSG_WARNING ( "Could not read 'eta' field for offline identifier" );
218 continue ; // skip and go to next record
221 if ( buffer.fail() ) {
222 ATH_MSG_WARNING ( "Could not read 'phi' field for offline identifier" );
223 continue ; // skip and go to next record
225 ATH_MSG_VERBOSE ( "Det=" << det << " SubDet=" << subdet << " BarrelEC=" << barrel_ec
226 << " Sampling=" << layer << " Region=" << region << " Eta=" << eta << " Phi=" << phi );
229 ATH_MSG_WARNING ( "Det=" << det << " is not LArCalorimeter -- cannot handle it!" );
233 if ( subdet == 1 ) { // LArEM
234 id = m_emId->channel_id(barrel_ec,layer,region,eta,phi) ;
235 ATH_MSG_VERBOSE ( "LAr EM Identifier=" << id );
236 } else if ( subdet == 2 ) { // LArHEC
237 id = m_hecId->channel_id(barrel_ec,layer,region,eta,phi) ;
238 ATH_MSG_VERBOSE ( "LAr HEC Identifier=" << id );
239 } else if ( subdet == 3 ) { // LArFCAL
240 // id = m_fcalId->channel_id(det,layer,region,eta,phi) ;
241 // log << MSG::VERBOSE << "LAr FCAL Identifier=" << id << endmsg ;
242 ATH_MSG_WARNING ( "Subdet=" << subdet
243 << " is LArFCAL -- conversion to online channel not implemented yet!" );
246 ATH_MSG_WARNING ( "Subdet=" << subdet << " is unknown -- cannot handle it!" );
251 chID = cabling->createSignalChannelID(id) ;
252 } catch ( LArID_Exception & except ) {
253 ATH_MSG_WARNING ( "Could not get HWId for offline Id " << id );
258 if ( ! good_chID ) continue ; // skip and go to next record
260 } else { // get HWIdentifier from online "coordinates"
262 buffer >> barrel_ec ;
263 if ( buffer.fail() ) {
264 ATH_MSG_WARNING ( "Could not read 'barrel_ec' field for online identifier" );
265 continue ; // skip and go to next record
268 if ( buffer.fail() ) {
269 ATH_MSG_WARNING ( "Could not read 'posneg' field for online identifier" );
270 continue ; // skip and go to next record
273 if ( buffer.fail() ) {
274 ATH_MSG_WARNING ( "Could not read 'feedthrough' field for online identifier" );
275 continue ; // skip and go to next record
278 if ( buffer.fail() ) {
279 ATH_MSG_WARNING ( "Could not read 'slot' field for online identifier" );
280 continue ; // skip and go to next record
283 if ( buffer.fail() ) {
284 ATH_MSG_WARNING ( "Could not read 'channel' field for online identifier" );
285 continue ; // skip and go to next record
287 if ( m_useCalibLines ) {
288 chID = m_onlineHelper->calib_channel_Id(barrel_ec,posneg,ft,slot,channel) ;
290 chID = m_onlineHelper->channel_Id(barrel_ec,posneg,ft,slot,channel) ;
293 } // here the HWIdentifier is obtained!
295 if ( ! good_chID ) continue ; // skip and go to next record
301 const float defaultValue = -999 ;
302 for ( unsigned i=0 ; i<npar ; i++ ) pRead[i] = defaultValue ;
303 for ( unsigned i=0 ; i<npar ; i++ ) {
304 //if ( buffer.eof() ) {
305 //log << MSG::DEBUG << "end-of-record reached when reading parameter " << i << " of channel " << chID.get_compact() << endmsg ;
309 if ( buffer.fail() ) {
310 ATH_MSG_WARNING ( "failure when reading parameter " << i << " of channel " << chID.get_compact() );
314 // store into parameters vector
315 msg() << MSG::VERBOSE << "read ch=" << chID.get_compact() ;
316 for ( unsigned i=0 ; i<npar ; i++ ) msg() << " par[" << i << "]=" << pRead[i] ;
318 for ( unsigned gain=0 ; gain<3 ; gain++ ) {
320 StatusCode sc = set(m_dataclass,chID,gain,pRead) ;
321 if ( sc.isFailure() ) {
322 ATH_MSG_WARNING ( "Could not set parameters for ch=" << chID.get_compact() << " gain=" << gain );
324 } catch ( LArID_Exception & except ) {
325 ATH_MSG_WARNING ( "Bad HWId " << chID );
332 } // end of while(1) i.e. the loop through all file records
334 ATH_MSG_DEBUG ( "end of file reached, read " << nrec << " records" );
335 return StatusCode::SUCCESS ;