VDColdboxChannelMapService_service.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////////////////////////
2 // Class: VDColdboxChannelMapService
3 // Module type: service
4 // File: VDColdboxChannelMapService.h
5 // Author: Tom Junk, October 2021
6 //
7 // Implementation of hardware-offline channel mapping reading from a file.
8 ///////////////////////////////////////////////////////////////////////////////////////////////////
9 
12 
13 
15 
16  std::string channelMapFile = pset.get<std::string>("FileName");
17  std::string fullname;
18  cet::search_path sp("FW_SEARCH_PATH");
19  sp.find_file(channelMapFile, fullname);
20 
21  if (fullname.empty()) {
22  std::cout << "Input file " << channelMapFile << " not found" << std::endl;
23  throw cet::exception("File not found");
24  }
25  else
26  std::cout << "VD Coldbox Channel Map: Building TPC wiremap from file " << channelMapFile << std::endl;
27 
28  std::ifstream inFile(fullname, std::ios::in);
30  while (std::getline(inFile,line)) {
31  VDCBChanInfo chinfo;
32  std::stringstream linestream(line);
33  linestream >>
34  chinfo.offlchan >>
35  chinfo.wib >>
36  chinfo.wibconnector >>
37  chinfo.cebchan >>
38  chinfo.femb >>
39  chinfo.asic >>
40  chinfo.asicchan >>
41  chinfo.connector >>
42  chinfo.stripid;
43  chinfo.valid = true;
44  chantoinfomap[chinfo.offlchan] = chinfo;
45  infotochanmap[chinfo.wib][chinfo.wibconnector][chinfo.cebchan] = chinfo.offlchan;
46  }
47  inFile.close();
48 }
49 
51 }
52 
53 // The function below gets cold electronics info from offline channel number. Sets valid to be false if
54 // there is no corresponding cold electronics channel
55 // if not found in the map, return a chan info struct filled with -1's and set the valid flag to false.
56 
58 {
60  auto fm = chantoinfomap.find(offlchan);
61  if (fm == chantoinfomap.end())
62  {
63  r.offlchan = -1;
64  r.wib = -1;
65  r.wibconnector = -1;
66  r.cebchan = -1;
67  r.femb = -1;
68  r.asic = -1;
69  r.asicchan = -1;
70  r.connector = -1;
71  r.stripid = "INVALID";
72  r.valid = false;
73  }
74  else
75  {
76  r = fm->second;
77  }
78  return r;
79 }
80 
81 
82  // The function below uses conventions from Nitish's spreadsheet. WIB: 1-3, wibconnector: 1-4, cechan: 0-127
83  // It returns an offline channel number of -1 if the wib, wibconnector, and cechan are not in the map
84 
86 {
87  int r = -1;
88  auto fm1 = infotochanmap.find(wib);
89  if (fm1 == infotochanmap.end()) return r;
90  auto& m1 = fm1->second;
91  auto fm2 = m1.find(wibconnector);
92  if (fm2 == m1.end()) return r;
93  auto& m2 = fm2->second;
94  auto fm3 = m2.find(cechan);
95  if (fm3 == m2.end()) return r;
96  r = fm3->second;
97  return r;
98 }
99 
100  // For convenience, the function below uses conventions from the DAQ WIB header, with two FEMBs per fiber
101  // on FELIX readout: slot: 0-2, fiber=1 or 2, cehcan: 0-255
102  // it returns a channel number of -1 if the slot, fiber, chan combination is not in the map
103 
105 {
106  int wc = fiber*2 - 1;
107  if (chan>127)
108  {
109  chan -= 128;
110  wc++;
111  }
112  return getOfflChanFromWIBConnectorInfo(slot+1,wc,chan);
113 }
114 
115 
std::unordered_map< int, VDCBChanInfo > chantoinfomap
std::unordered_map< int, std::unordered_map< int, std::unordered_map< int, int > > > infotochanmap
std::string string
Definition: nybbler.cc:12
static constexpr double fm3
Definition: Units.h:77
VDColdboxChannelMapService(fhicl::ParameterSet const &pset)
static constexpr double m2
Definition: Units.h:72
T get(std::string const &key) const
Definition: ParameterSet.h:271
static constexpr double fm2
Definition: Units.h:76
TFile * inFile
Definition: makeDST.cxx:36
#define DEFINE_ART_SERVICE(svc)
int getOfflChanFromSlotFiberChan(int slot, int fiber, int chan)
void line(double t, double *p, double &x, double &y, double &z)
std::string find_file(std::string const &filename) const
Definition: search_path.cc:96
static constexpr double fm
Definition: Units.h:75
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
int getOfflChanFromWIBConnectorInfo(int wib, int wibconnector, int cechan)