CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
NtpProducer.h
Go to the documentation of this file.
1 #ifndef UtilAlgos_NtpProducer_h
2 #define UtilAlgos_NtpProducer_h
3 
19 
20 template <typename C>
21 class NtpProducer : public edm::EDProducer {
22 public:
26  ~NtpProducer() override;
27 
28 protected:
30  void produce(edm::Event&, const edm::EventSetup&) override;
31 
32 private:
36  std::vector<std::pair<std::string, StringObjectFunction<typename C::value_type> > > tags_;
39  bool eventInfo_;
40 };
41 
42 template <typename C>
44  : srcToken_(consumes<C>(par.template getParameter<edm::InputTag>("src"))),
45  lazyParser_(par.template getUntrackedParameter<bool>("lazyParser", false)),
46  prefix_(par.template getUntrackedParameter<std::string>("prefix", "")),
47  eventInfo_(par.template getUntrackedParameter<bool>("eventInfo", true)) {
48  std::vector<edm::ParameterSet> variables = par.template getParameter<std::vector<edm::ParameterSet> >("variables");
49  std::vector<edm::ParameterSet>::const_iterator q = variables.begin(), end = variables.end();
50  if (eventInfo_) {
51  produces<edm::EventNumber_t>(prefix_ + "EventNumber").setBranchAlias(prefix_ + "EventNumber");
52  produces<unsigned int>(prefix_ + "RunNumber").setBranchAlias(prefix_ + "RunNumber");
53  produces<unsigned int>(prefix_ + "LumiBlock").setBranchAlias(prefix_ + "Lumiblock");
54  }
55  for (; q != end; ++q) {
56  std::string tag = prefix_ + q->getUntrackedParameter<std::string>("tag");
57  StringObjectFunction<typename C::value_type> quantity(q->getUntrackedParameter<std::string>("quantity"),
58  lazyParser_);
59  tags_.push_back(std::make_pair(tag, quantity));
60  produces<std::vector<float> >(tag).setBranchAlias(tag);
61  }
62 }
63 
64 template <typename C>
66 
67 template <typename C>
69  edm::Handle<C> coll;
70  iEvent.getByToken(srcToken_, coll);
71  if (eventInfo_) {
72  std::unique_ptr<edm::EventNumber_t> event(new edm::EventNumber_t);
73  std::unique_ptr<unsigned int> run(new unsigned int);
74  std::unique_ptr<unsigned int> lumi(new unsigned int);
75  *event = iEvent.id().event();
76  *run = iEvent.id().run();
77  *lumi = iEvent.luminosityBlock();
78  iEvent.put(std::move(event), prefix_ + "EventNumber");
79  iEvent.put(std::move(run), prefix_ + "RunNumber");
80  iEvent.put(std::move(lumi), prefix_ + "LumiBlock");
81  }
82  typename std::vector<std::pair<std::string, StringObjectFunction<typename C::value_type> > >::const_iterator
83  q = tags_.begin(),
84  end = tags_.end();
85  for (; q != end; ++q) {
86  std::unique_ptr<std::vector<float> > x(new std::vector<float>);
87  x->reserve(coll->size());
88  for (typename C::const_iterator elem = coll->begin(); elem != coll->end(); ++elem) {
89  x->push_back(q->second(*elem));
90  }
91  iEvent.put(std::move(x), q->first);
92  }
93 }
94 
95 #endif
RunNumber_t run() const
Definition: EventID.h:38
EventNumber_t event() const
Definition: EventID.h:40
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool eventInfo_
Definition: NtpProducer.h:39
std::string prefix_
Definition: NtpProducer.h:38
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
unsigned long long EventNumber_t
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< C > srcToken_
label of the collection to be read in
Definition: NtpProducer.h:34
def move
Definition: eostools.py:511
uint16_t const *__restrict__ x
Definition: gpuClustering.h:39
void produce(edm::Event &, const edm::EventSetup &) override
process an event
Definition: NtpProducer.h:68
list lumi
Definition: dqmdumpme.py:53
~NtpProducer() override
destructor
Definition: NtpProducer.h:65
edm::EventID id() const
Definition: EventBase.h:59
NtpProducer(const edm::ParameterSet &)
constructor from parameter set
Definition: NtpProducer.h:43
string end
Definition: dataset.py:937
std::vector< std::pair< std::string, StringObjectFunction< typename C::value_type > > > tags_
variable tags
Definition: NtpProducer.h:36
bool lazyParser_
Definition: NtpProducer.h:37
def template
Definition: svgfig.py:521