Skip to content

Commit 9442f94

Browse files
committed
code cleanup from requested changes
1 parent 8b5120e commit 9442f94

6 files changed

Lines changed: 40 additions & 39 deletions

File tree

sbncode/BeamSpillInfoRetriever/POTTools.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ namespace sbn::pot{
2020
if (ctb_frag.Trigger(word_i)->IsHLT() && ctb_frag.Trigger(word_i)->IsTrigger(HLT))
2121
{
2222
foundHLT = true;
23-
uint64_t RawprevPTBTimeStamp = ctb_frag.PTBWord(word_i)->prevTS * 20;
24-
uint64_t RawcurrPTBTimeStamp = ctb_frag.Trigger(word_i)->timestamp * 20;
25-
double currTS_candidate = std::bitset<64>(RawcurrPTBTimeStamp/20).to_ullong()/50e6;
23+
uint64_t RawprevPTBTimeStamp = ctb_frag.PTBWord(word_i)->prevTS;
24+
uint64_t RawcurrPTBTimeStamp = ctb_frag.Trigger(word_i)->timestamp;
25+
std::uint64_t currTS_candidate = std::bitset<64>(RawcurrPTBTimeStamp).to_ullong() * 20;
2626
if(currTS_candidate < PTBInfo.currPTBTimeStamp){
27-
PTBInfo.prevPTBTimeStamp = std::bitset<64>(RawprevPTBTimeStamp / 20).to_ullong()/50e6;
27+
PTBInfo.prevPTBTimeStamp = std::bitset<64>(RawprevPTBTimeStamp).to_ullong() * 20;
2828
PTBInfo.currPTBTimeStamp = currTS_candidate;
2929
PTBInfo.GateCounter = ctb_frag.Trigger(word_i)->gate_counter;
3030
}
@@ -43,9 +43,9 @@ namespace sbn::pot{
4343
}
4444
}
4545

46-
std::vector<PTBInfo_t> extractAllPTBInfo(art::Handle<std::vector<artdaq::Fragment> > cont_frags) {
46+
std::vector<PTBInfo_t> extractAllPTBInfo(std::vector<artdaq::Fragment> const& cont_frags) {
4747
std::vector<PTBInfo_t> PTBInfoVec;
48-
for (auto const& cont : *cont_frags)
48+
for (auto const& cont : cont_frags)
4949
{
5050
artdaq::ContainerFragment cont_frag(cont);
5151
for (size_t fragi = 0; fragi < cont_frag.block_count(); ++fragi)
@@ -58,9 +58,8 @@ namespace sbn::pot{
5858
PTBInfo_t PTBInfo;
5959
uint64_t RawprevPTBTimeStamp = ctb_frag.PTBWord(word_i)->prevTS;
6060
uint64_t RawcurrPTBTimeStamp = ctb_frag.Trigger(word_i)->timestamp;
61-
double currTS_candidate = std::bitset<64>(RawcurrPTBTimeStamp).to_ullong()/50e6;
62-
PTBInfo.prevPTBTimeStamp = std::bitset<64>(RawprevPTBTimeStamp).to_ullong()/50e6;
63-
PTBInfo.currPTBTimeStamp = currTS_candidate;
61+
PTBInfo.prevPTBTimeStamp = std::bitset<64>(RawprevPTBTimeStamp).to_ullong() * 20;
62+
PTBInfo.currPTBTimeStamp = std::bitset<64>(RawcurrPTBTimeStamp).to_ullong() * 20;
6463
PTBInfo.GateCounter = ctb_frag.Trigger(word_i)->gate_counter;
6564
PTBInfo.isHLT = ctb_frag.Trigger(word_i)->IsHLT();
6665
PTBInfo.triggerWord = ctb_frag.Trigger(word_i)->trigger_word;

sbncode/BeamSpillInfoRetriever/POTTools.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
namespace sbn::pot{
1919

2020
typedef struct PTBInfo_t {
21-
double currPTBTimeStamp = 1e20;
22-
double prevPTBTimeStamp = 0;
21+
std::uint64_t currPTBTimeStamp = UINT64_MAX; ///< Timestamp in UTC nanoseconds since Unix epoch (converted from 20ns clock ticks)
22+
std::uint64_t prevPTBTimeStamp = 0;
2323
unsigned int GateCounter = 0;
2424
bool isHLT = false;
25-
uint64_t triggerWord = 0;
25+
uint64_t triggerWord = 0; ///< Timestamp in s since beam extraction signal
2626
} PTBInfo_t;
2727

2828
typedef struct TriggerInfo_t {
2929
int gate_type = 0; ///< Source of the spill: `1`: BNB, `2`: NuMI
30-
double t_current_event = 0;
30+
double t_current_event = 0; ///< Timestamp in UTC seconds since Unix epoch (converted from 20ns clock ticks)
3131
double t_previous_event = 0;
3232
unsigned int number_of_gates_since_previous_event = 0;
3333
std::int64_t WR_to_Spill_conversion = 0;
@@ -52,7 +52,7 @@ namespace sbn::pot{
5252
* @param cont_frags The PTB fragments to examine.
5353
* @return Vector of PTBInfo_t containing all triggers found.
5454
*/
55-
std::vector<PTBInfo_t> extractAllPTBInfo(art::Handle<std::vector<artdaq::Fragment> > cont_frags);
55+
std::vector<PTBInfo_t> extractAllPTBInfo(std::vector<artdaq::Fragment> const& cont_frags);
5656

5757
/**
5858
* @brief Extracts information from TDC for use in SBND POT accounting.

sbncode/BeamSpillInfoRetriever/SBNDBNBRetriever/SBNDBNBRetriever_module.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ sbn::pot::TriggerInfo_t sbn::SBNDBNBRetriever::extractTriggerInfo(art::Event con
123123
else{
124124
// If missing TDC, use PTB instead
125125
mf::LogDebug("SBNDBNBRetriever") << " Missing TDC Container Fragments!!! " << std::endl;
126-
triggerInfo.t_current_event = PTBInfo.currPTBTimeStamp - fBESOffset;
126+
triggerInfo.t_current_event = PTBInfo.currPTBTimeStamp / 1e9 - fBESOffset;
127127
}
128128

129-
triggerInfo.t_previous_event = PTBInfo.prevPTBTimeStamp - fBESOffset;
129+
triggerInfo.t_previous_event = PTBInfo.prevPTBTimeStamp / 1e9 - fBESOffset;
130130
triggerInfo.number_of_gates_since_previous_event = PTBInfo.GateCounter;
131131

132-
double PTBandCurrOffset = PTBInfo.currPTBTimeStamp - triggerInfo.t_current_event - fBESOffset;
132+
double PTBandCurrOffset = PTBInfo.currPTBTimeStamp / 1e9 - triggerInfo.t_current_event - fBESOffset;
133133

134134
// Catch for an issue seen a few times where PTB off by a second.
135135
// Only need to correct prevTS because either currTS is from TDC

sbncode/BeamSpillInfoRetriever/SBNDBNBZEROBIASRetriever/SBNDBNBZEROBIASRetriever_module.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ sbn::pot::TriggerInfo_t sbn::SBNDBNBZEROBIASRetriever::extractTriggerInfo(art::E
126126
else{
127127
// If missing TDC, use PTB instead
128128
mf::LogDebug("SBNDBNBZEROBIASRetriever") << " Missing TDC Container Fragments!!!" << std::endl;
129-
triggerInfo.t_current_event = PTBInfo.currPTBTimeStamp - fBESOffset;
129+
triggerInfo.t_current_event = PTBInfo.currPTBTimeStamp / 1e9 - fBESOffset;
130130
}
131131

132-
triggerInfo.t_previous_event = PTBInfo.prevPTBTimeStamp - fBESOffset;
132+
triggerInfo.t_previous_event = PTBInfo.prevPTBTimeStamp / 1e9 - fBESOffset;
133133
triggerInfo.number_of_gates_since_previous_event = PTBInfo.GateCounter;
134134

135-
double PTBandCurrOffset = PTBInfo.currPTBTimeStamp - triggerInfo.t_current_event - fBESOffset;
135+
double PTBandCurrOffset = PTBInfo.currPTBTimeStamp / 1e9 - triggerInfo.t_current_event - fBESOffset;
136136

137137
// Catch for an issue seen a few times where PTB off by a second.
138138
// Only need to correct prevTS because either currTS is from TDC

sbncode/CAFMaker/CAFMaker_module.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,7 @@ bool CAFMaker::GetPsetParameter(const fhicl::ParameterSet& pset,
13801380

13811381
//......................................................................
13821382
void CAFMaker::produce(art::Event& evt) noexcept {
1383+
mf::LogInfo("CAFMaker") << "CAFMaker::produce called for event: " << evt.id();
13831384

13841385
bool const firstInFile = (fIndexInFile++ == 0);
13851386

@@ -1720,13 +1721,14 @@ void CAFMaker::produce(art::Event& evt) noexcept {
17201721
art::Handle<artdaq::Fragments> ptb_frags_handle;
17211722
evt.getByLabel(PTB_itag, ptb_frags_handle);
17221723
if (ptb_frags_handle.isValid()) {
1723-
try {
1724-
std::vector<sbn::pot::PTBInfo_t> ptb_triggers = sbn::pot::extractAllPTBInfo(ptb_frags_handle);
1725-
FillPTBTriggersSBND(ptb_triggers, srtrigger);
1726-
}
1727-
catch (...) {
1728-
std::cout << "CAFMaker: Failed to extract PTB triggers" << std::endl;
1729-
}
1724+
mf::LogDebug("CAFMaker") << "Found ContainerPTB, extracting PTB triggers...";
1725+
std::vector<sbn::pot::PTBInfo_t> ptb_triggers = sbn::pot::extractAllPTBInfo(*ptb_frags_handle);
1726+
mf::LogDebug("CAFMaker") << "Extracted " << ptb_triggers.size() << " PTB triggers";
1727+
FillPTBTriggersSBND(ptb_triggers, srtrigger);
1728+
mf::LogDebug("CAFMaker") << "PTB HLT triggers: " << srtrigger.ptb_hlt_timestamp.size()
1729+
<< ", LLT triggers: " << srtrigger.ptb_llt_timestamp.size();
1730+
} else {
1731+
mf::LogDebug("CAFMaker") << "ContainerPTB not found for event " << evt.id();
17301732
}
17311733
}
17321734

sbncode/CAFMaker/FillTrigger.cxx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include<iostream>
2+
#include <bitset>
23
#include "sbncode/CAFMaker/FillTrigger.h"
34

45
namespace caf
@@ -82,18 +83,17 @@ namespace caf
8283

8384
// Decode trigger words: each set bit becomes a separate entry with the same timestamp
8485
for(const auto& trig : ptb_triggers) {
85-
std::uint64_t triggerWord = trig.triggerWord;
86-
for(int bit = 0; bit < 64; ++bit) {
87-
std::uint64_t bitMask = 1ULL << bit;
88-
if(triggerWord & bitMask) {
89-
if(trig.isHLT) {
90-
triggerInfo.ptb_hlt_timestamp.push_back(trig.currPTBTimeStamp);
91-
triggerInfo.ptb_hlt_bit.push_back(bit);
92-
} else {
93-
triggerInfo.ptb_llt_timestamp.push_back(trig.currPTBTimeStamp);
94-
triggerInfo.ptb_llt_bit.push_back(bit);
95-
}
96-
}
86+
// Choose destination vectors based on trigger type
87+
auto& ptb_timestamp = trig.isHLT ? triggerInfo.ptb_hlt_timestamp : triggerInfo.ptb_llt_timestamp;
88+
auto& ptb_bit = trig.isHLT ? triggerInfo.ptb_hlt_bit : triggerInfo.ptb_llt_bit;
89+
90+
std::bitset<64> const triggerWord { trig.triggerWord };
91+
// currPTBTimeStamp is already in nanoseconds (uint64_t), use directly
92+
// Loop variable is uint8_t since we know bit values are 0-63 (fits in uint8_t)
93+
for(std::uint8_t bit = 0; bit < triggerWord.size(); ++bit) {
94+
if(!triggerWord[bit]) continue;
95+
ptb_timestamp.push_back(trig.currPTBTimeStamp);
96+
ptb_bit.push_back(bit);
9797
}
9898
}
9999
}

0 commit comments

Comments
 (0)