ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_StrawAlignDbSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include "TRT_StrawAlignDbSvc.h"
11#include <fstream>
12#include <iostream>
13#include <iomanip>
14#include <sstream>
15
17
18#include "GaudiKernel/IToolSvc.h"
21
22#include "Identifier/Identifier.h"
24
25ATLAS_NO_CHECK_FILE_THREAD_SAFETY; // This class uses const_cast, regFcn (callback) and DataHandle. Legacy code
26
28 ISvcLocator* pSvcLocator )
29 : base_class(name,pSvcLocator),
30 m_detStore("DetectorStore",name),
31 m_par_dxcontainerkey("/TRT/Calib/DX"),
34 m_trtid(nullptr),
35 m_trtman(nullptr),
36 m_streamer("AthenaOutputStreamTool/CondStream1")
37{
38 declareProperty("StrawTextFile",m_par_strawtextfile);
39 declareProperty("ForceCallback",m_par_forcecallback);
40 declareProperty("StreamTool",m_streamer);
41 declareProperty("DetectorStore",m_detStore);
42}
43
44
46= default;
47
48
50{
51 ATH_MSG_INFO ("TRT_StrawAlignDbSvc initialize method called");
52
53 ATH_CHECK( m_detStore->retrieve(m_trtid,"TRT_ID") );
54 ATH_CHECK( m_detStore->retrieve(m_trtman,"TRT") );
55
56
57 bool dxcontainerexists = m_detStore->StoreGateSvc::contains<StrawDxContainer>(m_par_dxcontainerkey) ;
58
59 if( dxcontainerexists ) {
60 ATH_MSG_INFO (" dx container exists - reg callback ");
62 ATH_MSG_ERROR ("Could not register IOV callback for key: " << m_par_dxcontainerkey);
63
64 } else {
65
66 // create, record and update data handle
67 ATH_MSG_INFO ("Creating new dx container");
68 auto dxcontainer = std::make_unique<StrawDxContainer>();
69
70 // reading from file
71 if( !m_par_strawtextfile.empty() ) {
72 ATH_CHECK( this->readTextFile(dxcontainer.get(),
74 }
75
76 ATH_CHECK( m_detStore->record(std::move(dxcontainer), m_par_dxcontainerkey) );
77 }
78
79 return StatusCode::SUCCESS;
80}
81
82
84{
85 ATH_MSG_INFO ("TRT_StrawAlignDbSvc finalize method called");
86 return StatusCode::SUCCESS;
87}
88
89StatusCode TRT_StrawAlignDbSvc::writeTextFile(const std::string& filename) const
90{
91 ATH_MSG_INFO (" Write straw alignment data to text file " << filename);
92 std::ofstream outfile(filename.c_str());
93
94
95 // first reduce the container as much as possible
96 // getDxContainer()->crunch() ;
97
98 StrawDxContainer::FlatContainer packedstrawdata ;
99 const StrawDxContainer* dxcontainer = getConstDxContainer();
100 dxcontainer->getall( packedstrawdata ) ;
101
102 // now, we store the entries
103 ATH_MSG_INFO ("Number of entries in flatcontainer: "
104 << packedstrawdata.size());
105
106 for(auto & it : packedstrawdata) {
107 const TRTCond::ExpandedIdentifier& calid = it.first ;
108 // get the end point corrections. if not the right type, store zeros.
109 float dx1=dxcontainer->getDx1(calid) ;
110 float dx2=dxcontainer->getDx2(calid) ;
111 float dxerr=dxcontainer->getDxErr(calid) ;
112 outfile << calid << " "
113 << std::setprecision(5)
114 << std::setw(12) << dx1 << " "
115 << std::setw(12) << dx2 << " "
116 << std::setw(12) << dxerr << std::endl ;
117 }
118 outfile.close() ;
119 return StatusCode::SUCCESS ;
120}
121
122
123
124StatusCode TRT_StrawAlignDbSvc::readTextFile(const std::string& filename)
125{
126 return readTextFile( getDxContainer(), filename );
127}
128
129
130StatusCode TRT_StrawAlignDbSvc::readTextFile(StrawDxContainer* dxcontainer,
131 const std::string& filename)
132{
133 ATH_MSG_INFO ("Reading straw alignment data from text file " << filename);
134
135 if(!dxcontainer) {
136 ATH_MSG_WARNING (" Could not find the container ");
137 return StatusCode::FAILURE;
138 }
139 dxcontainer->clear() ;
140 std::ifstream infile(filename.c_str()) ;
142 float dx1,dx2,dxerr;
143 int nentries(0) ;
144 while ((infile >> id >> dx1 >> dx2 >> dxerr ) ) {
145 setDx(id,dx1,dx2,dxerr) ;
146 ATH_MSG_DEBUG (" read from file: dx1 " << dx1 << " dx2 " << dx2 << " dxerr " << dxerr);
147 ++nentries ;
148 }
149 size_t dxfootprint = dxcontainer->footprint() ;
150 ATH_MSG_INFO (" read " << nentries << " from file. ");
151 ATH_MSG_INFO (" dx footprints " << dxfootprint);
152 ATH_MSG_INFO (" (no compression) ");
153
154 // force a call back in the geometry
155 int i(0);
156 std::list<std::string> keys ;
157 (const_cast<InDetDD::TRT_DetectorManager*>(m_trtman))->align(i,keys).ignore() ;
158
159 return StatusCode::SUCCESS ;
160}
161
162
164{
165 ATH_MSG_INFO ("entering streamOutObjects ");
166
167 // Get Output Stream tool for writing
168 ATH_CHECK( m_streamer.retrieve() );
169
170 IAthenaOutputStreamTool* streamer=const_cast<IAthenaOutputStreamTool*>(&(*m_streamer));
171
172 ATH_CHECK( streamer->connectOutput() );
173
175 typeKeys.push_back( IAthenaOutputStreamTool::TypeKeyPair(StrawDxContainer::classname(),m_par_dxcontainerkey)) ;
176 getDxContainer()->crunch() ;
177
178 ATH_CHECK( streamer->streamObjects(typeKeys) );
179 ATH_CHECK( streamer->commitOutput() );
180
181 ATH_MSG_INFO (" Streamed out and committed " << typeKeys.size() << " objects ");
182 return StatusCode::SUCCESS;
183}
184
185
186StatusCode TRT_StrawAlignDbSvc::registerObjects(std::string tag, int run1, int event1, int run2, int event2) const
187{
188 ATH_MSG_INFO ("registerObjects with IOV ");
189 ATH_MSG_INFO ("Run/evt1 [" << run1 << "," << event1 << "]");
190 ATH_MSG_INFO ("Run/evt2 [" << run2 << "," << event2 << "]");
191
192 // get pointer to registration svc
193 SmartIF<IIOVRegistrationSvc> regsvc{service("IOVRegistrationSvc")};
194 ATH_CHECK( regsvc.isValid() );
195
196 if (StatusCode::SUCCESS==regsvc->registerIOV(StrawDxContainer::classname(),
197 m_par_dxcontainerkey,tag,run1,run2,event1,event2))
198 ATH_MSG_INFO ("Registered StrawDxContainer object with key " << m_par_dxcontainerkey);
199 else
200 ATH_MSG_ERROR ("Could not register StrawDxContainer object with key " << m_par_dxcontainerkey);
201
202 return( StatusCode::SUCCESS);
203}
204
205
207{
208 for (std::list<std::string>::const_iterator
209 itr=keys.begin(); itr!=keys.end(); ++itr)
210 ATH_MSG_INFO (" IOVCALLBACK for key " << *itr << " number " << I);
211
212 // if constants need to be read from textfile, we use the call back routine to refill the IOV objects
214
215 return StatusCode::SUCCESS;
216}
217
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Interface to an output stream tool.
This is an interface to a tool used to register conditions objects in the Interval of Validity (IOV) ...
#define IOVSVC_CALLBACK_ARGS_P(I, K)
short hand for IOVSvc call back argument list, to be used when access to formal arguments is needed,...
Definition IOVSvcDefs.h:42
#define I(x, y, z)
Definition MD5.cxx:116
interface to TRT straw alignment constants
#define ATLAS_NO_CHECK_FILE_THREAD_SAFETY
This is a tool that allows streaming out of DataObjects.
virtual StatusCode streamObjects(const TypeKeyPairs &typeKeys, const std::string &outputName="")=0
std::pair< std::string, std::string > TypeKeyPair
Stream out objects.
virtual StatusCode connectOutput(const std::string &outputName="")=0
Connect to the output stream Must connectOutput BEFORE streaming Only specify "outputName" if one wan...
std::vector< TypeKeyPair > TypeKeyPairs
virtual StatusCode commitOutput(bool doCommit=false)=0
Commit the output stream after having streamed out objects Must commitOutput AFTER streaming.
The Detector Manager for all TRT Detector elements, it acts as the interface to the detector elements...
TRT_StrawAlignDbSvc(const std::string &name, ISvcLocator *pSvcLocator)
constructor
const DataHandle< StrawDxContainer > m_dxcontainer
virtual StatusCode readTextFile(const std::string &file)
read calibration from text file into TDS
virtual ~TRT_StrawAlignDbSvc()
destructor
StatusCode writeTextFile(const std::string &file) const
write calibration constants to flat text file
StatusCode IOVCallBack(IOVSVC_CALLBACK_ARGS)
IOV call back for dx objects. normally this doesn't do anything.
const InDetDD::TRT_DetectorManager * m_trtman
void setDx(const TRTCond::ExpandedIdentifier &id, float dx1, float dx2, float dxerr)
set endpoints for a TRTCond::ExpandedIdentifier
virtual StatusCode finalize()
tool finalize
StatusCode streamOutObjects() const
write the calibration objects to output, after cleaning
virtual StatusCode initialize()
tool initialize
StrawDxContainer * getDxContainer() const
access to containers
StatusCode registerObjects(std::string tag, int run1, int event1, int run2, int event2) const
register calibration objects with the IoV service
const StrawDxContainer * getConstDxContainer() const
ServiceHandle< StoreGateSvc > m_detStore
ToolHandle< IAthenaOutputStreamTool > m_streamer