8 |
|
// Authors: C.Paus |
9 |
|
//-------------------------------------------------------------------------------------------------- |
10 |
|
|
11 |
< |
#ifndef TREEFILLER_BASEFILLER_H |
12 |
< |
#define TREEFILLER_BASEFILLER_H |
11 |
> |
#ifndef MITPROD_TREEFILLER_BASEFILLER_H |
12 |
> |
#define MITPROD_TREEFILLER_BASEFILLER_H |
13 |
|
|
14 |
|
#include "FWCore/Framework/interface/Event.h" |
15 |
– |
#include "FWCore/ParameterSet/interface/ParameterSet.h" |
15 |
|
#include "FWCore/Framework/interface/Frameworkfwd.h" |
16 |
+ |
#include "FWCore/ParameterSet/interface/ParameterSet.h" |
17 |
+ |
#include "FWCore/MessageLogger/interface/MessageLogger.h" |
18 |
+ |
#include "DataFormats/Common/interface/Handle.h" |
19 |
|
#include "MitAna/DataUtil/interface/TreeWriter.h" |
20 |
+ |
#include "MitProd/ObjectService/interface/ObjectService.h" |
21 |
+ |
#include "MitProd/TreeFiller/interface/FillMitTree.h" |
22 |
+ |
#include <TString.h> |
23 |
|
|
24 |
|
namespace mithep |
25 |
|
{ |
26 |
+ |
class BranchTable; |
27 |
+ |
|
28 |
|
class BaseFiller |
29 |
|
{ |
30 |
|
public: |
31 |
|
BaseFiller(const edm::ParameterSet &cfg, const char *name, bool active=true); |
32 |
|
virtual ~BaseFiller() {} |
33 |
|
|
34 |
< |
bool Active() const { return active_; } |
34 |
> |
bool Active() const { return active_; } |
35 |
> |
void AddBranchDep(const char *n, const char *d); |
36 |
> |
void AddBranchDep(const std::string &n, const char *d) |
37 |
> |
{ AddBranchDep(n.c_str(), d); } |
38 |
> |
void AddBranchDep(const std::string &n, const std::string &d) |
39 |
> |
{ AddBranchDep(n.c_str(), d.c_str()); } |
40 |
|
virtual void BookDataBlock(TreeWriter &tws) = 0; |
41 |
|
virtual void FillDataBlock(const edm::Event &e, const edm::EventSetup &es) = 0; |
42 |
< |
const std::string &Name() const { return name_; } |
42 |
> |
const std::string &Name() const { return name_; } |
43 |
|
virtual void ResolveLinks(const edm::Event &e, const edm::EventSetup &es) {} |
44 |
+ |
int Verbose() const { return verbose_; } |
45 |
+ |
bool Verify() const { return verify_; } |
46 |
|
|
47 |
|
protected: |
48 |
< |
const edm::ParameterSet &Conf() const { return config_; } |
48 |
> |
const edm::ParameterSet &Conf() const { return config_; } |
49 |
> |
void PrintErrorAndExit(const char *msg) const; |
50 |
> |
template <typename TYPE> |
51 |
> |
void GetProduct(const std::string name, edm::Handle<TYPE> &prod, |
52 |
> |
const edm::Event &event) const; |
53 |
> |
template <typename TYPE> |
54 |
> |
bool GetProductSafe(const std::string name, edm::Handle<TYPE> &prod, |
55 |
> |
const edm::Event &event) const; |
56 |
> |
|
57 |
> |
ObjectService *OS() { return FillMitTree::os(); } |
58 |
|
|
59 |
|
const std::string name_; //name of this filler |
60 |
+ |
const std::string brtname_; //name of branch table (def = BranchTable) |
61 |
|
const edm::ParameterSet config_; //parameter set for this filler |
62 |
|
const bool active_; //=1 if active |
63 |
+ |
const bool verify_; //=1 if verificatin code is active |
64 |
+ |
const int verbose_; //verbosity level (do not introduce more than 0-4 levels) |
65 |
+ |
BranchTable *brtable_; //branch dependency table |
66 |
|
}; |
67 |
|
} |
68 |
+ |
|
69 |
+ |
//-------------------------------------------------------------------------------------------------- |
70 |
+ |
template <typename TYPE> |
71 |
+ |
inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle<TYPE> &prod, |
72 |
+ |
const edm::Event &event) const |
73 |
+ |
{ |
74 |
+ |
// Try to access data collection from EDM file. We check if we really get just one |
75 |
+ |
// product with the given name. If not we print an error and exit. |
76 |
+ |
|
77 |
+ |
try { |
78 |
+ |
event.getByLabel(edm::InputTag(edmname),prod); |
79 |
+ |
if (!prod.isValid()) |
80 |
+ |
throw edm::Exception(edm::errors::Configuration, "BaseFiller::GetProduct()\n") |
81 |
+ |
<< "Cannot get collection with label " << edmname << std::endl; |
82 |
+ |
} catch (...) { |
83 |
+ |
edm::LogError("BaseFiller") << "Cannot get collection with label " |
84 |
+ |
<< edmname << std::endl; |
85 |
+ |
PrintErrorAndExit(Form("Cannot get collection with label %s", edmname.c_str())); |
86 |
+ |
} |
87 |
+ |
} |
88 |
+ |
|
89 |
+ |
//-------------------------------------------------------------------------------------------------- |
90 |
+ |
template <typename TYPE> |
91 |
+ |
inline bool mithep::BaseFiller::GetProductSafe(const std::string edmname, edm::Handle<TYPE> &prod, |
92 |
+ |
const edm::Event &event) const |
93 |
+ |
{ |
94 |
+ |
// Try to safely access data collection from EDM file. We check if we really get just one |
95 |
+ |
// product with the given name. If not, we return false. |
96 |
+ |
|
97 |
+ |
try { |
98 |
+ |
event.getByLabel(edm::InputTag(edmname),prod); |
99 |
+ |
if (!prod.isValid()) |
100 |
+ |
return false; |
101 |
+ |
} catch (...) { |
102 |
+ |
return false; |
103 |
+ |
} |
104 |
+ |
return true; |
105 |
+ |
} |
106 |
|
#endif |