ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/interface/BaseFiller.h
Revision: 1.15
Committed: Mon Jun 15 15:00:23 2009 UTC (15 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_011, Mit_010a, Mit_010, Mit_009c, Mit_009b
Changes since 1.14: +4 -6 lines
Log Message:
Added proper fwd defs plus split up complilation of MitAna/DataTree LinkDefs.

File Contents

# User Rev Content
1 paus 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.15 // $Id: BaseFiller.h,v 1.14 2009/03/15 11:20:40 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 loizides 1.15 #include "DataFormats/Common/interface/Handle.h"
15 paus 1.1 #include "FWCore/Framework/interface/Event.h"
16 loizides 1.8 #include "FWCore/Framework/interface/Frameworkfwd.h"
17 paus 1.1 #include "FWCore/ParameterSet/interface/ParameterSet.h"
18 loizides 1.8 #include "FWCore/MessageLogger/interface/MessageLogger.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 loizides 1.14 class BranchTable;
25 loizides 1.15 class ObjectService;
26 loizides 1.14
27 paus 1.1 class BaseFiller
28     {
29     public:
30 loizides 1.6 BaseFiller(const edm::ParameterSet &cfg, const char *name, bool active=true);
31 paus 1.1 virtual ~BaseFiller() {}
32    
33 loizides 1.14 bool Active() const { return active_; }
34     void AddBranchDep(const char *n, const char *d);
35     void AddBranchDep(const std::string &n, const char *d)
36     { AddBranchDep(n.c_str(), d); }
37     void AddBranchDep(const std::string &n, const std::string &d)
38     { AddBranchDep(n.c_str(), d.c_str()); }
39 loizides 1.7 virtual void BookDataBlock(TreeWriter &tws) = 0;
40     virtual void FillDataBlock(const edm::Event &e, const edm::EventSetup &es) = 0;
41 loizides 1.14 const std::string &Name() const { return name_; }
42 loizides 1.7 virtual void ResolveLinks(const edm::Event &e, const edm::EventSetup &es) {}
43 loizides 1.14 int Verbose() const { return verbose_; }
44     bool Verify() const { return verify_; }
45 paus 1.1
46     protected:
47 loizides 1.14 const edm::ParameterSet &Conf() const { return config_; }
48 loizides 1.8 void PrintErrorAndExit(const char *msg) const;
49     template <typename TYPE>
50 loizides 1.11 void GetProduct(const std::string name, edm::Handle<TYPE> &prod,
51 loizides 1.8 const edm::Event &event) const;
52 loizides 1.11 template <typename TYPE>
53     bool GetProductSafe(const std::string name, edm::Handle<TYPE> &prod,
54     const edm::Event &event) const;
55 loizides 1.15 ObjectService *OS();
56 loizides 1.6
57 loizides 1.11 const std::string name_; //name of this filler
58 loizides 1.14 const std::string brtname_; //name of branch table (def = BranchTable)
59 loizides 1.11 const edm::ParameterSet config_; //parameter set for this filler
60     const bool active_; //=1 if active
61 loizides 1.13 const bool verify_; //=1 if verificatin code is active
62     const int verbose_; //verbosity level (do not introduce more than 0-4 levels)
63 loizides 1.14 BranchTable *brtable_; //branch dependency table
64 paus 1.1 };
65     }
66 loizides 1.8
67     //--------------------------------------------------------------------------------------------------
68     template <typename TYPE>
69 loizides 1.11 inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle<TYPE> &prod,
70 loizides 1.8 const edm::Event &event) const
71     {
72     // Try to access data collection from EDM file. We check if we really get just one
73     // product with the given name. If not we print an error and exit.
74    
75     try {
76 loizides 1.11 event.getByLabel(edm::InputTag(edmname),prod);
77     if (!prod.isValid())
78 loizides 1.8 throw edm::Exception(edm::errors::Configuration, "BaseFiller::GetProduct()\n")
79     << "Cannot get collection with label " << edmname << std::endl;
80     } catch (...) {
81     edm::LogError("BaseFiller") << "Cannot get collection with label "
82     << edmname << std::endl;
83     PrintErrorAndExit(Form("Cannot get collection with label %s", edmname.c_str()));
84     }
85     }
86 loizides 1.11
87     //--------------------------------------------------------------------------------------------------
88     template <typename TYPE>
89     inline bool mithep::BaseFiller::GetProductSafe(const std::string edmname, edm::Handle<TYPE> &prod,
90     const edm::Event &event) const
91     {
92     // Try to safely access data collection from EDM file. We check if we really get just one
93     // product with the given name. If not, we return false.
94    
95     try {
96     event.getByLabel(edm::InputTag(edmname),prod);
97     if (!prod.isValid())
98     return false;
99     } catch (...) {
100     return false;
101     }
102     return true;
103     }
104 paus 1.1 #endif