ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/interface/BaseFiller.h
Revision: 1.10
Committed: Wed Jul 30 08:39:50 2008 UTC (16 years, 9 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.9: +2 -1 lines
Log Message:
Use PairInt as name for key.

File Contents

# User Rev Content
1 paus 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.10 // $Id: BaseFiller.h,v 1.9 2008/07/28 23:13:43 paus 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 loizides 1.10 #include <TString.h>
21 paus 1.1
22     namespace mithep
23     {
24     class BaseFiller
25     {
26     public:
27 loizides 1.6 BaseFiller(const edm::ParameterSet &cfg, const char *name, bool active=true);
28 paus 1.1 virtual ~BaseFiller() {}
29    
30 loizides 1.3 bool Active() const { return active_; }
31 loizides 1.7 virtual void BookDataBlock(TreeWriter &tws) = 0;
32     virtual void FillDataBlock(const edm::Event &e, const edm::EventSetup &es) = 0;
33 loizides 1.3 const std::string &Name() const { return name_; }
34 loizides 1.7 virtual void ResolveLinks(const edm::Event &e, const edm::EventSetup &es) {}
35 paus 1.1
36     protected:
37 loizides 1.6 const edm::ParameterSet &Conf() const { return config_; }
38 loizides 1.8 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 loizides 1.6
43 paus 1.9 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 paus 1.1 };
47     }
48 loizides 1.8
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 paus 1.1 #endif