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 |
39 |
|
const edm::ParameterSet &Conf() const { return config_; } |
40 |
|
void PrintErrorAndExit(const char *msg) const; |
41 |
|
template <typename TYPE> |
42 |
< |
void GetProduct(const std::string name, edm::Handle<TYPE> &product, |
42 |
> |
void GetProduct(const std::string name, edm::Handle<TYPE> &prod, |
43 |
|
const edm::Event &event) const; |
44 |
+ |
template <typename TYPE> |
45 |
+ |
bool GetProductSafe(const std::string name, edm::Handle<TYPE> &prod, |
46 |
+ |
const edm::Event &event) const; |
47 |
+ |
|
48 |
+ |
ObjectService *OS() { return FillMitTree::os(); } |
49 |
|
|
50 |
< |
const std::string name_; // name of this filler |
51 |
< |
const edm::ParameterSet config_; // parameter set for this filler |
52 |
< |
const bool active_; // =1 if active |
50 |
> |
const std::string name_; //name of this filler |
51 |
> |
const edm::ParameterSet config_; //parameter set for this filler |
52 |
> |
const bool active_; //=1 if active |
53 |
|
}; |
54 |
|
} |
55 |
|
|
56 |
|
//-------------------------------------------------------------------------------------------------- |
57 |
|
template <typename TYPE> |
58 |
< |
inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle<TYPE> &product, |
58 |
> |
inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle<TYPE> &prod, |
59 |
|
const edm::Event &event) const |
60 |
|
{ |
61 |
|
// Try to access data collection from EDM file. We check if we really get just one |
62 |
|
// product with the given name. If not we print an error and exit. |
63 |
|
|
64 |
|
try { |
65 |
< |
event.getByLabel(edm::InputTag(edmname),product); |
66 |
< |
if (!product.isValid()) |
65 |
> |
event.getByLabel(edm::InputTag(edmname),prod); |
66 |
> |
if (!prod.isValid()) |
67 |
|
throw edm::Exception(edm::errors::Configuration, "BaseFiller::GetProduct()\n") |
68 |
|
<< "Cannot get collection with label " << edmname << std::endl; |
69 |
|
} catch (...) { |
72 |
|
PrintErrorAndExit(Form("Cannot get collection with label %s", edmname.c_str())); |
73 |
|
} |
74 |
|
} |
75 |
+ |
|
76 |
+ |
//-------------------------------------------------------------------------------------------------- |
77 |
+ |
template <typename TYPE> |
78 |
+ |
inline bool mithep::BaseFiller::GetProductSafe(const std::string edmname, edm::Handle<TYPE> &prod, |
79 |
+ |
const edm::Event &event) const |
80 |
+ |
{ |
81 |
+ |
// Try to safely access data collection from EDM file. We check if we really get just one |
82 |
+ |
// product with the given name. If not, we return false. |
83 |
+ |
|
84 |
+ |
try { |
85 |
+ |
event.getByLabel(edm::InputTag(edmname),prod); |
86 |
+ |
if (!prod.isValid()) |
87 |
+ |
return false; |
88 |
+ |
} catch (...) { |
89 |
+ |
return false; |
90 |
+ |
} |
91 |
+ |
return true; |
92 |
+ |
} |
93 |
|
#endif |