DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
detchannelmaps
src
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
17
dune::TPCChannelMapSP::TPCChannelMapSP
() {
18
fSubstituteCrate
= 1;
19
fNChans
= 0;
20
}
21
22
void
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
76
dune::TPCChannelMapSP::TPCChanInfo_t
dune::TPCChannelMapSP::GetChanInfoFromElectronicsIDs
(
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
99
dune::TPCChannelMapSP::TPCChanInfo_t
dune::TPCChannelMapSP::GetChanInfoFromOfflChan
(
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
111
size_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
}
TPCChannelMapSP.h
detid
detid
Definition
TriggerActivity_serialization.hpp:47
dune::TPCChannelMapSP::make_hash
size_t make_hash(unsigned int detid, unsigned int crate, unsigned int slot, unsigned int stream, unsigned int streamch) const
Definition
TPCChannelMapSP.cpp:111
dune::TPCChannelMapSP::GetChanInfoFromOfflChan
TPCChanInfo_t GetChanInfoFromOfflChan(unsigned int offlchan) const
Definition
TPCChannelMapSP.cpp:99
dune::TPCChannelMapSP::OfflToChanInfo
std::unordered_map< unsigned int, TPCChanInfo_t > OfflToChanInfo
Definition
TPCChannelMapSP.h:79
dune::TPCChannelMapSP::ReadMapFromFile
void ReadMapFromFile(std::string &fullname)
Definition
TPCChannelMapSP.cpp:22
dune::TPCChannelMapSP::fSubstituteCrate
unsigned int fSubstituteCrate
Definition
TPCChannelMapSP.h:70
dune::TPCChannelMapSP::DetToChanInfo
std::unordered_map< size_t, TPCChanInfo_t > DetToChanInfo
Definition
TPCChannelMapSP.h:75
dune::TPCChannelMapSP::TPCChanInfo_t
struct dune::TPCChannelMapSP::TPCChanInfo TPCChanInfo_t
dune::TPCChannelMapSP::fNChans
unsigned int fNChans
Definition
TPCChannelMapSP.h:69
dune::TPCChannelMapSP::check_offline_channel
void check_offline_channel(unsigned int offlineChannel) const
Definition
TPCChannelMapSP.h:83
dune::TPCChannelMapSP::TPCChannelMapSP
TPCChannelMapSP()
Definition
TPCChannelMapSP.cpp:17
dune::TPCChannelMapSP::GetChanInfoFromElectronicsIDs
TPCChanInfo_t GetChanInfoFromElectronicsIDs(unsigned int detid, unsigned int crate, unsigned int slot, unsigned int stream, unsigned int streamchan) const
Definition
TPCChannelMapSP.cpp:76
dune::TPCChannelMapSP::TPCChanInfo::femb
unsigned int femb
Definition
TPCChannelMapSP.h:36
dune::TPCChannelMapSP::TPCChanInfo::asicchan
unsigned int asicchan
Definition
TPCChannelMapSP.h:38
dune::TPCChannelMapSP::TPCChanInfo::chan_in_plane
unsigned int chan_in_plane
Definition
TPCChannelMapSP.h:35
dune::TPCChannelMapSP::TPCChanInfo::stream
unsigned int stream
Definition
TPCChannelMapSP.h:32
dune::TPCChannelMapSP::TPCChanInfo::offlchan
unsigned int offlchan
Definition
TPCChannelMapSP.h:27
dune::TPCChannelMapSP::TPCChanInfo::valid
bool valid
Definition
TPCChannelMapSP.h:39
dune::TPCChannelMapSP::TPCChanInfo::asic
unsigned int asic
Definition
TPCChannelMapSP.h:37
dune::TPCChannelMapSP::TPCChanInfo::crate
unsigned int crate
Definition
TPCChannelMapSP.h:30
dune::TPCChannelMapSP::TPCChanInfo::slot
unsigned int slot
Definition
TPCChannelMapSP.h:31
dune::TPCChannelMapSP::TPCChanInfo::detid
unsigned int detid
Definition
TPCChannelMapSP.h:28
dune::TPCChannelMapSP::TPCChanInfo::detelement
unsigned int detelement
Definition
TPCChannelMapSP.h:29
dune::TPCChannelMapSP::TPCChanInfo::plane
unsigned int plane
Definition
TPCChannelMapSP.h:34
dune::TPCChannelMapSP::TPCChanInfo::streamchan
unsigned int streamchan
Definition
TPCChannelMapSP.h:33
Generated on
for DUNE-DAQ by
1.17.0