CMS 3D CMS Logo

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