12 |
|
#define 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 <TString.h> |
21 |
|
|
22 |
|
namespace mithep |
23 |
|
{ |
24 |
|
class BaseFiller |
25 |
|
{ |
26 |
|
public: |
27 |
< |
BaseFiller(const edm::ParameterSet&, const char *en, const char *mn); |
27 |
> |
BaseFiller(const edm::ParameterSet &cfg, const char *name, bool active=true); |
28 |
|
virtual ~BaseFiller() {} |
29 |
|
|
30 |
< |
virtual bool Active() { return active_; } |
31 |
< |
virtual void BookDataBlock(TreeWriter *tws) = 0; |
32 |
< |
virtual void FillDataBlock(const edm::Event&, const edm::EventSetup&) = 0; |
33 |
< |
virtual void ResolveLinks (const edm::Event&, const edm::EventSetup&) {} |
30 |
> |
bool Active() const { return active_; } |
31 |
> |
virtual void BookDataBlock(TreeWriter &tws) = 0; |
32 |
> |
virtual void FillDataBlock(const edm::Event &e, const edm::EventSetup &es) = 0; |
33 |
> |
const std::string &Name() const { return name_; } |
34 |
> |
virtual void ResolveLinks(const edm::Event &e, const edm::EventSetup &es) {} |
35 |
|
|
36 |
|
protected: |
37 |
< |
const edm::ParameterSet &config_; |
38 |
< |
std::string edmName_; |
39 |
< |
std::string mitName_; |
40 |
< |
const bool active_; |
37 |
> |
const edm::ParameterSet &Conf() const { return config_; } |
38 |
> |
void PrintErrorAndExit(const char *msg) const; |
39 |
> |
template <typename TYPE> |
40 |
> |
void GetProduct(const std::string name, edm::Handle<TYPE> &product, |
41 |
> |
const edm::Event &event) const; |
42 |
> |
|
43 |
> |
const std::string name_; // name of this filler |
44 |
> |
const edm::ParameterSet config_; // parameter set for this filler |
45 |
> |
const bool active_; // =1 if active |
46 |
|
}; |
47 |
|
} |
48 |
+ |
|
49 |
+ |
//-------------------------------------------------------------------------------------------------- |
50 |
+ |
template <typename TYPE> |
51 |
+ |
inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle<TYPE> &product, |
52 |
+ |
const edm::Event &event) const |
53 |
+ |
{ |
54 |
+ |
// Try to access data collection from EDM file. We check if we really get just one |
55 |
+ |
// product with the given name. If not we print an error and exit. |
56 |
+ |
|
57 |
+ |
try { |
58 |
+ |
event.getByLabel(edm::InputTag(edmname),product); |
59 |
+ |
if (!product.isValid()) |
60 |
+ |
throw edm::Exception(edm::errors::Configuration, "BaseFiller::GetProduct()\n") |
61 |
+ |
<< "Cannot get collection with label " << edmname << std::endl; |
62 |
+ |
} catch (...) { |
63 |
+ |
edm::LogError("BaseFiller") << "Cannot get collection with label " |
64 |
+ |
<< edmname << std::endl; |
65 |
+ |
PrintErrorAndExit(Form("Cannot get collection with label %s", edmname.c_str())); |
66 |
+ |
} |
67 |
+ |
} |
68 |
|
#endif |