39 {
41
42 SG::WriteCondHandle<PixelCablingCondData> writeHandle(
m_writeKey, ctx);
43 ATH_MSG_DEBUG(
"Conditions updates every event!!! This should be avoided once RegionSelectorTable is fixed!!");
44 if (writeHandle.isValid()) {
45 ATH_MSG_DEBUG(
"CondHandle " << writeHandle.fullKey() <<
" is already valid.. In theory this should not be called, but may happen if multiple concurrent events are being processed out of order.");
46 return StatusCode::SUCCESS;
47 }
48
49
50 std::unique_ptr<PixelCablingCondData> writeCdo(std::make_unique<PixelCablingCondData>());
51
52
53 int barrel_ec{}, eta_module{};
54
55
58 uint32_t sl_40_fmt{}, sl_40_link{}, sl_80_fmt{}, sl_80_link{};
59
60
63
64
65 std::string DCSname;
67
68 SG::ReadCondHandle<PixelModuleData> moduleDataHandle(
m_moduleDataKey, ctx);
69 const PixelModuleData *moduleData = *moduleDataHandle;
70
71
72 std::ofstream output_mapping_file_raw;
73 if (moduleData->
getCablingMapToFile()) { output_mapping_file_raw.open(
"pixel_cabling_map_raw.txt"); }
74 std::ofstream output_mapping_file_interpreted;
75 if (moduleData->
getCablingMapToFile()) { output_mapping_file_interpreted.open(
"pixel_cabling_map_interpreted.txt"); }
76
77 std::stringstream instr;
79 SG::ReadCondHandle<AthenaAttributeList> readHandle(
m_readKey, ctx);
80 const AthenaAttributeList* readCdo = *readHandle;
81 if (readCdo==nullptr) {
83 return StatusCode::FAILURE;
84 }
85 writeHandle.addDependency(readHandle);
86
87 ATH_MSG_DEBUG(
"Size of AthenaAttributeList " << readHandle.fullKey() <<
" readCdo->size()= " << readCdo->size());
89
90 const coral::Blob& blob_cabling=(*readCdo)["CablingMapData"].data<coral::Blob>();
91 const char* p_cabling = static_cast<const char*>(blob_cabling.startingAddress());
92
93 unsigned int len_cabling = blob_cabling.size()/
sizeof(
char);
94 ATH_MSG_DEBUG(
"blob_cabling.size() = " << blob_cabling.size() <<
", len_cabling = " << len_cabling);
95
96 instr.str(std::string(p_cabling,blob_cabling.size()));
97 }
98 else {
102 ATH_MSG_FATAL(
"Mapping File: " << cablingFilename <<
" not found!");
103 return StatusCode::FAILURE;
104 }
106 if (!fin) { return StatusCode::FAILURE; }
107 instr <<
fin.rdbuf();
108
110 ATH_MSG_DEBUG(
"Refilled pixel cabling from file \"" << cablingFilename <<
"\"");
111 }
112
113
114
115 std::map<uint32_t,bool> rodReadoutMap = SG::ReadCondHandle<PixelReadoutSpeedData>(
m_readoutspeedKey, ctx)->getReadoutMap();
116
117 while (instr.good() && getline(instr, line)) {
118
120
121
122 if (
line.empty()) {
continue; }
123 if (line[0]==' ' || line[0]=='#') { continue; }
124
125
126 if (
line.length()<21) {
continue; }
127
128
129 if (
line.substr(
line.length()-3,
line.length())==
"GMT") {
continue; }
130
131 std::istringstream
parse(line);
132
133 parse >> barrel_ec >> layer_disk >> phi_module >> eta_module >> std::hex >> robid >> rodid >> sl_40_fmt >> sl_40_link >> sl_80_fmt >> sl_80_link >> DCSname;
134
135
137 output_mapping_file_interpreted << barrel_ec << "\t" << layer_disk << "\t" << phi_module << "\t"
138 << eta_module << "\t" << std::hex << robid << "\t" << rodid << "\t"
139 << sl_40_fmt << "\t" << sl_40_link << "\t" << sl_80_fmt << "\t"
140 << sl_80_link << "\t" << DCSname << std::dec << std::endl;
141 }
142
143
144
145 if (layer_disk>100){
146 ATH_MSG_ERROR(
"Value for layer_disk is insane: "<<layer_disk);
147 return StatusCode::FAILURE;
148 }
149
150 if (!std::in_range<int>(layer_disk) || !std::in_range<int>(phi_module)) {
151 ATH_MSG_ERROR(
"Input value out of range for wafer_id arguments: "
152 << "layer_disk=" << layer_disk
153 << ", phi_module=" << phi_module);
154 return StatusCode::FAILURE;
155 }
156
157 Identifier offlineId =
m_pixelID->wafer_id(barrel_ec,layer_disk,phi_module,eta_module);
158
159
160 if ((robid & 0xFFFFFF)>=0x140000) {
161 linknumber = sl_40_link | (sl_40_fmt<<4) | (sl_80_link<<8) | (sl_80_fmt<<12);
162 }
163
164 else {
165 bool readoutSpeed = false;
166 if (rodReadoutMap.find(rodid)!=rodReadoutMap.end()) { readoutSpeed=rodReadoutMap[rodid]; }
167
168 if (!readoutSpeed) { linknumber=(sl_40_link & 0xF) | ((sl_40_fmt & 0xF)<<4); }
169 else { linknumber=(sl_80_link & 0xF) | ((sl_80_fmt & 0xF)<<4); }
170 }
171
172
173 onlineId = (robid & 0xFFFFFF) | (linknumber<<24);
174
175 IdentifierHash hashId;
176
177
178 IdContext cntxpixel =
m_pixelID->wafer_context();
179 if (
m_pixelID->get_hash(offlineId, hashId, &cntxpixel)) {
181 }
182
183 if (hashId>
m_pixelID->wafer_hash_max()) {
184 ATH_MSG_ERROR(
"IdHash overflow! HashId is 0x" << std::hex << hashId);
185 ATH_MSG_ERROR(
"not mapped OfflineID: " << std::hex << offlineId << std::dec <<
" barrel_ec: " << barrel_ec
186 << " layer_disk: " << layer_disk << " phi_module: " << phi_module << " eta_module: " << eta_module);
187 ATH_MSG_ERROR(
"to OnlineID: 0x" << std::hex << onlineId <<
" robid: 0x" << robid <<
" rodid: 0x" << rodid << std::dec
188 << " link: 0x" << std::hex << " -> Linknumber: 0x" << linknumber << " HashId: 0x" << hashId << std::dec);
189
190
191 if (eta_module>
m_pixelID->eta_module_max(offlineId) || eta_module<m_pixelID->eta_module_min(offlineId)) {
192
195 }
196 else {
197 ATH_MSG_ERROR(
"eta_module range exceeded: Got eta_module = " << eta_module
198 <<
", but allowed range is [" <<
m_pixelID->eta_module_min(offlineId)
199 <<
"," <<
m_pixelID->eta_module_max(offlineId) <<
"]");
200 ATH_MSG_ERROR(
"Input geometry tag may not be compatible with mapping file");
201 }
202 }
203 }
204 if (!std::in_range<int>(robid) || !std::in_range<int>(rodid)) [[
unlikely]]{
205 ATH_MSG_ERROR(
"Input value out of range for add_entry_robrod arguments: "
206 << "robid=" << robid
207 << ", rodid=" << rodid);
208 return StatusCode::FAILURE;
209 }
210
211 writeCdo->add_entry_onoff(onlineId, offlineId);
212 writeCdo->add_entry_offon(offlineId, onlineId);
213 writeCdo->add_entry_offlineList(robid,offlineId);
214 writeCdo->add_entry_offrob(offlineId, robid);
215 writeCdo->add_entry_rodrob(rodid, robid);
216 writeCdo->add_entry_robrod(robid, rodid);
217 writeCdo->add_entry_DCSoffline(DCSname, offlineId);
218
219
220 ATH_MSG_DEBUG(
"Mapped offlineID: " << std::hex << offlineId <<
" to onlineID: 0x" << onlineId
221 << ", robID: 0x" << robid << ", barrel_ec: " << std::dec << barrel_ec << ", layer_disk: " << layer_disk
222 << ", eta_module: " << eta_module << ", phi_module: " << phi_module << ", linknumber: 0x" << std::hex << linknumber);
223 }
224
226 output_mapping_file_raw.close();
227 output_mapping_file_interpreted.close();
228 }
229
230 ATH_MSG_DEBUG(
"Size of ROD readoutspeed map: " << rodReadoutMap.size());
231 writeCdo->set_readout_map(std::move(rodReadoutMap));
232
233 if (writeHandle.record(std::move(writeCdo)).isFailure()) {
234 ATH_MSG_FATAL(
"Could not record PixelCablingCondData " << writeHandle.key() <<
" with EventRange " << writeHandle.getRange() <<
" into Conditions Store");
235 return StatusCode::FAILURE;
236 }
237 ATH_MSG_DEBUG(
"recorded new CDO " << writeHandle.key() <<
" with range " << writeHandle.getRange() <<
" into Conditions Store");
238
239 return StatusCode::SUCCESS;
240}
#define ATH_MSG_WARNING(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
SG::ReadCondHandleKey< AthenaAttributeList > m_readKey
SG::ReadCondHandleKey< PixelModuleData > m_moduleDataKey
SG::ReadCondHandleKey< PixelReadoutSpeedData > m_readoutspeedKey
SG::WriteCondHandleKey< PixelCablingCondData > m_writeKey
const PixelID * m_pixelID
const std::string & getCablingMapFileName() const
bool getCablingMapToFile() const