ATLAS Offline Software
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 
12 using HepGeom::Translate3D;
13 using HepGeom::Rotate3D;
14 using CLHEP::Hep3Vector;
15 
17 
18 LArAlignDbAlg::LArAlignDbAlg(const std::string& name, ISvcLocator* pSvcLocator) :
19  AthAlgorithm(name, pSvcLocator),
20  m_regSvc("IOVRegistrationSvc",name),
21  m_streamer("AthenaOutputStreamTool")
22 {
23 }
24 
25 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
27 {
28 }
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 
99  if(detStore()->contains<DetCondKeyTrans>(LAR_ALIGN)) {
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 
177  IAthenaOutputStreamTool::TypeKeyPairs typeKeys(npairs);
178 
179  IAthenaOutputStreamTool::TypeKeyPair align("DetCondKeyTrans", LAR_ALIGN);
180  typeKeys[0] = 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 
LAR_ALIGN
#define LAR_ALIGN
Definition: LArAlignDbAlg.cxx:10
IAthenaOutputStreamTool::TypeKeyPairs
std::vector< TypeKeyPair > TypeKeyPairs
Definition: IAthenaOutputStreamTool.h:100
run.infile
string infile
Definition: run.py:13
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
DetCondKeyTrans
Class to hold set of HepGeom::Transform3D keyed by string value for storage in the conditions DB typi...
Definition: DetCondKeyTrans.h:27
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArAlignDbAlg::~LArAlignDbAlg
~LArAlignDbAlg()
Definition: LArAlignDbAlg.cxx:26
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
yodamerge_tmp.axis
list axis
Definition: yodamerge_tmp.py:241
DetCondKeyTrans::print
void print() const
Definition: DetCondKeyTrans.cxx:30
LArAlignDbAlg::m_streamer
ToolHandle< IAthenaOutputStreamTool > m_streamer
Definition: LArAlignDbAlg.h:47
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
LArAlignDbAlg::createCondObjects
StatusCode createCondObjects()
Definition: LArAlignDbAlg.cxx:95
LArAlignDbAlg::execute
virtual StatusCode execute() override
Definition: LArAlignDbAlg.cxx:51
x
#define x
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
LArAlignDbAlg::m_regSvc
ServiceHandle< IIOVRegistrationSvc > m_regSvc
Definition: LArAlignDbAlg.h:46
LArAlignDbAlg::m_outpTag
StringProperty m_outpTag
Definition: LArAlignDbAlg.h:44
LArAlignDbAlg::m_inpFile
StringProperty m_inpFile
Definition: LArAlignDbAlg.h:42
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
z
#define z
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IAthenaOutputStreamTool::TypeKeyPair
std::pair< std::string, std::string > TypeKeyPair
Stream out objects.
Definition: IAthenaOutputStreamTool.h:99
LArAlignDbAlg::registerCondObjects
StatusCode registerCondObjects()
Definition: LArAlignDbAlg.cxx:191
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DetCondKeyTrans.h
LArAlignDbAlg::m_outpFile
StringProperty m_outpFile
Definition: LArAlignDbAlg.h:43
LArAlignDbAlg::LArAlignDbAlg
LArAlignDbAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArAlignDbAlg.cxx:18
AthAlgorithm
Definition: AthAlgorithm.h:47
LArAlignDbAlg::initialize
virtual StatusCode initialize() override
Definition: LArAlignDbAlg.cxx:31
LArAlignDbAlg::finalize
virtual StatusCode finalize() override
Definition: LArAlignDbAlg.cxx:77
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
LArAlignDbAlg::printCondObjects
StatusCode printCondObjects()
Definition: LArAlignDbAlg.cxx:142
LArAlignDbAlg.h
LArAlignDbAlg::streamOutCondObjects
StatusCode streamOutCondObjects()
Definition: LArAlignDbAlg.cxx:168
y
#define y
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArAlignDbAlg::m_regIOV
BooleanProperty m_regIOV
Definition: LArAlignDbAlg.h:40
LArAlignDbAlg::m_writeCondObjs
BooleanProperty m_writeCondObjs
Definition: LArAlignDbAlg.h:39
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37