ATLAS Offline Software
Loading...
Searching...
No Matches
LArHVIdMappingReader.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
3 */
10
11
17#include <sstream>
18#include <fstream>
19
20
22 : AthMessaging ("LArHVIdMappingReader")
23{
24}
25
26
28 const LArHVLineID& hvlineHelper,
29 const LArElectrodeID& electrodeHelper,
30 hvlineMap_t& hvlineMap,
31 electrodeMap_t& electrodeMap) const
32{
33 hvlineMap.clear();
34 electrodeMap.clear();
35
36 std::string content;
37 if (attrList) {
38 content = fromAttrList (*attrList);
39 }
40 else {
41 content = fromFile();
42 }
43
44 if (content.empty()) {
45 return StatusCode::FAILURE;
46 }
47
48 return fillHV (content,
49 hvlineHelper,
50 electrodeHelper,
51 hvlineMap,
52 electrodeMap);
53}
54
55
56std::string
58{
59 std::ostringstream attrStr1;
60 coral::AttributeList::const_iterator itr = attrList.begin();
61 itr->toOutputStream(attrStr1);
62 std::string::size_type pos = attrStr1.str().find(':');
63 if (pos == std::string::npos)
64 pos = 0;
65 else
66 pos++;
67 std::string Line = attrStr1.str().substr(pos);
68 ATH_MSG_DEBUG(" Line " << Line );
69 return Line;
70}
71
72
74{
75 ATH_MSG_WARNING( " Cannot find /LAR/IdentifierOfl/HVLineToElectrodeMap from database, Use ASCII file indeed !!!");
76 std::string tablename = PathResolver::find_file ("HVLineToElectrode.data", "DATAPATH");
77 if (tablename.empty()) {
78 ATH_MSG_FATAL( "[fillHVMap] Could not locate HVLineToElectrode.data file as well");
79 return "";
80 }
81 else{
82 ATH_MSG_DEBUG("[fillHVMap] have located HVLineToElectrode.data OK !");
83 }
84 const char * tablefile = tablename.c_str() ;
85 std::ifstream myfile(tablefile);
86 // get pointer to associated buffer object
87 std::filebuf* pbuf = myfile.rdbuf();
88 int size = pbuf->pubseekoff (0,std::ios::end,std::ios::in);
89 pbuf->pubseekpos (0,std::ios::in);
90 // allocate memory to contain file data
91 std::string buffer;
92 buffer.resize (size, ' ');
93 // get file data
94 pbuf->sgetn (buffer.data(),size);
95 myfile.close();
96 return buffer;
97}
98
99
100StatusCode
101LArHVIdMappingReader::fillHV (const std::string& content,
102 const LArHVLineID& hvlineHelper,
103 const LArElectrodeID& electrodeHelper,
104 hvlineMap_t& hvlineMap,
105 electrodeMap_t& electrodeMap) const
106{
107 ATH_MSG_DEBUG("[fillHVMap] entering fillHVMap()..." );
108
109 hvlineMap.clear();
110 electrodeMap.clear();
111
112 std::istringstream infile;
113 infile.str (content);
114
115 int dummy;
116 int hvcannode;
117 int hvline;
118 int hvpartition;
119 int hvcanline;
120 int detect;
121 int side;
122 int mod;
123 int hvphi;
124 int hveta;
125 int hvgap;
126 int min;
127 int max;
128 ATH_MSG_DEBUG("start reading infile " );
129 while (infile
130 >> dummy
131 >> hvcannode
132 >> hvline
133 >> hvpartition
134 >> hvcanline
135 >> detect
136 >> side
137 >> mod
138 >> hvphi
139 >> hveta
140 >> hvgap
141 >> min
142 >> max )
143 {// Fill Maps
144 if (max > 1000) // Crude check against reading nonsense.
145 std::abort();
146 ATH_MSG_DEBUG("[fillHVMap] listing HVLineToElectrode :("
147 << dummy << ") hvline=["
148 << hvpartition << "."
149 << hvcanline << "."
150 << hvcannode << "."
151 << hvline << "] electrode=["
152 << detect << "."
153 << side << "."
154 << mod << "."
155 << hvphi << "."
156 << hveta << "."
157 << hvgap << " min="
158 << min << " max="
159 << max << "]"
160 );
161
162 std::vector<HWIdentifier> electrodeIdvec;
163 HWIdentifier hvlineId = hvlineHelper.HVLineId(hvpartition,hvcanline,hvcannode,hvline);
164
165 if( max > min ){
166 if (min < 0) min = 0;
167 if (max < 0) max = 0;
168 if (min > 1000) min = 1000; // Shouldn't happen.
169 for( int ielec=min; ielec<max+1; ielec++){
170 ATH_MSG_VERBOSE("[fillHVMap] defining electrodeId: [det="
171 << detect << " side="
172 << side << " mod="
173 << mod << " phi="
174 << hvphi << " eta="
175 << hveta << " gap="
176 << hvgap << " ielec="
177 << ielec << "]" );
178 HWIdentifier electrodeId =
179 electrodeHelper.ElectrodeId(detect,side,mod,hvphi,hveta,hvgap,ielec);
180 electrodeIdvec.push_back(electrodeId);
181
182 // Check if electrode is already in map ?
183 hvlineMap.emplace (electrodeId, hvlineId);
184 }
185 }
186 else{
187 HWIdentifier electrodeId = electrodeHelper.ElectrodeId(detect,side,mod,hvphi,hveta,hvgap,min);
188 electrodeIdvec.push_back(electrodeId);
189
190 // Check if electrode is already in map ?
191 hvlineMap.emplace (electrodeId, hvlineId);
192 }
193
194 std::vector<HWIdentifier>& l = electrodeMap[hvlineId];
195 l.insert (l.end(), electrodeIdvec.begin(), electrodeIdvec.end());
196 }
197
198 ATH_MSG_DEBUG(" end reading infile " );
199 ATH_MSG_DEBUG("[fillHV] Mapping electrode-to-hvline : number of Ids= "<<hvlineMap.size());
200 ATH_MSG_DEBUG("[fillHV] Mapping hvline-to-electrode : number of Ids= "<<electrodeMap.size());
201 ATH_MSG_DEBUG("[fillHV] exiting fillHVMap ... OK" );
202 return StatusCode::SUCCESS;
203}
204
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helper to read HV ID mapping data from a file or conditions.
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
An AttributeList represents a logical row of attributes in a metadata table.
Helper for the Liquid Argon Calorimeter cell at the electrode level.
HWIdentifier ElectrodeId(int det, int side, int mod, int phi, int eta, int gap, int elec) const
Create an Electrode identifier from fields.
StatusCode fillHV(const std::string &content, const LArHVLineID &hvlineHelper, const LArElectrodeID &electrodeHelper, hvlineMap_t &hvlineMap, electrodeMap_t &electrodeMap) const
std::string fromFile() const
std::map< HWIdentifier, HWIdentifier > hvlineMap_t
StatusCode read(const AthenaAttributeList *attrList, const LArHVLineID &hvlineHelper, const LArElectrodeID &electrodeHelper, hvlineMap_t &hvlineMap, electrodeMap_t &electrodeMap) const
std::string fromAttrList(const AthenaAttributeList &attrList) const
std::map< HWIdentifier, std::vector< HWIdentifier > > electrodeMap_t
Helper for the Liquid Argon Calorimeter High-Voltage identifiers.
Definition LArHVLineID.h:43
HWIdentifier HVLineId(int part, int canline, int cannode, int line) const
Create an HighVoltage line identifier from fields.
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)