ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitEdm/Producers/interface/BaseCandProducer.h
Revision: 1.1
Committed: Sat Sep 27 05:48:25 2008 UTC (16 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre2, Mit_008pre1, Mit_006b, Mit_006a, Mit_006, Mit_005, Mit_004
Log Message:
Cleanup

File Contents

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2     // $Id: BaseCandidate.h,v 1.4 2008/09/10 03:28:38 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