CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CalibFormats/SiStripObjects/src/SiStripHashedDetId.cc

Go to the documentation of this file.
00001 #include "CalibFormats/SiStripObjects/interface/SiStripHashedDetId.h"
00002 #include "DataFormats/DetId/interface/DetId.h"
00003 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include <iostream>
00006 #include <iomanip>
00007 #include <sstream>
00008 
00009 using namespace sistrip;
00010 
00011 // -----------------------------------------------------------------------------
00012 //
00013 SiStripHashedDetId::SiStripHashedDetId( const std::vector<uint32_t>& raw_ids ) 
00014   : detIds_(),
00015     id_(0),
00016     iter_(detIds_.begin())
00017 {
00018   LogTrace(mlCabling_)
00019     << "[SiStripHashedDetId::" << __func__ << "]"
00020     << " Constructing object...";
00021   init(raw_ids);
00022 }
00023 
00024 // -----------------------------------------------------------------------------
00025 //
00026 SiStripHashedDetId::SiStripHashedDetId( const std::vector<DetId>& det_ids ) 
00027   : detIds_(),
00028     id_(0),
00029     iter_(detIds_.begin())
00030 {
00031   LogTrace(mlCabling_)
00032     << "[SiStripHashedDetId::" << __func__ << "]"
00033     << " Constructing object...";
00034   detIds_.clear();
00035   detIds_.reserve(16000);
00036   std::vector<DetId>::const_iterator iter = det_ids.begin();
00037   for ( ; iter != det_ids.end(); ++iter ) {
00038     detIds_.push_back( iter->rawId() );
00039   }
00040   init(detIds_);
00041 }
00042 
00043 // -----------------------------------------------------------------------------
00044 //
00045 SiStripHashedDetId::SiStripHashedDetId( const SiStripHashedDetId& input ) 
00046   : detIds_(),
00047     id_(0),
00048     iter_(detIds_.begin())
00049 {
00050   LogTrace(mlCabling_)
00051     << "[SiStripHashedDetId::" << __func__ << "]"
00052     << " Constructing object...";
00053   detIds_.reserve( input.end() - input.begin() );
00054   std::copy( input.begin(), input.end(), detIds_.begin() );
00055 }
00056 
00057 // -----------------------------------------------------------------------------
00058 //
00059 SiStripHashedDetId::SiStripHashedDetId() 
00060   : detIds_(),
00061     id_(0),
00062     iter_(detIds_.begin())
00063 {
00064   LogTrace(mlCabling_) 
00065     << "[SiStripHashedDetId::" << __func__ << "]"
00066     << " Constructing object...";
00067 }
00068 
00069 // -----------------------------------------------------------------------------
00070 //
00071 SiStripHashedDetId::~SiStripHashedDetId() {
00072   LogTrace(mlCabling_)
00073     << "[SiStripHashedDetId::" << __func__ << "]"
00074     << " Destructing object...";
00075   detIds_.clear();
00076 }
00077 
00078 // -----------------------------------------------------------------------------
00079 //
00080 void SiStripHashedDetId::init( const std::vector<uint32_t>& raw_ids ) {
00081   detIds_.clear();
00082   detIds_.reserve(16000);
00083   const_iterator iter = raw_ids.begin();
00084   for ( ; iter != raw_ids.end(); ++iter ) {
00085     SiStripDetId detid(*iter);
00086     if ( *iter != sistrip::invalid32_ && 
00087          *iter != sistrip::invalid_ && 
00088          detid.det() == DetId::Tracker && 
00089          ( detid.subDetector() == SiStripDetId::TID || 
00090            detid.subDetector() == SiStripDetId::TIB || 
00091            detid.subDetector() == SiStripDetId::TOB || 
00092            detid.subDetector() == SiStripDetId::TEC ) ) { 
00093       detIds_.push_back(*iter);
00094     } else {
00095       edm::LogWarning(mlCabling_)
00096         << "[SiStripHashedDetId::" << __func__ << "]"
00097         << " DetId 0x" 
00098         << std::hex << std::setw(8) << std::setfill('0') << *iter
00099         << " is not from the strip tracker!";
00100     }
00101   }
00102   if ( !detIds_.empty() ) {
00103     std::sort( detIds_.begin(), detIds_.end() );
00104     id_ = detIds_.front();
00105     iter_ = detIds_.begin();
00106   }
00107 }
00108 
00109 // -----------------------------------------------------------------------------
00110 //
00111 std::ostream& operator<< ( std::ostream& os, const SiStripHashedDetId& input ) {
00112   std::stringstream ss;
00113   ss << "[SiStripHashedDetId::" << __func__ << "]"
00114      << " Found " << input.end() - input.begin()
00115      << " entries in DetId hash map:"
00116      << std::endl;
00117   SiStripHashedDetId::const_iterator iter = input.begin();
00118   for ( ; iter != input.end(); ++iter ) {
00119     ss << " Index: "
00120        << std::dec << std::setw(5) << std::setfill(' ')
00121        << iter - input.begin() 
00122        << "  DetId: 0x"
00123        << std::hex << std::setw(8) << std::setfill('0')
00124        << *iter << std::endl;
00125   }
00126   os << ss.str();
00127   return os;
00128 }