ATLAS Offline Software
Loading...
Searching...
No Matches
SiDistWriteAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5// SiDistWriteAlg.cxx
6// Richard Hawkings, started 27/3/07
7// simple algorithm to manage silicon (PIXEL/SCT) module distortion data
8
9#include <fstream>
10#include <iostream>
11
16
17SiDistWriteAlg::SiDistWriteAlg(const std::string& name, ISvcLocator* pSvcLocator)
18 :AthAlgorithm (name, pSvcLocator),
19
20 m_pixid(nullptr),m_sctid(nullptr),
21 m_first(true),
22 m_par_print(false),
23 m_par_size(3),
25 m_par_distkey("/Indet/PixelDist")
26{
27
28
31 declareProperty("ArraySize",m_par_size);
33}
34
37
39{
40 ATH_MSG_DEBUG( "SiDistWriteAlg::initialize()" );
41 // check StoreGate service available
42 ATH_CHECK(evtStore().retrieve());
43
44 // get detector store
45 ATH_CHECK(detStore().retrieve());
46
47
48 // get identifier helpers
49 if ((StatusCode::SUCCESS!=detStore()->retrieve(m_pixid)) ||
50 (StatusCode::SUCCESS!=detStore()->retrieve(m_sctid))) {
51 ATH_MSG_ERROR( "Could not get helpers from detector store");
52 }
53 ATH_MSG_DEBUG( "Distortion information in TDS at key " <<
55 if (!m_par_readfile.empty())
56 ATH_MSG_DEBUG ( "Read distortion parameters from file"
57 << m_par_readfile );
59 "Distortion information will be printed on first event" );
60 return StatusCode::SUCCESS;
61}
62
64 return StatusCode::SUCCESS;
65}
66
68 if (m_first) {
69 if (!m_par_readfile.empty()) readFile();
70 if (m_par_print) print();
71 m_first=false;
72 }
73 return StatusCode::SUCCESS;
74}
75
77 // create structure in TDS
78 ATH_MSG_DEBUG ( "Create new DetCondCFloat of size " << m_par_size
79 << " in TDS" );
80 std::unique_ptr<DetCondCFloat> pdist(new DetCondCFloat(m_par_size,m_par_distkey));
81 // read data from text file
82 ATH_MSG_DEBUG ( "Opening text file " << m_par_readfile <<
83 " to get distortion data" );
84 std::ifstream infile;
85 infile.open(m_par_readfile.c_str());
86 if (!infile) {
87 ATH_MSG_ERROR( "Problem opening input file" );
88 return false;
89 }
90 // loop over lines in file
91 int nline=0;
92 int nadd=0;
93 while (infile) {
94 std::string tmpline;
95 std::getline(infile,tmpline);
96 if (!infile) break;
97 std::istringstream instring(tmpline);
98 std::string ident;
100 float x,y,z;
101 instring >> ident >> identhash >> x >> y >> z;
102 ATH_MSG_DEBUG( "Read identifier: " << ident << " hash " <<
103 identhash << " x" << x << " y " << y << " z " << z );
104 // construct the identifier and crosscheck
105 Identifier identifier;
106 if (makeIdent(ident,identhash,identifier)) {
107 float fbuf[3];
108 fbuf[0]=x;
109 fbuf[1]=y;
110 fbuf[2]=z;
111 pdist->add(identifier,fbuf);
112 ++nadd;
113 } else {
114 ATH_MSG_ERROR( "Problem constructing identifier " << ident << " / " << identhash);
115 }
116 ++nline;
117 }
118 infile.close();
119 ATH_MSG_DEBUG ( "Read distortions for " << nline << " modules" <<
120 " of which " << nadd << " successfully added" );
121 // record in StoreGate
122 if (StatusCode::SUCCESS==detStore()->record(std::move(pdist),m_par_distkey)) {
123 ATH_MSG_DEBUG ( "Recorded DetCondCFloat " << m_par_distkey << " in TDS" );
124 } else {
125 ATH_MSG_ERROR("Failed to record DetCondCFloat " << m_par_distkey << " in TDS");
126 return false;
127 }
128 return true;
129}
130
131bool SiDistWriteAlg::makeIdent(const std::string& ident,
132 const Identifier32::value_type identhash, Identifier& identifier) {
133 // parse the [a.b.c.d.e.f.CLHEP::g] string to extract 7 fields
134 // remove the leading [ immediately
135 std::string lident=ident.substr(1);
136 for (unsigned int i=0;i<lident.size();++i) {
137 // transform ] and . to spaces
138 if (lident[i]==']' || lident[i]=='.') lident[i]=' ';
139 }
140 std::istringstream instring(lident);
141 int atlas{},det{},bec{},layer{},phi{},eta,side{};
142 instring >> atlas >> det >> bec >> layer >> phi >> eta >> side;
143 if ((bec<-2) or (bec>2)){
144 ATH_MSG_ERROR("bec value is "<<bec);
145 }
146 if (det==1) {
147 identifier=m_pixid->wafer_id(bec,layer,phi,eta);
148 } else if (det==2) {
149 identifier=m_sctid->wafer_id(bec,layer,phi,eta,side);
150 } else {
151 ATH_MSG_ERROR( "Unknown detector type " << det);
152 return false;
153 }
154 // cross check with the supplied identifier compact value
155 // (get 32-bit part, as it's only a wafer_id)
156 return (identifier.get_identifier32().get_compact()==identhash);
157}
158
160 ATH_MSG_DEBUG ( "Print distortion parameters at " << m_par_distkey );
161 // retrieve distortions from Storegate and print in detail
162 const DetCondCFloat* pdist=nullptr;
163 if (StatusCode::SUCCESS==detStore()->retrieve(pdist,m_par_distkey)) {
164 pdist->print2();
165 } else {
166 ATH_MSG_ERROR( "Unable to retrieve distortion parameters " );
167 }
168}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
#define y
#define x
#define z
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
DetCondCFloat is a class to hold sets of Identifiers and arrays of floats for detector element specif...
void print2() const
unsigned int value_type
StatusCode execute()
std::string m_par_readfile
const SCT_ID * m_sctid
bool makeIdent(const std::string &ident, const Identifier32::value_type identhash, Identifier &identifier)
std::string m_par_distkey
const PixelID * m_pixid
StatusCode finalize()
SiDistWriteAlg(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize()