ATLAS Offline Software
Loading...
Searching...
No Matches
LArAlignDbAlg.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 "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
52{
53 ATH_MSG_DEBUG(" in execute() " );
54
55 const EventContext& context = getContext();
56 int nrun = context.eventID().run_number();
57 int nevt = context.eventID().event_number();
58
59 ATH_MSG_DEBUG( " Event: [" << nrun << "," << nevt << "]" );
60
61 // If I need to write out the conditions object I'll do that on the first event
62 if (m_writeCondObjs && nevt==1) {
63 ATH_MSG_DEBUG( "Creating conditions objects for run " << nrun );
64
67 } else {
68 // Read objects from DetectorStore
70 }
71
72 return StatusCode::SUCCESS;
73}
74
75// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
76
78{
79 ATH_MSG_DEBUG( " in finalize() " );
80 if(m_writeCondObjs) {
82 ATH_MSG_DEBUG( " Streamed out OK " );
83 }
84
85 if(m_regIOV) {
87 ATH_MSG_DEBUG( " Register OK " );
88 }
89
90 return StatusCode::SUCCESS;
91}
92
93// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
94
96{
97 ATH_MSG_INFO(" in createCondObjects() " );
98
100 ATH_MSG_INFO( " DetCondKeyTrans already exists, do nothing " );
101 return StatusCode::SUCCESS;
102 }
103
104 // Read input file, construct relevant transforms
105 std::ifstream infile;
106 infile.open(m_inpFile.value().c_str());
107
108 if(!infile.is_open()) {
109 ATH_MSG_ERROR( "Unable to open " << m_inpFile << " for reading" );
110 return StatusCode::FAILURE;
111 }
112
113 auto transforms = std::make_unique<DetCondKeyTrans>();
114
115 char commentSign = '#';
116 std::string commentLine;
117 std::string key;
118 double x, y, z, theta, phi, rotationAngle;
119
120 while(!infile.eof()) {
121 infile >> key;
122 if(key.empty()) continue;
123 if(key[0]==commentSign)
124 std::getline(infile,commentLine);
125 else {
126 infile >> theta >> phi >> rotationAngle >> x >> y >> z;
127
128 Hep3Vector axis(sin(theta)*cos(phi),sin(theta)*sin(phi),cos(theta));
129 transforms->setTransform(key,Translate3D(x,y,z)*Rotate3D(rotationAngle,axis));
130 }
131 }
132 infile.close();
133
134 ATH_CHECK( detStore()->record(std::move(transforms),LAR_ALIGN) );
135 ATH_MSG_DEBUG( " Recorded LAr/Align " );
136
137 return StatusCode::SUCCESS;
138}
139
140// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
141
143{
144 const DetCondKeyTrans* align;
145 StatusCode sc = detStore()->retrieve(align, LAR_ALIGN);
146
147 if(sc.isFailure())
148 ATH_MSG_WARNING( " Could not find DetCondKeyTrans" );
149 else if(nullptr == align)
150 ATH_MSG_WARNING(" DetCondKeyTrans ptr is 0" );
151 else {
152 std::cout << " \n\n**************************************************** \n";
153 std::cout << " **** **** \n";
154 std::cout << " **** Printing Conditions Objects **** \n";
155 std::cout << " **** **** \n";
156 std::cout << " **************************************************** \n";
157
158 align->print();
159
160 std::cout << " **** **** **** **** END **** **** **** **** \n\n\n";
161 }
162
163 return StatusCode::SUCCESS;
164}
165
166// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
167
169{
170 ATH_MSG_DEBUG( " entering streamOutCondObjects " );
171
172 ATH_CHECK( m_streamer->connectOutput(m_outpFile.value()) );
173 ATH_MSG_DEBUG(" Did connect stream to output" );
174
175 int npairs = 1;
176
178
179 IAthenaOutputStreamTool::TypeKeyPair align("DetCondKeyTrans", LAR_ALIGN);
180 typeKeys[0] = std::move(align);
181
182 ATH_CHECK( m_streamer->streamObjects(typeKeys) );
183 ATH_CHECK( m_streamer->commitOutput() );
184
185 return StatusCode::SUCCESS;
186}
187
188
189// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
190
192{
193 ATH_MSG_DEBUG( "entering registerCondObject()" );
194
195 std::string objname = "DetCondKeyTrans";
196
197 // Register the IOV DB with the conditions data written out
198 ATH_CHECK( m_regSvc->registerIOV(objname, m_outpTag) );
199 return StatusCode::SUCCESS;
200}
201
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 with parameters:
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
virtual StatusCode execute() override
StringProperty m_inpFile
BooleanProperty m_regIOV
ServiceHandle< IIOVRegistrationSvc > m_regSvc
StatusCode registerCondObjects()
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:114