LastDoubleProducingService_service.cc
Go to the documentation of this file.
1 //===================================================================
2 // The "LastDoubleProducingService" is used in combination with the
3 // "IntProducingService" to test the availability of products. Since
4 // IntProducingService comes before LastDoubleProducingService
5 // alphabetically, the callbacks for this service will be called after
6 // those of IntProducingService. In that case, the
7 // IntProducingService will have created its IntProduct already, but
8 // the system is designed so that any products produced by a service
9 // are inaccessible to other ProducingServices at the same callback
10 // level (i.e. postReadRun). This service tests that behavior.
11 // ===================================================================
12 
18 #include "fhiclcpp/types/Atom.h"
19 
20 #include <cassert>
21 
22 namespace {
23 
24  class LastDoubleProducingService : public art::ProducingService {
25  public:
26  struct Config {
27  fhicl::Atom<std::string> source_input_label{
28  fhicl::Name{"source_input_label"}};
29  fhicl::Atom<std::string> service_input_label{
30  fhicl::Name{"service_input_label"}};
32  fhicl::Atom<unsigned> branchType{fhicl::Name("branchType"), art::InEvent};
33  };
34  using Parameters = art::ServiceTable<Config>;
35  explicit LastDoubleProducingService(Parameters const&);
36 
37  private:
38  void postReadRun(art::Run&) override;
39  void postReadSubRun(art::SubRun&) override;
40  void postReadEvent(art::Event&) override;
41 
42  art::InputTag const sourceTag_;
43  art::InputTag const serviceTag_;
44  double const value_;
45  art::BranchType const branchType_;
46  };
47 
48  LastDoubleProducingService::LastDoubleProducingService(Parameters const& p)
49  : sourceTag_{p().source_input_label()}
50  , serviceTag_{p().service_input_label()}
51  , value_{p().value()} // enums don't usually have a conversion from string
52  , branchType_{art::BranchType(p().branchType())}
53  {
54  switch (branchType_) {
55  case art::InEvent:
56  produces<arttest::DoubleProduct>("", art::Persistable::No);
57  break;
58  case art::InSubRun:
59  produces<arttest::DoubleProduct, art::InSubRun>("",
61  break;
62  case art::InRun:
63  produces<arttest::DoubleProduct, art::InRun>("", art::Persistable::No);
64  break;
65  default:
67  << "Unknown branch type " << branchType_ << ".\n";
68  }
69  }
70 
71  void
72  LastDoubleProducingService::postReadRun(art::Run& r)
73  {
74  if (branchType_ != art::InRun)
75  return;
76 
77  // Cannot access produced products from other producing services
79  assert(!r.getByLabel(serviceTag_, h));
80  assert(!h.isValid());
81 
82  // Can access present products from the source
83  auto const& vh = r.getValidHandle<arttest::IntProduct>(sourceTag_);
84  r.put(std::make_unique<arttest::DoubleProduct>(value_ + vh->value),
85  art::fullRun());
86  }
87 
88  void
89  LastDoubleProducingService::postReadSubRun(art::SubRun& sr)
90  {
91  if (branchType_ != art::InSubRun)
92  return;
93 
94  // Cannot access produced products from other producing services
96  assert(!sr.getByLabel(serviceTag_, h));
97  assert(!h.isValid());
98 
99  // Can access present products from the source
100  auto const& vh = sr.getValidHandle<arttest::IntProduct>(sourceTag_);
101  sr.put(std::make_unique<arttest::DoubleProduct>(value_ + vh->value),
102  art::fullSubRun());
103  }
104 
105  void
106  LastDoubleProducingService::postReadEvent(art::Event& e)
107  {
108  if (branchType_ != art::InEvent)
109  return;
110 
111  // Cannot access produced products from other producing services
113  assert(!e.getByLabel(serviceTag_, h));
114  assert(!h.isValid());
115 
116  // Can access present products from the source
117  auto const& vh = e.getValidHandle<arttest::IntProduct>(sourceTag_);
118  e.put(std::make_unique<arttest::DoubleProduct>(value_ + vh->value));
119  }
120 }
121 
122 DEFINE_ART_PRODUCING_SERVICE(LastDoubleProducingService)
constexpr auto fullRun()
Definition: Run.h:21
bool isValid() const
Definition: Handle.h:190
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:435
const double e
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:480
#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
h
training ###############################
Definition: train_cnn.py:186