12 #include "art/Framework/Core/EDAnalyzer.h"
13 #include "art/Framework/Core/ModuleMacros.h"
14 #include "art/Framework/Principal/Handle.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "art/Framework/Principal/SummedValue.h"
17 #include "canvas/Utilities/InputTag.h"
18 #include "fhiclcpp/types/Atom.h"
19 #include "messagefacility/MessageLogger/MessageLogger.h"
20 #include "range/v3/view.hpp"
80 Comment(
"data product (subrun level) with the summary information"),
84 Name(
"SummaryCategory"),
85 Comment(
"name of the output category the summary is sent to"),
90 Name(
"RunSummaryCategory"),
91 Comment(
"name of the output category the summary is sent to"),
115 virtual void endSubRun(art::SubRun
const& subRun)
override;
118 virtual void endJob()
override;
138 std::map<art::RunID, art::SummedValue<sumdata::POTSummary>>
fRunPOT;
162 , fPOTtag(config().SummaryTag())
163 , fSummaryOutputCategory(config().SummaryCategory())
164 , fRunOutputCategory(config().RunSummaryCategory())
172 auto const& ID = subRun.id();
177 art::Handle<sumdata::POTSummary> summaryHandle;
178 if (!subRun.getByLabel(fPOTtag, summaryHandle)) {
179 ++fMissingSubrunFragments[ID];
180 mf::LogDebug(fSummaryOutputCategory)
181 <<
"Fragment of subrun " << ID <<
" has no '" << fPOTtag.encode() <<
"' POT summary.";
185 ++fPresentSubrunFragments[ID];
192 fRunPOT[ID.runID()].update(summaryHandle);
193 MF_LOG_TRACE(fSummaryOutputCategory)
194 <<
"Fragment #" << fPresentSubrunFragments[ID] <<
" of subrun " << ID <<
": "
208 if (!fRunOutputCategory.empty()) {
210 if (!fMissingSubrunFragments.empty()) printMissingSubrunList();
226 printSummary(totalPOT);
238 mf::LogVerbatim log{fRunOutputCategory};
239 log <<
size(fMissingSubrunFragments) <<
" subruns lack POT information:";
241 auto const fend = fPresentSubrunFragments.cend();
243 for (
auto const& [
id, nMissing] : fMissingSubrunFragments) {
246 unsigned int nFragments = nMissing;
247 auto const iFound = fPresentSubrunFragments.find(
id);
248 if (iFound != fend) nFragments += iFound->second;
250 log <<
"\n" <<
id <<
": " << nMissing <<
" / " << nFragments <<
" \"fragments\"";
262 std::map<art::RunID, unsigned int> subrunCount;
263 for (art::SubRunID
const& ID : fPresentSubrunFragments | ranges::views::keys)
264 ++subrunCount[ID.runID()];
266 mf::LogVerbatim log{fRunOutputCategory};
267 log <<
"POT from " <<
size(fRunPOT) <<
" runs:";
268 for (
auto const& [
id,
POT] : fRunPOT) {
269 log <<
"\n " <<
id <<
" (" << subrunCount[id]
281 mf::LogVerbatim{fSummaryOutputCategory}
282 <<
"Aggregated POT from " << fRunPOT.size() <<
" runs (" << fPresentSubrunFragments.size()
291 using namespace std::string_literals;
fhicl::Atom< art::InputTag > SummaryTag
POTaccumulator(Parameters const &config)
Configuration-checking constructor.
std::string fSummaryOutputCategory
Name of the main stream for output.
std::map< art::RunID, art::SummedValue< sumdata::POTSummary > > fRunPOT
Partial count of POT in the run, per run.
std::size_t size(FixedBins< T, C > const &) noexcept
fhicl::Atom< std::string > SummaryCategory
POTaccumulator & operator=(POTaccumulator const &)=delete
static std::string to_string(sumdata::POTSummary const &POT)
Converts the information from POT in a compact string.
virtual void endJob() override
Prints the general summary.
fhicl::Atom< std::string > RunSummaryCategory
Collection of configuration parameters for the module.
void printRunSummary() const
Prints the list of POT per run.
std::string fRunOutputCategory
Name of the run stream for output.
void printMissingSubrunList() const
Prints the list of subruns with partial or missing POT information.
BEGIN_PROLOG vertical distance to the surface Name
Prints on console the total Protons On Target from the input subruns.
void aggregate(POTSummary const &other)
art::EDAnalyzer::Table< Config > Parameters
Type to enable module parameters description by art.
std::string to_string(WindowPattern const &pattern)
then echo File list $list not found else cat $list while read file do echo $file sed s
virtual void analyze(art::Event const &event) override
virtual void endSubRun(art::SubRun const &subRun) override
Collects information from each subrun.
std::map< art::SubRunID, unsigned int > fPresentSubrunFragments
Count of subrun fragments with POT information.
art::InputTag fPOTtag
Name of sumdata::POTSummary data product.
void printSummary(sumdata::POTSummary const &totalPOT) const
Prints the total POT summary totalPOT.
std::map< art::SubRunID, unsigned int > fMissingSubrunFragments
Count of subrun fragments without POT information.