IcebergChannelMapService_service.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////////////////////////
2 // Class: IcebergChannelMapService
3 // Module type: service
4 // File: IcebergChannelMapService.h
5 // Author: Tom Junk, November 2018
6 //
7 // Implementation of hardware-offline channel mapping reading from a file.
8 ///////////////////////////////////////////////////////////////////////////////////////////////////
9 
12 
13 // Bad channel value
14 unsigned int bad() {
16  return val;
17 }
18 
20 
27 
28  std::string channelMapFile = pset.get<std::string>("FileName");
29 
30  std::string fullname;
31  cet::search_path sp("FW_SEARCH_PATH");
32  sp.find_file(channelMapFile, fullname);
33 
34  if (fullname.empty()) {
35  std::cout << "Input file " << channelMapFile << " not found" << std::endl;
36  throw cet::exception("File not found");
37  }
38  else
39  std::cout << "Iceberg Channel Map: Building RCE TPC wiremap from file " << channelMapFile << std::endl;
40 
41  std::ifstream inFile(fullname, std::ios::in);
43 
44  while (std::getline(inFile,line)) {
45  unsigned int crateNo, slotNo, fiberNo, FEMBChannel, StreamChannel, slotID, fiberID, chipNo, chipChannel, asicNo, asicChannel, planeType, offlineChannel;
46  std::stringstream linestream(line);
47  linestream >> crateNo >> slotNo >> fiberNo>> FEMBChannel >> StreamChannel >> slotID >> fiberID >> chipNo >> chipChannel >> asicNo >> asicChannel >> planeType >> offlineChannel;
48 
49  // fill lookup tables. Throw an exception if any number is out of expected bounds.
50  // checking for negative values produces compiler warnings as these are unsigned ints
51 
52  if (offlineChannel >= fNChans)
53  {
54  throw cet::exception("IcebergChannelMapService") << "Ununderstood Offline Channel: " << offlineChannel << "\n";
55  }
56  if (crateNo >= fNCrates)
57  {
58  throw cet::exception("IcebergChannelMapService") << "Ununderstood Crate Number: " << crateNo << "\n";
59  }
60  if (slotNo >= fNSlots)
61  {
62  throw cet::exception("IcebergChannelMapService") << "Ununderstood Slot Number: " << slotNo << "\n";
63  }
64  if (fiberNo >= fNFibers)
65  {
66  throw cet::exception("IcebergChannelMapService") << "Ununderstood Fiber Number: " << fiberNo << "\n";
67  }
68  if (StreamChannel >= fNFEMBChans)
69  {
70  throw cet::exception("IcebergChannelMapService") << "Ununderstood FEMB (Stream) Channel Number: " << StreamChannel << "\n";
71  }
72 
73  farrayCsfcToOffline[crateNo][slotNo][fiberNo][StreamChannel] = offlineChannel;
74  fvAPAMap[offlineChannel] = crateNo;
75  fvWIBMap[offlineChannel] = slotNo;
76  fvFEMBMap[offlineChannel] = fiberNo;
77  fvFEMBChannelMap[offlineChannel] = FEMBChannel;
78  fvStreamChannelMap[offlineChannel] = StreamChannel;
79  fvSlotIdMap[offlineChannel] = slotID;
80  fvFiberIdMap[offlineChannel] = fiberID;
81  fvChipMap[offlineChannel] = chipNo;
82  fvChipChannelMap[offlineChannel] = chipChannel;
83  fvASICMap[offlineChannel] = asicNo;
84  fvASICChannelMap[offlineChannel] = asicChannel;
85  fvPlaneMap[offlineChannel] = planeType;
86 
87  }
88  inFile.close();
89 
90 
91 
92  std::string FELIXchannelMapFile = pset.get<std::string>("FELIXFileName");
93  sp.find_file(FELIXchannelMapFile, fullname);
94 
95  if (fullname.empty()) {
96  std::cout << "Input file " << FELIXchannelMapFile << " not found" << std::endl;
97  throw cet::exception("File not found");
98  }
99  else
100  std::cout << "Iceberg Channel Map: Building FELIX TPC wiremap from file " << channelMapFile << std::endl;
101 
102  std::ifstream FELIXinFile(fullname, std::ios::in);
103 
104  while (std::getline(FELIXinFile,line)) {
105  unsigned int crateNo, slotNo, fiberNo, FEMBChannel, StreamChannel, slotID, fiberID, chipNo, chipChannel, asicNo, asicChannel, planeType, offlineChannel;
106  std::stringstream linestream(line);
107  linestream >> crateNo >> slotNo >> fiberNo>> FEMBChannel >> StreamChannel >> slotID >> fiberID >> chipNo >> chipChannel >> asicNo >> asicChannel >> planeType >> offlineChannel;
108 
109  // fill lookup tables. Throw an exception if any number is out of expected bounds.
110  // checking for negative values produces compiler warnings as these are unsigned ints
111 
112  if (offlineChannel >= fNChans)
113  {
114  throw cet::exception("IcebergChannelMapService") << "Ununderstood Offline Channel: " << offlineChannel << "\n";
115  }
116  if (crateNo >= fNCrates)
117  {
118  throw cet::exception("IcebergChannelMapService") << "Ununderstood Crate Number: " << crateNo << "\n";
119  }
120  if (slotNo >= fNSlots)
121  {
122  throw cet::exception("IcebergChannelMapService") << "Ununderstood Slot Number: " << slotNo << "\n";
123  }
124  if (fiberNo >= fNFibers)
125  {
126  throw cet::exception("IcebergChannelMapService") << "Ununderstood Fiber Number: " << fiberNo << "\n";
127  }
128  if (StreamChannel >= fNFEMBChans)
129  {
130  throw cet::exception("IcebergChannelMapService") << "Ununderstood FEMB (Stream) Channel Number: " << StreamChannel << "\n";
131  }
132 
133  fFELIXarrayCsfcToOffline[crateNo][slotNo][fiberNo][StreamChannel] = offlineChannel;
134  fFELIXvAPAMap[offlineChannel] = crateNo;
135  fFELIXvWIBMap[offlineChannel] = slotNo;
136  fFELIXvFEMBMap[offlineChannel] = fiberNo;
137  fFELIXvFEMBChannelMap[offlineChannel] = FEMBChannel;
138  fFELIXvStreamChannelMap[offlineChannel] = StreamChannel;
139  fFELIXvSlotIdMap[offlineChannel] = slotID;
140  fFELIXvFiberIdMap[offlineChannel] = fiberID;
141  fFELIXvChipMap[offlineChannel] = chipNo;
142  fFELIXvChipChannelMap[offlineChannel] = chipChannel;
143  fFELIXvASICMap[offlineChannel] = asicNo;
144  fFELIXvASICChannelMap[offlineChannel] = asicChannel;
145  fFELIXvPlaneMap[offlineChannel] = planeType;
146 
147  }
148  inFile.close();
149 
150 
151  std::string SSPchannelMapFile = pset.get<std::string>("SSPFileName");
152 
153  std::string SSPfullname;
154  sp.find_file(SSPchannelMapFile, SSPfullname);
155 
156  if (SSPfullname.empty()) {
157  std::cout << "Input file for SSP Channel Map " << SSPchannelMapFile << " not found in FW_SEARCH_PATH " << std::endl;
158  throw cet::exception("File not found");
159  }
160  else
161  std::cout << "Iceberg Channel Map: Building SSP channel map from file " << SSPchannelMapFile << std::endl;
162 
163  std::ifstream SSPinFile(SSPfullname, std::ios::in);
164 
165  while (std::getline(SSPinFile,line)) {
166  unsigned int onlineChannel, APA, SSP, SSPGlobal, ChanWithinSSP, OpDetNo, offlineChannel;
167  std::stringstream linestream(line);
168  linestream >> onlineChannel >> APA >> SSP >> SSPGlobal >> ChanWithinSSP >> OpDetNo >> offlineChannel;
169 
170  // fill lookup tables. Throw an exception if any number is out of expected bounds.
171  // checking for negative values produces compiler warnings as these are unsigned ints
172 
173  if (onlineChannel >= fNSSPChans)
174  {
175  throw cet::exception("IcebergChannelMapService") << "Ununderstood SSP Online Channel: " << onlineChannel << "\n";
176  }
177  if (offlineChannel >= fNSSPChans)
178  {
179  throw cet::exception("IcebergChannelMapService") << "Ununderstood SSP Offline Channel: " << offlineChannel << "\n";
180  }
181  if (APA > fNAPAs) // APAs count from 1
182  {
183  throw cet::exception("IcebergChannelMapService") << "Ununderstood APA Number in SSP map file: " << APA << "\n";
184  }
185  //if (SSP >= fNSSPsPerAPA) -- These checks don't make sense
186  // {
187  // throw cet::exception("IcebergChannelMapService") << "Ununderstood SSP number within this APA: " << SSP << " " << APA << "\n";
188  // }
189  //if (SSPGlobal >= fNSSPs)
190  // {
191  // throw cet::exception("IcebergChannelMapService") << "Ununderstood Global SSP number: " << SSPGlobal << "\n";
192  // }
193  if (ChanWithinSSP >= fNChansPerSSP)
194  {
195  throw cet::exception("IcebergChannelMapService") << "Ununderstood Channel within SSP Number: " << ChanWithinSSP << " " << SSPGlobal << "\n";
196  }
197  if (OpDetNo >= 60)
198  {
199  throw cet::exception("IcebergChannelMapService") << "Ununderstood SSP Module Number: " << OpDetNo << "\n";
200  }
201 
202  farraySSPOnlineToOffline[onlineChannel] = offlineChannel;
203  farraySSPOfflineToOnline[offlineChannel] = onlineChannel;
204  fvSSPAPAMap[offlineChannel] = APA;
205  fvSSPWithinAPAMap[offlineChannel] = SSP;
206  fvSSPGlobalMap[offlineChannel] = SSPGlobal;
207  fvSSPChanWithinSSPMap[offlineChannel] = ChanWithinSSP;
208  fvOpDetNoMap[offlineChannel] = OpDetNo;
209  }
210  SSPinFile.close();
211 }
212 
214 }
215 
216 // assumes crate goes from 1-6, in "installed crate ordering"
217 // assumes slot goes from 0-5.
218 // assumes fiber goes from 1-4.
219 // These conventions are observed in Run 2973, a cryo commissioning run.
220 
221 unsigned int dune::IcebergChannelMapService::GetOfflineNumberFromDetectorElements(unsigned int crate, unsigned int slot, unsigned int fiber, unsigned int streamchannel, FelixOrRCE frswitch) {
222 
223  unsigned int offlineChannel=0;
224  unsigned int lcrate = crate;
225  unsigned int lslot = slot;
226  unsigned int lfiber = fiber;
227 
228  if (crate > fNCrates || crate == 0)
229  {
231  {
232  mf::LogWarning("IcebergChannelMapService: Bad Crate Number, expecting a number of 1. Falling back to 1. Ununderstood crate number=") << crate;
233  }
235  lcrate = 1;
236  }
237 
238  if (slot >= fNSlots)
239  {
241  {
242  mf::LogWarning("IcebergChannelMapService: Bad slot number, using slot number zero as a fallback. Ununderstood slot number: ") << slot;
243  }
245  lslot = 0;
246  }
247 
248  if (fiber > fNFibers || fiber == 0)
249  {
251  {
252  mf::LogWarning("IcebergChannelMapService: Bad fiber number, falling back to 1. Ununderstood fiber number: ") << fiber;
253  }
255  lfiber = 1;
256  }
257 
258  if (streamchannel >= fNFEMBChans)
259  {
260  throw cet::exception("IcebergChannelMapService") << "Ununderstood Stream (FEMB) chan: "
261  << crate << " " << slot << " " << fiber << " " << streamchannel << "\n";
262  }
263 
264  if (frswitch == kRCE)
265  {
266  offlineChannel = farrayCsfcToOffline[lcrate-1][lslot][lfiber-1][streamchannel];
267  }
268  else
269  {
270  offlineChannel = fFELIXarrayCsfcToOffline[lcrate-1][lslot][lfiber-1][streamchannel];
271  }
272 
273  return offlineChannel;
274 }
275 
276 // does not depend on FELIX or RCE -- offline channels should always map to the same APA/crate regardless of RCE or FELIX
277 
278 unsigned int dune::IcebergChannelMapService::APAFromOfflineChannel(unsigned int offlineChannel) const {
279  check_offline_channel(offlineChannel);
280  return fvAPAMap[offlineChannel];
281  // return fFELIXvAPAMap[offlineChannel]; // -- FELIX one -- should be the same
282 }
283 
284 
285 // does not depend on FELIX or RCE
286 
287 unsigned int dune::IcebergChannelMapService::WIBFromOfflineChannel(unsigned int offlineChannel) const {
288  check_offline_channel(offlineChannel);
289  return fvWIBMap[offlineChannel];
290  // return fFELIXvWIBMap[offlineChannel]; // -- FELIX one -- should be the same
291 }
292 
293 // does not depend on FELIX or RCE
294 
295 unsigned int dune::IcebergChannelMapService::FEMBFromOfflineChannel(unsigned int offlineChannel) const {
296  check_offline_channel(offlineChannel);
297  return fvFEMBMap[offlineChannel]+1;
298  //return fFELIXvFEMBMap[offlineChannel];
299 }
300 
301 // does not depend on FELIX or RCE
302 
303 unsigned int dune::IcebergChannelMapService::FEMBChannelFromOfflineChannel(unsigned int offlineChannel) const {
304  check_offline_channel(offlineChannel);
305  return fvFEMBChannelMap[offlineChannel];
306  // return fFELIXvFEMBChannelMap[offlineChannel]; // -- FELIX one -- should be the same
307 }
308 
309 // this one does depend on FELIX or RCE
310 
311 unsigned int dune::IcebergChannelMapService::StreamChannelFromOfflineChannel(unsigned int offlineChannel, FelixOrRCE frswitch) const {
312  check_offline_channel(offlineChannel);
313  if (frswitch == kRCE)
314  {
315  return fvStreamChannelMap[offlineChannel];
316  }
317  else
318  {
319  return fFELIXvStreamChannelMap[offlineChannel];
320  }
321 }
322 
323 // does not depend on FELIX or RCE
324 
325 unsigned int dune::IcebergChannelMapService::SlotIdFromOfflineChannel(unsigned int offlineChannel) const {
326  check_offline_channel(offlineChannel);
327  return fvSlotIdMap[offlineChannel];
328  // return fFELIXvSlotIdMap[offlineChannel]; // -- FELIX one -- should be the same
329 }
330 
331 // may potentially depend on FELIX or RCE, but if fibers are switched between the WIB and the FELIX or RCE,
332 // we can fix this in the channel map but report with this method the fiber coming out of the WIB, not the
333 // one going in to the FELIX or RCE
334 
335 unsigned int dune::IcebergChannelMapService::FiberIdFromOfflineChannel(unsigned int offlineChannel) const {
336  check_offline_channel(offlineChannel);
337  return fvFiberIdMap[offlineChannel];
338 }
339 
340 // does not depend on FELIX or RCE
341 
342 unsigned int dune::IcebergChannelMapService::ChipFromOfflineChannel(unsigned int offlineChannel) const {
343  check_offline_channel(offlineChannel);
344  return fvChipMap[offlineChannel];
345 }
346 
347 unsigned int dune::IcebergChannelMapService::AsicFromOfflineChannel(unsigned int offlineChannel) const {
348  check_offline_channel(offlineChannel);
349  return fvChipMap[offlineChannel];
350 }
351 
352 unsigned int dune::IcebergChannelMapService::ChipChannelFromOfflineChannel(unsigned int offlineChannel) const {
353  check_offline_channel(offlineChannel);
354  return fvChipChannelMap[offlineChannel];
355 }
356 
357 // from David Adams -- use the chip channel instead of the asic channel
358 
359 unsigned int dune::IcebergChannelMapService::AsicChannelFromOfflineChannel(unsigned int offlineChannel) const {
360  check_offline_channel(offlineChannel);
361  return fvChipChannelMap[offlineChannel];
362 }
363 
364 // really shouldn't be using this as it doesn't mean asic
365 
366 unsigned int dune::IcebergChannelMapService::ASICFromOfflineChannel(unsigned int offlineChannel) {
368  {
369  mf::LogWarning("IcebergChannelMapService: Deprecated call to ASICFromOfflineChannel. Use AsicLinkFromOfflineChannel");
370  }
372  check_offline_channel(offlineChannel);
373  return fvASICMap[offlineChannel];
374 }
375 
376 unsigned int dune::IcebergChannelMapService::AsicLinkFromOfflineChannel(unsigned int offlineChannel) const {
377  check_offline_channel(offlineChannel);
378  return fvASICMap[offlineChannel];
379 }
380 
381 unsigned int dune::IcebergChannelMapService::ASICChannelFromOfflineChannel(unsigned int offlineChannel) {
383  {
384  mf::LogWarning("IcebergChannelMapService: Deprecated call to ASICChannelFromOfflineChannel. Not a meaningful number -- channels are grouped by 16's not 8's");
385  }
387  check_offline_channel(offlineChannel);
388  return fvASICChannelMap[offlineChannel];
389 }
390 
391 unsigned int dune::IcebergChannelMapService::PlaneFromOfflineChannel(unsigned int offlineChannel) const {
392  check_offline_channel(offlineChannel);
393  return fvPlaneMap[offlineChannel];
394 }
395 
397 {
398  size_t result=0;
399  size_t s = sizeof(size_t)*8;
400  for (size_t j=0; j<s; ++j)
401  {
402  if (i & 1) ++result;
403  i >>= 1;
404  }
405  return result;
406 }
407 
409 {
410  unsigned int lchannel = onlineChannel;
411 
412  if (onlineChannel > fNSSPChans)
413  {
415  {
416  mf::LogWarning("IcebergChannelMapService: Online Channel Number too high, using zero as a fallback: ") << onlineChannel;
417  }
419  lchannel = 0;
420  }
421  return farraySSPOnlineToOffline[lchannel];
422 }
423 
424 unsigned int dune::IcebergChannelMapService::SSPOnlineChannelFromOfflineChannel(unsigned int offlineChannel) const
425 {
426  SSP_check_offline_channel(offlineChannel);
427  return farraySSPOfflineToOnline[offlineChannel];
428 }
429 
430 unsigned int dune::IcebergChannelMapService::SSPAPAFromOfflineChannel(unsigned int offlineChannel) const
431 {
432  SSP_check_offline_channel(offlineChannel);
433  return fvSSPAPAMap[offlineChannel];
434 }
435 
436 unsigned int dune::IcebergChannelMapService::SSPWithinAPAFromOfflineChannel(unsigned int offlineChannel) const
437 {
438  SSP_check_offline_channel(offlineChannel);
439  return fvSSPWithinAPAMap[offlineChannel];
440 }
441 
442 unsigned int dune::IcebergChannelMapService::SSPGlobalFromOfflineChannel(unsigned int offlineChannel) const
443 {
444  SSP_check_offline_channel(offlineChannel);
445  return fvSSPGlobalMap[offlineChannel];
446 }
447 
448 unsigned int dune::IcebergChannelMapService::SSPChanWithinSSPFromOfflineChannel(unsigned int offlineChannel) const
449 {
450  SSP_check_offline_channel(offlineChannel);
451  return fvSSPChanWithinSSPMap[offlineChannel];
452 }
453 
454 unsigned int dune::IcebergChannelMapService::OpDetNoFromOfflineChannel(unsigned int offlineChannel) const
455 {
456  SSP_check_offline_channel(offlineChannel);
457  return fvOpDetNoMap[offlineChannel];
458 }
459 
unsigned int SSPAPAFromOfflineChannel(unsigned int offlineChannel) const
static QCString result
unsigned int SSPOfflineChannelFromOnlineChannel(unsigned int onlineChannel)
unsigned int farrayCsfcToOffline[1][3][4][128]
std::string string
Definition: nybbler.cc:12
unsigned int ASICChannelFromOfflineChannel(unsigned int offlineChannel)
Returns ASIC channel number – to be deprecated.
unsigned int AsicChannelFromOfflineChannel(unsigned int offlineChannel) const
void check_offline_channel(unsigned int offlineChannel) const
unsigned int FiberIdFromOfflineChannel(unsigned int offlineChannel) const
Returns global fiber ID.
unsigned int SlotIdFromOfflineChannel(unsigned int offlineChannel) const
Returns global slot ID.
unsigned int OpDetNoFromOfflineChannel(unsigned int offlineChannel) const
unsigned int ChipChannelFromOfflineChannel(unsigned int offlineChannel) const
Returns chip channel number.
unsigned int AsicLinkFromOfflineChannel(unsigned int offlineChannel) const
unsigned int GetOfflineNumberFromDetectorElements(unsigned int crate, unsigned int slot, unsigned int fiber, unsigned int fembchannel, FelixOrRCE frswitch)
unsigned int SSPOnlineChannelFromOfflineChannel(unsigned int offlineChannel) const
struct dune::tde::crate crate
unsigned int AsicFromOfflineChannel(unsigned int offlineChannel) const
enum dune::IcebergChannelMapService::_FelixOrRCE FelixOrRCE
unsigned int SSPChanWithinSSPFromOfflineChannel(unsigned int offlineChannel) const
T get(std::string const &key) const
Definition: ParameterSet.h:271
unsigned int StreamChannelFromOfflineChannel(unsigned int offlineChannel, FelixOrRCE frswitch) const
Returns RCE(FELIX) stream(frame) channel.
unsigned int fFELIXarrayCsfcToOffline[6][5][4][128]
unsigned int APAFromOfflineChannel(unsigned int offlineChannel) const
Returns APA/crate.
static int max(int a, int b)
IcebergChannelMapService(fhicl::ParameterSet const &pset)
TFile * inFile
Definition: makeDST.cxx:36
#define DEFINE_ART_SERVICE(svc)
void line(double t, double *p, double &x, double &y, double &z)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
unsigned int FEMBChannelFromOfflineChannel(unsigned int offlineChannel) const
Returns FEMB channel.
std::string find_file(std::string const &filename) const
Definition: search_path.cc:96
unsigned int ChipFromOfflineChannel(unsigned int offlineChannel) const
Returns chip number.
unsigned int ASICFromOfflineChannel(unsigned int offlineChannel)
Returns ASIC number – to be deprecated.
unsigned int PlaneFromOfflineChannel(unsigned int offlineChannel) const
Returns plane.
unsigned int SSPWithinAPAFromOfflineChannel(unsigned int offlineChannel) const
unsigned int bad()
unsigned int SSPGlobalFromOfflineChannel(unsigned int offlineChannel) const
unsigned int WIBFromOfflineChannel(unsigned int offlineChannel) const
Returns WIB/slot.
unsigned int FEMBFromOfflineChannel(unsigned int offlineChannel) const
Returns FEMB/fiber.
static QCString * s
Definition: config.cpp:1042
void SSP_check_offline_channel(unsigned int offlineChannel) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)