Skip to content

Commit 036321e

Browse files
Merge pull request #581 from SBNSoftware/feature/maxd_PTBDecoderUpdate
Feature/maxd ptb decoder update
2 parents bbf2ea0 + 90118e9 commit 036321e

9 files changed

Lines changed: 772 additions & 8 deletions

File tree

sbndcode/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_subdirectory(OpT0Finder)
2121
add_subdirectory(ShowerAna)
2222
add_subdirectory(Commissioning)
2323
add_subdirectory(Trigger)
24+
add_subdirectory(PTBAna)
2425

2526
# subdirectory for gallery stuff
2627
add_subdirectory(gallery)

sbndcode/Decoders/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ add_subdirectory(PTB)
33
add_subdirectory(SPECTDC)
44
add_subdirectory(PMT)
55
add_subdirectory(CRT)
6-
76
install_fhicl()

sbndcode/Decoders/PTB/SBNDPTBDecoder_module.cc

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ SBNDPTBDecoder::SBNDPTBDecoder(fhicl::ParameterSet const & p)
7878

7979
void SBNDPTBDecoder::produce(art::Event & evt)
8080
{
81-
82-
8381
// look first for container fragments and then non-container fragments
84-
8582
std::vector<raw::ptb::sbndptb> sbndptbs;
8683

8784
art::InputTag itag1(fInputLabel, fInputContainerInstance);
@@ -117,6 +114,61 @@ void SBNDPTBDecoder::produce(art::Event & evt)
117114
evt.put(std::make_unique<std::vector<raw::ptb::sbndptb>>(std::move(sbndptbs)),fOutputInstance);
118115
}
119116

117+
118+
void print_fragment_words(const artdaq::Fragment& frag, size_t wordNum, size_t bitsPerWord ) {
119+
120+
const __uint8_t* data_ptr = reinterpret_cast<const __uint8_t*>(frag.dataBegin());
121+
size_t wordCount = frag.dataSizeBytes() / (bitsPerWord / 8);
122+
for (size_t w = 0; w < wordCount; w++) {
123+
// Check if the current word index matches the specified word index
124+
if (w == wordNum) {
125+
// Print the bits for the specified n-bit word
126+
for (int i = (bitsPerWord-1); i >= 0; --i) {
127+
// Calculate the byte index and bit index
128+
size_t byteIndex = w * (bitsPerWord / 8) + (i / 8);
129+
int bitIndex = (i % 8); // Get the correct bit position in the byte
130+
// Print the bit
131+
std::cout << static_cast<int>((data_ptr[byteIndex] >> bitIndex) & 1);
132+
if (i % 8 == 0) {
133+
std::cout << " ";
134+
}
135+
}
136+
std::cout << std::endl; // New line after printing the word
137+
}
138+
}
139+
}
140+
141+
142+
//Copied from Lines 1382-1406 from sbndaq-artdaq/sbndaq-artdaq/ArtModules/SBND/EventAna_module.cc
143+
144+
/*******************************************
145+
* Note: Below for the Timestamp conversion,
146+
* The PTB TS is in UTC seconds since the Unix epoch in 50MHz clock ticks.
147+
* This means to recover seconds since the Unix epoch use: sec_since_epoch = TS / 50e6
148+
* and of course nanosec_since_epoch = (TS / 50e6) * 1e9 = TS * 20
149+
*
150+
* Note: The `CTBFragment` constructor grabs the chunk of memory the artDAQ fragment occupies.
151+
* Since we know a priori the number of PTB words (from the TCP header) and the size (128b for all words)
152+
* we can loop over the memory addresses, casting each 128b into the correct word type given by each word's `type`.
153+
*
154+
* There are 5 word types with the following bit arrangement:
155+
* Feeback = | 3b Word Type | 61b Payload | 64b Timestamp | (here Payload is split into code, source, payload1, payload2)
156+
* LLT, HLT = | 3b Word Type | 61b Payload | 64b Timestamp |
157+
* Channel Status = | 3b Word Type | 64b Payload | 61b Timestamp | (Larger Payload to fit all input channels)
158+
*
159+
* Word Type:
160+
* - 0x0 = Feedback/Error Word -> Errors from the firmware, should abort the run
161+
* - 0x1 = Low Level Trigger (LLT) -> Holds a record of any asserted LLTs
162+
* - 0x2 = High Level Trigger (HLT) -> Holds a record of any asserted HLTs
163+
* - 0x3 = Channel status -> Holds a record of any asserted inputs
164+
* - 0x7 = Timestamp Word -> No payload just a timestamp, these are periodic
165+
*
166+
* Note: Payload AND'd with mask the size of the expected number of bits just
167+
* to make sure we don't get any unexpected garbage bits since we aren't using
168+
* the full bits of the variable type e.g. uint64_t, unint16_t..
169+
**************************************/
170+
171+
120172
void SBNDPTBDecoder::_process_PTB_AUX(const artdaq::Fragment& frag, ptbsv_t &sout)
121173
{
122174
sbndaq::CTBFragment ctbfrag(frag); // somehow the name CTBFragment stuck
@@ -145,8 +197,19 @@ void SBNDPTBDecoder::_process_PTB_AUX(const artdaq::Fragment& frag, ptbsv_t &sou
145197
tstruct.timestamp = ctbfrag.Trigger(iword)->timestamp;
146198
if (ctbfrag.Trigger(iword)->IsHLT())
147199
{
200+
201+
if (*(frag.metadata<int>()) == 2){ //If data is taken with 192b PTB words
202+
tstruct.prev_timestamp = ctbfrag.PTBWord(iword)->prevTS;
203+
tstruct.gate_counter = ctbfrag.Trigger(iword)->gate_counter;
204+
}
205+
else if (*(frag.metadata<int>()) != 2){ //If data is taken with 128b PTB words
206+
tstruct.prev_timestamp = 0;
207+
tstruct.gate_counter = 0;
208+
}
209+
148210
ix = sout.HLTrigs.size();
149211
sout.HLTrigs.push_back(tstruct);
212+
150213
if (fDebugLevel > 0)
151214
{
152215
std::cout << "SBNDPTBDecoder_module: found HLT: " << wt << " " << ix << std::endl;

sbndcode/Decoders/PTB/classes_def.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55
-->
66

77
<lcgdict>
8-
<class name="raw::ptb::Trigger" ClassVersion="10">
8+
<class name="raw::ptb::Trigger" ClassVersion="11">
9+
<version ClassVersion="11" checksum="1173933314"/>
910
<version ClassVersion="10" checksum="983962440"/>
1011
</class>
11-
<class name="raw::ptb::ChStatus" ClassVersion="10">
12+
<class name="raw::ptb::ChStatus" ClassVersion="11">
13+
<version ClassVersion="11" checksum="1302570871"/>
1214
<version ClassVersion="10" checksum="2716777827"/>
1315
</class>
14-
<class name="raw::ptb::Feedback" ClassVersion="10">
16+
<class name="raw::ptb::Feedback" ClassVersion="11">
17+
<version ClassVersion="11" checksum="2612286493"/>
1518
<version ClassVersion="10" checksum="404427229"/>
1619
</class>
17-
<class name="raw::ptb::Misc" ClassVersion="10">
20+
<class name="raw::ptb::Misc" ClassVersion="11">
21+
<version ClassVersion="11" checksum="686355011"/>
1822
<version ClassVersion="10" checksum="1110799137"/>
1923
</class>
2024
<class name="raw::ptb::WordIndex" ClassVersion="10">

sbndcode/Decoders/PTB/sbndptb.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ namespace raw {
1818
namespace ptb {
1919

2020
struct Trigger {
21+
ULong64_t prev_timestamp;
2122
ULong64_t timestamp;
2223
ULong64_t trigger_word;
24+
uint32_t gate_counter;
2325
uint32_t word_type;
2426
};
2527

2628
struct ChStatus {
29+
ULong64_t prev_timestamp;
2730
ULong64_t timestamp;
2831
uint32_t beam;
2932
uint32_t crt;
@@ -35,6 +38,7 @@ namespace raw {
3538
};
3639

3740
struct Feedback {
41+
ULong64_t prev_timestamp;
3842
ULong64_t timestamp;
3943
uint32_t code;
4044
uint32_t source;
@@ -43,6 +47,7 @@ namespace raw {
4347
};
4448

4549
struct Misc {
50+
ULong64_t prev_timestamp;
4651
ULong64_t timestamp;
4752
ULong64_t payload;
4853
uint32_t word_type;

sbndcode/PTBAna/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
art_make(
2+
MODULE_LIBRARIES
3+
ROOT::Tree
4+
larsim::Utils
5+
sbndcode_GeoWrappers
6+
)
7+
install_fhicl()

0 commit comments

Comments
 (0)