ATLAS Offline Software
Loading...
Searching...
No Matches
TRTCondRead.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <fstream>
6#include <iostream>
7#include <string>
8#include "TRTCondRead.h"
13
20TRTCondRead::TRTCondRead(const std::string &name, ISvcLocator *pSvcLocator)
21 : AthAlgorithm(name, pSvcLocator) {}
22
24{
25
26 ATH_MSG_DEBUG("TRTCondRead::initialize() called");
27
28 ATH_CHECK(m_TRTCalDbTool.retrieve());
29
30 // Get TRT ID helper
31 ATH_CHECK(detStore()->retrieve(m_trtid, "TRT_ID"));
32
33 return StatusCode::SUCCESS;
34}
35
37{
38
39 // Write text file.
40 if (!m_par_caloutputfile.empty())
41 {
42 ATH_MSG_INFO(" Writing calibration constants to text file " << m_par_caloutputfile);
43 std::ofstream outfile(m_par_caloutputfile);
44 // if ((m_par_caloutputfile.value()).contains("caliboutput")) TO BE CORRECTED when C++23
45 if (m_par_caloutputfile.value().find("caliboutput") != std::string::npos)
46 {
47 ATH_MSG_INFO("File name: "<< m_par_caloutputfile);
49 }
50 // else if ((m_par_caloutputfile.value()).contains("erroroutput")) TO BE CORRECTED when C++23
51 else if (m_par_caloutputfile.value().find("erroroutput") != std::string::npos)
52 {
53 ATH_MSG_INFO("File name: "<< m_par_caloutputfile);
55 }
56 else
57 {
58 ATH_MSG_WARNING("The file name must contain either 'caliboutput' or 'erroroutput' ");
59 }
60 outfile.close();
61 }
62
63 // Quick spot check of the T0s
64 ATH_MSG_INFO(" Spot check of T0 in every 10'th straw_layer in phi_modules 0, 10, 20 and 30");
65 for (std::vector<Identifier>::const_iterator it = m_trtid->straw_layer_begin(); it != m_trtid->straw_layer_end(); ++it)
66 {
67 Identifier id = m_trtid->straw_id(*it, 0);
68 if (m_trtid->phi_module(id) % 10 == 0 && m_trtid->straw_layer(id) % 10 == 0)
69 {
70 float t0 = m_TRTCalDbTool->getT0(id);
71 ATH_MSG_INFO(" bec: " << m_trtid->barrel_ec(id) << " lay: " << m_trtid->layer_or_wheel(id) << " phi: " << m_trtid->phi_module(id) << " slay: " << m_trtid->straw_layer(id) << " t0: " << t0);
72 }
73 }
74
75 ATH_MSG_INFO("");
76 ATH_MSG_INFO("List of straws with T0=0 :");
77
78 int nzeros = 0;
79 for (std::vector<Identifier>::const_iterator it = m_trtid->straw_layer_begin(); it != m_trtid->straw_layer_end(); ++it)
80 {
81 int nStrawsInLayer = m_trtid->straw_max(*it);
82 for (int i = 0; i <= nStrawsInLayer; i++)
83 {
84 Identifier strid = m_trtid->straw_id(*it, i);
85 if (m_TRTCalDbTool->getT0(strid) == 0)
86 {
87 ATH_MSG_INFO(" bec: " << m_trtid->barrel_ec(strid) << " lay: " << m_trtid->layer_or_wheel(strid)
88 << " phi: " << m_trtid->phi_module(strid) << " slay: " << m_trtid->straw_layer(strid) << " straw: " << m_trtid->straw(strid));
89 nzeros++;
90 }
91 }
92 }
93
94 if (nzeros > 10)
95 {
96 ATH_MSG_INFO(" Several cases of T0=0. Check the input text file and assign default T0 values instead of zero ");
97 }
98 ATH_MSG_INFO("");
99
100 return StatusCode::SUCCESS;
101}
102
104{
105 return StatusCode::SUCCESS;
106}
107
108StatusCode TRTCondRead::writeCalibTextFile(std::ostream &outfile) const
109{
110 const RtRelationContainer *rtContainer = m_TRTCalDbTool->getRtContainer();
111 const StrawT0Container *t0Container = m_TRTCalDbTool->getT0Container();
112
113 // first store rtrelations
114 outfile << "# Rtrelation" << std::endl;
116 rtContainer->getall(rtrelations);
117 for (RtRelationContainer::FlatContainer::iterator it = rtrelations.begin(); it != rtrelations.end(); ++it)
118 {
119 // write the identifier
120 outfile << it->first << " : ";
121 // write the rt-relation via the factory
122 TRTCond::RtRelationFactory::writeToFile(outfile, **(it->second));
123 outfile << std::endl;
124 }
125
126 // now store the t0s
127 outfile << "# StrawT0" << std::endl;
128 StrawT0Container::FlatContainer packedstrawdata;
129 t0Container->getall(packedstrawdata);
130 float t0(0), t0err(0);
131 for (TRTCond::StrawT0Container::FlatContainer::iterator it = packedstrawdata.begin(); it != packedstrawdata.end(); ++it)
132 {
133 const TRTCond::ExpandedIdentifier &calid = it->first;
134 t0Container->unpack(calid, *it->second, t0, t0err);
135 outfile << calid << " : " << t0 << " " << t0err << std::endl;
136 }
137
138 return StatusCode::SUCCESS;
139}
140
141StatusCode TRTCondRead::writeErrorTextFile(std::ostream &outfile) const
142{
143 const RtRelationContainer *errContainer = m_TRTCalDbTool->getErrContainer();
144 const RtRelationContainer *slopeContainer = m_TRTCalDbTool->getSlopeContainer();
145
146 // then store errors2d
147 outfile << "# RtErrors" << std::endl;
149 errContainer->getall(errors);
150 for (RtRelationContainer::FlatContainer::iterator it = errors.begin();
151 it != errors.end(); ++it)
152 {
153 // write the identifier
154 outfile << it->first << " : ";
155 // write the errors via the factory
156 TRTCond::RtRelationFactory::writeToFile(outfile, **(it->second));
157 outfile << std::endl;
158 }
159
160 // then store slopes
161 outfile << "# RtSlopes" << std::endl;
163 slopeContainer->getall(slopes);
164 for (RtRelationContainer::FlatContainer::iterator it = slopes.begin();
165 it != slopes.end(); ++it)
166 {
167 // write the identifier
168 outfile << it->first << " : ";
169 // write the slopes via the factory
170 TRTCond::RtRelationFactory::writeToFile(outfile, **(it->second));
171 outfile << std::endl;
172 }
173
174 return StatusCode::SUCCESS;
175}
176
178{
179 return TRTCond::ExpandedIdentifier(m_trtid->barrel_ec(id), m_trtid->layer_or_wheel(id),
180 m_trtid->phi_module(id), m_trtid->straw_layer(id),
181 m_trtid->straw(id), level);
182}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Algorithm to read TRT calibration constants from db and dump them to a text file.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
ToolHandle< ITRT_CalDbTool > m_TRTCalDbTool
Definition TRTCondRead.h:56
virtual StatusCode execute(void) override
TRTCond::RtRelationMultChanContainer RtRelationContainer
Definition TRTCondRead.h:34
virtual StatusCode initialize(void) override
virtual StatusCode finalize(void) override
TRTCond::StrawT0MultChanContainer StrawT0Container
Definition TRTCondRead.h:35
TRTCondRead(const std::string &name, ISvcLocator *pSvcLocator)
constructor
const TRT_ID * m_trtid
trt id helper
Definition TRTCondRead.h:58
virtual StatusCode writeCalibTextFile(std::ostream &) const
write calibration constants or errors to flat text file
Gaudi::Property< std::string > m_par_caloutputfile
Definition TRTCondRead.h:57
virtual TRTCond::ExpandedIdentifier trtcondid(const Identifier &id, int level=TRTCond::ExpandedIdentifier::STRAW) const
create an TRTCond::ExpandedIdentifier from a TRTID identifier
virtual StatusCode writeErrorTextFile(std::ostream &) const
void getall(typename DaughterContainer::FlatContainer &entries) const
get a flat vector with all values.
static void writeToFile(std::ostream &os, const RtRelation &rt)
write method
RtRelationLayerContainer::FlatContainer FlatContainer
typedef
void unpack(const ExpandedIdentifier &id, const StrawT0 &sd, float &t0, float &t0err) const
public method to unpack a StrawT0 object
StrawT0ContainerTemplate< ExpandedIdentifier::LAYERWHEEL >::FlatContainer FlatContainer
typedefs