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
21
22void dune::TPCChannelMapSP::ReadMapFromFile(std::string& fullname)
23{
24 fNChans = 0;
25
26 std::ifstream inFile(fullname, std::ios::in);
27 std::string line;
28
29 while (std::getline(inFile, line)) {
30 std::stringstream linestream(line);
31
32 TPCChanInfo_t chanInfo;
33 linestream >>
34 chanInfo.offlchan >>
35 chanInfo.detid >>
36 chanInfo.detelement >>
37 chanInfo.crate >>
38 chanInfo.slot >>
39 chanInfo.stream >>
40 chanInfo.streamchan >>
41 chanInfo.plane >>
42 chanInfo.chan_in_plane >>
43 chanInfo.femb >>
44 chanInfo.asic >>
45 chanInfo.asicchan;
46
47 chanInfo.valid = true;
48 ++fNChans;
49
50 // fill maps.
51
52 check_offline_channel(chanInfo.offlchan);
53
54 auto hashval = make_hash(chanInfo.detid,chanInfo.crate,chanInfo.slot,chanInfo.stream,chanInfo.streamchan);
55 if ( DetToChanInfo.find(hashval) != DetToChanInfo.end() ){
56 std::cout << "TPCChannelMapSP: duplicate electronics channel found. detid, crate, slot, stream, streamchan: " <<
57 chanInfo.detid << " " <<
58 chanInfo.crate << " " <<
59 chanInfo.slot << " " <<
60 chanInfo.stream << " " <<
61 chanInfo.streamchan << std::endl;
62 throw std::range_error("Duplicate Electronics ID");
63 }
64 DetToChanInfo[hashval] = chanInfo;
65
66 if ( OfflToChanInfo.find(chanInfo.offlchan) != OfflToChanInfo.end() ) {
67 std::cout << "TPCChannelMapSP: duplicate offline channel found: " <<
68 chanInfo.offlchan << std::endl;
69 throw std::range_error("Duplicate Offline TPC Channel ID");
70 }
71 OfflToChanInfo[chanInfo.offlchan] = chanInfo;
72 }
73 inFile.close();
74}
75
77 unsigned int detid,
78 unsigned int crate,
79 unsigned int slot,
80 unsigned int stream,
81 unsigned int streamchan) const
82{
83 size_t h = make_hash(detid,crate,slot,stream,streamchan);
84 auto ret = DetToChanInfo.find(h);
85 if (ret == DetToChanInfo.end())
86 {
87 h = make_hash(detid,fSubstituteCrate,slot,stream,streamchan);
88 ret = DetToChanInfo.find(h);
89 if (ret == DetToChanInfo.end())
90 {
91 TPCChanInfo_t badInfo = {};
92 badInfo.valid = false;
93 return badInfo;
94 }
95 }
96 return ret->second;
97}
98
100 unsigned int offlineChannel) const
101{
102 auto ci = OfflToChanInfo.find(offlineChannel);
103 if (ci == OfflToChanInfo.end()) {
104 TPCChanInfo_t badInfo = {};
105 badInfo.valid = false;
106 return badInfo;
107 }
108 return ci->second;
109}
110
111size_t dune::TPCChannelMapSP::make_hash( unsigned int detid, //6 bits
112 unsigned int crate, //10 bits
113 unsigned int slot, //4 bits
114 unsigned int stream, //8 bits
115 unsigned int streamch //12 bits
116 ) const
117{
118 size_t hashval = (((size_t)detid & 0x3f)<<34);
119 hashval ^=((crate & 0x3ff)<<24);
120 hashval ^=((slot & 0xf)<<20);
121 hashval ^=((stream & 0xff)<<12);
122 hashval ^=(streamch & 0xfff);
123 return hashval;
124}
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
void ReadMapFromFile(std::string &fullname)
unsigned int fSubstituteCrate
TPCChanInfo_t GetChanInfoFromElectronicsIDs(unsigned int detid, unsigned int crate, unsigned int slot, unsigned int stream, unsigned int streamchan) const