ATLAS Offline Software
TRTCondRead.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <fstream>
6 #include <iostream>
7 #include <string>
13 
14 
15 
16 
23 TRTCondRead::TRTCondRead(const std::string& name, ISvcLocator* pSvcLocator)
24  :AthAlgorithm (name, pSvcLocator),
25  m_TRTCalDbTool("TRT_CalDbTool",this),
26  m_setup(false),
27  m_par_caloutputfile(""), // must be either nothing, caliboutput.txt or erroroutput.txt
28  m_trtid(0),
29  m_detstore("DetectorStore",name)
30 {
31  // declare algorithm parameters
32  declareProperty("DetectorStore",m_detstore);
33  declareProperty("CalibOutputFile",m_par_caloutputfile);
34 }
35 
37 {}
38 
40 
41  ATH_MSG_DEBUG("TRTCondRead::initialize() called");
42 
43  //
44  // Get ID helper
45  StatusCode sc = detStore()->retrieve(m_trtid,"TRT_ID");
46  if ( sc.isFailure() ) {
47  ATH_MSG_FATAL( "Could not retrieve TRT ID helper." );
48  return sc;
49  }
50 
51  if(m_TRTCalDbTool.retrieve().isFailure()) {
52  ATH_MSG_FATAL("failed to retrieve TRT_CalDbTool");
53  return StatusCode::FAILURE;
54  }
55 
56 
57  return StatusCode::SUCCESS;
58 }
59 
61 
62  StatusCode sc = StatusCode::SUCCESS;
63  //
64  // at first event:
65  if (!m_setup) {
66 
67 
68 
69  //Write text file.
70  if (!m_par_caloutputfile.empty()) {
71  ATH_MSG_INFO( " Writing calibration constants to text file " << m_par_caloutputfile);
72  std::ofstream outfile(m_par_caloutputfile.c_str());
73  if(m_par_caloutputfile=="caliboutput.txt") {
75  }else if(m_par_caloutputfile=="erroroutput.txt") {
77  } else {
78  ATH_MSG_INFO( " You must use either caliboutput.txt or erroroutput.txt as file name " );
79  }
80  outfile.close();
81  }
82 
83  //Quick spot check of the T0s
84  ATH_MSG_INFO(" Spot check of T0 in every 10'th straw_layer in phi_modules 0, 10, 20 and 30");
85  for(std::vector<Identifier>::const_iterator it=m_trtid->straw_layer_begin();it!=m_trtid->straw_layer_end();++it) {
86  Identifier id = m_trtid->straw_id(*it,0);
87  if(m_trtid->phi_module(id)%10==0 && m_trtid->straw_layer(id)%10==0) {
88  float t0 = m_TRTCalDbTool->getT0(id);
89  ATH_MSG_INFO( " bec: " << m_trtid->barrel_ec(id) << " lay: " << m_trtid->layer_or_wheel(id) <<
90  " phi: " << m_trtid->phi_module(id) << " slay: " << m_trtid->straw_layer(id) << " t0: " << t0);
91  }
92  }
93 
94  m_setup=true;
95 
96  }
97 
98  return sc;
99 }
100 
102  return StatusCode::SUCCESS;
103 }
104 
106 {
107  const RtRelationContainer* rtContainer = m_TRTCalDbTool->getRtContainer() ;
108  const StrawT0Container* t0Container = m_TRTCalDbTool->getT0Container() ;
109 
110  // first store rtrelations
111  outfile << "# Rtrelation" << std::endl ;
113  rtContainer->getall( rtrelations ) ;
114  for( RtRelationContainer::FlatContainer::iterator it = rtrelations.begin() ;
115  it != rtrelations.end(); ++it) {
116  // write the identifier
117  outfile << it->first << " : " ;
118  // write the rt-relation via the factory
120  outfile << std::endl ;
121  }
122 
123  // now store the t0s
124  outfile << "# StrawT0" << std::endl ;
125  StrawT0Container::FlatContainer packedstrawdata ;
126  t0Container->getall( packedstrawdata ) ;
127  float t0(0), t0err(0);
128  for( TRTCond::StrawT0Container::FlatContainer::iterator it = packedstrawdata.begin() ;
129  it != packedstrawdata.end(); ++it) {
130  const TRTCond::ExpandedIdentifier& calid = it->first ;
131  t0Container->unpack(calid,*it->second,t0,t0err) ;
132  outfile << calid << " : " << t0 << " " << t0err << std::endl ;
133  }
134 
135  return StatusCode::SUCCESS ;
136 }
137 
138 
140 {
141  const RtRelationContainer* errContainer = m_TRTCalDbTool->getErrContainer() ;
142  const RtRelationContainer* slopeContainer = m_TRTCalDbTool->getSlopeContainer() ;
143 
144 
145  // then store errors2d
146  outfile << "# RtErrors" << std::endl ;
148  errContainer->getall( errors ) ;
150  it != errors.end(); ++it) {
151  // write the identifier
152  outfile << it->first << " : " ;
153  // write the errors via the factory
155  outfile << std::endl ;
156  }
157 
158  // then store slopes
159  outfile << "# RtSlopes" << std::endl ;
161  slopeContainer->getall( slopes ) ;
162  for( RtRelationContainer::FlatContainer::iterator it = slopes.begin() ;
163  it != slopes.end(); ++it) {
164  // write the identifier
165  outfile << it->first << " : " ;
166  // write the slopes via the factory
168  outfile << std::endl ;
169  }
170 
171 
172  return StatusCode::SUCCESS ;
173 }
174 
175 
177 {
180  m_trtid->straw(id),level ) ;
181 }
182 
183 
184 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TRTCondRead::writeCalibTextFile
virtual StatusCode writeCalibTextFile(std::ostream &) const
write calibration constants or errors to flat text file
Definition: TRTCondRead.cxx:105
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DinesRtRelation.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TRTCondRead::m_setup
bool m_setup
true at first event
Definition: TRTCondRead.h:59
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TRTCondRead::initialize
virtual StatusCode initialize(void) override
Definition: TRTCondRead.cxx:39
TRTCondRead::finalize
virtual StatusCode finalize(void) override
Definition: TRTCondRead.cxx:101
TRTCondRead.h
Algorithm to read TRT calibration constants from db and dump them to a text file.
TRTCondRead::TRTCondRead
TRTCondRead(const std::string &name, ISvcLocator *pSvcLocator)
constructor
Definition: TRTCondRead.cxx:23
BasicRtRelation.h
TRT_ID::straw_layer_end
const_id_iterator straw_layer_end(void) const
Definition: TRT_ID.h:961
TRTCondRead::writeErrorTextFile
virtual StatusCode writeErrorTextFile(std::ostream &) const
Definition: TRTCondRead.cxx:139
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TRTCondRead::~TRTCondRead
~TRTCondRead(void)
destructor
Definition: TRTCondRead.cxx:36
TRTCondRead::trtcondid
virtual TRTCond::ExpandedIdentifier trtcondid(const Identifier &id, int level=TRTCond::ExpandedIdentifier::STRAW) const
create an TRTCond::ExpandedIdentifier from a TRTID identifier
Definition: TRTCondRead.cxx:176
TRT_ID::straw
int straw(const Identifier &id) const
Definition: TRT_ID.h:902
TRTCond::RtRelationFactory::writeToFile
static void writeToFile(std::ostream &os, const RtRelation &rt)
write method
Definition: RtRelationFactory.h:54
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
BinnedRtRelation.h
TRT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: TRT_ID.h:866
TRT_ID::straw_layer
int straw_layer(const Identifier &id) const
Definition: TRT_ID.h:893
TRTCond::StrawT0MultChanContainer::unpack
void unpack(const ExpandedIdentifier &id, const StrawT0 &sd, float &t0, float &t0err) const
public method to unpack a StrawT0 object
Definition: StrawT0MultChanContainer.h:66
TRT_ID::layer_or_wheel
int layer_or_wheel(const Identifier &id) const
Definition: TRT_ID.h:884
AthAlgorithm
Definition: AthAlgorithm.h:47
mergePhysValFiles.errors
list errors
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:43
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TRTCondRead::m_par_caloutputfile
std::string m_par_caloutputfile
Definition: TRTCondRead.h:60
TRTCondRead::m_detstore
ServiceHandle< StoreGateSvc > m_detstore
Definition: TRTCondRead.h:62
TRT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: TRT_ID.h:875
RtRelationFactory.h
TRTCondRead::execute
virtual StatusCode execute(void) override
Definition: TRTCondRead.cxx:60
TRTCondRead::m_TRTCalDbTool
ToolHandle< ITRT_CalDbTool > m_TRTCalDbTool
Definition: TRTCondRead.h:58
TRTCond::MultChanContainer::getall
void getall(typename DaughterContainer::FlatContainer &entries) const
get a flat vector with all values.
Definition: MultChanContainer.h:336
TRTCond::RtRelationMultChanContainer::FlatContainer
RtRelationLayerContainer::FlatContainer FlatContainer
typedef
Definition: RtRelationMultChanContainer.h:32
TRT_ID::straw_layer_begin
const_id_iterator straw_layer_begin(void) const
Iterators over full set of straw_layer ids. Straw_layer ids are sorted.
Definition: TRT_ID.h:953
TRTCond::ExpandedIdentifier
Identifier for TRT detector elements in the conditions code.
Definition: InnerDetector/InDetConditions/TRT_ConditionsData/TRT_ConditionsData/ExpandedIdentifier.h:30
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
TRTCond::StrawT0MultChanContainer
Definition: StrawT0MultChanContainer.h:31
TRTCond::StrawT0MultChanContainer::FlatContainer
StrawT0ContainerTemplate< ExpandedIdentifier::LAYERWHEEL >::FlatContainer FlatContainer
typedefs
Definition: StrawT0MultChanContainer.h:34
TRT_ID::straw_id
Identifier straw_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer, int straw) const
Three ways of getting id for a single straw:
Definition: TRT_ID.h:581
TRTCondRead::m_trtid
const TRT_ID * m_trtid
trt id helper
Definition: TRTCondRead.h:61
TRTCond::RtRelationMultChanContainer
Definition: RtRelationMultChanContainer.h:29
Identifier
Definition: IdentifierFieldParser.cxx:14