ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/interface/BaseFiller.h
Revision: 1.19
Committed: Thu Mar 18 20:20:59 2010 UTC (15 years, 1 month ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, HEAD
Branch point for: Mit_025c_branch
Changes since 1.18: +2 -2 lines
Log Message:
Fix beginrun,beginjob mess

File Contents

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