ATLAS Offline Software
LArAlignDbAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 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_writeCondObjs(false),
21  m_regIOV(false),
22  m_streamName("CondStream1"),
23  m_inpFile("LArAlign.inp"),
24  m_outpFile("LArAlign-TEST.pool.root"),
25  m_outpTag("LARAlign-TEST"),
26  m_regSvc("IOVRegistrationSvc",name),
27  m_streamer("AthenaOutputStreamTool")
28 {
29  declareProperty("WriteCondObjs", m_writeCondObjs);
30  declareProperty("RegisterIOV", m_regIOV);
31  declareProperty("StreamName", m_streamName);
32  declareProperty("InpFile", m_inpFile);
33  declareProperty("OutpFile", m_outpFile);
34  declareProperty("TagName", m_outpTag);
35 }
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
39 {
40 }
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
44 {
45  ATH_MSG_DEBUG(" in initialize()" );
46 
47  // Get Output Stream tool for writing
48  if(m_writeCondObjs) {
49  ATH_CHECK( m_streamer.retrieve() );
50  }
51 
52  // Get the IOVRegistrationSvc when needed
53  if(m_regIOV) {
54  ATH_CHECK( m_regSvc.retrieve() );
55  ATH_MSG_DEBUG( "Found IOVRegistrationSvc " );
56  }
57 
58  return StatusCode::SUCCESS;
59 }
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
62 
64 {
65  ATH_MSG_DEBUG(" in execute() " );
66 
67  const EventContext& context = getContext();
68  int nrun = context.eventID().run_number();
69  int nevt = context.eventID().event_number();
70 
71  ATH_MSG_DEBUG( " Event: [" << nrun << "," << nevt << "]" );
72 
73  // If I need to write out the conditions object I'll do that on the first event
74  if (m_writeCondObjs && nevt==1) {
75  ATH_MSG_DEBUG( "Creating conditions objects for run " << nrun );
76 
79  } else {
80  // Read objects from DetectorStore
82  }
83 
84  return StatusCode::SUCCESS;
85 }
86 
87 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
88 
90 {
91  ATH_MSG_DEBUG( " in finalize() " );
92  if(m_writeCondObjs) {
94  ATH_MSG_DEBUG( " Streamed out OK " );
95  }
96 
97  if(m_regIOV) {
99  ATH_MSG_DEBUG( " Register OK " );
100  }
101 
102  return StatusCode::SUCCESS;
103 }
104 
105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
106 
108 {
109  ATH_MSG_INFO(" in createCondObjects() " );
110 
111  if(detStore()->contains<DetCondKeyTrans>(LAR_ALIGN)) {
112  ATH_MSG_INFO( " DetCondKeyTrans already exists, do nothing " );
113  return StatusCode::SUCCESS;
114  }
115 
116  // Read input file, construct relevant transforms
117  std::ifstream infile;
118  infile.open(m_inpFile.value().c_str());
119 
120  if(!infile.is_open()) {
121  ATH_MSG_ERROR( "Unable to open " << m_inpFile << " for reading" );
122  return StatusCode::FAILURE;
123  }
124 
125  auto transforms = std::make_unique<DetCondKeyTrans>();
126 
127  char commentSign = '#';
128  std::string commentLine;
129  std::string key;
130  double x, y, z, theta, phi, rotationAngle;
131 
132  while(!infile.eof()) {
133  infile >> key;
134  if(key.empty()) continue;
135  if(key[0]==commentSign)
136  std::getline(infile,commentLine);
137  else {
138  infile >> theta >> phi >> rotationAngle >> x >> y >> z;
139 
140  Hep3Vector axis(sin(theta)*cos(phi),sin(theta)*sin(phi),cos(theta));
141  transforms->setTransform(key,Translate3D(x,y,z)*Rotate3D(rotationAngle,axis));
142  }
143  }
144  infile.close();
145 
146  ATH_CHECK( detStore()->record(std::move(transforms),LAR_ALIGN) );
147  ATH_MSG_DEBUG( " Recorded LAr/Align " );
148 
149  return StatusCode::SUCCESS;
150 }
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
153 
155 {
156  const DetCondKeyTrans* align;
157  StatusCode sc = detStore()->retrieve(align, LAR_ALIGN);
158 
159  if(sc.isFailure())
160  ATH_MSG_WARNING( " Could not find DetCondKeyTrans" );
161  else if(nullptr == align)
162  ATH_MSG_WARNING(" DetCondKeyTrans ptr is 0" );
163  else {
164  std::cout << " \n\n**************************************************** \n";
165  std::cout << " **** **** \n";
166  std::cout << " **** Printing Conditions Objects **** \n";
167  std::cout << " **** **** \n";
168  std::cout << " **************************************************** \n";
169 
170  align->print();
171 
172  std::cout << " **** **** **** **** END **** **** **** **** \n\n\n";
173  }
174 
175  return StatusCode::SUCCESS;
176 }
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
179 
181 {
182  ATH_MSG_DEBUG( " entering streamOutCondObjects " );
183 
184  ATH_CHECK( m_streamer->connectOutput(m_outpFile.value()) );
185  ATH_MSG_DEBUG(" Did connect stream to output" );
186 
187  int npairs = 1;
188 
189  IAthenaOutputStreamTool::TypeKeyPairs typeKeys(npairs);
190 
191  IAthenaOutputStreamTool::TypeKeyPair align("DetCondKeyTrans", LAR_ALIGN);
192  typeKeys[0] = align;
193 
194  ATH_CHECK( m_streamer->streamObjects(typeKeys) );
195  ATH_CHECK( m_streamer->commitOutput() );
196 
197  return StatusCode::SUCCESS;
198 }
199 
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
202 
204 {
205  ATH_MSG_DEBUG( "entering registerCondObject()" );
206 
207  std::string objname = "DetCondKeyTrans";
208 
209  // Register the IOV DB with the conditions data written out
210  ATH_CHECK( m_regSvc->registerIOV(objname, m_outpTag) );
211  return StatusCode::SUCCESS;
212 }
213 
LAR_ALIGN
#define LAR_ALIGN
Definition: LArAlignDbAlg.cxx:10
LArAlignDbAlg::execute
StatusCode execute()
Definition: LArAlignDbAlg.cxx:63
IAthenaOutputStreamTool::TypeKeyPairs
std::vector< TypeKeyPair > TypeKeyPairs
Definition: IAthenaOutputStreamTool.h:99
run.infile
string infile
Definition: run.py:13
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
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
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArAlignDbAlg::~LArAlignDbAlg
~LArAlignDbAlg()
Definition: LArAlignDbAlg.cxx:38
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:71
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:107
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:98
LArAlignDbAlg::registerCondObjects
StatusCode registerCondObjects()
Definition: LArAlignDbAlg.cxx:203
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArAlignDbAlg::m_streamName
StringProperty m_streamName
Definition: LArAlignDbAlg.h:41
LArAlignDbAlg::printCondObjects
StatusCode printCondObjects()
Definition: LArAlignDbAlg.cxx:154
LArAlignDbAlg.h
LArAlignDbAlg::streamOutCondObjects
StatusCode streamOutCondObjects()
Definition: LArAlignDbAlg.cxx:180
LArAlignDbAlg::finalize
StatusCode finalize()
Definition: LArAlignDbAlg.cxx:89
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
LArAlignDbAlg::initialize
StatusCode initialize()
Definition: LArAlignDbAlg.cxx:43
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37