34 #include <unordered_map> 78 Name{
"OpFlashModuleLabel"},
79 Comment{
"tag of the recob::OpFlash collection to be dumped"}};
82 Name(
"PrintOpHitAssociations"),
83 Comment(
"also prints a list of optical hits associated to the flash"),
87 Name(
"OutputCategory"),
88 Comment(
"the messagefacility category used for the output"),
113 struct ProductSourceEntry_t {
114 std::size_t index = 0;
117 using ProductSourceDirectory_t = std::unordered_map<art::ProductID, ProductSourceEntry_t>;
133 template <std::
size_t S
ide = 1U,
typename Assns,
typename Event>
134 ProductSourceDirectory_t buildAssnsSourceDirectory(Assns
const& assns, Event
const&
event)
137 ProductSourceDirectory_t
dir;
140 for (
auto const& ptrs : assns)
141 dir.try_emplace(std::get<Side>(ptrs).
id());
144 std::size_t index{0};
145 for (
auto& [
id, info] : dir)
146 info = {index++,
event.getProductDescription(
id).get()};
152 void printAssociatedOpHits(std::ostream& out,
154 ProductSourceDirectory_t
const* sourceMap,
155 std::string
const&
indent,
156 int const itemsPerLine)
158 out <<
hits.size() <<
" hits associated:";
160 const bool bPrintSources = sourceMap && (sourceMap->size() >= 2);
162 if (itemsLeft-- <= 0) {
163 itemsLeft += itemsPerLine;
168 if (bPrintSources) out <<
"S#" << sourceMap->at(hitPtr.id()).index <<
";";
169 out <<
"#" << hitPtr.key() <<
"]";
170 if (!hitPtr.isAvailable())
continue;
179 out <<
" peak time=" << hit.
PeakTime();
180 out <<
" p.e.=" << hit.
PE();
186 struct dumpAssociatedOpHits {
187 std::vector<art::Ptr<recob::OpHit>>
const&
hits;
188 ProductSourceDirectory_t
const* sourceMap;
191 std::ostream&
operator<<(std::ostream& out, dumpAssociatedOpHits
const&
hits)
193 printAssociatedOpHits(out, hits.hits, hits.sourceMap,
"", 18);
218 auto const& OpFlashHandle =
event.getValidHandle<std::vector<recob::OpFlash>>(
fOpFlashModuleTag);
221 <<
"Event " <<
event.id() <<
" contains " << OpFlashHandle->size() <<
" '" 224 std::optional
const flashHits =
226 std::make_optional<art::FindManyP<recob::OpHit>>(OpFlashHandle, event,
fOpFlashModuleTag) :
228 ProductSourceDirectory_t
const sourceMap =
230 buildAssnsSourceDirectory<1>(
232 ProductSourceDirectory_t{};
238 out <<
"OpFlash #" << iFlash <<
": " << flash;
240 if (flashHits) out <<
"\n " << dumpAssociatedOpHits{flashHits->at(iFlash), &sourceMap};
244 if (sourceMap.size() > 1) {
246 out <<
"Hits were from " << sourceMap.size() <<
" data products (SRC):";
247 for (
auto const& [index, info] :
util::values(sourceMap))
248 out <<
" [S#" << index <<
"] '" << info->inputTag().encode() <<
"'";
251 else if (sourceMap.size() == 1) {
253 << sourceMap.begin()->second.info->inputTag().encode() <<
"'.";
void analyze(const art::Event &evt) override
Does the printing.
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::string const fOutputCategory
Category for mf::LogInfo output.
fhicl::Atom< bool > PrintOpHitAssociations
Prints the content of all the flashes on screen.
Definition of util::enumerate().
bool const fPrintOpHitAssociations
Whether to print optical hits.
EDAnalyzer(fhicl::ParameterSet const &pset)
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
bool HasStartTime() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
#define DEFINE_ART_MODULE(klass)
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
std::string indent(std::size_t const i)
fhicl::Atom< art::InputTag > OpFlashModuleLabel
art::InputTag const fOpFlashModuleTag
Optical hit data product tag.
Detector simulation of raw signals on wires.
Stream & operator<<(Stream &&out, CallInfo_t const &info)
Helper operator to insert a call information in a stream with default options.
Definition of util::values() and util::const_values().
DumpOpFlashes(Parameters const &config)
Default constructor.
Event finding and building.
fhicl::Atom< std::string > OutputCategory