All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
daq::TriggerDecoder Class Reference

Tool decoding the trigger information from DAQ. More...

Inheritance diagram for daq::TriggerDecoder:
daq::IDecoder daq::IDecoder

Classes

struct  TriggerGateTypes
 Codes of gate types from the trigger hardware. More...
 

Public Member Functions

 TriggerDecoder (fhicl::ParameterSet const &pset)
 
virtual void produces (art::ProducesCollector &) override
 The space point building should output the hit collection for those hits which combine to form space points - a nice noise filter! More...
 
virtual void configure (const fhicl::ParameterSet &) override
 Interface for configuring the particular algorithm tool. More...
 
virtual void initializeDataProducts () override
 Initialize any data products the tool will output. More...
 
virtual void process_fragment (const artdaq::Fragment &fragment) override
 Given a set of recob hits, run DBscan to form 3D clusters. More...
 
virtual void outputDataProducts (art::Event &event) override
 Output the data products to the event store. More...
 
 TriggerDecoder (fhicl::ParameterSet const &pset)
 
virtual void consumes (art::ConsumesCollector &collector) override
 Declare to the framework what you expect to read. More...
 
virtual void produces (art::ProducesCollector &) override
 The space point building should output the hit collection for those hits which combine to form space points - a nice noise filter! More...
 
virtual void configure (const fhicl::ParameterSet &) override
 Interface for configuring the particular algorithm tool. More...
 
virtual void initializeDataProducts () override
 Initialize any data products the tool will output. More...
 
virtual void setupRun (art::Run const &run) override
 Preparation to process a new run. More...
 
virtual void process_fragment (const artdaq::Fragment &fragment) override
 Given a set of recob hits, run DBscan to form 3D clusters. More...
 
virtual void outputDataProducts (art::Event &event) override
 Output the data products to the event store. More...
 
- Public Member Functions inherited from daq::IDecoder
virtual ~IDecoder () noexcept=default
 Virtual Destructor. More...
 
virtual void setupEvent (art::Event const &event)
 Preparation to process a new event. More...
 

Private Types

using nanoseconds = util::quantities::nanosecond
 
using TriggerCollection = std::vector< raw::ExternalTrigger >
 
using TriggerPtr = std::unique_ptr< TriggerCollection >
 
using RelativeTriggerCollection = std::vector< raw::Trigger >
 
using BeamGateInfoCollection = std::vector< sim::BeamGateInfo >
 
using BeamGateInfoPtr = std::unique_ptr< BeamGateInfoCollection >
 
using ExtraInfoPtr = std::unique_ptr< sbn::ExtraTriggerInfo >
 
using microseconds = util::quantities::microsecond
 
using nanoseconds = util::quantities::nanosecond
 
using TriggerCollection = std::vector< raw::ExternalTrigger >
 
using TriggerPtr = std::unique_ptr< TriggerCollection >
 
using RelativeTriggerCollection = std::vector< raw::Trigger >
 
using BeamGateInfoCollection = std::vector< sim::BeamGateInfo >
 
using BeamGateInfoPtr = std::unique_ptr< BeamGateInfoCollection >
 
using ExtraInfoPtr = std::unique_ptr< sbn::ExtraTriggerInfo >
 

Private Member Functions

icarus::ICARUSTriggerUDPFragment makeTriggerFragment (artdaq::Fragment const &fragment) const
 Creates a ICARUSTriggerInfo from a generic fragment. More...
 
icarus::ICARUSTriggerInfo parseTriggerString (std::string_view data) const
 Parses the trigger data packet with the "standard" parser. More...
 
icarus::ICARUSTriggerV2Fragment makeTriggerFragment (artdaq::Fragment const &fragment) const
 Creates a ICARUSTriggerInfo from a generic fragment. More...
 
icarus::ICARUSTriggerInfo parseTriggerString (std::string_view data) const
 Parses the trigger data packet with the "standard" parser. More...
 
icarus::KeyValuesData parseTriggerStringAsCSV (std::string const &data) const
 Parses the trigger data packet with a CSV parser. More...
 

Static Private Member Functions

static std::string_view firstLine (std::string const &s, std::string const &endl="\0\n\r"s)
 
static std::uint64_t makeTimestamp (unsigned int s, unsigned int ns)
 Combines second and nanosecond counts into a 64-bit timestamp. More...
 
static long long int timestampDiff (std::uint64_t a, std::uint64_t b)
 Returns the difference a - b. More...
 
static std::string_view firstLine (std::string const &s, std::string const &endl="\0\n\r"s)
 
static std::uint64_t makeTimestamp (unsigned int s, unsigned int ns)
 Combines second and nanosecond counts into a 64-bit timestamp. More...
 
static long long int timestampDiff (std::uint64_t a, std::uint64_t b)
 Returns the difference a - b. More...
 
static std::uint64_t encodeLVDSbits (short int cryostat, short int connector, std::uint64_t connectorWord)
 
static sim::BeamType_t simGateType (sbn::triggerSource source)
 Returns the beam type corresponding to the specified trigger source. More...
 

Private Attributes

TriggerPtr fTrigger
 
TriggerPtr fPrevTrigger
 
std::unique_ptr
< RelativeTriggerCollection
fRelTrigger
 
ExtraInfoPtr fTriggerExtra
 
BeamGateInfoPtr fBeamGateInfo
 
bool fDiagnosticOutput
 Produces large number of diagnostic messages, use with caution! More...
 
bool fDebug
 Use this for debugging this tool. More...
 
long fLastEvent = 0
 
detinfo::DetectorTimings const fDetTimings
 Detector clocks and timings. More...
 
art::InputTag fTriggerConfigTag
 Data product with hardware trigger configuration. More...
 
icarus::TriggerConfiguration
const * 
fTriggerConfiguration = nullptr
 Cached pointer to the trigger configuration of the current run, if any. More...
 

Static Private Attributes

static std::string const CurrentTriggerInstanceName {}
 Name of the data product instance for the current trigger. More...
 
static std::string const PreviousTriggerInstanceName { "previous" }
 Name of the data product instance for the previous trigger. More...
 
static constexpr double UnknownBeamTime = std::numeric_limits<double>::max()
 
static constexpr nanoseconds BNBgateDuration { 1600. }
 
static constexpr nanoseconds NuMIgateDuration { 9500. }
 

Detailed Description

Tool decoding the trigger information from DAQ.

Produces:

Besides the main data product (empty instance name) an additional std::vector<raw::ExternalTrigger> data product with instance name "previous" is also produced, which relays the same kind of information but for the previous trigger. This information also comes from the trigger DAQ. If no previous trigger is available, this collection will be empty.

Timestamps and corrections

The reference trigger time is driven by the trigger fragment time, which is expected to have been derived from the actual trigger time from the White Rabbit system properly corrected to UTC by the board reader.

All absolute timestamps are corrected to be on that same scale. The absolute timestamps related to the White Rabbit time are added an offset to achieve this correction; this offset is stored in the data product (sbn::ExtraTriggerInfo::WRtimeToTriggerTime).

Produces:

Besides the main data product (empty instance name) an additional std::vector<raw::ExternalTrigger> data product with instance name "previous" is also produced, which relays the same kind of information but for the previous trigger. This information also comes from the trigger DAQ. If no previous trigger is available, this collection will be empty.

Timestamps and corrections

The reference trigger time is driven by the trigger fragment time, which is expected to have been derived from the actual trigger time from the White Rabbit system properly corrected to UTC by the board reader.

All absolute timestamps are corrected to be on that same scale. The absolute timestamps related to the White Rabbit time are added an offset to achieve this correction; this offset is stored in the data product (sbn::ExtraTriggerInfo::WRtimeToTriggerTime).

Configuration

Definition at line 128 of file TriggerDecoder_tool.cc.

Member Typedef Documentation

Definition at line 144 of file TriggerDecoder_tool.cc.

Definition at line 230 of file TriggerDecoderV2_tool.cc.

Definition at line 145 of file TriggerDecoder_tool.cc.

Definition at line 231 of file TriggerDecoderV2_tool.cc.

using daq::TriggerDecoder::ExtraInfoPtr = std::unique_ptr<sbn::ExtraTriggerInfo>
private

Definition at line 146 of file TriggerDecoder_tool.cc.

using daq::TriggerDecoder::ExtraInfoPtr = std::unique_ptr<sbn::ExtraTriggerInfo>
private

Definition at line 232 of file TriggerDecoderV2_tool.cc.

Definition at line 213 of file TriggerDecoderV2_tool.cc.

Definition at line 130 of file TriggerDecoder_tool.cc.

Definition at line 214 of file TriggerDecoderV2_tool.cc.

Definition at line 143 of file TriggerDecoder_tool.cc.

Definition at line 229 of file TriggerDecoderV2_tool.cc.

Definition at line 141 of file TriggerDecoder_tool.cc.

Definition at line 227 of file TriggerDecoderV2_tool.cc.

using daq::TriggerDecoder::TriggerPtr = std::unique_ptr<TriggerCollection>
private

Definition at line 142 of file TriggerDecoder_tool.cc.

using daq::TriggerDecoder::TriggerPtr = std::unique_ptr<TriggerCollection>
private

Definition at line 228 of file TriggerDecoderV2_tool.cc.

Constructor & Destructor Documentation

daq::TriggerDecoder::TriggerDecoder ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 205 of file TriggerDecoder_tool.cc.

206  : fDetTimings
207  { art::ServiceHandle<detinfo::DetectorClocksService>()->DataForJob() }
208  {
209  this->configure(pset);
210  }
detinfo::DetectorTimings const fDetTimings
Detector clocks and timings.
virtual void configure(const fhicl::ParameterSet &) override
Interface for configuring the particular algorithm tool.
daq::TriggerDecoder::TriggerDecoder ( fhicl::ParameterSet const &  pset)
explicit

Member Function Documentation

void daq::TriggerDecoder::configure ( const fhicl::ParameterSet &  )
overridevirtual

Interface for configuring the particular algorithm tool.

Parameters
ParameterSetThe input set of parameters for configuration

Implements daq::IDecoder.

Definition at line 223 of file TriggerDecoder_tool.cc.

224  {
225  fDiagnosticOutput = pset.get<bool>("DiagnosticOutput", false);
226  fDebug = pset.get<bool>("Debug", false);
227  return;
228  }
bool fDiagnosticOutput
Produces large number of diagnostic messages, use with caution!
bool fDebug
Use this for debugging this tool.
virtual void daq::TriggerDecoder::configure ( const fhicl::ParameterSet &  )
overridevirtual

Interface for configuring the particular algorithm tool.

Parameters
ParameterSetThe input set of parameters for configuration

Implements daq::IDecoder.

void daq::TriggerDecoder::consumes ( art::ConsumesCollector &  )
overridevirtual

Declare to the framework what you expect to read.

Reimplemented from daq::IDecoder.

Definition at line 314 of file TriggerDecoderV2_tool.cc.

314  {
315  collector.consumes<icarus::TriggerConfiguration, art::InRun>
317  }
art::InputTag fTriggerConfigTag
Data product with hardware trigger configuration.
std::uint64_t daq::TriggerDecoder::encodeLVDSbits ( short int  cryostat,
short int  connector,
std::uint64_t  connectorWord 
)
staticprivate

Encodes the connectorWord LVDS bits from the specified cryostat and connector into the format required by sbn::ExtraTriggerInfo.

Definition at line 755 of file TriggerDecoderV2_tool.cc.

756  {
757  /*
758  * Encoding of the LVDS channels from the trigger:
759  * * east wall: `00<C0P2><C0P1><C0P0>00<C1P2><C1P1><C1P0>`
760  * * west wall: `00<C2P2><C2P1><C2P0>00<C3P2><C3P1><C3P0>`
761  * The prescription from `sbn::ExtraTriggerInfo` translates into:
762  * * east wall: `00<C3P2><C3P1><C3P0>00<C2P2><C2P1><C2P0>`
763  * * west wall: `00<C1P2><C1P1><C1P0>00<C0P2><C0P1><C0P0>`
764  * Therefore, the two 32-bit half-words need to be swapped
765  * This holds for both cryostats, and both walls.
766  */
767 
768  std::uint64_t lsw = connectorWord & 0xFFFFFFFFULL;
769  std::uint64_t msw = connectorWord >> 32ULL;
770  assert(connectorWord == ((msw << 32ULL) | lsw));
771  std::swap(lsw, msw);
772  return (msw << 32ULL) | lsw;
773  } // TriggerDecoder::encodeLVDSbits()
std::string_view daq::TriggerDecoder::firstLine ( std::string const &  s,
std::string const &  endl = "\0\n\r"s 
)
staticprivate

Definition at line 485 of file TriggerDecoder_tool.cc.

486  {
487  return { s.data(), std::min(s.find_first_of(endl), s.size()) };
488  }
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
static std::string_view daq::TriggerDecoder::firstLine ( std::string const &  s,
std::string const &  endl = "\0\n\r"s 
)
staticprivate
void daq::TriggerDecoder::initializeDataProducts ( )
overridevirtual

Initialize any data products the tool will output.

Implements daq::IDecoder.

Definition at line 230 of file TriggerDecoder_tool.cc.

231  {
232  //use until different object chosen
233  //fTrigger = new raw::Trigger();
234  fTrigger = std::make_unique<TriggerCollection>();
235  fPrevTrigger = std::make_unique<TriggerCollection>();
236  fRelTrigger = std::make_unique<RelativeTriggerCollection>();
238  fTriggerExtra = std::make_unique<sbn::ExtraTriggerInfo>();
239  return;
240  }
BeamGateInfoPtr fBeamGateInfo
std::vector< sim::BeamGateInfo > BeamGateInfoCollection
std::unique_ptr< BeamGateInfoCollection > BeamGateInfoPtr
std::unique_ptr< RelativeTriggerCollection > fRelTrigger
virtual void daq::TriggerDecoder::initializeDataProducts ( )
overridevirtual

Initialize any data products the tool will output.

Implements daq::IDecoder.

static std::uint64_t daq::TriggerDecoder::makeTimestamp ( unsigned int  s,
unsigned int  ns 
)
inlinestaticprivate

Combines second and nanosecond counts into a 64-bit timestamp.

Definition at line 192 of file TriggerDecoder_tool.cc.

193  { return s * 1000000000ULL + ns; }
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
static std::uint64_t daq::TriggerDecoder::makeTimestamp ( unsigned int  s,
unsigned int  ns 
)
inlinestaticprivate

Combines second and nanosecond counts into a 64-bit timestamp.

Definition at line 285 of file TriggerDecoderV2_tool.cc.

286  { return s * 1000000000ULL + ns; }
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
icarus::ICARUSTriggerV2Fragment daq::TriggerDecoder::makeTriggerFragment ( artdaq::Fragment const &  fragment) const
private

Creates a ICARUSTriggerInfo from a generic fragment.

Definition at line 244 of file TriggerDecoder_tool.cc.

245  {
246  try {
247  return icarus::ICARUSTriggerUDPFragment { fragment };
248  }
249  catch(std::exception const& e) {
250  mf::LogSystem("TriggerDecoder")
251  << "Error while creating trigger fragment from:\n"
252  << sbndaq::dumpFragment(fragment)
253  << "\nError message: " << e.what();
254  throw;
255  }
256  catch(...) {
257  mf::LogSystem("TriggerDecoder")
258  << "Unidentified exception while creating trigger fragment from:"
259  << sbndaq::dumpFragment(fragment);
260  throw;
261  }
262  } // TriggerDecoder::parseTriggerString()
details::DumpFragWrap dumpFragment(artdaq::Fragment const &frag)
Dump a artDAQ fragment into an output stream.
do i e
icarus::ICARUSTriggerV2Fragment daq::TriggerDecoder::makeTriggerFragment ( artdaq::Fragment const &  fragment) const
private

Creates a ICARUSTriggerInfo from a generic fragment.

void daq::TriggerDecoder::outputDataProducts ( art::Event &  event)
overridevirtual

Output the data products to the event store.

Parameters
eventThe event store objects

Implements daq::IDecoder.

Definition at line 473 of file TriggerDecoder_tool.cc.

474  {
475  //Place trigger data object into raw data store
476  event.put(std::move(fTrigger), CurrentTriggerInstanceName);
477  event.put(std::move(fRelTrigger), CurrentTriggerInstanceName);
478  event.put(std::move(fPrevTrigger), PreviousTriggerInstanceName);
479  event.put(std::move(fBeamGateInfo), CurrentTriggerInstanceName);
480  event.put(std::move(fTriggerExtra));
481  return;
482  }
static std::string const CurrentTriggerInstanceName
Name of the data product instance for the current trigger.
BeamGateInfoPtr fBeamGateInfo
static std::string const PreviousTriggerInstanceName
Name of the data product instance for the previous trigger.
std::unique_ptr< RelativeTriggerCollection > fRelTrigger
virtual void daq::TriggerDecoder::outputDataProducts ( art::Event &  event)
overridevirtual

Output the data products to the event store.

Parameters
eventThe event store objects

Implements daq::IDecoder.

icarus::ICARUSTriggerInfo daq::TriggerDecoder::parseTriggerString ( std::string_view  data) const
private

Parses the trigger data packet with the "standard" parser.

Definition at line 266 of file TriggerDecoder_tool.cc.

267  {
268  try {
269  return icarus::parse_ICARUSTriggerString(data.data());
270  }
271  catch(std::exception const& e) {
272  mf::LogSystem("TriggerDecoder")
273  << "Error while running standard parser on " << data.length()
274  << "-char long trigger string:\n==>|" << data
275  << "|<==\nError message: " << e.what();
276  throw;
277  }
278  catch(...) {
279  mf::LogSystem("TriggerDecoder")
280  << "Unidentified exception while running standard parser on "
281  << data.length() << "-char long trigger string:\n==>|" << data << "|.";
282  throw;
283  }
284  } // TriggerDecoder::parseTriggerString()
do i e
icarus::ICARUSTriggerInfo daq::TriggerDecoder::parseTriggerString ( std::string_view  data) const
private

Parses the trigger data packet with the "standard" parser.

icarus::KeyValuesData daq::TriggerDecoder::parseTriggerStringAsCSV ( std::string const &  data) const
private

Parses the trigger data packet with a CSV parser.

Definition at line 406 of file TriggerDecoderV2_tool.cc.

407  {
409  parser.addPatterns({
410  { "Cryo. (EAST|WEST) Connector . and .", 1U }
411  , { "Trigger Type", 1U }
412  });
413  std::string_view const dataLine = firstLine(data);
414  try {
415  return parser(dataLine);
416  }
418  mf::LogError("TriggerDecoder")
419  << "Error parsing " << dataLine.length()
420  << "-char long trigger string:\n==>|" << dataLine
421  << "|<==\nError message: " << e.what() << std::endl;
422  throw;
423  }
424  } // TriggerDecoder::parseTriggerStringAsCSV()
Parser to fill a KeyValuesData structure out of a character buffer.
KeyedCSVparser & addPatterns(std::initializer_list< std::pair< std::regex, unsigned int >> patterns)
Adds known patterns.
do i e
static std::string_view firstLine(std::string const &s, std::string const &endl="\0\n\r"s)
void daq::TriggerDecoder::process_fragment ( const artdaq::Fragment &  fragment)
overridevirtual

Given a set of recob hits, run DBscan to form 3D clusters.

Parameters
fragmentThe artdaq fragment to process

Implements daq::IDecoder.

Definition at line 288 of file TriggerDecoder_tool.cc.

289  {
290  // artdaq_ts is reworked by the trigger board reader to match the corrected
291  // trigger time; to avoid multiple (potentially inconsistent) corrections,
292  // the decoder trusts it and references all the times with respect to it.
293  uint64_t const artdaq_ts = fragment.timestamp();
294  icarus::ICARUSTriggerUDPFragment frag { makeTriggerFragment(fragment) };
295  std::string data = frag.GetDataString();
296  char *buffer = const_cast<char*>(data.c_str());
297 
298  icarus::ICARUSTriggerInfo datastream_info = parseTriggerString(buffer);
299  uint64_t const raw_wr_ts // this is raw, unadultered, uncorrected
300  = makeTimestamp(frag.getWRSeconds(), frag.getWRNanoSeconds());
301 
302  // correction (explicitly converted to signed)
303  int64_t const WRtimeToTriggerTime
304  = static_cast<int64_t>(artdaq_ts) - raw_wr_ts;
305  auto const correctWRtime = [WRtimeToTriggerTime](uint64_t time)
306  { return time + WRtimeToTriggerTime; };
307  assert(correctWRtime(raw_wr_ts) == artdaq_ts);
308 
309  // --- END ---- TEMPORARY --------------------------------------------------
310  int gate_type = datastream_info.gate_type;
311  long delta_gates_bnb [[maybe_unused]] = frag.getDeltaGatesBNB();
312  long delta_gates_numi [[maybe_unused]] = frag.getDeltaGatesOther(); //this is actually NuMI due to abrupt changes in trigger board logic
313  long delta_gates_other [[maybe_unused]] = frag.getDeltaGatesNuMI();
314  uint64_t lastTrigger = 0;
315 
316  // --- BEGIN -- TEMPORARY --------------------------------------------------
317  // remove this part when the beam gate timestamp is available via fragment
318  // or via the parser
319  auto const parsedData = icarus::details::KeyedCSVparser{}(firstLine(data));
320  unsigned int beamgate_count { std::numeric_limits<unsigned int>::max() };
321  std::uint64_t beamgate_ts { artdaq_ts }; // we cheat
322  /* [20210717, petrillo@slac.stanford.edu] `(pBeamGateInfo->nValues() == 3)`:
323  * this is an attempt to "support" a few Run0 runs (6017 to roughly 6043)
324  * which have the beam gate information truncated; this workaround should
325  * be removed when there is enough ICARUS data that these runs become
326  * uninteresting.
327  */
328  if (auto pBeamGateInfo = parsedData.findItem("Beam_TS");
329  pBeamGateInfo && (pBeamGateInfo->nValues() == 3)
330  ) {
331  // if gate information is found, it must be complete
332  beamgate_count = pBeamGateInfo->getNumber<unsigned int>(0U);
333 
334  uint64_t const raw_bg_ts = makeTimestamp( // raw and uncorrected too
335  pBeamGateInfo->getNumber<unsigned int>(1U),
336  pBeamGateInfo->getNumber<unsigned int>(2U)
337  );
338 
339  // assuming the raw times from the fragment are on the same time scale
340  // (same offset corrections)
341  beamgate_ts += raw_bg_ts - raw_wr_ts;
342 
343  } // if has gate information
344  // --- END ---- TEMPORARY --------------------------------------------------
345 
347  {
348  std::cout << "Full Timestamp = " << artdaq_ts
349  << "\nBeam gate " << beamgate_count << " at "
350  << (beamgate_ts/1'000'000'000) << "." << std::setfill('0')
351  << std::setw(9) << (beamgate_ts%1'000'000'000) << std::setfill(' ')
352  << " s (" << timestampDiff(beamgate_ts, artdaq_ts)
353  << " ns relative to trigger)" << std::endl;
354 
355  // note that this parsing is independent from the one used above
356  std::string_view const dataLine = firstLine(data);
357  try {
358  auto const parsedData = icarus::details::KeyedCSVparser{}(dataLine);
359  std::cout << "Parsed data (from " << dataLine.size() << " characters): "
360  << parsedData << std::endl;
361  }
363  mf::LogError("TriggerDecoder")
364  << "Error parsing " << dataLine.length()
365  << "-char long trigger string:\n==>|" << dataLine
366  << "|<==\nError message: " << e.what() << std::endl;
367  throw;
368  }
369 
370  if (fDebug) { // this grows tiresome quickly when processing many events
371  std::cout << "Trigger packet content:\n" << dataLine
372  << "\nFull trigger fragment dump:"
373  << sbndaq::dumpFragment(fragment) << std::endl;
374  }
375  }
376 
377  //
378  // extra trigger info
379  //
380  sbn::triggerSource beamGateBit;
381  switch (gate_type) {
382  case TriggerGateTypes::BNB: beamGateBit = sbn::triggerSource::BNB; break;
383  case TriggerGateTypes::NuMI: beamGateBit = sbn::triggerSource::NuMI; break;
384  case TriggerGateTypes::OffbeamBNB: beamGateBit = sbn::triggerSource::OffbeamBNB; break;
385  case TriggerGateTypes::OffbeamNuMI: beamGateBit = sbn::triggerSource::OffbeamNuMI; break;
386  default: beamGateBit = sbn::triggerSource::Unknown;
387  } // switch gate_type
388 
389  fTriggerExtra->sourceType = beamGateBit;
390  fTriggerExtra->triggerTimestamp = artdaq_ts;
391  fTriggerExtra->beamGateTimestamp = beamgate_ts;
392  fTriggerExtra->triggerID = datastream_info.wr_event_no;
393  fTriggerExtra->gateID = datastream_info.gate_id;
394  /* TODO (may need to add WRtimeToTriggerTime to some timestamps):
395  fTriggerExtra->triggerCount
396  fTriggerExtra->gateCount
397  fTriggerExtra->gateCountFromPreviousTrigger
398  fTriggerExtra->anyTriggerCountFromPreviousTrigger
399  fTriggerExtra->anyGateCountFromPreviousTrigger
400  fTriggerExtra->anyPreviousTriggerSourceType
401  fTriggerExtra->anyGateCountFromAnyPreviousTrigger
402  fTriggerExtra->previousTriggerTimestamp
403  fTriggerExtra->anyPreviousTriggerTimestamp
404  */
405  fTriggerExtra->WRtimeToTriggerTime = WRtimeToTriggerTime;
406 
407  //
408  // absolute time trigger (raw::ExternalTrigger)
409  //
410  fTrigger->emplace_back
411  (fTriggerExtra->triggerID, fTriggerExtra->triggerTimestamp);
412 
413  //
414  // previous absolute time trigger (raw::ExternalTrigger)
415  //
416  if(fTriggerExtra->triggerID == 1)
417  {
418  fLastEvent = 0;
419  }
420  else
421  {
422  fLastEvent = fTriggerExtra->triggerID - 1;
423  lastTrigger = frag.getLastTimestampBNB();
424  fPrevTrigger->emplace_back(fLastEvent, lastTrigger);
425  }
426 
427  //
428  // beam gate
429  //
430  // beam gate - trigger: hope it's negative...
431  nanoseconds const gateStartFromTrigger{
432  static_cast<double>(timestampDiff
433  (fTriggerExtra->beamGateTimestamp, fTriggerExtra->triggerTimestamp)
434  )
435  }; // narrowing!!
436  auto const elecGateStart = fDetTimings.TriggerTime() + gateStartFromTrigger;
437  auto const simGateStart = fDetTimings.toSimulationTime(elecGateStart);
438  switch (gate_type) {
440  fBeamGateInfo->emplace_back
441  (simGateStart.value(), BNBgateDuration.value(), sim::kBNB);
442  break;
444  fBeamGateInfo->emplace_back
445  (simGateStart.value(), NuMIgateDuration.value(), sim::kNuMI);
446  break;
448  fBeamGateInfo->emplace_back
449  (simGateStart.value(), BNBgateDuration.value(), sim::kBNB);
450  break;
452  fBeamGateInfo->emplace_back
453  (simGateStart.value(), NuMIgateDuration.value(), sim::kNuMI);
454  break;
455  default:
456  mf::LogWarning("TriggerDecoder") << "Unsupported gate type #" << gate_type;
457  } // switch gate_type
458 
459  //
460  // relative time trigger (raw::Trigger)
461  //
462  fRelTrigger->emplace_back(
463  static_cast<unsigned int>(datastream_info.wr_event_no), // counter
464  fDetTimings.TriggerTime().value(), // trigger_time
465  elecGateStart.value(), // beamgate_time
466  mask(beamGateBit) // bits
467  );
468 
469  //Once we have full trigger data object, set up and place information into there
470  return;
471  }
Parser to fill a KeyValuesData structure out of a character buffer.
detinfo::DetectorTimings const fDetTimings
Detector clocks and timings.
bool fDiagnosticOutput
Produces large number of diagnostic messages, use with caution!
static constexpr nanoseconds NuMIgateDuration
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
BeamGateInfoPtr fBeamGateInfo
NuMI.
Definition: BeamTypes.h:12
util::quantities::nanosecond nanoseconds
icarus::ICARUSTriggerUDPFragment makeTriggerFragment(artdaq::Fragment const &fragment) const
Creates a ICARUSTriggerInfo from a generic fragment.
constexpr mask_t< EnumType > mask(EnumType bit, OtherBits...otherBits)
Returns a mask with all specified bits set.
bool fDebug
Use this for debugging this tool.
simulation_time toSimulationTime(FromTime time) const
Converts a time point into simulation time scale.
electronics_time TriggerTime() const
std::unique_ptr< RelativeTriggerCollection > fRelTrigger
static long long int timestampDiff(std::uint64_t a, std::uint64_t b)
Returns the difference a - b.
static std::uint64_t makeTimestamp(unsigned int s, unsigned int ns)
Combines second and nanosecond counts into a 64-bit timestamp.
BNB.
Definition: BeamTypes.h:11
details::DumpFragWrap dumpFragment(artdaq::Fragment const &frag)
Dump a artDAQ fragment into an output stream.
do i e
triggerSource
Type of beam or beam gate or other trigger source.
Definition: BeamBits.h:97
static constexpr nanoseconds BNBgateDuration
static std::string_view firstLine(std::string const &s, std::string const &endl="\0\n\r"s)
BEGIN_PROLOG could also be cout
icarus::ICARUSTriggerInfo parseTriggerString(std::string_view data) const
Parses the trigger data packet with the &quot;standard&quot; parser.
virtual void daq::TriggerDecoder::process_fragment ( const artdaq::Fragment &  fragment)
overridevirtual

Given a set of recob hits, run DBscan to form 3D clusters.

Parameters
fragmentThe artdaq fragment to process

Implements daq::IDecoder.

void daq::TriggerDecoder::produces ( art::ProducesCollector &  )
overridevirtual

The space point building should output the hit collection for those hits which combine to form space points - a nice noise filter!

Implements daq::IDecoder.

Definition at line 213 of file TriggerDecoder_tool.cc.

214  {
215  collector.produces<TriggerCollection>(CurrentTriggerInstanceName);
216  collector.produces<TriggerCollection>(PreviousTriggerInstanceName);
220  }
static std::string const CurrentTriggerInstanceName
Name of the data product instance for the current trigger.
std::vector< sim::BeamGateInfo > BeamGateInfoCollection
static std::string const PreviousTriggerInstanceName
Name of the data product instance for the previous trigger.
Additional information on trigger.
std::vector< raw::Trigger > RelativeTriggerCollection
std::vector< raw::ExternalTrigger > TriggerCollection
virtual void daq::TriggerDecoder::produces ( art::ProducesCollector &  )
overridevirtual

The space point building should output the hit collection for those hits which combine to form space points - a nice noise filter!

Implements daq::IDecoder.

void daq::TriggerDecoder::setupRun ( art::Run const &  run)
overridevirtual

Preparation to process a new run.

To be called on every art run transition.

Reimplemented from daq::IDecoder.

Definition at line 427 of file TriggerDecoderV2_tool.cc.

427  {
428 
430  ? nullptr
431  : &(run.getProduct<icarus::TriggerConfiguration>(fTriggerConfigTag))
432  ;
433 
434  } // TriggerDecoder::setupRun()
icarus::TriggerConfiguration const * fTriggerConfiguration
Cached pointer to the trigger configuration of the current run, if any.
art::InputTag fTriggerConfigTag
Data product with hardware trigger configuration.
sim::BeamType_t daq::TriggerDecoder::simGateType ( sbn::triggerSource  source)
staticprivate

Returns the beam type corresponding to the specified trigger source.

Definition at line 776 of file TriggerDecoderV2_tool.cc.

777  {
778  switch (source) {
779  case sbn::triggerSource::BNB:
780  case sbn::triggerSource::OffbeamBNB:
781  return sim::kBNB;
782  case sbn::triggerSource::NuMI:
783  case sbn::triggerSource::OffbeamNuMI:
784  return sim::kNuMI;
785  case sbn::triggerSource::Calib:
786  return sim::kUnknown;
787  default:
788  mf::LogWarning("TriggerDecoder") << "Unsupported trigger source " << name(source);
789  return sim::kUnknown;
790  } // switch source
791  } // TriggerDecoder::simGateType()
do source
Unknown beam type.
Definition: BeamTypes.h:10
NuMI.
Definition: BeamTypes.h:12
BNB.
Definition: BeamTypes.h:11
then echo fcl name
static long long int daq::TriggerDecoder::timestampDiff ( std::uint64_t  a,
std::uint64_t  b 
)
inlinestaticprivate

Returns the difference a - b.

Definition at line 195 of file TriggerDecoder_tool.cc.

196  { return static_cast<long long int>(a) - static_cast<long long int>(b); }
process_name gaushit a
static long long int daq::TriggerDecoder::timestampDiff ( std::uint64_t  a,
std::uint64_t  b 
)
inlinestaticprivate

Returns the difference a - b.

Definition at line 288 of file TriggerDecoderV2_tool.cc.

289  { return static_cast<long long int>(a) - static_cast<long long int>(b); }
process_name gaushit a

Member Data Documentation

static constexpr nanoseconds daq::TriggerDecoder::BNBgateDuration { 1600. }
staticprivate

Definition at line 185 of file TriggerDecoder_tool.cc.

std::string const daq::TriggerDecoder::CurrentTriggerInstanceName {}
staticprivate

Name of the data product instance for the current trigger.

Definition at line 170 of file TriggerDecoder_tool.cc.

BeamGateInfoPtr daq::TriggerDecoder::fBeamGateInfo
private

Definition at line 151 of file TriggerDecoder_tool.cc.

bool daq::TriggerDecoder::fDebug
private

Use this for debugging this tool.

Definition at line 153 of file TriggerDecoder_tool.cc.

detinfo::DetectorTimings const daq::TriggerDecoder::fDetTimings
private

Detector clocks and timings.

Definition at line 160 of file TriggerDecoder_tool.cc.

bool daq::TriggerDecoder::fDiagnosticOutput
private

Produces large number of diagnostic messages, use with caution!

Definition at line 152 of file TriggerDecoder_tool.cc.

long daq::TriggerDecoder::fLastEvent = 0
private

Definition at line 158 of file TriggerDecoder_tool.cc.

TriggerPtr daq::TriggerDecoder::fPrevTrigger
private

Definition at line 148 of file TriggerDecoder_tool.cc.

std::unique_ptr< RelativeTriggerCollection > daq::TriggerDecoder::fRelTrigger
private

Definition at line 149 of file TriggerDecoder_tool.cc.

TriggerPtr daq::TriggerDecoder::fTrigger
private

Definition at line 147 of file TriggerDecoder_tool.cc.

art::InputTag daq::TriggerDecoder::fTriggerConfigTag
private

Data product with hardware trigger configuration.

Definition at line 238 of file TriggerDecoderV2_tool.cc.

icarus::TriggerConfiguration const* daq::TriggerDecoder::fTriggerConfiguration = nullptr
private

Cached pointer to the trigger configuration of the current run, if any.

Definition at line 247 of file TriggerDecoderV2_tool.cc.

ExtraInfoPtr daq::TriggerDecoder::fTriggerExtra
private

Definition at line 150 of file TriggerDecoder_tool.cc.

static constexpr nanoseconds daq::TriggerDecoder::NuMIgateDuration { 9500. }
staticprivate

Definition at line 186 of file TriggerDecoder_tool.cc.

std::string const daq::TriggerDecoder::PreviousTriggerInstanceName { "previous" }
staticprivate

Name of the data product instance for the previous trigger.

Definition at line 173 of file TriggerDecoder_tool.cc.

static constexpr double daq::TriggerDecoder::UnknownBeamTime = std::numeric_limits<double>::max()
staticprivate

Definition at line 175 of file TriggerDecoder_tool.cc.


The documentation for this class was generated from the following files: