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 |
|
{ |
29 |
|
BaseFiller(const edm::ParameterSet &cfg, const char *name, bool active=true); |
30 |
|
virtual ~BaseFiller() {} |
31 |
|
|
32 |
< |
bool Active() const { return active_; } |
33 |
< |
virtual void BookDataBlock(TreeWriter &tws) = 0; |
34 |
< |
virtual void FillDataBlock(const edm::Event&, const edm::EventSetup&) = 0; |
35 |
< |
const std::string &Name() const { return name_; } |
36 |
< |
virtual void ResolveLinks(const edm::Event&, const edm::EventSetup&) {} |
32 |
> |
bool Active() const { return active_; } |
33 |
> |
virtual void BookDataBlock(TreeWriter &tws) = 0; |
34 |
> |
virtual void FillDataBlock(const edm::Event &e, const edm::EventSetup &es) = 0; |
35 |
> |
const std::string &Name() const { return name_; } |
36 |
> |
virtual void ResolveLinks(const edm::Event &e, const edm::EventSetup &es) {} |
37 |
> |
int Verbose() const { return verbose_;} |
38 |
> |
bool Verify() const { return verify_;} |
39 |
|
|
40 |
|
protected: |
41 |
< |
const edm::ParameterSet &Conf() const { return config_; } |
41 |
> |
const edm::ParameterSet &Conf() const { return config_; } |
42 |
> |
void PrintErrorAndExit(const char *msg) const; |
43 |
> |
template <typename TYPE> |
44 |
> |
void GetProduct(const std::string name, edm::Handle<TYPE> &prod, |
45 |
> |
const edm::Event &event) const; |
46 |
> |
template <typename TYPE> |
47 |
> |
bool GetProductSafe(const std::string name, edm::Handle<TYPE> &prod, |
48 |
> |
const edm::Event &event) const; |
49 |
> |
|
50 |
> |
ObjectService *OS() { return FillMitTree::os(); } |
51 |
|
|
52 |
|
const std::string name_; //name of this filler |
53 |
|
const edm::ParameterSet config_; //parameter set for this filler |
54 |
|
const bool active_; //=1 if active |
55 |
+ |
const bool verify_; //=1 if verificatin code is active |
56 |
+ |
const int verbose_; //verbosity level (do not introduce more than 0-4 levels) |
57 |
|
}; |
58 |
|
} |
59 |
+ |
|
60 |
+ |
//-------------------------------------------------------------------------------------------------- |
61 |
+ |
template <typename TYPE> |
62 |
+ |
inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle<TYPE> &prod, |
63 |
+ |
const edm::Event &event) const |
64 |
+ |
{ |
65 |
+ |
// Try to access data collection from EDM file. We check if we really get just one |
66 |
+ |
// product with the given name. If not we print an error and exit. |
67 |
+ |
|
68 |
+ |
try { |
69 |
+ |
event.getByLabel(edm::InputTag(edmname),prod); |
70 |
+ |
if (!prod.isValid()) |
71 |
+ |
throw edm::Exception(edm::errors::Configuration, "BaseFiller::GetProduct()\n") |
72 |
+ |
<< "Cannot get collection with label " << edmname << std::endl; |
73 |
+ |
} catch (...) { |
74 |
+ |
edm::LogError("BaseFiller") << "Cannot get collection with label " |
75 |
+ |
<< edmname << std::endl; |
76 |
+ |
PrintErrorAndExit(Form("Cannot get collection with label %s", edmname.c_str())); |
77 |
+ |
} |
78 |
+ |
} |
79 |
+ |
|
80 |
+ |
//-------------------------------------------------------------------------------------------------- |
81 |
+ |
template <typename TYPE> |
82 |
+ |
inline bool mithep::BaseFiller::GetProductSafe(const std::string edmname, edm::Handle<TYPE> &prod, |
83 |
+ |
const edm::Event &event) const |
84 |
+ |
{ |
85 |
+ |
// Try to safely access data collection from EDM file. We check if we really get just one |
86 |
+ |
// product with the given name. If not, we return false. |
87 |
+ |
|
88 |
+ |
try { |
89 |
+ |
event.getByLabel(edm::InputTag(edmname),prod); |
90 |
+ |
if (!prod.isValid()) |
91 |
+ |
return false; |
92 |
+ |
} catch (...) { |
93 |
+ |
return false; |
94 |
+ |
} |
95 |
+ |
return true; |
96 |
+ |
} |
97 |
|
#endif |