ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/interface/BaseFiller.h
(Generate patch)

Comparing UserCode/MitProd/TreeFiller/interface/BaseFiller.h (file contents):
Revision 1.10 by loizides, Wed Jul 30 08:39:50 2008 UTC vs.
Revision 1.17 by loizides, Wed Oct 21 13:25:29 2009 UTC

# Line 8 | Line 8
8   // Authors: C.Paus
9   //--------------------------------------------------------------------------------------------------
10  
11 < #ifndef TREEFILLER_BASEFILLER_H
12 < #define TREEFILLER_BASEFILLER_H
11 > #ifndef MITPROD_TREEFILLER_BASEFILLER_H
12 > #define MITPROD_TREEFILLER_BASEFILLER_H
13  
14 + #include "DataFormats/Common/interface/Handle.h"
15   #include "FWCore/Framework/interface/Event.h"
16   #include "FWCore/Framework/interface/Frameworkfwd.h"
17   #include "FWCore/ParameterSet/interface/ParameterSet.h"
18   #include "FWCore/MessageLogger/interface/MessageLogger.h"
18 #include "DataFormats/Common/interface/Handle.h"
19   #include "MitAna/DataUtil/interface/TreeWriter.h"
20   #include <TString.h>
21  
22   namespace mithep
23   {
24 +  class BranchTable;
25 +  class ObjectService;
26 +
27    class BaseFiller
28    {
29      public:
30        BaseFiller(const edm::ParameterSet &cfg, const char *name, bool active=true);
31        virtual ~BaseFiller() {}
32  
33 <      bool                     Active() const { return active_; }
34 <      virtual void             BookDataBlock(TreeWriter &tws)                                = 0;
33 >      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 >      virtual void             BookDataBlock(TreeWriter &tws, const edm::EventSetup &es)     = 0;
40        virtual void             FillDataBlock(const edm::Event &e, const edm::EventSetup &es) = 0;
41 <      const std::string       &Name()   const { return name_; }
41 >      const std::string       &Name()    const { return name_;         }
42        virtual void             ResolveLinks(const edm::Event &e, const edm::EventSetup &es)    {}
43 +      int                      Verbose() const { return verbose_;      }
44 +      bool                     Verify()  const { return verify_;       }
45  
46      protected:
47 <      const edm::ParameterSet &Conf()   const { return config_; }
47 >      const edm::ParameterSet &Conf()    const { return config_;       }
48        void                     PrintErrorAndExit(const char *msg) const;
49        template <typename TYPE>
50 <      void                     GetProduct(const std::string name, edm::Handle<TYPE> &product,
50 >      void                     GetProduct(const std::string name, edm::Handle<TYPE> &prod,
51                                            const edm::Event &event) const;    
52 <
53 <      const std::string        name_;    // name of this filler
54 <      const edm::ParameterSet  config_;  // parameter set for this filler
55 <      const bool               active_;  // =1 if active
52 >      template <typename TYPE>
53 >      bool                     GetProductSafe(const std::string name, edm::Handle<TYPE> &prod,
54 >                                              const edm::Event &event) const;    
55 >      ObjectService           *OS();
56 >
57 >      const std::string        name_;    //name of this filler
58 >      const std::string        brtname_; //name of branch table (def = BranchTable)
59 >      const edm::ParameterSet  config_;  //parameter set for this filler
60 >      const bool               active_;  //=1 if active
61 >      const bool               verify_;  //=1 if verificatin code is active
62 >      const int                verbose_; //verbosity level (do not introduce more than 0-4 levels)
63 >      BranchTable             *brtable_; //branch dependency table
64    };
65   }
66  
67   //--------------------------------------------------------------------------------------------------
68   template <typename TYPE>
69 < inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle<TYPE> &product,
69 > inline void mithep::BaseFiller::GetProduct(const std::string edmname, edm::Handle<TYPE> &prod,
70                                             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 <    event.getByLabel(edm::InputTag(edmname),product);
77 <    if (!product.isValid())
76 >    event.getByLabel(edm::InputTag(edmname),prod);
77 >    if (!prod.isValid())
78        throw edm::Exception(edm::errors::Configuration, "BaseFiller::GetProduct()\n")
79 <        << "Cannot get collection with label " << edmname << std::endl;
79 >        << "Cannot get collection with label " << edmname << " for " << Name() <<  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()));
82 >                                << edmname << " for " << Name() << std::endl;
83 >    PrintErrorAndExit(Form("Cannot get collection with label %s for %s",
84 >                           edmname.c_str(), name_.c_str()));
85 >  }
86 > }
87 >
88 > //--------------------------------------------------------------------------------------------------
89 > template <typename TYPE>
90 > inline bool mithep::BaseFiller::GetProductSafe(const std::string edmname, edm::Handle<TYPE> &prod,
91 >                                               const edm::Event &event) const
92 > {
93 >  // Try to safely access data collection from EDM file. We check if we really get just one
94 >  // product with the given name. If not, we return false.
95 >
96 >  try {
97 >    event.getByLabel(edm::InputTag(edmname),prod);
98 >    if (!prod.isValid())
99 >      return false;
100 >  } catch (...) {
101 >    return false;
102    }
103 +  return true;
104   }
105   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines