DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TPCChannelMapSP.cpp
Go to the documentation of this file.
1
2// Class: TPCChannelMapSP
3// Module type: standalone algorithm
4// File: TPCChannelMapSP.cxx
5// Author: Tom Junk, Jan 2025
6//
7// Implementation of hardware-offline channel mapping reading from a file.
9
10#include "TPCChannelMapSP.h"
11
12#include <fstream>
13#include <iostream>
14#include <sstream>
15#include <stdexcept>
16
22
23void
25{
26 fNChans = 0;
27
28 std::ifstream inFile(fullname, std::ios::in);
29 std::string line;
30
31 while (std::getline(inFile, line)) {
32 std::stringstream linestream(line);
33
34 TPCChanInfo_t chanInfo;
35 linestream >> chanInfo.offlchan >> chanInfo.detid >> chanInfo.detelement >> chanInfo.crate >> chanInfo.slot >>
36 chanInfo.stream >> chanInfo.streamchan >> chanInfo.plane >> chanInfo.chan_in_plane >> chanInfo.femb >>
37 chanInfo.asic >> chanInfo.asicchan;
38
39 chanInfo.valid = true;
40 ++fNChans;
41
42 // fill maps.
43
45
46 auto hashval = make_hash(chanInfo.detid, chanInfo.crate, chanInfo.slot, chanInfo.stream, chanInfo.streamchan);
47 if (DetToChanInfo.find(hashval) != DetToChanInfo.end()) {
48 std::cout << "TPCChannelMapSP: duplicate electronics channel found. detid, crate, slot, stream, streamchan: "
49 << chanInfo.detid << " " << chanInfo.crate << " " << chanInfo.slot << " " << chanInfo.stream << " "
50 << chanInfo.streamchan << std::endl;
51 throw std::range_error("Duplicate Electronics ID");
52 }
53 DetToChanInfo[hashval] = chanInfo;
54
55 if (OfflToChanInfo.find(chanInfo.offlchan) != OfflToChanInfo.end()) {
56 std::cout << "TPCChannelMapSP: duplicate offline channel found: " << chanInfo.offlchan << std::endl;
57 throw std::range_error("Duplicate Offline TPC Channel ID");
58 }
59 OfflToChanInfo[chanInfo.offlchan] = chanInfo;
60 }
61 inFile.close();
62}
63
66 unsigned int crate,
67 unsigned int slot,
68 unsigned int stream,
69 unsigned int streamchan) const
70{
71 size_t h = make_hash(detid, crate, slot, stream, streamchan);
72 auto ret = DetToChanInfo.find(h);
73 if (ret == DetToChanInfo.end()) {
74 h = make_hash(detid, fSubstituteCrate, slot, stream, streamchan);
75 ret = DetToChanInfo.find(h);
76 if (ret == DetToChanInfo.end()) {
77 TPCChanInfo_t badInfo = {};
78 badInfo.valid = false;
79 return badInfo;
80 }
81 }
82 return ret->second;
83}
84
86dune::TPCChannelMapSP::GetChanInfoFromOfflChan(unsigned int offlineChannel) const
87{
88 auto ci = OfflToChanInfo.find(offlineChannel);
89 if (ci == OfflToChanInfo.end()) {
90 TPCChanInfo_t badInfo = {};
91 badInfo.valid = false;
92 return badInfo;
93 }
94 return ci->second;
95}
96
97size_t
99 unsigned int crate, // 10 bits
100 unsigned int slot, // 4 bits
101 unsigned int stream, // 8 bits
102 unsigned int streamch // 12 bits
103) const
104{
105 size_t hashval = (((size_t)detid & 0x3f) << 34);
106 hashval ^= ((crate & 0x3ff) << 24);
107 hashval ^= ((slot & 0xf) << 20);
108 hashval ^= ((stream & 0xff) << 12);
109 hashval ^= (streamch & 0xfff);
110 return hashval;
111}
size_t make_hash(unsigned int detid, unsigned int crate, unsigned int slot, unsigned int stream, unsigned int streamch) const
TPCChanInfo_t GetChanInfoFromOfflChan(unsigned int offlchan) const
std::unordered_map< unsigned int, TPCChanInfo_t > OfflToChanInfo
void ReadMapFromFile(std::string &fullname)
unsigned int fSubstituteCrate
std::unordered_map< size_t, TPCChanInfo_t > DetToChanInfo
struct dune::TPCChannelMapSP::TPCChanInfo TPCChanInfo_t
void check_offline_channel(unsigned int offlineChannel) const
TPCChanInfo_t GetChanInfoFromElectronicsIDs(unsigned int detid, unsigned int crate, unsigned int slot, unsigned int stream, unsigned int streamchan) const