IntProducingService_service.cc
Go to the documentation of this file.
6 #include "fhiclcpp/types/Atom.h"
7 
8 namespace {
9 
10  class IntProducingService : public art::ProducingService {
11  public:
12  struct Config {
13  fhicl::Atom<int> ivalue{fhicl::Name("ivalue")};
14  fhicl::Atom<unsigned> branchType{fhicl::Name("branchType"), art::InEvent};
15  };
16  using Parameters = art::ServiceTable<Config>;
17  explicit IntProducingService(Parameters const&);
18 
19  private:
20  void postReadRun(art::Run&) override;
21  void postReadSubRun(art::SubRun&) override;
22  void postReadEvent(art::Event&) override;
23 
24  int const value_;
25  art::BranchType const branchType_;
26  };
27 
28  IntProducingService::IntProducingService(Parameters const& p)
29  : value_{p().ivalue()} // enums don't usually have a conversion from string
30  , branchType_{art::BranchType(p().branchType())}
31  {
32  switch (branchType_) {
33  case art::InEvent:
34  produces<arttest::IntProduct>("", art::Persistable::No);
35  break;
36  case art::InSubRun:
37  produces<arttest::IntProduct, art::InSubRun>("", art::Persistable::No);
38  break;
39  case art::InRun:
40  produces<arttest::IntProduct, art::InRun>("", art::Persistable::No);
41  break;
42  default:
44  << "Unknown branch type " << branchType_ << ".\n";
45  }
46  }
47 
48  void
49  IntProducingService::postReadRun(art::Run& r)
50  {
51  if (branchType_ == art::InRun)
52  r.put(std::make_unique<arttest::IntProduct>(value_), art::fullRun());
53  }
54 
55  void
56  IntProducingService::postReadSubRun(art::SubRun& sr)
57  {
58  if (branchType_ == art::InSubRun)
59  sr.put(std::make_unique<arttest::IntProduct>(value_), art::fullSubRun());
60  }
61 
62  void
63  IntProducingService::postReadEvent(art::Event& e)
64  {
65  if (branchType_ == art::InEvent)
66  e.put(std::make_unique<arttest::IntProduct>(value_));
67  }
68 }
69 
70 DEFINE_ART_PRODUCING_SERVICE(IntProducingService)
constexpr auto fullRun()
Definition: Run.h:21
const double e
#define DEFINE_ART_PRODUCING_SERVICE(klass)
p
Definition: test.py:228
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
BranchType
Definition: BranchType.h:18
constexpr auto fullSubRun()
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:692
static const double sr
Definition: Units.h:167
AdcRoiViewer::Name Name