10 #include "art/Framework/Core/SharedFilter.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "canvas/Persistency/Common/TriggerResults.h"
15 #include "canvas/Persistency/Common/HLTGlobalStatus.h"
16 #include "canvas/Persistency/Common/HLTPathStatus.h"
17 #include "canvas/Persistency/Common/HLTenums.h"
18 #include "canvas/Utilities/InputTag.h"
19 #include "canvas/Utilities/Exception.h"
20 #include "fhiclcpp/types/Atom.h"
21 #include "fhiclcpp/ParameterSetRegistry.h"
22 #include "fhiclcpp/ParameterSet.h"
23 #include "cetlib_except/exception.h"
63 fhicl::Atom<std::string>
Path {
65 Comment{
"trigger path specification: \"<process name:path name>\"" }
69 Name{
"ResponseWhenNotRun" },
70 Comment{
"filter response when the reference path was not run" },
75 Name{
"ResponseOnError" },
76 Comment{
"filter response when the reference path threw an exception" },
89 virtual bool filter(art::Event& event,
const art::ProcessingFrame&)
override;
95 art::InputTag
const tag;
107 (art::Event
const& event, art::InputTag
const& tag)
const;
112 (art::TriggerResults
const& results, std::string
const&
name)
const;
116 std::vector<std::string>
pathNames(art::TriggerResults
const& results)
const;
130 : art::SharedFilter{ params }
131 , fTriggerSpec { parseTriggerSpec(params().Path()) }
132 , fResponseWhenNotRun{ params().ResponseWhenNotRun() }
133 , fResponseOnError { params().ResponseOnError() }
136 async<art::InEvent>();
143 (art::Event& event,
const art::ProcessingFrame&)
146 art::TriggerResults
const& trgResults
147 = readTriggerResults(event, fTriggerSpec.tag);
149 art::HLTPathStatus
const&
path = findPath(trgResults, fTriggerSpec.path);
151 return responseFromPath(path);
158 (art::Event
const& event, art::InputTag
const& tag)
const
162 return event.getProduct<art::TriggerResults>(tag);
164 catch (art::Exception
const&
e) {
165 if (e.categoryCode() != art::errors::ProductNotFound)
throw;
167 std::optional<std::vector<art::InputTag>> available;
169 std::vector<art::Handle<art::TriggerResults>>
const& triggerHandles
170 =
event.getMany<art::TriggerResults>();
172 for (art::Handle<art::TriggerResults>
const& handle: triggerHandles) {
173 if (handle.isValid() && handle.provenance())
174 available->push_back(handle.provenance()->inputTag());
179 art::Exception
msg { e.categoryCode(),
"", e };
180 msg <<
"Trigger data product '" << tag.encode() <<
"' not found.";
182 msg <<
"\n" << available->size() <<
" trigger products available";
183 if (available->empty())
msg <<
".";
186 for (art::InputTag
const& tag: *available)
187 msg <<
"\n - '" << tag.encode() <<
"'";
198 (art::TriggerResults
const& results, std::string
const&
name)
const
200 std::vector<std::string>
const names = pathNames(results);
206 auto iPathName = names.end();
210 iPathName = std::find(names.begin(), names.end(),
name);
211 if (iPathName != names.end())
break;
215 iPathName = std::find_if(names.begin(), names.end(),
216 [
name](std::string
const&
s)
218 std::size_t
const iSep =
s.find(
':');
219 return ((iSep == std::string::npos)?
s:
s.substr(iSep+1)) == name;
225 if (iPathName == names.end()) {
226 cet::exception
e{
"FilterOnArtPathOutcome" };
227 e <<
"The trigger path '" << fTriggerSpec.tag.process()
228 <<
"' does not include '" << name <<
"'! The " << names.size()
229 <<
" available paths are:";
230 for (std::string
const& pathName: names)
231 e <<
"\n - '" << pathName <<
"'";
236 std::size_t
const pathIndex =
std::distance(names.begin(), iPathName);
238 return results.at(pathIndex);
245 (art::TriggerResults
const& results)
const
251 fhicl::ParameterSet pset;
255 throw art::Exception(art::errors::Unknown)
256 <<
"FilterOnArtPathOutcome::findPath cannot find the trigger names for\n"
257 <<
"a process for which the configuration has requested that the\n"
258 <<
"OutputModule use TriggerResults to select events from. This should\n"
259 <<
"be impossible, please send information to reproduce this problem to\n"
260 <<
"the art developers at artists@fnal.gov.\n";
262 auto const names = pset.get<std::vector<std::string>>(
"trigger_paths", {});
263 if (
names.size() != results.size()) {
264 throw art::Exception(art::errors::Unknown)
265 <<
"FilterOnArtPathOutcome::findPath: path names vector and\n"
266 <<
"TriggerResults are different sizes (" <<
names.size()
267 <<
" vs. " << results.size() <<
"). This should be impossible,\n"
268 <<
"please send information to reproduce this problem to\n"
269 <<
"the art developers.\n";
279 (art::HLTPathStatus
const&
path)
const
282 if (!path.wasrun()) {
283 return fResponseWhenNotRun;
285 else if (path.error()) {
286 return fResponseOnError;
288 else return path.accept();
297 std::string processName, pathName;
298 auto const iSep = spec.find(
':');
299 if (iSep == std::string::npos) {
303 processName = spec.substr(0, iSep);
304 pathName = spec.substr(iSep + 1);
307 return { art::InputTag{
"TriggerResults",
"", processName }, pathName };
std::string const path
Name of the path to be read.
fhicl::Atom< std::string > Path
art::HLTPathStatus const & findPath(art::TriggerResults const &results, std::string const &name) const
bool const fResponseOnError
What to do if path ended with error.
FilterOnArtPathOutcome(Parameters const ¶ms, const art::ProcessingFrame &)
Constructor. No surprise here.
art::InputTag const tag
Input tag of the trigger result data product.
std::vector< std::string > pathNames(art::TriggerResults const &results) const
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
art::SharedFilter::Table< Config > Parameters
bool responseFromPath(art::HLTPathStatus const &path) const
Translates a path status into the response from this filter.
Filter module using a response an existing trigger path response.
BEGIN_PROLOG vertical distance to the surface Name
fhicl::Atom< bool > ResponseOnError
virtual bool filter(art::Event &event, const art::ProcessingFrame &) override
static const std::vector< std::string > names
fhicl::Atom< bool > ResponseWhenNotRun
then echo File list $list not found else cat $list while read file do echo $file sed s
TriggerSpec const fTriggerSpec
Trigger configuration.
static TriggerSpec parseTriggerSpec(std::string const &spec)
Parses a trigger path specification.
bool const fResponseWhenNotRun
What to do if path was not run at all.
art::TriggerResults const & readTriggerResults(art::Event const &event, art::InputTag const &tag) const
Reads the needed trigger data product, and throws if not found.