DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
PdspChannelMapService.cpp
Go to the documentation of this file.
1
10// Class: PdspChannelMapService
11// Module type: service
12// File: PdspChannelMapService.h
13// Author: Jingbo Wang (jiowang@ucdavis.edu), February 2018
14//
15// Implementation of hardware-offline channel mapping reading from a file.
17
18#include "logging/Logging.hpp"
19
21
22#include <limits>
23#include <sstream>
24#include <stdexcept>
25#include <string>
26
27namespace dunedaq {
28namespace detchannelmaps {
29
30// Bad channel value
31unsigned int
33{
34 unsigned int val = std::numeric_limits<unsigned int>::max();
35 return val;
36}
37
38PdspChannelMapService::PdspChannelMapService(std::string rcename, std::string felixname)
39{
40
47
48 std::ifstream inFile(rcename, std::ios::in);
49 if (inFile.bad() || inFile.fail() || !inFile.is_open()) {
50 throw std::runtime_error(std::string("Bad file ") + std::string(rcename));
51 }
52 std::string line;
53
54 while (std::getline(inFile, line)) {
55 unsigned int crateNo, slotNo, fiberNo, FEMBChannel, StreamChannel, slotID, fiberID, chipNo, chipChannel, asicNo,
56 asicChannel, planeType, offlineChannel;
57 std::stringstream linestream(line);
58 linestream >> crateNo >> slotNo >> fiberNo >> FEMBChannel >> StreamChannel >> slotID >> fiberID >> chipNo >>
59 chipChannel >> asicNo >> asicChannel >> planeType >> offlineChannel;
60
61 // fill lookup tables. Throw an exception if any number is out of expected bounds.
62 // checking for negative values produces compiler warnings as these are unsigned ints
63
64 if (offlineChannel >= fNChans) {
65 throw std::logic_error("Ununderstood Offline Channel");
66 }
67 if (crateNo >= fNCrates) {
68 throw std::logic_error("Ununderstood Crate Number");
69 }
70 if (slotNo >= fNSlots) {
71 throw std::logic_error("Ununderstood Slot Number");
72 }
73 if (fiberNo >= fNFibers) {
74 throw std::logic_error("Ununderstood Fiber Number");
75 }
76 if (StreamChannel >= fNFEMBChans) {
77 throw std::logic_error("Ununderstood FEMB (Stream) Channel Number");
78 }
79
80 farrayCsfcToOffline[crateNo][slotNo][fiberNo][StreamChannel] = offlineChannel;
81 fvAPAMap[offlineChannel] = crateNo;
82 fvWIBMap[offlineChannel] = slotNo;
83 fvFEMBMap[offlineChannel] = fiberNo;
84 fvFEMBChannelMap[offlineChannel] = FEMBChannel;
85 fvStreamChannelMap[offlineChannel] = StreamChannel;
86 fvSlotIdMap[offlineChannel] = slotID;
87 fvFiberIdMap[offlineChannel] = fiberID;
88 fvChipMap[offlineChannel] = chipNo;
89 fvChipChannelMap[offlineChannel] = chipChannel;
90 fvASICMap[offlineChannel] = asicNo;
91 fvASICChannelMap[offlineChannel] = asicChannel;
92 fvPlaneMap[offlineChannel] = planeType;
93 }
94 inFile.close();
95
96 std::ifstream FELIXinFile(felixname, std::ios::in);
97 if (FELIXinFile.bad() || FELIXinFile.fail() || !FELIXinFile.is_open()) {
98 throw std::runtime_error(std::string("Bad file ") + std::string(felixname));
99 }
100
101 while (std::getline(FELIXinFile, line)) {
102 unsigned int crateNo, slotNo, fiberNo, FEMBChannel, StreamChannel, slotID, fiberID, chipNo, chipChannel, asicNo,
103 asicChannel, planeType, offlineChannel;
104 std::stringstream linestream(line);
105 linestream >> crateNo >> slotNo >> fiberNo >> FEMBChannel >> StreamChannel >> slotID >> fiberID >> chipNo >>
106 chipChannel >> asicNo >> asicChannel >> planeType >> offlineChannel;
107
108 // fill lookup tables. Throw an exception if any number is out of expected bounds.
109 // checking for negative values produces compiler warnings as these are unsigned ints
110
111 if (offlineChannel >= fNChans) {
112 throw std::logic_error("Ununderstood Offline Channel");
113 }
114 if (crateNo >= fNCrates) {
115 throw std::logic_error("Ununderstood Crate Number");
116 }
117 if (slotNo >= fNSlots) {
118 throw std::logic_error("Ununderstood Slot Number");
119 }
120 if (fiberNo >= fNFibers) {
121 throw std::logic_error("Ununderstood Fiber Number");
122 }
123 if (StreamChannel >= fNFEMBChans) {
124 throw std::logic_error("Ununderstood FEMB (Stream) Channel Number");
125 }
126
127 fFELIXarrayCsfcToOffline[crateNo][slotNo][fiberNo][StreamChannel] = offlineChannel;
128 fFELIXvAPAMap[offlineChannel] = crateNo;
129 fFELIXvWIBMap[offlineChannel] = slotNo;
130 fFELIXvFEMBMap[offlineChannel] = fiberNo;
131 fFELIXvFEMBChannelMap[offlineChannel] = FEMBChannel;
132 fFELIXvStreamChannelMap[offlineChannel] = StreamChannel;
133 fFELIXvSlotIdMap[offlineChannel] = slotID;
134 fFELIXvFiberIdMap[offlineChannel] = fiberID;
135 fFELIXvChipMap[offlineChannel] = chipNo;
136 fFELIXvChipChannelMap[offlineChannel] = chipChannel;
137 fFELIXvASICMap[offlineChannel] = asicNo;
138 fFELIXvASICChannelMap[offlineChannel] = asicChannel;
139 fFELIXvPlaneMap[offlineChannel] = planeType;
140 }
141 inFile.close();
142
143 // APA numbering -- hardcoded here.
144 // Installation numbering:
145 // APA5 APA6 APA4
146 // beam -->
147 // APA3 APA2 APA1
148 //
149 // The Offline numbering:
150 // APA1 APA3 APA5
151 // beam -->
152 // APA0 APA2 APA4
153 //
154 fvInstalledAPA[0] = 3;
155 fvInstalledAPA[1] = 5;
156 fvInstalledAPA[2] = 2;
157 fvInstalledAPA[3] = 6;
158 fvInstalledAPA[4] = 1;
159 fvInstalledAPA[5] = 4;
160
161 // and the inverse map -- shifted by 1 -- the above list must start counting at 1.
162
163 for (size_t i = 0; i < 6; ++i) {
165 }
166
167} // NOLINT(readability/fn_size)
168
169// assumes crate goes from 1-6, in "installed crate ordering"
170// assumes slot goes from 0-5.
171// assumes fiber goes from 1-4.
172// These conventions are observed in Run 2973, a cryo commissioning run.
173
174unsigned int
176 unsigned int slot,
177 unsigned int fiber,
178 unsigned int streamchannel,
179 FelixOrRCE frswitch)
180{
181
182 unsigned int offlineChannel = 0;
183 unsigned int lcrate = crate;
184 unsigned int lslot = slot;
185 unsigned int lfiber = fiber;
186
187 if (crate > fNCrates || crate == 0) {
189 TLOG() << "PdspChannelMapService: Bad Crate Number, expecting a number between 1 and 6. "
190 << "Falling back to 1. Ununderstood crate number=" << crate;
191 }
193 lcrate = 1;
194 }
195
196 if (slot >= fNSlots) {
198 TLOG() << "PdspChannelMapService: Bad slot number, using slot number zero as a fallback. "
199 << "Ununderstood slot number: " << slot;
200 }
202 lslot = 0;
203 }
204
205 if (fiber > fNFibers || fiber == 0) {
207 TLOG() << "PdspChannelMapService: Bad fiber number, falling back to 1. "
208 << "Ununderstood fiber number: " << fiber;
209 }
211 lfiber = 1;
212 }
213
214 if (streamchannel >= fNFEMBChans) {
215 TLOG() << streamchannel << " >= " << fNFEMBChans;
216 throw std::logic_error("Ununderstood Stream (FEMB) chan");
217 }
218
219 if (frswitch == kRCE) {
220 offlineChannel = farrayCsfcToOffline[fvTPCSet_VsInstalledAPA[lcrate - 1]][lslot][lfiber - 1][streamchannel];
221 } else {
222 offlineChannel = fFELIXarrayCsfcToOffline[fvTPCSet_VsInstalledAPA[lcrate - 1]][lslot][lfiber - 1][streamchannel];
223 }
224
225 return offlineChannel;
226}
227
228// does not depend on FELIX or RCE -- offline channels should always map to the same APA/crate regardless of RCE or
229// FELIX
230
231unsigned int
232PdspChannelMapService::APAFromOfflineChannel(unsigned int offlineChannel) const
233{
234 check_offline_channel(offlineChannel);
235 return fvAPAMap[offlineChannel];
236 // return fFELIXvAPAMap[offlineChannel]; // -- FELIX one -- should be the same
237}
238
239unsigned int
241{
242 check_offline_channel(offlineChannel);
243 unsigned int offlineAPA = fvAPAMap[offlineChannel];
244 if (offlineAPA > 5) {
245 throw std::logic_error("Offline APA Number out of range");
246 }
247 return fvInstalledAPA[fvAPAMap[offlineChannel]];
248}
249
250// does not depend on FELIX or RCE
251
252unsigned int
253PdspChannelMapService::WIBFromOfflineChannel(unsigned int offlineChannel) const
254{
255 check_offline_channel(offlineChannel);
256 return fvWIBMap[offlineChannel];
257 // return fFELIXvWIBMap[offlineChannel]; // -- FELIX one -- should be the same
258}
259
260// does not depend on FELIX or RCE
261
262unsigned int
263PdspChannelMapService::FEMBFromOfflineChannel(unsigned int offlineChannel) const
264{
265 check_offline_channel(offlineChannel);
266 return fvFEMBMap[offlineChannel] + 1;
267 // return fFELIXvFEMBMap[offlineChannel];
268}
269
270// does not depend on FELIX or RCE
271
272unsigned int
274{
275 check_offline_channel(offlineChannel);
276 return fvFEMBChannelMap[offlineChannel];
277 // return fFELIXvFEMBChannelMap[offlineChannel]; // -- FELIX one -- should be the same
278}
279
280// this one does depend on FELIX or RCE
281
282unsigned int
283PdspChannelMapService::StreamChannelFromOfflineChannel(unsigned int offlineChannel, FelixOrRCE frswitch) const
284{
285 check_offline_channel(offlineChannel);
286 if (frswitch == kRCE) {
287 return fvStreamChannelMap[offlineChannel];
288 } else {
289 return fFELIXvStreamChannelMap[offlineChannel];
290 }
291}
292
293// does not depend on FELIX or RCE
294
295unsigned int
296PdspChannelMapService::SlotIdFromOfflineChannel(unsigned int offlineChannel) const
297{
298 check_offline_channel(offlineChannel);
299 return fvSlotIdMap[offlineChannel];
300 // return fFELIXvSlotIdMap[offlineChannel]; // -- FELIX one -- should be the same
301}
302
303// may potentially depend on FELIX or RCE, but if fibers are switched between the WIB and the FELIX or RCE,
304// we can fix this in the channel map but report with this method the fiber coming out of the WIB, not the
305// one going in to the FELIX or RCE
306
307unsigned int
308PdspChannelMapService::FiberIdFromOfflineChannel(unsigned int offlineChannel) const
309{
310 check_offline_channel(offlineChannel);
311 return fvFiberIdMap[offlineChannel];
312}
313
314// does not depend on FELIX or RCE
315
316unsigned int
317PdspChannelMapService::ChipFromOfflineChannel(unsigned int offlineChannel) const
318{
319 check_offline_channel(offlineChannel);
320 return fvChipMap[offlineChannel];
321}
322
323unsigned int
324PdspChannelMapService::AsicFromOfflineChannel(unsigned int offlineChannel) const
325{
326 check_offline_channel(offlineChannel);
327 return fvChipMap[offlineChannel];
328}
329
330unsigned int
332{
333 check_offline_channel(offlineChannel);
334 return fvChipChannelMap[offlineChannel];
335}
336
337// from David Adams -- use the chip channel instead of the asic channel
338
339unsigned int
341{
342 check_offline_channel(offlineChannel);
343 return fvChipChannelMap[offlineChannel];
344}
345
346// really shouldn't be using this as it doesn't mean asic
347
348unsigned int
350{
352 TLOG() << "PdspChannelMapService: Deprecated call to ASICFromOfflineChannel. "
353 << "Use AsicLinkFromOfflineChannel";
354 }
356 check_offline_channel(offlineChannel);
357 return fvASICMap[offlineChannel];
358}
359
360unsigned int
362{
363 check_offline_channel(offlineChannel);
364 return fvASICMap[offlineChannel];
365}
366
367unsigned int
369{
371 TLOG() << "PdspChannelMapService: Deprecated call to ASICChannelFromOfflineChannel. "
372 << "Not a meaningful number -- channels are grouped by 16's not 8's";
373 }
375 check_offline_channel(offlineChannel);
376 return fvASICChannelMap[offlineChannel];
377}
378
379unsigned int
380PdspChannelMapService::PlaneFromOfflineChannel(unsigned int offlineChannel) const
381{
382 check_offline_channel(offlineChannel);
383 return fvPlaneMap[offlineChannel];
384}
385
386size_t
388{
389 size_t result = 0;
390 size_t s = sizeof(size_t) * 8;
391 for (size_t j = 0; j < s; ++j) {
392 if (i & 1)
393 ++result;
394 i >>= 1;
395 }
396 return result;
397}
398
399unsigned int
401{
402 unsigned int lchannel = onlineChannel;
403
404 if (onlineChannel > fNSSPChans) {
406 TLOG() << "PdspChannelMapService: Online Channel Number too high, using zero as a fallback: " << onlineChannel;
407 }
409 lchannel = 0;
410 }
411 return farraySSPOnlineToOffline[lchannel];
412}
413
414unsigned int
416{
417 SSP_check_offline_channel(offlineChannel);
418 return farraySSPOfflineToOnline[offlineChannel];
419}
420
421unsigned int
422PdspChannelMapService::SSPAPAFromOfflineChannel(unsigned int offlineChannel) const
423{
424 SSP_check_offline_channel(offlineChannel);
425 return fvSSPAPAMap[offlineChannel];
426}
427
428unsigned int
430{
431 SSP_check_offline_channel(offlineChannel);
432 return fvSSPWithinAPAMap[offlineChannel];
433}
434
435unsigned int
437{
438 SSP_check_offline_channel(offlineChannel);
439 return fvSSPGlobalMap[offlineChannel];
440}
441
442unsigned int
444{
445 SSP_check_offline_channel(offlineChannel);
446 return fvSSPChanWithinSSPMap[offlineChannel];
447}
448
449unsigned int
450PdspChannelMapService::OpDetNoFromOfflineChannel(unsigned int offlineChannel) const
451{
452 SSP_check_offline_channel(offlineChannel);
453 return fvOpDetNoMap[offlineChannel];
454}
455
456} // namespace detchannelmaps
457} // namespace dunedaq
void check_offline_channel(unsigned int offlineChannel) const
unsigned int AsicFromOfflineChannel(unsigned int offlineChannel) const
unsigned int SSPChanWithinSSPFromOfflineChannel(unsigned int offlineChannel) const
unsigned int AsicLinkFromOfflineChannel(unsigned int offlineChannel) const
unsigned int FEMBFromOfflineChannel(unsigned int offlineChannel) const
Returns FEMB/fiber.
unsigned int ChipChannelFromOfflineChannel(unsigned int offlineChannel) const
Returns chip channel number.
unsigned int OpDetNoFromOfflineChannel(unsigned int offlineChannel) const
unsigned int ChipFromOfflineChannel(unsigned int offlineChannel) const
Returns chip number.
unsigned int ASICChannelFromOfflineChannel(unsigned int offlineChannel)
Returns ASIC channel number – to be deprecated.
unsigned int SSPOnlineChannelFromOfflineChannel(unsigned int offlineChannel) const
unsigned int FiberIdFromOfflineChannel(unsigned int offlineChannel) const
Returns global fiber ID.
unsigned int SSPGlobalFromOfflineChannel(unsigned int offlineChannel) const
unsigned int ASICFromOfflineChannel(unsigned int offlineChannel)
Returns ASIC number – to be deprecated.
unsigned int SlotIdFromOfflineChannel(unsigned int offlineChannel) const
Returns global slot ID.
enum dunedaq::detchannelmaps::PdspChannelMapService::_FelixOrRCE FelixOrRCE
unsigned int APAFromOfflineChannel(unsigned int offlineChannel) const
Returns APA/crate.
unsigned int StreamChannelFromOfflineChannel(unsigned int offlineChannel, FelixOrRCE frswitch) const
Returns RCE(FELIX) stream(frame) channel.
unsigned int AsicChannelFromOfflineChannel(unsigned int offlineChannel) const
unsigned int WIBFromOfflineChannel(unsigned int offlineChannel) const
Returns WIB/slot.
unsigned int InstalledAPAFromOfflineChannel(unsigned int offlineChannel) const
Returns APA/crate in installation notation.
unsigned int SSPAPAFromOfflineChannel(unsigned int offlineChannel) const
unsigned int SSPOfflineChannelFromOnlineChannel(unsigned int onlineChannel)
unsigned int SSPWithinAPAFromOfflineChannel(unsigned int offlineChannel) const
unsigned int GetOfflineNumberFromDetectorElements(unsigned int crate, unsigned int slot, unsigned int fiber, unsigned int fembchannel, FelixOrRCE frswitch)
unsigned int FEMBChannelFromOfflineChannel(unsigned int offlineChannel) const
Returns FEMB channel.
void SSP_check_offline_channel(unsigned int offlineChannel) const
unsigned int PlaneFromOfflineChannel(unsigned int offlineChannel) const
Returns plane.
#define TLOG(...)
Definition macro.hpp:22
Including Qt Headers.