CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DigiCollectionFP420.cc
Go to the documentation of this file.
1 // File: DigiCollectionFP420.cc
3 // Date: 12.2006
4 // Description: DigiCollectionFP420 for FP420
5 // Modifications:
7 //#include "SimRomanPot/SimFP420/interface/DigiCollectionFP420.h"
8 //#include "SimRomanPot/DataFormats/interface/DigiCollectionFP420.h"
10 
11 #include <algorithm>
12 //#include <iostream>
13 //#define mydigidebug
14 
15 void DigiCollectionFP420::put(Range input, unsigned int detID) {
16  // put in Digis of detID
17 
18  // store size of vector before put
20 
21  // put in HDigiFP420s from input
22  bool first = true;
23 
24  // fill input in temporary vector for sorting
25  std::vector<HDigiFP420> temporary;
26  DigiCollectionFP420::ContainerIterator sort_begin = input.first;
27  DigiCollectionFP420::ContainerIterator sort_end = input.second;
28 #ifdef mydigidebug
29  std::cout <<" !!!!!!!!!!!!!!!! DigiCollectionFP420:: !!!! put !!!! start detID=" << detID << std::endl;
30 #endif
31  for ( ;sort_begin != sort_end; ++sort_begin ) {
32  temporary.push_back(*sort_begin);
33 #ifdef mydigidebug
34  std::cout <<"digi put: temporary.push_back " << std::endl;
35 #endif
36  } // for
37  std::sort(temporary.begin(),temporary.end());
38 
39  // iterators over input
42  for ( ;begin != end; ++begin ) {
43  container_.push_back(*begin);
44  if ( first ) {
45  inputRange.first = container_.size()-1;
46 #ifdef mydigidebug
47  std::cout <<"digi put:first container_.size() = " << container_.size() << std::endl;
48  std::cout <<"digi put:first inputRange.first = " << inputRange.first << std::endl;
49 #endif
50  first = false;
51  } // if
52  } //for
53 
54  // since we start from 0, then the last element will be size-1
55  if(container_.size() != 0) {
56  inputRange.second = container_.size()-1;
57  }
58  else {
59  inputRange.first = container_.size();
60  inputRange.second = container_.size();
61  }
62 #ifdef mydigidebug
63  std::cout <<"digi put: container_.size() = " << container_.size() << std::endl;
64  std::cout <<"digi put: inputRange.first = " << inputRange.first << std::endl;
65  std::cout <<"digi put: inputRange.second = " << inputRange.second << std::endl;
66 #endif
67 
68  // fill map
69  map_[detID] = inputRange;
70 
71 }
72 
73 
75  container_.clear();
76 }
78 
80 
81  std::vector<HDigiFP420> temporary;
82  DigiCollectionFP420::ContainerIterator sort_begin = input.first;
83  DigiCollectionFP420::ContainerIterator sort_end = input.second;
84  for ( ;sort_begin != sort_end; ++sort_begin ) {
85  temporary.push_back(*sort_begin);
86  }
87  std::sort(temporary.begin(),temporary.end());
88 
89  // temporary.clear();
92  for ( ;begin != end; ++begin ) {
93  container_.push_back(*begin);
94  }
95  //container_.clear();
96  inputRange.first = container_.size()-container_.size();
97  inputRange.second = container_.size()-container_.size();
98 
99 #ifdef mydigidebug
100  std::cout <<"digi putclear: container_.size() = " << container_.size() << std::endl;
101  std::cout <<"digi putclear: inputRange.first = " << inputRange.first << std::endl;
102  std::cout <<"digi putclear: inputRange.second = " << inputRange.second << std::endl;
103 #endif
104 
105 
106  map_[detID] = inputRange;
107 }
108 
109 
110 
111 
112 
113 
114 const DigiCollectionFP420::Range DigiCollectionFP420::get(unsigned int detID) const {
115  // get Digis of detID
116 
117 #ifdef mydigidebug
118  std::cout <<"DigiCollectionFP420::get1:detID= " << detID << std::endl;
119 #endif
120  // next 2 lines work OK also:
121  // DigiCollectionFP420::RegistryIterator returnIndex = map_.find(detID);
122  // DigiCollectionFP420::IndexRange returnIndexRange = returnIndex->second;
123  // but use one:
124  DigiCollectionFP420::IndexRange returnIndexRange = map_[detID];
125  //
126  DigiCollectionFP420::Range returnRange;
127  returnRange.first = container_.begin()+returnIndexRange.first;
128  if(returnIndexRange.second != 0 ) {
129  returnRange.second = container_.begin()+returnIndexRange.second+1;
130  }else{
131  returnRange.second = container_.begin()+returnIndexRange.second;
132  }
133 
134 #ifdef mydigidebug
135  std::cout <<"digi get1: container_.size() = " << container_.size() << std::endl;
136  std::cout <<"digi get1: returnIndexRange.first= " << returnIndexRange.first << std::endl;
137  std::cout <<"digi get1: returnIndexRange.second= " << returnIndexRange.second << std::endl;
138 #endif
139  return returnRange;
140 }
141 
142 
143 const DigiCollectionFP420::Range DigiCollectionFP420::get1(unsigned int detID) const {
144  // get Digis of detID
145 
146 #ifdef mydigidebug
147  std::cout <<"DigiCollectionFP420::get :detID= " << detID << std::endl;
148 #endif
149  DigiCollectionFP420::RegistryIterator returnIndex = map_.find(detID);
150  DigiCollectionFP420::IndexRange returnIndexRange = returnIndex->second;
151 #ifdef mydigidebug
152  std::cout <<"DigiCollectionFP420::get : returnIndexRange.first= " << returnIndexRange.first << std::endl;
153  std::cout <<"DigiCollectionFP420::get : returnIndexRange.second= " << returnIndexRange.second << std::endl;
154 #endif
155 
156  DigiCollectionFP420::Range returnRange;
157  returnRange.first = container_.begin()+returnIndexRange.first;
158  if(returnIndexRange.second != 0 ) {
159  returnRange.second = container_.begin()+returnIndexRange.second+1;
160  }else{
161  returnRange.second = container_.begin()+returnIndexRange.second;
162  }
163 #ifdef mydigidebug
164  std::cout <<"DigiCollectionFP420::get : container_.size() = " << container_.size() << std::endl;
165  std::cout <<"DigiCollectionFP420::get : returnIndexRange.first= " << returnIndexRange.first << std::endl;
166  std::cout <<"DigiCollectionFP420::get : returnIndexRange.second= " << returnIndexRange.second << std::endl;
167 #endif
168  return returnRange;
169 }
170 
171 
172 
173 
174 
175 
176 
177 const std::vector<unsigned int> DigiCollectionFP420::detIDs() const {
178  // returns vector of detIDs in map
179 
182 
183 #ifdef mydigidebug
184  std::cout <<"DigiCollectionFP420::detIDs:start " << std::endl;
185 #endif
186  std::vector<unsigned int> output;
187 
188  for (; begin != end; ++begin) {
189  output.push_back(begin->first);
190  }
191 
192  return output;
193 
194 }
195 
196 // -----------------------------------------------------------------------------
197 // Appends HDigiFP420s to the vector of the given DetId.
198 void DigiCollectionFP420::add( unsigned int& det_id,
199  std::vector<HDigiFP420>& digis ) {
200 
201 #ifdef mydigidebug
202  std::cout <<"DigiCollectionFP420::add: det_id= " << det_id << std::endl;
203 #endif
204  digiMap_[det_id].reserve( digiMap_[det_id].size() + digis.size() );
205  if ( digiMap_[det_id].empty() ) {
206  digiMap_[det_id] = digis;
207  } else {
208  copy( digis.begin(), digis.end(), back_inserter(digiMap_[det_id]) );
209  }
210 }
211 
212 // -----------------------------------------------------------------------------
213 // Returns (by reference) all Digis for a given DetId.
214 void DigiCollectionFP420::digis( unsigned int& det_id,
215  std::vector<HDigiFP420>& digis ) const {
216 #ifdef mydigidebug
217  std::cout <<"DigiCollectionFP420::digis:det_id= " << det_id << std::endl;
218 #endif
219  if ( digiMap_.find( det_id ) != digiMap_.end() ) {
220  digis = digiMap_[det_id];
221  } else {
222  digis = std::vector<HDigiFP420>();
223  }
224 }
225 
226 // -----------------------------------------------------------------------------
227 // Returns (by reference) vector of DetIds with Digis.
228 void DigiCollectionFP420::detIDs( std::vector<unsigned int>& det_ids ) const {
229  det_ids.clear();
230  det_ids.reserve( static_cast<unsigned int>(digiMap_.size()) );
231 #ifdef mydigidebug
232  std::cout <<"DigiCollectionFP420:: detIDs: digiMap size= " << digiMap_.size() << std::endl;
233 #endif
234  HDigiFP420Container::const_iterator iter;
235  for (iter = digiMap_.begin(); iter != digiMap_.end(); iter++ ) {
236  det_ids.push_back( iter->first );
237  }
238 }
inputRange
Get input source.
std::vector< HDigiFP420 >::const_iterator ContainerIterator
const Range get1(unsigned int detID) const
std::pair< unsigned int, unsigned int > IndexRange
void digis(unsigned int &det_id, std::vector< HDigiFP420 > &digis) const
std::map< unsigned int, IndexRange >::const_iterator RegistryIterator
void put(Range input, unsigned int detID)
void add(unsigned int &det_id, std::vector< HDigiFP420 > &digis)
void putclear(Range input, unsigned int detID)
#define end
Definition: vmac.h:38
HDigiFP420Container digiMap_
bool first
Definition: L1TdeRCT.cc:94
std::pair< ContainerIterator, ContainerIterator > Range
const std::vector< unsigned int > detIDs() const
std::vector< HDigiFP420 > container_
#define begin
Definition: vmac.h:31
const Range get(unsigned int detID) const
tuple cout
Definition: gather_cfg.py:121
tuple size
Write out results.