ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitEdm/Producers/interface/BaseCandProducer.h
Revision: 1.2
Committed: Fri Mar 20 18:01:47 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_011, Mit_010a, Mit_010, Mit_009c, Mit_009b, Mit_009a, Mit_009, Mit_008
Changes since 1.1: +2 -2 lines
Log Message:
Cleanup

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: BaseCandProducer.h,v 1.1 2008/09/27 05:48:25 loizides Exp $
3 //
4 // BaseCandProducer
5 //
6 // Base class for all more specific candidate producers.
7 //
8 // Authors: C.Paus
9 //--------------------------------------------------------------------------------------------------
10
11 #ifndef MITEDM_PRODUCERS_BASECANDPRODUCER_H
12 #define MITEDM_PRODUCERS_BASECANDPRODUCER_H
13
14 #include <vector>
15 #include <iostream>
16 #include <TString.h>
17 #include "FWCore/Framework/interface/Frameworkfwd.h"
18 #include "FWCore/Framework/interface/EDProducer.h"
19 #include "FWCore/Framework/interface/Event.h"
20 #include "FWCore/Framework/interface/MakerMacros.h"
21 #include "FWCore/ParameterSet/interface/ParameterSet.h"
22
23 namespace mitedm
24 {
25 class BaseCandProducer : public edm::EDProducer
26 {
27 public:
28 explicit BaseCandProducer(const edm::ParameterSet&);
29 ~BaseCandProducer() {}
30
31 protected:
32 void beginJob(const edm::EventSetup&) {}
33 void produce(edm::Event&, const edm::EventSetup&) = 0;
34 void endJob() {}
35
36 // generic accessors to make the code more simple
37 void PrintErrorAndExit(const char *msg) const;
38 template <typename TYPE>
39 bool GetProduct(const std::string name, edm::Handle<TYPE> &product,
40 const edm::Event &event, bool ignore = true) const;
41
42 // Parameters always being used
43 int oPid_; // pid of candidate particle
44 };
45
46 //------------------------------------------------------------------------------------------------
47 template <typename TYPE>
48 inline bool BaseCandProducer::GetProduct(const std::string edmName, edm::Handle<TYPE> &product,
49 const edm::Event &evt, bool ignore) const
50 {
51 // Try to access data collection from EDM file. We check if we really get just one
52 // product with the given name. If not we print an error and exit.
53
54 try {
55 evt.getByLabel(edm::InputTag(edmName),product);
56 if (! product.isValid())
57 throw edm::Exception(edm::errors::Configuration, "BaseCandProducer::GetProduct()\n")
58 << "Cannot get collection with label " << edmName << std::endl;
59 } catch (...) {
60 if (ignore)
61 return false;
62 else {
63 edm::LogError("BaseCandProducer") << "Cannot get collection with label "
64 << edmName << std::endl;
65 PrintErrorAndExit(Form("Cannot get collection with label %s", edmName.c_str()));
66 }
67 }
68 return true;
69 }
70 }
71 #endif