CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ValueMapTraslator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ValueMapTraslator
4 // Class: ValueMapTraslator
5 //
13 //
14 // Original Author: Shervin Nourbakhsh,32 4-C03,+41227672087,
15 // Created: Sat Jul 13 15:40:56 CEST 2013
16 // $Id$
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
28 
31 
33 
36 
37 //#define DEBUG
38 //
39 // class declaration
40 //
41 
43  typedef double value_t;
45 
46  public:
47  explicit ValueMapTraslator(const edm::ParameterSet&);
49 
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52  private:
53  virtual void beginJob() ;
54  virtual void produce(edm::Event&, const edm::EventSetup&);
55  virtual void endJob() ;
56 
57  virtual void beginRun(edm::Run&, edm::EventSetup const&);
58  virtual void endRun(edm::Run&, edm::EventSetup const&);
61 
62  // ----------member data ---------------------------
66 
70 };
71 
72 //
73 // constants, enums and typedefs
74 //
75 
76 
77 //
78 // static data member definitions
79 //
80 
81 //
82 // constructors and destructor
83 //
85  referenceCollectionTAG(iConfig.getParameter<edm::InputTag>("referenceCollection")),
86  oldreferenceCollectionTAG(iConfig.getParameter<edm::InputTag>("oldreferenceCollection")),
87  inputCollectionTAG(iConfig.getParameter<edm::InputTag>("inputCollection")),
88  outputCollectionName(iConfig.getParameter<std::string>("outputCollection"))
89 {
90  //now do what ever other initialization is needed
91  referenceToken_ = consumes<reco::GsfElectronCollection>(referenceCollectionTAG);
92  oldreferenceToken_ = consumes<reco::GsfElectronCollection>(oldreferenceCollectionTAG);
93  inputToken_ = consumes< Map_t >(inputCollectionTAG);
95  produces< Map_t >(outputCollectionName);
96 
97 }
98 
99 
101 {
102 
103  // do anything here that needs to be done at desctruction time
104  // (e.g. close files, deallocate resources etc.)
105 
106 }
107 
108 
109 //
110 // member functions
111 //
112 
113 // ------------ method called to produce the data ------------
114 void
116 {
117  using namespace edm;
118  std::vector<value_t> valueVector;
119  std::auto_ptr<Map_t> valueVectorPtr(new Map_t());
120 
121  //------------------------------
123  Handle< reco::GsfElectronCollection > oldreferenceHandle;
124  Handle< Map_t > inputHandle;
125 
126  iEvent.getByToken( referenceToken_, referenceHandle);
127  iEvent.getByToken( oldreferenceToken_, oldreferenceHandle);
128  iEvent.getByToken( inputToken_, inputHandle);
129 
130  for(Map_t::const_iterator valueMap_itr = inputHandle->begin();
131  valueMap_itr != inputHandle->end();
132  valueMap_itr++){
133  for(unsigned int i = 0; i < valueMap_itr.size(); i++){
134 #ifdef DEBUG
135  std::cout << valueMap_itr[i] << std::endl;
136 #endif
137  // valueVector.push_back((valueMap_itr[i])); //valueMap_itr-inputHandle->begin()]));
138  }
139  break;
140  }
141 
142 #ifdef DEBUG
143  std::cout << "Size: " << referenceHandle->size() << "\t" << oldreferenceHandle->size() << "\t" << inputHandle->size() << "\t" << valueVector.size() << std::endl;
144 #endif
145  for(reco::GsfElectronCollection::const_iterator electronNew = referenceHandle->begin();
146  electronNew!= referenceHandle->end();
147  electronNew++){
148 
149  for(reco::GsfElectronCollection::const_iterator electron = oldreferenceHandle->begin();
150  electron!= oldreferenceHandle->end();
151  electron++){
152  //if(electronNew->GsfTrackF
153  if(electron->gsfTrack() != electronNew->gsfTrack()) continue;
154  //if(fabs(electronNew->eta() - electron->eta())>0.0001) continue;
155  //if(fabs(electronNew->phi() - electron->phi())>0.0001) continue;
156 
157  reco::GsfElectronRef eleRef(oldreferenceHandle, electron-oldreferenceHandle->begin());
158  reco::GsfElectronRef eleRef2(referenceHandle, electronNew-referenceHandle->begin());
159 
160 #ifdef DEBUG
161  std::cout << eleRef->eta() << "\t" << eleRef2->eta() << "\t"
162  << eleRef->phi() << "\t" << eleRef2->phi() << "\t"
163  << eleRef->energy() << "\t" << eleRef2->energy() << "\t"
164  << (eleRef->gsfTrack() == eleRef2->gsfTrack()) << "\t"
165  << (eleRef == eleRef2) << "\t"
166  << (*inputHandle)[eleRef] << std::endl;
167 #endif
168  valueVector.push_back((*inputHandle)[eleRef]); //valueMap_itr-inputHandle->begin()]));
169  }
170  }
171  //#endif
172  Map_t::Filler filler(*valueVectorPtr);
173  filler.insert(referenceHandle, valueVector.begin(), valueVector.end());
174  filler.fill();
175 
176  iEvent.put(valueVectorPtr);
177 
178 }
179 
180 // ------------ method called once each job just before starting event loop ------------
181 void
183 {
184 }
185 
186 // ------------ method called once each job just after ending the event loop ------------
187 void
189 }
190 
191 // ------------ method called when starting to processes a run ------------
192 void
194 {
195 }
196 
197 // ------------ method called when ending the processing of a run ------------
198 void
200 {
201 }
202 
203 // ------------ method called when starting to processes a luminosity block ------------
204 void
206 {
207 }
208 
209 // ------------ method called when ending the processing of a luminosity block ------------
210 void
212 {
213 }
214 
215 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
216 void
218  //The following says we do not know what parameters are allowed so do no validation
219  // Please change this to state exactly what you do use, even if it is no parameters
221  desc.setUnknown();
222  descriptions.addDefault(desc);
223 }
224 
225 //define this as a plug-in
ValueMapTraslator(const edm::ParameterSet &)
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
void valueVector(const std::map< K, V > &extract, std::vector< V > &output)
Definition: Operators.h:43
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
virtual void beginLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
edm::ValueMap< value_t > Map_t
virtual void endJob()
std::string outputCollectionName
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
edm::InputTag inputCollectionTAG
edm::InputTag oldreferenceCollectionTAG
edm::EDGetTokenT< reco::GsfElectronCollection > referenceToken_
edm::EDGetTokenT< reco::GsfElectronCollection > oldreferenceToken_
virtual void endLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
virtual void produce(edm::Event &, const edm::EventSetup &)
virtual void endRun(edm::Run &, edm::EventSetup const &)
container::const_iterator begin() const
Definition: ValueMap.h:174
edm::EDGetTokenT< Map_t > inputToken_
tuple cout
Definition: gather_cfg.py:145
virtual void beginRun(edm::Run &, edm::EventSetup const &)
virtual void beginJob()
edm::InputTag referenceCollectionTAG
Definition: Run.h:43