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