CMS 3D CMS Logo

DigiCollectionFP420.cc

Go to the documentation of this file.
00001 
00002 // File: DigiCollectionFP420.cc
00003 // Date: 12.2006
00004 // Description: DigiCollectionFP420 for FP420
00005 // Modifications: 
00007 //#include "SimRomanPot/SimFP420/interface/DigiCollectionFP420.h"
00008 //#include "SimRomanPot/DataFormats/interface/DigiCollectionFP420.h"
00009 #include "DataFormats/FP420Digi/interface/DigiCollectionFP420.h"
00010 
00011 //#include <iostream>
00012 //#define mydigidebug
00013 
00014 void DigiCollectionFP420::put(Range input, unsigned int detID) {
00015   // put in Digis of detID
00016   
00017   // store size of vector before put
00018   IndexRange inputRange;
00019   
00020   // put in HDigiFP420s from input
00021   bool first = true;
00022   
00023   // fill input in temporary vector for sorting
00024   std::vector<HDigiFP420> temporary;
00025   DigiCollectionFP420::ContainerIterator sort_begin = input.first;
00026   DigiCollectionFP420::ContainerIterator sort_end = input.second;
00027 #ifdef mydigidebug
00028   std::cout <<"   !!!!!!!!!!!!!!!!    DigiCollectionFP420:: !!!!  put !!!!  start detID=" << detID << std::endl;
00029 #endif
00030   for ( ;sort_begin != sort_end; ++sort_begin ) {
00031     temporary.push_back(*sort_begin);
00032 #ifdef mydigidebug
00033     std::cout <<"digi put: temporary.push_back " << std::endl;
00034 #endif
00035   } // for
00036   std::sort(temporary.begin(),temporary.end());
00037   
00038   // iterators over input
00039   DigiCollectionFP420::ContainerIterator begin = temporary.begin();
00040   DigiCollectionFP420::ContainerIterator end = temporary.end();
00041   for ( ;begin != end; ++begin ) {
00042     container_.push_back(*begin);
00043     if ( first ) {
00044       inputRange.first = container_.size()-1;
00045 #ifdef mydigidebug
00046       std::cout <<"digi put:first  container_.size() = " << container_.size() << std::endl;
00047       std::cout <<"digi put:first  inputRange.first = " << inputRange.first << std::endl;
00048 #endif
00049       first = false;
00050     } // if
00051   } //for
00052   
00053   // since we start from 0, then the last element will be size-1
00054   if(container_.size() != 0) {
00055     inputRange.second = container_.size()-1;
00056   }
00057   else {
00058     inputRange.first = container_.size();
00059     inputRange.second = container_.size();
00060   }
00061 #ifdef mydigidebug
00062   std::cout <<"digi put: container_.size() = " << container_.size() << std::endl;
00063   std::cout <<"digi put:  inputRange.first = " << inputRange.first << std::endl;
00064   std::cout <<"digi put:  inputRange.second = " << inputRange.second << std::endl;
00065 #endif
00066   
00067   // fill map
00068   map_[detID] = inputRange;
00069   
00070 }
00071 
00072 
00073 void DigiCollectionFP420::clear() {
00074   container_.clear();
00075 }
00076 void DigiCollectionFP420::putclear(DigiCollectionFP420::Range input, unsigned int detID) {
00077   
00078   DigiCollectionFP420::IndexRange inputRange;
00079   
00080   std::vector<HDigiFP420> temporary;
00081   DigiCollectionFP420::ContainerIterator sort_begin = input.first;
00082   DigiCollectionFP420::ContainerIterator sort_end = input.second;
00083   for ( ;sort_begin != sort_end; ++sort_begin ) {
00084     temporary.push_back(*sort_begin);
00085   }
00086   std::sort(temporary.begin(),temporary.end());
00087   
00088   //    temporary.clear();
00089   DigiCollectionFP420::ContainerIterator begin = temporary.begin();
00090   DigiCollectionFP420::ContainerIterator end = temporary.end();
00091   for ( ;begin != end; ++begin ) {
00092     container_.push_back(*begin);
00093   }
00094   //container_.clear();
00095   inputRange.first = container_.size()-container_.size();
00096   inputRange.second = container_.size()-container_.size();
00097   
00098 #ifdef mydigidebug
00099   std::cout <<"digi putclear: container_.size() = " << container_.size() << std::endl;
00100   std::cout <<"digi putclear:  inputRange.first = " << inputRange.first << std::endl;
00101   std::cout <<"digi putclear:  inputRange.second = " << inputRange.second << std::endl;
00102 #endif
00103   
00104   
00105   map_[detID] = inputRange;
00106 }
00107 
00108 
00109 
00110 
00111 
00112 
00113 const DigiCollectionFP420::Range DigiCollectionFP420::get(unsigned int detID) const {
00114   // get Digis of detID
00115   
00116 #ifdef mydigidebug
00117   std::cout <<"DigiCollectionFP420::get1:detID= " << detID << std::endl;
00118 #endif
00119   // next 2 lines work OK also:
00120   //  DigiCollectionFP420::RegistryIterator returnIndex = map_.find(detID);
00121   //  DigiCollectionFP420::IndexRange returnIndexRange = returnIndex->second;
00122   // but use one:
00123   DigiCollectionFP420::IndexRange returnIndexRange = map_[detID];
00124   //
00125   DigiCollectionFP420::Range returnRange;
00126   returnRange.first  = container_.begin()+returnIndexRange.first;
00127   if(returnIndexRange.second != 0 ) {
00128     returnRange.second = container_.begin()+returnIndexRange.second+1;
00129   }else{
00130     returnRange.second = container_.begin()+returnIndexRange.second;
00131   }
00132   
00133 #ifdef mydigidebug
00134   std::cout <<"digi get1: container_.size() = " << container_.size() << std::endl;
00135   std::cout <<"digi get1: returnIndexRange.first= " << returnIndexRange.first << std::endl;
00136   std::cout <<"digi get1: returnIndexRange.second= " << returnIndexRange.second << std::endl;
00137 #endif
00138   return returnRange;
00139 }
00140 
00141 
00142 const DigiCollectionFP420::Range DigiCollectionFP420::get1(unsigned int detID) const {
00143   // get Digis of detID
00144   
00145 #ifdef mydigidebug
00146   std::cout <<"DigiCollectionFP420::get :detID= " << detID << std::endl;
00147 #endif
00148   DigiCollectionFP420::RegistryIterator returnIndex = map_.find(detID);
00149   DigiCollectionFP420::IndexRange returnIndexRange = returnIndex->second;
00150 #ifdef mydigidebug
00151   std::cout <<"DigiCollectionFP420::get : returnIndexRange.first= " << returnIndexRange.first << std::endl;
00152   std::cout <<"DigiCollectionFP420::get : returnIndexRange.second= " << returnIndexRange.second << std::endl;
00153 #endif
00154   
00155   DigiCollectionFP420::Range returnRange;
00156   returnRange.first  = container_.begin()+returnIndexRange.first;
00157   if(returnIndexRange.second != 0 ) {
00158     returnRange.second = container_.begin()+returnIndexRange.second+1;
00159   }else{
00160     returnRange.second = container_.begin()+returnIndexRange.second;
00161   }
00162 #ifdef mydigidebug
00163   std::cout <<"DigiCollectionFP420::get : container_.size() = " << container_.size() << std::endl;
00164   std::cout <<"DigiCollectionFP420::get : returnIndexRange.first= " << returnIndexRange.first << std::endl;
00165   std::cout <<"DigiCollectionFP420::get : returnIndexRange.second= " << returnIndexRange.second << std::endl;
00166 #endif
00167   return returnRange;
00168 }
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 const std::vector<unsigned int> DigiCollectionFP420::detIDs() const {
00177   // returns vector of detIDs in map
00178   
00179   DigiCollectionFP420::RegistryIterator begin = map_.begin();
00180   DigiCollectionFP420::RegistryIterator end   = map_.end();
00181   
00182 #ifdef mydigidebug
00183   std::cout <<"DigiCollectionFP420::detIDs:start " << std::endl;
00184 #endif
00185   std::vector<unsigned int> output;
00186   
00187   for (; begin != end; ++begin) {
00188     output.push_back(begin->first);
00189   }
00190   
00191   return output;
00192   
00193 }
00194 
00195 // -----------------------------------------------------------------------------
00196 // Appends HDigiFP420s to the vector of the given DetId.
00197 void DigiCollectionFP420::add( unsigned int& det_id, 
00198                                std::vector<HDigiFP420>& digis ) {
00199   
00200 #ifdef mydigidebug
00201   std::cout <<"DigiCollectionFP420::add:    det_id=    " << det_id << std::endl;
00202 #endif
00203   digiMap_[det_id].reserve( digiMap_[det_id].size() + digis.size() );
00204   if ( digiMap_[det_id].empty() ) { 
00205     digiMap_[det_id] = digis;
00206   } else {
00207     copy( digis.begin(), digis.end(), back_inserter(digiMap_[det_id]) );
00208   }
00209 }
00210 
00211 // -----------------------------------------------------------------------------
00212 // Returns (by reference) all Digis for a given DetId.
00213 void DigiCollectionFP420::digis( unsigned int& det_id,
00214                                  std::vector<HDigiFP420>& digis ) const {
00215 #ifdef mydigidebug
00216   std::cout <<"DigiCollectionFP420::digis:det_id= " << det_id << std::endl;
00217 #endif
00218   if ( digiMap_.find( det_id ) != digiMap_.end() ) { 
00219     digis = digiMap_[det_id];
00220   } else {
00221     digis = std::vector<HDigiFP420>();
00222   }
00223 }
00224 
00225 // -----------------------------------------------------------------------------
00226 // Returns (by reference) vector of DetIds with Digis.
00227 void DigiCollectionFP420::detIDs( std::vector<unsigned int>& det_ids ) const {
00228   det_ids.clear(); 
00229   det_ids.reserve( static_cast<unsigned int>(digiMap_.size()) );
00230 #ifdef mydigidebug
00231   std::cout <<"DigiCollectionFP420::  detIDs:  digiMap    size= " << digiMap_.size() << std::endl;
00232 #endif
00233   HDigiFP420Container::const_iterator iter;
00234   for (iter = digiMap_.begin(); iter != digiMap_.end(); iter++ ) {
00235     det_ids.push_back( iter->first );
00236   }
00237 }

Generated on Tue Jun 9 17:30:46 2009 for CMSSW by  doxygen 1.5.4