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