ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_StrawAlignDbSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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_DEBUG(" dx container exists - do nothing ");
61
62 } else {
63
64 // create, record and update data handle
65 ATH_MSG_INFO ("Creating new dx container");
66 auto dxcontainer = std::make_unique<StrawDxContainer>();
67
68 // reading from file
69 if( !m_par_strawtextfile.empty() ) {
70 ATH_CHECK( this->readTextFile(dxcontainer.get(),
72 }
73
74 ATH_CHECK( m_detStore->record(std::move(dxcontainer), m_par_dxcontainerkey) );
75 }
76
77 return StatusCode::SUCCESS;
78}
79
80
82{
83 ATH_MSG_INFO ("TRT_StrawAlignDbSvc finalize method called");
84 return StatusCode::SUCCESS;
85}
86
87StatusCode TRT_StrawAlignDbSvc::writeTextFile(const std::string& filename) const
88{
89 ATH_MSG_INFO (" Write straw alignment data to text file " << filename);
90 std::ofstream outfile(filename.c_str());
91
92
93 // first reduce the container as much as possible
94 // getDxContainer()->crunch() ;
95
96 StrawDxContainer::FlatContainer packedstrawdata ;
97 const StrawDxContainer* dxcontainer = getConstDxContainer();
98 dxcontainer->getall( packedstrawdata ) ;
99
100 // now, we store the entries
101 ATH_MSG_INFO ("Number of entries in flatcontainer: "
102 << packedstrawdata.size());
103
104 for(auto & it : packedstrawdata) {
105 const TRTCond::ExpandedIdentifier& calid = it.first ;
106 // get the end point corrections. if not the right type, store zeros.
107 float dx1=dxcontainer->getDx1(calid) ;
108 float dx2=dxcontainer->getDx2(calid) ;
109 float dxerr=dxcontainer->getDxErr(calid) ;
110 outfile << calid << " "
111 << std::setprecision(5)
112 << std::setw(12) << dx1 << " "
113 << std::setw(12) << dx2 << " "
114 << std::setw(12) << dxerr << std::endl ;
115 }
116 outfile.close() ;
117 return StatusCode::SUCCESS ;
118}
119
120
121
122StatusCode TRT_StrawAlignDbSvc::readTextFile(const std::string& filename)
123{
124 return readTextFile( getDxContainer(), filename );
125}
126
127
128StatusCode TRT_StrawAlignDbSvc::readTextFile(StrawDxContainer* dxcontainer,
129 const std::string& filename)
130{
131 ATH_MSG_INFO ("Reading straw alignment data from text file " << filename);
132
133 if(!dxcontainer) {
134 ATH_MSG_WARNING (" Could not find the container ");
135 return StatusCode::FAILURE;
136 }
137 dxcontainer->clear() ;
138 std::ifstream infile(filename.c_str()) ;
140 float dx1,dx2,dxerr;
141 int nentries(0) ;
142 while ((infile >> id >> dx1 >> dx2 >> dxerr ) ) {
143 setDx(id,dx1,dx2,dxerr) ;
144 ATH_MSG_DEBUG (" read from file: dx1 " << dx1 << " dx2 " << dx2 << " dxerr " << dxerr);
145 ++nentries ;
146 }
147 size_t dxfootprint = dxcontainer->footprint() ;
148 ATH_MSG_INFO (" read " << nentries << " from file. ");
149 ATH_MSG_INFO (" dx footprints " << dxfootprint);
150 ATH_MSG_INFO (" (no compression) ");
151
152 // force a call back in the geometry
153// (const_cast<InDetDD::TRT_DetectorManager*>(m_trtman))->align().ignore() ;
154
155 return StatusCode::SUCCESS ;
156}
157
158
160{
161 ATH_MSG_INFO ("entering streamOutObjects ");
162
163 // Get Output Stream tool for writing
164 ATH_CHECK( m_streamer.retrieve() );
165
166 IAthenaOutputStreamTool* streamer=const_cast<IAthenaOutputStreamTool*>(&(*m_streamer));
167
168 ATH_CHECK( streamer->connectOutput() );
169
171 typeKeys.push_back( IAthenaOutputStreamTool::TypeKeyPair(StrawDxContainer::classname(),m_par_dxcontainerkey)) ;
172 getDxContainer()->crunch() ;
173
174 ATH_CHECK( streamer->streamObjects(typeKeys) );
175 ATH_CHECK( streamer->commitOutput() );
176
177 ATH_MSG_INFO (" Streamed out and committed " << typeKeys.size() << " objects ");
178 return StatusCode::SUCCESS;
179}
180
181
182StatusCode TRT_StrawAlignDbSvc::registerObjects(std::string tag, int run1, int event1, int run2, int event2) const
183{
184 ATH_MSG_INFO ("registerObjects with IOV ");
185 ATH_MSG_INFO ("Run/evt1 [" << run1 << "," << event1 << "]");
186 ATH_MSG_INFO ("Run/evt2 [" << run2 << "," << event2 << "]");
187
188 // get pointer to registration svc
189 SmartIF<IIOVRegistrationSvc> regsvc{service("IOVRegistrationSvc")};
190 ATH_CHECK( regsvc.isValid() );
191
192 if (StatusCode::SUCCESS==regsvc->registerIOV(StrawDxContainer::classname(),
193 m_par_dxcontainerkey,tag,run1,run2,event1,event2))
194 ATH_MSG_INFO ("Registered StrawDxContainer object with key " << m_par_dxcontainerkey);
195 else
196 ATH_MSG_ERROR ("Could not register StrawDxContainer object with key " << m_par_dxcontainerkey);
197
198 return( StatusCode::SUCCESS);
199}
200
201
203{
204 /*
205 for (std::list<std::string>::const_iterator
206 itr=keys.begin(); itr!=keys.end(); ++itr)
207 ATH_MSG_INFO (" IOVCALLBACK for key " << *itr << " number " << I);
208 */
209
210 // if constants need to be read from textfile, we use the call back routine to refill the IOV objects
212
213 return StatusCode::SUCCESS;
214}
215
#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) ...
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.
TRT_StrawAlignDbSvc(const std::string &name, ISvcLocator *pSvcLocator)
constructor
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
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
StatusCode IOVCallBack()
IOV call back for dx objects. normally this doesn't do anything.
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