Line data Source code
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 :
10 : #include "VDColdboxChannelMapService.hpp"
11 :
12 : #include <fstream>
13 : #include <sstream>
14 :
15 : namespace dunedaq {
16 : namespace detchannelmaps {
17 :
18 0 : VDColdboxChannelMapService::VDColdboxChannelMapService(std::string filename)
19 : {
20 :
21 0 : std::ifstream inFile(filename, std::ios::in);
22 0 : if (inFile.bad() || inFile.fail() || !inFile.is_open()) {
23 0 : throw std::runtime_error(std::string("VDColdboxChannelMapService: Invalid map file ") + std::string(filename));
24 : }
25 :
26 0 : std::string line;
27 0 : while (std::getline(inFile, line)) {
28 0 : VDCBChanInfo chinfo;
29 0 : std::stringstream linestream(line);
30 0 : linestream >> chinfo.offlchan >> chinfo.wib >> chinfo.wibconnector >> chinfo.cebchan >> chinfo.femb >>
31 0 : chinfo.asic >> chinfo.asicchan >> chinfo.connector >> chinfo.stripid;
32 0 : chinfo.valid = true;
33 0 : chantoinfomap[chinfo.offlchan] = chinfo;
34 0 : infotochanmap[chinfo.wib][chinfo.wibconnector][chinfo.cebchan] = chinfo.offlchan;
35 0 : }
36 0 : inFile.close();
37 0 : }
38 :
39 : // The function below gets cold electronics info from offline channel number. Sets valid to be false if
40 : // there is no corresponding cold electronics channel
41 : // if not found in the map, return a chan info struct filled with -1's and set the valid flag to false.
42 :
43 : VDColdboxChannelMapService::VDCBChanInfo
44 0 : VDColdboxChannelMapService::getChanInfoFromOfflChan(int offlchan)
45 : {
46 0 : VDCBChanInfo r;
47 0 : auto fm = chantoinfomap.find(offlchan);
48 0 : if (fm == chantoinfomap.end()) {
49 0 : r.offlchan = -1;
50 0 : r.wib = -1;
51 0 : r.wibconnector = -1;
52 0 : r.cebchan = -1;
53 0 : r.femb = -1;
54 0 : r.asic = -1;
55 0 : r.asicchan = -1;
56 0 : r.connector = -1;
57 0 : r.stripid = "INVALID";
58 0 : r.valid = false;
59 : } else {
60 0 : r = fm->second;
61 : }
62 0 : return r;
63 0 : }
64 :
65 : // The function below uses conventions from Nitish's spreadsheet. WIB: 1-3, wibconnector: 1-4, cechan: 0-127
66 : // It returns an offline channel number of -1 if the wib, wibconnector, and cechan are not in the map
67 :
68 : int
69 0 : VDColdboxChannelMapService::getOfflChanFromWIBConnectorInfo(int wib, int wibconnector, int cechan)
70 : {
71 : // int r = -1;
72 : // auto fm1 = infotochanmap.find(wib);
73 : // if (fm1 == infotochanmap.end()) return r;
74 : // auto& m1 = fm1->second;
75 : // auto fm2 = m1.find(wibconnector);
76 : // if (fm2 == m1.end()) return r;
77 : // auto& m2 = fm2->second;
78 : // auto fm3 = m2.find(cechan);
79 : // if (fm3 == m2.end()) return r;
80 : // r = fm3->second;
81 : // return r;
82 0 : try {
83 0 : return infotochanmap.at(wib).at(wibconnector).at(cechan);
84 0 : } catch (...) {
85 0 : return -1;
86 0 : }
87 : // return -1;
88 : }
89 :
90 : // For convenience, the function below uses conventions from the DAQ WIB header, with two FEMBs per fiber
91 : // on FELIX readout: slot: 0-2, fiber=1 or 2, cehcan: 0-255
92 : // it returns a channel number of -1 if the slot, fiber, chan combination is not in the map
93 :
94 : int
95 0 : VDColdboxChannelMapService::getOfflChanFromSlotFiberChan(int slot, int fiber, int chan)
96 : {
97 0 : int wc = fiber * 2 - 1;
98 0 : if (chan > 127) {
99 0 : chan -= 128;
100 0 : wc++;
101 : }
102 0 : return getOfflChanFromWIBConnectorInfo(slot + 1, wc, chan);
103 : }
104 :
105 : } // namespace detchannelsmap
106 : } // namespace dunedaq
|