Revision: | 1.3 |
Committed: | Thu Feb 11 14:55:22 2010 UTC (15 years, 2 months ago) by yilmaz |
Content type: | text/plain |
Branch: | MAIN |
CVS Tags: | Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, V07-05-00, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, ConvRejection-10-06-09, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, HEAD |
Branch point for: | Mit_025c_branch |
Changes since 1.2: | +2 -2 lines |
Log Message: | event setup stuff moved to beginRun from beginJob |
# | User | Rev | Content |
---|---|---|---|
1 | loizides | 1.1 | //-------------------------------------------------------------------------------------------------- |
2 | yilmaz | 1.3 | // $Id: BaseCandProducer.h,v 1.2 2009/03/20 18:01:47 loizides Exp $ |
3 | loizides | 1.1 | // |
4 | // BaseCandProducer | ||
5 | // | ||
6 | // Base class for all more specific candidate producers. | ||
7 | // | ||
8 | // Authors: C.Paus | ||
9 | //-------------------------------------------------------------------------------------------------- | ||
10 | |||
11 | #ifndef MITEDM_PRODUCERS_BASECANDPRODUCER_H | ||
12 | #define MITEDM_PRODUCERS_BASECANDPRODUCER_H | ||
13 | |||
14 | #include <vector> | ||
15 | #include <iostream> | ||
16 | #include <TString.h> | ||
17 | #include "FWCore/Framework/interface/Frameworkfwd.h" | ||
18 | #include "FWCore/Framework/interface/EDProducer.h" | ||
19 | #include "FWCore/Framework/interface/Event.h" | ||
20 | #include "FWCore/Framework/interface/MakerMacros.h" | ||
21 | #include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
22 | |||
23 | namespace mitedm | ||
24 | { | ||
25 | class BaseCandProducer : public edm::EDProducer | ||
26 | { | ||
27 | public: | ||
28 | explicit BaseCandProducer(const edm::ParameterSet&); | ||
29 | ~BaseCandProducer() {} | ||
30 | |||
31 | protected: | ||
32 | yilmaz | 1.3 | void beginJob() {} |
33 | loizides | 1.1 | void produce(edm::Event&, const edm::EventSetup&) = 0; |
34 | void endJob() {} | ||
35 | |||
36 | // generic accessors to make the code more simple | ||
37 | void PrintErrorAndExit(const char *msg) const; | ||
38 | template <typename TYPE> | ||
39 | bool GetProduct(const std::string name, edm::Handle<TYPE> &product, | ||
40 | const edm::Event &event, bool ignore = true) const; | ||
41 | |||
42 | // Parameters always being used | ||
43 | int oPid_; // pid of candidate particle | ||
44 | }; | ||
45 | |||
46 | //------------------------------------------------------------------------------------------------ | ||
47 | template <typename TYPE> | ||
48 | inline bool BaseCandProducer::GetProduct(const std::string edmName, edm::Handle<TYPE> &product, | ||
49 | loizides | 1.2 | const edm::Event &evt, bool ignore) const |
50 | loizides | 1.1 | { |
51 | // Try to access data collection from EDM file. We check if we really get just one | ||
52 | // product with the given name. If not we print an error and exit. | ||
53 | |||
54 | try { | ||
55 | evt.getByLabel(edm::InputTag(edmName),product); | ||
56 | if (! product.isValid()) | ||
57 | throw edm::Exception(edm::errors::Configuration, "BaseCandProducer::GetProduct()\n") | ||
58 | << "Cannot get collection with label " << edmName << std::endl; | ||
59 | } catch (...) { | ||
60 | if (ignore) | ||
61 | return false; | ||
62 | else { | ||
63 | edm::LogError("BaseCandProducer") << "Cannot get collection with label " | ||
64 | << edmName << std::endl; | ||
65 | PrintErrorAndExit(Form("Cannot get collection with label %s", edmName.c_str())); | ||
66 | } | ||
67 | } | ||
68 | return true; | ||
69 | } | ||
70 | } | ||
71 | #endif |