ATLAS Offline Software
Loading...
Searching...
No Matches
LArAlignDbAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "LArAlignDbAlg.h"
7
8#include <fstream>
9
10#define LAR_ALIGN "/LAR/Align"
11
12using HepGeom::Translate3D;
13using HepGeom::Rotate3D;
14using CLHEP::Hep3Vector;
15
17
18LArAlignDbAlg::LArAlignDbAlg(const std::string& name, ISvcLocator* pSvcLocator) :
19 AthAlgorithm(name, pSvcLocator),
20 m_regSvc("IOVRegistrationSvc",name),
21 m_streamer("AthenaOutputStreamTool")
22{
23}
24
25// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
29
30// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
32{
33 ATH_MSG_DEBUG(" in initialize()" );
34
35 // Get Output Stream tool for writing
36 if(m_writeCondObjs) {
37 ATH_CHECK( m_streamer.retrieve() );
38 }
39
40 // Get the IOVRegistrationSvc when needed
41 if(m_regIOV) {
42 ATH_CHECK( m_regSvc.retrieve() );
43 ATH_MSG_DEBUG( "Found IOVRegistrationSvc " );
44 }
45
46 return StatusCode::SUCCESS;
47}
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
50
51StatusCode LArAlignDbAlg::execute(const EventContext& ctx)
52{
53 ATH_MSG_DEBUG(" in execute() " );
54
55 int nrun = ctx.eventID().run_number();
56 int nevt = ctx.eventID().event_number();
57
58 ATH_MSG_DEBUG( " Event: [" << nrun << "," << nevt << "]" );
59
60 // If I need to write out the conditions object I'll do that on the first event
61 if (m_writeCondObjs && nevt==1) {
62 ATH_MSG_DEBUG( "Creating conditions objects for run " << nrun );
63
66 } else {
67 // Read objects from DetectorStore
69 }
70
71 return StatusCode::SUCCESS;
72}
73
74// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
75
77{
78 ATH_MSG_DEBUG( " in finalize() " );
79 if(m_writeCondObjs) {
81 ATH_MSG_DEBUG( " Streamed out OK " );
82 }
83
84 if(m_regIOV) {
86 ATH_MSG_DEBUG( " Register OK " );
87 }
88
89 return StatusCode::SUCCESS;
90}
91
92// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
93
95{
96 ATH_MSG_INFO(" in createCondObjects() " );
97
99 ATH_MSG_INFO( " DetCondKeyTrans already exists, do nothing " );
100 return StatusCode::SUCCESS;
101 }
102
103 // Read input file, construct relevant transforms
104 std::ifstream infile;
105 infile.open(m_inpFile.value().c_str());
106
107 if(!infile.is_open()) {
108 ATH_MSG_ERROR( "Unable to open " << m_inpFile << " for reading" );
109 return StatusCode::FAILURE;
110 }
111
112 auto transforms = std::make_unique<DetCondKeyTrans>();
113
114 char commentSign = '#';
115 std::string commentLine;
116 std::string key;
117 double x, y, z, theta, phi, rotationAngle;
118
119 while(!infile.eof()) {
120 infile >> key;
121 if(key.empty()) continue;
122 if(key[0]==commentSign)
123 std::getline(infile,commentLine);
124 else {
125 infile >> theta >> phi >> rotationAngle >> x >> y >> z;
126
127 Hep3Vector axis(sin(theta)*cos(phi),sin(theta)*sin(phi),cos(theta));
128 transforms->setTransform(key,Translate3D(x,y,z)*Rotate3D(rotationAngle,axis));
129 }
130 }
131 infile.close();
132
133 ATH_CHECK( detStore()->record(std::move(transforms),LAR_ALIGN) );
134 ATH_MSG_DEBUG( " Recorded LAr/Align " );
135
136 return StatusCode::SUCCESS;
137}
138
139// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
140
142{
143 const DetCondKeyTrans* align;
144 StatusCode sc = detStore()->retrieve(align, LAR_ALIGN);
145
146 if(sc.isFailure())
147 ATH_MSG_WARNING( " Could not find DetCondKeyTrans" );
148 else if(nullptr == align)
149 ATH_MSG_WARNING(" DetCondKeyTrans ptr is 0" );
150 else {
151 std::cout << " \n\n**************************************************** \n";
152 std::cout << " **** **** \n";
153 std::cout << " **** Printing Conditions Objects **** \n";
154 std::cout << " **** **** \n";
155 std::cout << " **************************************************** \n";
156
157 align->print();
158
159 std::cout << " **** **** **** **** END **** **** **** **** \n\n\n";
160 }
161
162 return StatusCode::SUCCESS;
163}
164
165// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
166
168{
169 ATH_MSG_DEBUG( " entering streamOutCondObjects " );
170
171 ATH_CHECK( m_streamer->connectOutput(m_outpFile.value()) );
172 ATH_MSG_DEBUG(" Did connect stream to output" );
173
174 int npairs = 1;
175
177
178 IAthenaOutputStreamTool::TypeKeyPair align("DetCondKeyTrans", LAR_ALIGN);
179 typeKeys[0] = std::move(align);
180
181 ATH_CHECK( m_streamer->streamObjects(typeKeys) );
182 ATH_CHECK( m_streamer->commitOutput() );
183
184 return StatusCode::SUCCESS;
185}
186
187
188// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
189
191{
192 ATH_MSG_DEBUG( "entering registerCondObject()" );
193
194 std::string objname = "DetCondKeyTrans";
195
196 // Register the IOV DB with the conditions data written out
197 ATH_CHECK( m_regSvc->registerIOV(objname, m_outpTag) );
198 return StatusCode::SUCCESS;
199}
200
Scalar phi() const
phi method
Scalar theta() const
theta method
#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)
#define LAR_ALIGN
static Double_t sc
#define y
#define x
#define z
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
const ServiceHandle< StoreGateSvc > & detStore() const
Class to hold set of HepGeom::Transform3D keyed by string value for storage in the conditions DB typi...
std::pair< std::string, std::string > TypeKeyPair
Stream out objects.
std::vector< TypeKeyPair > TypeKeyPairs
StringProperty m_inpFile
BooleanProperty m_regIOV
ServiceHandle< IIOVRegistrationSvc > m_regSvc
StatusCode registerCondObjects()
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
StringProperty m_outpTag
StringProperty m_outpFile
virtual StatusCode initialize() override
virtual StatusCode finalize() override
LArAlignDbAlg(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandle< IAthenaOutputStreamTool > m_streamer
StatusCode printCondObjects()
StatusCode createCondObjects()
BooleanProperty m_writeCondObjs
StatusCode streamOutCondObjects()
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116