ATLAS Offline Software
Loading...
Searching...
No Matches
AlignWrt.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5// AlignWrt.cxx
6// Richard Hawkings, started 15/4/04
7// Algorithm to create ID Alignment database in TDS and optionally write
8// it to conditions database
9//
10#include <fstream>
12#include "GaudiKernel/SmartDataPtr.h"
17
20
21
22InDetAlignWrt::InDetAlignWrt(const std::string& name, ISvcLocator* pSvcLocator)
23 :AthAlgorithm (name, pSvcLocator),
24 p_iddbtool("InDetAlignDBTool"),
25 p_migratetool("InDetAlignDBTool/InDetAlignMigrate"),
26 p_eventinfo (nullptr),
27 m_setup (false),
28 m_par_create(true),
29 m_par_wrt(false),
30 m_par_wrtiov(true),
31 m_par_print(false),
32 m_par_migrate(false),
33 m_par_rfile(""),
34 m_par_wfile(""),
36 m_par_ntuple(false),
37 m_par_wrtrun(-1),
39 m_par_run1(IOVTime::MINRUN),
40 m_par_run2(IOVTime::MAXRUN),
41 m_par_evt1(IOVTime::MINEVENT),
42 m_par_evt2(IOVTime::MAXEVENT),
43 m_par_iovtag(""),
44 m_par_dbtoolinst("InDetAlignDBTool"),
46 m_par_dettype(-1),
47 m_par_bec(-1),
48 m_par_layer(-1),
49 m_par_ring(-1),
50 m_par_sector(-1),
51 m_par_rphidisp(0.1),
52 m_par_rdisp(0.2),
53 m_par_zdisp(0.3),
55 m_par_irskip(0),
57 m_par_writetop(false),
59{
60
61 // declare algorithm parameters
64 declareProperty("WriteIOV",m_par_wrtiov);
69 declareProperty("RWNtuple",m_par_ntuple);
70 declareProperty("WriteRun",m_par_wrtrun);
71 declareProperty("WriteEvent",m_par_wrtevent);
72 declareProperty("ValidRun1",m_par_run1);
73 declareProperty("ValidRun2",m_par_run2);
74 declareProperty("ValidEvent1",m_par_evt1);
75 declareProperty("ValidEvent2",m_par_evt2);
80 declareProperty("DispBec",m_par_bec);
81 declareProperty("DispLayer",m_par_layer);
82 declareProperty("DispRing",m_par_ring);
83 declareProperty("DispSector",m_par_sector);
89 declareProperty("RndmSkip",m_par_irskip);
91
92 declareProperty("WriteTopTrans",m_par_writetop);
93 declareProperty("TopTransFile",m_par_topname);
94
95 declareProperty("InDetAlignDBTool",p_iddbtool);
96 declareProperty("InDetAlignMigrateTool",p_migratetool);
97}
98
99
102
104 ATH_MSG_DEBUG( "InDetAlignWrt::initialize() called" );
105 // get storegate pointers
106 if ( (evtStore().retrieve().isFailure()) ||
107 (detStore().retrieve().isFailure())) {
108 ATH_MSG_VERBOSE ("StoreGate or DetStore services not found" );
109 return StatusCode::FAILURE;
110 }
111
112
113 ATH_CHECK( p_iddbtool.retrieve() );
114
115 // get second InDetAlignDBTool for migration if needed
116 if (m_par_migrate) {
117 ATH_CHECK (p_migratetool.retrieve() );
118 }
119
120 if (msgLvl(MSG::DEBUG)) {
121 if (m_par_create) msg() << "ID Alignment database structures will be created" << endmsg;
122 if (m_par_rfile!="") {
123 if (m_par_ntuple) msg() << "Alignment constants will be initialised from ntuple: " << m_par_rfile << endmsg;
124 else msg() << "Alignment constants will be initialised from text file" << m_par_rfile << endmsg;
125 }
126 if (m_par_dispfile!="")
127 msg() << "Alignment constants will be set according to recipe in file " << m_par_dispfile << endmsg;
128 if (m_par_wrt)
129 msg() << "ID Alignment database structures will be written on run "
130 << m_par_wrtrun << " event " << m_par_wrtevent << endmsg;
131 if (m_par_wfile!="")
132 msg() << "Structures will be written on file " << m_par_wfile << endmsg;
133 if (m_par_writetop)
134 msg() << "Toplevel transforms will be read from file " << m_par_topname
135 << "and written on run " << m_par_wrtrun << " event " << m_par_wrtevent << endmsg;
136 if (!m_par_wrtiov)
137 msg() << "IOV writing will be suppressed - only output stream" << endmsg;
138 }
139
140 return StatusCode::SUCCESS;
141}
142
144
145 if (!m_setup) {
146 m_setup=true;
147 if (m_par_create) {
149 "Creating null alignment database from geometry information in GeoModel");
150 p_iddbtool->createDB();
151 }
152 if (m_par_rfile!="") {
153 if (m_par_ntuple) {
154 p_iddbtool->readNtuple(m_par_rfile);
155 } else {
156 p_iddbtool->readTextFile(m_par_rfile);
157 }
158 }
159 if (m_par_dispmode>0 || m_par_dispcsc>0) DispDB();
160 if (m_par_dispfile!="") dispFile();
161 if (m_par_print) p_iddbtool->printDB(2);
162 }
163 // make a fall back solution in case event info not available to prevent crash
164 int run = -1;
165 int event = 0;
166 if (evtStore()->contains< xAOD::EventInfo >( "EventInfo" ) &&
167 StatusCode::SUCCESS==evtStore()->retrieve(p_eventinfo)) {
168 run=p_eventinfo->runNumber();
169 event=p_eventinfo->eventNumber();
170 }
171
172 ATH_MSG_DEBUG( "In AlignWrt::execute for run/event " << run <<
173 "," << event );
174 // trigger database write by setting filter passed to false
175 if ((m_par_wrt || m_par_writetop) &&
177
178 return StatusCode::SUCCESS;
179}
180
181
183 if (m_par_wrtrun==-1) doOutput();
185 return StatusCode::SUCCESS;
186}
187
189 // displace silicon modules according to recipe in DispMode
190 // or use DispCSC if appropriate parameter is set
191 //if (m_par_dispcsc!=0) {
192 // ATH_MSG_DEBUG("DispCSC called for mode " << m_par_dispcsc );
193 // p_iddbtool->dispCSC(m_par_dettype, m_par_bec, m_par_layer, m_par_ring,
194 // m_par_sector, m_par_dispcsc);
195 //} else {
196 ATH_MSG_DEBUG( "DispDB called for mode " << m_par_dispmode );
199 //}
200}
201
204 "::dispFile() : Initialise AlignableTransforms from parameters file "
205 << m_par_dispfile );
206 std::ifstream infile;
207 infile.open(m_par_dispfile.c_str());
208 // loop over lines in file
209 int nline=0;
210 std::string cline;
211 int level,isyst,dettype,bec,layer,ring,sector;
212 float rpd,rd,zd;
213 while (infile >> level >> isyst >> dettype >> bec >> layer >> ring >>
214 sector >> rpd >>
215 rd >> zd) {
216 ++nline;
217 ATH_MSG_DEBUG( "Add displacement level " << level << " syst " <<
218 isyst << " to [det,bec,layer] [" << dettype << "," << bec << "," <<
219 layer << "] {rphi,r,z} {" << rpd << "," << rd << "," << zd << "}" );
220 p_iddbtool->dispGroup(dettype,bec,layer,ring,sector,
221 rpd,rd,zd,isyst,level,m_par_irskip);
222 } // end of input loop
223 ATH_MSG_DEBUG( "Read " << nline <<
224 " displacement recipe lines" );
225}
226
228 // write all objects and fill IOV database
229 if (m_par_wrt) {
230 // first sort, just in case
231 p_iddbtool->sortTrans();
232 if (m_par_wfile=="") {
233 ATH_MSG_DEBUG( "doOutput for AlignableTransforms" );
234 if (StatusCode::SUCCESS!=p_iddbtool->outputObjs())
235 msg(MSG::ERROR) << "Write of AlignableTransforms fails" << endmsg;
236 if (m_par_wrtiov)
238 } else {
240 }
241 }
242 if (m_par_writetop) {
243 genTopTrans();
244 }
245}
246
248 // generate top level transforms into TDS
249 ATH_MSG_DEBUG( "Initialise TOPTRANS from parameters file: " <<
252 std::ifstream infile;
253 infile.open(m_par_topname.c_str());
254 // loop over all lines in file
255 int nline=0;
256 std::string cline,key;
257 float xd,yd,zd,phi,theta,psi;
258 while (infile >> key >> xd >> yd >> zd >> phi >> theta >> psi) {
259 ++nline;
260 ATH_MSG_DEBUG( "Add transform name: " << key << " x/y/z " << xd << "," << yd <<
261 "," << zd << " phi/theta/psi " << phi << "," << theta << "," << psi );
262 HepGeom::Transform3D newtrans=HepGeom::Transform3D(CLHEP::HepRotation(phi,theta,psi),
263 CLHEP::Hep3Vector(xd,yd,zd));
264 dkp->setTransform(key,newtrans);
265 }
266 ATH_MSG_DEBUG( "Read " << nline << " lines from recipe file" );
267 // record object in TDS
268 if (StatusCode::SUCCESS==detStore()->record(dkp,"/GLOBAL/GEOM/TOPTRANS")) {
269 ATH_MSG_DEBUG( "Recorded TOPTRANS in TDS" );
270 } else {
271 ATH_MSG_DEBUG( "Failed to record TOPTRANS in TDS");
272 }
273}
274
276 ATH_MSG_DEBUG( "Convert Pixel/SCT alignment from old to new format");
277 // create new format database
278 p_migratetool->createDB();
279 // copy data from old to new database via temporary file
280 p_iddbtool->writeFile(false,"migrate.dat");
281 p_migratetool->readTextFile("migrate.dat");
282 p_migratetool->writeFile(false,"migrate.check");
283 // write data to POOL file and optionally IOV
284 if (StatusCode::SUCCESS!=p_migratetool->outputObjs())
285 msg(MSG::ERROR) << "Write of AlignableTransform fails" << endmsg;
286 if (m_par_wrtiov)
288}
Scalar phi() const
phi method
Scalar theta() const
theta method
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
This is an interface to a tool used to register conditions objects in the Interval of Validity (IOV) ...
Basic time unit for IOVSvc.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() const
Class to hold set of HepGeom::Transform3D keyed by string value for storage in the conditions DB typi...
void setTransform(const std::string &key, const HepGeom::Transform3D &trans)
Basic time unit for IOVSvc.
Definition IOVTime.h:33
void doOutput()
Definition AlignWrt.cxx:227
StatusCode initialize(void)
Definition AlignWrt.cxx:103
std::string m_par_iovtag
unsigned int m_par_evt1
ToolHandle< IInDetAlignDBTool > p_iddbtool
void doMigration()
Definition AlignWrt.cxx:275
std::string m_par_rfile
std::string m_par_dispfile
std::string m_par_wfile
unsigned int m_par_run2
StatusCode finalize(void)
Definition AlignWrt.cxx:182
const xAOD::EventInfo * p_eventinfo
std::string m_par_dbtoolinst
InDetAlignWrt(const std::string &name, ISvcLocator *pSvcLocator)
Definition AlignWrt.cxx:22
std::string m_par_topname
void genTopTrans()
Definition AlignWrt.cxx:247
ToolHandle< IInDetAlignDBTool > p_migratetool
unsigned int m_par_evt2
unsigned int m_par_run1
~InDetAlignWrt(void)
Definition AlignWrt.cxx:100
void dispFile()
Definition AlignWrt.cxx:202
StatusCode execute(void)
Definition AlignWrt.cxx:143
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
Definition run.py:1