Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:19

0001 #include "CalibFormats/SiStripObjects/interface/SiStripHashedDetId.h"
0002 #include "DataFormats/DetId/interface/DetId.h"
0003 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <iomanip>
0006 #include <iostream>
0007 #include <sstream>
0008 
0009 using namespace sistrip;
0010 
0011 // -----------------------------------------------------------------------------
0012 //
0013 SiStripHashedDetId::SiStripHashedDetId(const std::vector<uint32_t> &raw_ids)
0014     : detIds_(), id_(0), iter_(detIds_.begin()) {
0015   LogTrace(mlCabling_) << "[SiStripHashedDetId::" << __func__ << "]"
0016                        << " Constructing object...";
0017   init(raw_ids);
0018 }
0019 
0020 // -----------------------------------------------------------------------------
0021 //
0022 SiStripHashedDetId::SiStripHashedDetId(const std::vector<DetId> &det_ids) : detIds_(), id_(0), iter_(detIds_.begin()) {
0023   LogTrace(mlCabling_) << "[SiStripHashedDetId::" << __func__ << "]"
0024                        << " Constructing object...";
0025   detIds_.clear();
0026   detIds_.reserve(16000);
0027   std::vector<DetId>::const_iterator iter = det_ids.begin();
0028   for (; iter != det_ids.end(); ++iter) {
0029     detIds_.push_back(iter->rawId());
0030   }
0031   init(detIds_);
0032 }
0033 
0034 // -----------------------------------------------------------------------------
0035 //
0036 SiStripHashedDetId::SiStripHashedDetId(const SiStripHashedDetId &input) : detIds_(), id_(0), iter_(detIds_.begin()) {
0037   LogTrace(mlCabling_) << "[SiStripHashedDetId::" << __func__ << "]"
0038                        << " Constructing object...";
0039 
0040   // auxilliary vector to store the list of raw IDs
0041   std::vector<uint32_t> raw_ids;
0042   raw_ids.reserve(input.size());
0043 
0044   // Copy elements from input vector to detIds_ vector
0045   std::copy(input.begin(), input.end(), std::back_inserter(raw_ids));
0046 
0047   init(raw_ids);
0048 }
0049 
0050 // -----------------------------------------------------------------------------
0051 //
0052 SiStripHashedDetId::SiStripHashedDetId() : detIds_(), id_(0), iter_(detIds_.begin()) {
0053   LogTrace(mlCabling_) << "[SiStripHashedDetId::" << __func__ << "]"
0054                        << " Constructing object...";
0055 }
0056 
0057 // -----------------------------------------------------------------------------
0058 //
0059 SiStripHashedDetId::~SiStripHashedDetId() {
0060   LogTrace(mlCabling_) << "[SiStripHashedDetId::" << __func__ << "]"
0061                        << " Destructing object...";
0062   detIds_.clear();
0063 }
0064 
0065 // -----------------------------------------------------------------------------
0066 //
0067 void SiStripHashedDetId::init(const std::vector<uint32_t> &raw_ids) {
0068   detIds_.clear();
0069   detIds_.reserve(16000);
0070   const_iterator iter = raw_ids.begin();
0071   for (; iter != raw_ids.end(); ++iter) {
0072     DetId detectorId = DetId(*iter);
0073     if (*iter != sistrip::invalid32_ && *iter != sistrip::invalid_ && detectorId.det() == DetId::Tracker &&
0074         (detectorId.subdetId() == StripSubdetector::TID || detectorId.subdetId() == StripSubdetector::TIB ||
0075          detectorId.subdetId() == StripSubdetector::TOB || detectorId.subdetId() == StripSubdetector::TEC)) {
0076       detIds_.push_back(*iter);
0077     } else {
0078       edm::LogWarning(mlCabling_) << "[SiStripHashedDetId::" << __func__ << "]"
0079                                   << " DetId 0x" << std::hex << std::setw(8) << std::setfill('0') << *iter
0080                                   << " is not from the strip tracker!";
0081     }
0082   }
0083   if (!detIds_.empty()) {
0084     std::sort(detIds_.begin(), detIds_.end());
0085     id_ = detIds_.front();
0086     iter_ = detIds_.begin();
0087   }
0088 }
0089 
0090 // -----------------------------------------------------------------------------
0091 //
0092 std::ostream &operator<<(std::ostream &os, const SiStripHashedDetId &input) {
0093   std::stringstream ss;
0094   ss << "[SiStripHashedDetId::" << __func__ << "]"
0095      << " Found " << input.end() - input.begin() << " entries in DetId hash map:" << std::endl;
0096   SiStripHashedDetId::const_iterator iter = input.begin();
0097   for (; iter != input.end(); ++iter) {
0098     ss << " Index: " << std::dec << std::setw(5) << std::setfill(' ') << iter - input.begin() << "  DetId: 0x"
0099        << std::hex << std::setw(8) << std::setfill('0') << *iter << std::endl;
0100   }
0101   os << ss.str();
0102   return os;
0103 }