1 |
paus |
1.1 |
//--------------------------------------------------------------------------------------------------
|
2 |
loizides |
1.12 |
// $Id: BaseFiller.h,v 1.11 2008/07/30 16:39:57 loizides Exp $
|
3 |
paus |
1.1 |
//
|
4 |
|
|
// BaseFiller
|
5 |
|
|
//
|
6 |
|
|
// Base class to define the interface for a filler.
|
7 |
|
|
//
|
8 |
|
|
// Authors: C.Paus
|
9 |
|
|
//--------------------------------------------------------------------------------------------------
|
10 |
loizides |
1.2 |
|
11 |
loizides |
1.12 |
#ifndef MITPROD_TREEFILLER_BASEFILLER_H
|
12 |
|
|
#define MITPROD_TREEFILLER_BASEFILLER_H
|
13 |
paus |
1.1 |
|
14 |
|
|
#include "FWCore/Framework/interface/Event.h"
|
15 |
loizides |
1.8 |
#include "FWCore/Framework/interface/Frameworkfwd.h"
|
16 |
paus |
1.1 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
17 |
loizides |
1.8 |
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
18 |
|
|
#include "DataFormats/Common/interface/Handle.h"
|
19 |
paus |
1.1 |
#include "MitAna/DataUtil/interface/TreeWriter.h"
|
20 |
loizides |
1.11 |
#include "MitProd/ObjectService/interface/ObjectService.h"
|
21 |
|
|
#include "MitProd/TreeFiller/interface/FillMitTree.h"
|
22 |
loizides |
1.10 |
#include <TString.h>
|
23 |
paus |
1.1 |
|
24 |
|
|
namespace mithep
|
25 |
|
|
{
|
26 |
|
|
class BaseFiller
|
27 |
|
|
{
|
28 |
|
|
public:
|
29 |
loizides |
1.6 |
BaseFiller(const edm::ParameterSet &cfg, const char *name, bool active=true);
|
30 |
paus |
1.1 |
virtual ~BaseFiller() {}
|
31 |
|
|
|
32 |
loizides |
1.3 |
bool Active() const { return active_; }
|
33 |
loizides |
1.7 |
virtual void BookDataBlock(TreeWriter &tws) = 0;
|
34 |
|
|
virtual void FillDataBlock(const edm::Event &e, const edm::EventSetup &es) = 0;
|
35 |
loizides |
1.3 |
const std::string &Name() const { return name_; }
|
36 |
loizides |
1.7 |
virtual void ResolveLinks(const edm::Event &e, const edm::EventSetup &es) {}
|
37 |
paus |
1.1 |
|
38 |
|
|
protected:
|
39 |
loizides |
1.6 |
const edm::ParameterSet &Conf() const { return config_; }
|
40 |
loizides |
1.8 |
void PrintErrorAndExit(const char *msg) const;
|
41 |
|
|
template <typename TYPE>
|
42 |
loizides |
1.11 |
void GetProduct(const std::string name, edm::Handle<TYPE> &prod,
|
43 |
loizides |
1.8 |
const edm::Event &event) const;
|
44 |
loizides |
1.11 |
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 |
loizides |
1.6 |
|
50 |
loizides |
1.11 |
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 |
paus |
1.1 |
};
|
54 |
|
|
}
|
55 |
loizides |
1.8 |
|
56 |
|
|
//--------------------------------------------------------------------------------------------------
|
57 |
|
|
template <typename TYPE>
|
58 |
loizides |
1.11 |
inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle<TYPE> &prod,
|
59 |
loizides |
1.8 |
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 |
loizides |
1.11 |
event.getByLabel(edm::InputTag(edmname),prod);
|
66 |
|
|
if (!prod.isValid())
|
67 |
loizides |
1.8 |
throw edm::Exception(edm::errors::Configuration, "BaseFiller::GetProduct()\n")
|
68 |
|
|
<< "Cannot get collection with label " << edmname << std::endl;
|
69 |
|
|
} catch (...) {
|
70 |
|
|
edm::LogError("BaseFiller") << "Cannot get collection with label "
|
71 |
|
|
<< edmname << std::endl;
|
72 |
|
|
PrintErrorAndExit(Form("Cannot get collection with label %s", edmname.c_str()));
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
loizides |
1.11 |
|
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 |
paus |
1.1 |
#endif
|