21 #include "art/Framework/Core/ModuleMacros.h"
22 #include "art/Framework/Core/EDAnalyzer.h"
23 #include "art/Framework/Principal/Event.h"
24 #include "canvas/Persistency/Provenance/EventID.h"
25 #include "canvas/Utilities/InputTag.h"
26 #include "messagefacility/MessageLogger/MessageLogger.h"
27 #include "fhiclcpp/types/OptionalAtom.h"
28 #include "fhiclcpp/types/Atom.h"
39 namespace sbn {
class DumpTrigger; }
106 Name{
"TriggerTag" },
108 {
"tag of the simple trigger data product (raw::Trigger collection)" }
112 Name{
"BeamGateTag" },
113 Comment{
"tag of the beam gate information data product" }
117 Name{
"ExternalTriggerTag" },
119 "tag of additional trigger information data product"
120 " (raw::ExternalTrigger collection)"
125 Name{
"ExtraTriggerTag" },
126 Comment{
"tag of detailed SBN-specific trigger information data product" }
131 Comment{
"verbosity level [default: maximum]" },
132 std::numeric_limits<unsigned int>::max()
136 Name{
"OutputCategory" },
137 Comment{
"name of the category used for the output" },
157 virtual void analyze(art::Event
const& event)
override;
188 void dumpTrigger(std::vector<raw::Trigger>
const& triggers)
const;
191 void dumpTrigger(std::vector<raw::ExternalTrigger>
const& triggers)
const;
194 void dumpBeamGate(std::vector<sim::BeamGateInfo>
const& gates)
const;
201 std::pair<art::InputTag, bool>
inputTag
202 (std::optional<art::InputTag>
const& tag)
const;
207 template <
typename T>
208 unsigned int countConsume(std::optional<art::InputTag>
const& param);
217 struct dumpTimestamp {
222 std::ostream&
operator<< (std::ostream& out, dumpTimestamp tsw) {
223 return out << (tsw.ts / 1
'000'000
'000) << "." << std::setfill('0
')
224 << std::setw(9) << (tsw.ts % 1'000
'000'000) << std::setfill(
' ');
236 : art::EDAnalyzer(config)
238 , fTriggerTag { config().TriggerTag() }
239 , fBeamGateTag { config().BeamGateTag() }
240 , fExternalTag { config().ExternalTriggerTag() }
241 , fExtraTag { config().ExtraTriggerTag() }
242 , fVerbosity { config().Verbosity() }
243 , fOutputCategory{ config().OutputCategory() }
246 unsigned int nRequiredTriggers = 0U;
251 nRequiredTriggers += countConsume<std::vector<raw::Trigger>>(fTriggerTag);
253 += countConsume<std::vector<sim::BeamGateInfo>>(fBeamGateTag);
255 += countConsume<std::vector<raw::ExternalTrigger>>(fExternalTag);
256 nRequiredTriggers += countConsume<sbn::ExtraTriggerInfo>(fExtraTag);
261 if (nRequiredTriggers == 0U) {
262 throw art::Exception{ art::errors::Configuration }
263 <<
"At least one trigger data product needs to be specified.\n";
269 mf::LogInfo log{ fOutputCategory };
270 log <<
"Configuration:\n * dump:";
272 if (fTriggerTag) log <<
"\n - '" << fTriggerTag->encode() <<
"' (raw::Trigger)";
274 if (
auto const [ tag, req ] = inputTag(fExternalTag); !tag.empty()) {
275 log <<
"\n - '" << tag.encode() <<
"' (raw::ExternalTrigger)";
276 if (!req) log <<
" (if available)";
279 if (
auto const [ tag, req ] = inputTag(fExtraTag); !tag.empty()) {
280 log <<
"\n - '" << tag.encode() <<
"' (sbn::ExtraTriggerInfo)";
281 if (!req) log <<
" (if available)";
284 if (
auto const [ tag, req ] = inputTag(fBeamGateTag); !tag.empty()) {
285 log <<
"\n - '" << tag.encode() <<
"' (sim::BeamGateInfo)";
286 if (!req) log <<
" (if available)";
296 <<
"Trigger information in " <<
event.id() <<
":";
300 auto const& handle =
event.getHandle<std::vector<raw::Trigger>>(tag);
303 <<
"* raw::Trigger ('" << tag.encode() <<
"'):";
306 else if (req)
throw *(handle.whyFailed());
313 =
event.getHandle<std::vector<raw::ExternalTrigger>>(tag);
316 <<
"* raw::ExternalTrigger ('" << tag.encode() <<
"'):";
319 else if (req)
throw *(handle.whyFailed());
328 <<
"* sbn::ExtraTriggerInfo ('" << tag.encode() <<
"'):";
331 else if (req)
throw *(handle.whyFailed());
337 auto const& handle =
event.getHandle<std::vector<sim::BeamGateInfo>>(tag);
340 <<
"* sim::BeamGateInfo ('" << tag.encode() <<
"'):";
343 else if (req)
throw *(handle.whyFailed());
352 (std::vector<raw::Trigger>
const& triggers)
const
354 static std::string
const indent(4U,
' ');
356 if (triggers.empty()) {
357 mf::LogVerbatim{ fOutputCategory } << indent <<
"no triggers.";
360 if (triggers.size() > 1) {
361 mf::LogVerbatim{ fOutputCategory }
362 << indent <<
"[" << triggers.size() <<
" triggers]";
366 mf::LogVerbatim log { fOutputCategory };
368 if (triggers.size() > 1) log <<
"[" << iTrigger <<
"] ";
369 log <<
"trigger #" << trigger.TriggerNumber() <<
" at "
375 for (std::string
const&
name:
names(bitMask)) log <<
" " <<
name;
387 (std::vector<raw::ExternalTrigger>
const& triggers)
const
390 static std::string
const indent(4U,
' ');
392 if (triggers.empty()) {
393 mf::LogVerbatim{ fOutputCategory } << indent <<
"no triggers.";
396 if (triggers.size() > 1) {
397 mf::LogVerbatim{ fOutputCategory }
398 << indent <<
"[" << triggers.size() <<
" triggers]";
402 mf::LogVerbatim log { fOutputCategory };
404 if (triggers.size() > 1) log <<
"[" << iTrigger <<
"] ";
405 log <<
"trigger ID=" << trigger.GetTrigID()
406 <<
" at " << dumpTimestamp(trigger.GetTrigTime());
415 (std::vector<sim::BeamGateInfo>
const& gates)
const
418 static std::string
const indent(4U,
' ');
421 mf::LogVerbatim{ fOutputCategory } << indent <<
"no beam gates.";
424 if (gates.size() > 1) {
425 mf::LogVerbatim{ fOutputCategory }
426 << indent <<
"[" << gates.size() <<
" beam gates]";
430 mf::LogVerbatim log { fOutputCategory };
434 if (gates.size() > 1) log <<
"[" << iGate <<
"] ";
435 log <<
"beam gate [ " << start <<
" -- " <<
end <<
" ] (duration: "
436 << (
end - start) <<
") of type ";
437 switch (gate.BeamType()) {
442 log <<
"unsupported [code=" <<
static_cast<int>(gate.BeamType()) <<
"]";
453 static std::string
const indent(4U,
' ');
455 mf::LogVerbatim{ fOutputCategory } <<
util::addIndent(indent) << trigger;
462 (std::optional<art::InputTag>
const& tag)
const
465 { tag.value_or(fTriggerTag.value_or(art::InputTag{})), tag.has_value() };
470 template <
typename T>
472 (std::optional<art::InputTag>
const& param)
474 auto const [ tag, required ] = inputTag(param);
475 if (tag.empty())
return 0;
476 if (required) consumes<T>(tag);
477 else mayConsume<T>(tag);
478 return required? 1: 0;
Definitions of the trigger bits for SBN.
long long TriggerTimeStamp_t
type of trigger time stamp
std::string const fOutputCategory
Category used for message facility stream.
Definition of util::enumerate().
std::optional< art::InputTag > const fExtraTag
DumpTrigger(Parameters const &config)
Utility to have simple indentation in a stream.
std::pair< art::InputTag, bool > inputTag(std::optional< art::InputTag > const &tag) const
Returns the tag to try, and whether it is mandatory to find it.
virtual void analyze(art::Event const &event) override
Does the dumping.
fhicl::OptionalAtom< art::InputTag > ExtraTriggerTag
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Stream modifier that makes it "indented".
fhicl::OptionalAtom< art::InputTag > ExternalTriggerTag
std::optional< art::InputTag > const fExternalTag
Input additional trigger tag.
art::EDAnalyzer::Table< Config > Parameters
timescale_traits< SimulationTimeCategory >::time_point_t simulation_time
A point in time on the simulation time scale.
fhicl::Atom< unsigned int > Verbosity
unsigned int countConsume(std::optional< art::InputTag > const ¶m)
auto end(FixedBins< T, C > const &) noexcept
void dumpBeamGate(std::vector< sim::BeamGateInfo > const &gates) const
Dumps a LArSoft beam gate information data product.
BEGIN_PROLOG vertical distance to the surface Name
Dumps on console the content of trigger data products.
fhicl::OptionalAtom< art::InputTag > BeamGateTag
fhicl::Atom< std::string > OutputCategory
unsigned int const fVerbosity
Input extra trigger tag.
std::optional< art::InputTag > const fTriggerTag
Input trigger tag.
void dumpTrigger(std::vector< raw::Trigger > const &triggers) const
Dumps a simple LArSoft trigger data product.
std::optional< art::InputTag > const fBeamGateTag
Input beam gate tag.
static const std::vector< std::string > names
detinfo::timescales::simulation_time simulation_time
Data types for detinfo::DetectorTimings.
detinfo::timescales::electronics_time electronics_time
fhicl::OptionalAtom< art::InputTag > TriggerTag
std::ostream & operator<<(std::ostream &out, lar::example::CheatTrack const &track)
timescale_traits< ElectronicsTimeCategory >::time_point_t electronics_time
A point in time on the electronics time scale.