CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloRecHitCopy.cc
Go to the documentation of this file.
1 
5 
7 
8 #include <iostream>
9 
11 
12 {
13 
14  theInputRecHitCollectionTypes = p.getParameter<std::vector<unsigned> >("InputRecHitCollectionTypes");
15  theInputRecHitCollections = p.getParameter<std::vector<edm::InputTag> >("InputRecHitCollections");
16  theOutputRecHitCollections = p.getParameter<std::vector<std::string> >("OutputRecHitCollections");
17 
19 
20  for ( unsigned input=0; input<theInputRecHitCollectionTypes.size(); ++input ) {
21 
23  theOutputRecHitCollections[input] == "none" ?
24  false : true;
25 
27 
28  case 1:
29  {
30  //Preshower
31  theESRecHitCollectionToken = consumes<ESRecHitCollection>(theInputRecHitCollections[input]);
32  if ( !theOutputRecHitInstances[input] )
33  produces<ESRecHitCollection>();
34  else
35  produces<ESRecHitCollection>(theOutputRecHitCollections[input]);
36  }
37  break;
38 
39  case 2:
40  {
41  //Ecal Barrel
42  theEBRecHitCollectionToken = consumes<EBRecHitCollection>(theInputRecHitCollections[input]);
43  if ( !theOutputRecHitInstances[input] )
44  produces<EBRecHitCollection>();
45  else
46  produces<EBRecHitCollection>(theOutputRecHitCollections[input]);
47  }
48  break;
49 
50  case 3:
51  {
52  //EcalEndcap
53  theEERecHitCollectionToken = consumes<EERecHitCollection>(theInputRecHitCollections[input]);
54  if ( !theOutputRecHitInstances[input] )
55  produces<EERecHitCollection>();
56  else
57  produces<EERecHitCollection>(theOutputRecHitCollections[input]);
58  }
59  break;
60 
61  case 4:
62  {
63  //HCAL
64  theHBHERecHitCollectionToken = consumes<HBHERecHitCollection>(theInputRecHitCollections[input]);
65  if ( !theOutputRecHitInstances[input] )
66  produces<HBHERecHitCollection>();
67  else
68  produces<HBHERecHitCollection>(theOutputRecHitCollections[input]);
69  }
70  break;
71 
72  case 5:
73  {
74  //HO
75  theHORecHitCollectionToken = consumes<HORecHitCollection>(theInputRecHitCollections[input]);
76  if ( !theOutputRecHitInstances[input] )
77  produces<HORecHitCollection>();
78  else
79  produces<HORecHitCollection>(theOutputRecHitCollections[input]);
80  }
81  break;
82 
83  case 6:
84  {
85  //HF
86  theHFRecHitCollectionToken = consumes<HFRecHitCollection>(theInputRecHitCollections[input]);
87  if ( !theOutputRecHitInstances[input] )
88  produces<HFRecHitCollection>();
89  else
90  produces<HFRecHitCollection>(theOutputRecHitCollections[input]);
91  }
92  break;
93 
94  default:
95  // Should not happen
96  break;
97 
98  }
99 
100  }
101 
102 
103 }
104 
106 
107 void
109 {
110 
111 
112  for ( unsigned input=0; input<theInputRecHitCollectionTypes.size(); ++input ) {
113 
114  switch ( theInputRecHitCollectionTypes[input] ) {
115 
116  case 1:
117  {
118  //Preshower
119  std::auto_ptr< ESRecHitCollection > copiedESRecHitCollection( new ESRecHitCollection );
121  iEvent.getByToken(theESRecHitCollectionToken,ESRecHits);
122  ESRecHitCollection::const_iterator itES = ESRecHits->begin();
123  ESRecHitCollection::const_iterator lastES = ESRecHits->end();
124  // saves a bit of CPU
125  copiedESRecHitCollection->reserve(ESRecHits->size());
126  for ( ; itES!=lastES; ++itES++ ) {
127  EcalRecHit aHit(*itES);
128  copiedESRecHitCollection->push_back(aHit);
129  }
130  if ( !theOutputRecHitInstances[input] )
131  iEvent.put(copiedESRecHitCollection);
132  else
133  iEvent.put(copiedESRecHitCollection,theOutputRecHitCollections[input]);
134  }
135  break;
136 
137  case 2:
138  {
139  //Ecal Barrel
140  std::auto_ptr< EBRecHitCollection > copiedEBRecHitCollection( new EBRecHitCollection );
142  iEvent.getByToken(theEBRecHitCollectionToken,EBRecHits);
143  EBRecHitCollection::const_iterator itEB = EBRecHits->begin();
144  EBRecHitCollection::const_iterator lastEB = EBRecHits->end();
145  //saves a bit of CPU
146  copiedEBRecHitCollection->reserve(EBRecHits->size());
147 
148  for ( ; itEB!=lastEB; ++itEB++ ) {
149  EcalRecHit aHit(*itEB);
150  copiedEBRecHitCollection->push_back(aHit);
151  }
152  if ( !theOutputRecHitInstances[input] )
153  iEvent.put(copiedEBRecHitCollection);
154  else
155  iEvent.put(copiedEBRecHitCollection,theOutputRecHitCollections[input]);
156  }
157  break;
158 
159  case 3:
160  {
161  //EcalEndcap
162  std::auto_ptr< EERecHitCollection > copiedEERecHitCollection( new EERecHitCollection );
164  iEvent.getByToken(theEERecHitCollectionToken,EERecHits);
165  EERecHitCollection::const_iterator itEE = EERecHits->begin();
166  EERecHitCollection::const_iterator lastEE = EERecHits->end();
167  //saves a bit of CPU
168  copiedEERecHitCollection->reserve(EERecHits->size());
169 
170  for ( ; itEE!=lastEE; ++itEE++ ) {
171  EcalRecHit aHit(*itEE);
172  copiedEERecHitCollection->push_back(aHit);
173  }
174  if ( !theOutputRecHitInstances[input] )
175  iEvent.put(copiedEERecHitCollection);
176  else
177  iEvent.put(copiedEERecHitCollection,theOutputRecHitCollections[input]);
178  }
179  break;
180 
181  case 4:
182  {
183  //HCAL
184  std::auto_ptr< HBHERecHitCollection > copiedHBHERecHitCollection( new HBHERecHitCollection );
186  iEvent.getByToken(theHBHERecHitCollectionToken,HBHERecHits);
187  HBHERecHitCollection::const_iterator itHBHE = HBHERecHits->begin();
188  HBHERecHitCollection::const_iterator lastHBHE = HBHERecHits->end();
189  //saves a bit of CPU
190  copiedHBHERecHitCollection->reserve(HBHERecHits->size());
191 
192  for ( ; itHBHE!=lastHBHE; ++itHBHE++ ) {
193  HBHERecHit aHit(*itHBHE);
194  copiedHBHERecHitCollection->push_back(aHit);
195  }
196  if ( !theOutputRecHitInstances[input] )
197  iEvent.put(copiedHBHERecHitCollection);
198  else
199  iEvent.put(copiedHBHERecHitCollection,theOutputRecHitCollections[input]);
200  }
201  break;
202 
203  case 5:
204  {
205  //HO
206  std::auto_ptr< HORecHitCollection > copiedHORecHitCollection( new HORecHitCollection );
208  iEvent.getByToken(theHORecHitCollectionToken,HORecHits);
209  HORecHitCollection::const_iterator itHO = HORecHits->begin();
210  HORecHitCollection::const_iterator lastHO = HORecHits->end();
211  //saves a bit of CPU
212  copiedHORecHitCollection->reserve(HORecHits->size());
213 
214  for ( ; itHO!=lastHO; ++itHO++ ) {
215  HORecHit aHit(*itHO);
216  copiedHORecHitCollection->push_back(aHit);
217  }
218  if ( !theOutputRecHitInstances[input] )
219  iEvent.put(copiedHORecHitCollection);
220  else
221  iEvent.put(copiedHORecHitCollection,theOutputRecHitCollections[input]);
222  }
223  break;
224 
225  case 6:
226  {
227  //HF
228  std::auto_ptr< HFRecHitCollection > copiedHFRecHitCollection( new HFRecHitCollection );
230  iEvent.getByToken(theHFRecHitCollectionToken,HFRecHits);
231  HFRecHitCollection::const_iterator itHF = HFRecHits->begin();
232  HFRecHitCollection::const_iterator lastHF = HFRecHits->end();
233  //saves a bit of CPU
234  copiedHFRecHitCollection->reserve(HFRecHits->size());
235 
236  for ( ; itHF!=lastHF; ++itHF++ ) {
237  HFRecHit aHit(*itHF);
238  copiedHFRecHitCollection->push_back(aHit);
239  }
240  if ( !theOutputRecHitInstances[input] )
241  iEvent.put(copiedHFRecHitCollection);
242  else
243  iEvent.put(copiedHFRecHitCollection,theOutputRecHitCollections[input]);
244  }
245  break;
246 
247  default:
248  // Should not happen
249  break;
250 
251  }
252 
253  }
254 
255 }
256 
T getParameter(std::string const &) const
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
edm::EDGetTokenT< EERecHitCollection > theEERecHitCollectionToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
edm::EDGetTokenT< EBRecHitCollection > theEBRecHitCollectionToken
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< bool > theOutputRecHitInstances
std::vector< EcalRecHit >::const_iterator const_iterator
edm::EDGetTokenT< ESRecHitCollection > theESRecHitCollectionToken
edm::EDGetTokenT< HBHERecHitCollection > theHBHERecHitCollectionToken
static std::string const input
Definition: EdmProvDump.cc:44
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
edm::EDGetTokenT< HFRecHitCollection > theHFRecHitCollectionToken
std::vector< unsigned int > theInputRecHitCollectionTypes
std::vector< std::string > theOutputRecHitCollections
edm::EDGetTokenT< HORecHitCollection > theHORecHitCollectionToken
std::vector< edm::InputTag > theInputRecHitCollections
virtual ~CaloRecHitCopy()
CaloRecHitCopy(edm::ParameterSet const &p)