Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:31

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   detIds_.reserve(input.end() - input.begin());
0040   std::copy(input.begin(), input.end(), detIds_.begin());
0041 }
0042 
0043 // -----------------------------------------------------------------------------
0044 //
0045 SiStripHashedDetId::SiStripHashedDetId() : detIds_(), id_(0), iter_(detIds_.begin()) {
0046   LogTrace(mlCabling_) << "[SiStripHashedDetId::" << __func__ << "]"
0047                        << " Constructing object...";
0048 }
0049 
0050 // -----------------------------------------------------------------------------
0051 //
0052 SiStripHashedDetId::~SiStripHashedDetId() {
0053   LogTrace(mlCabling_) << "[SiStripHashedDetId::" << __func__ << "]"
0054                        << " Destructing object...";
0055   detIds_.clear();
0056 }
0057 
0058 // -----------------------------------------------------------------------------
0059 //
0060 void SiStripHashedDetId::init(const std::vector<uint32_t> &raw_ids) {
0061   detIds_.clear();
0062   detIds_.reserve(16000);
0063   const_iterator iter = raw_ids.begin();
0064   for (; iter != raw_ids.end(); ++iter) {
0065     DetId detectorId = DetId(*iter);
0066     if (*iter != sistrip::invalid32_ && *iter != sistrip::invalid_ && detectorId.det() == DetId::Tracker &&
0067         (detectorId.subdetId() == StripSubdetector::TID || detectorId.subdetId() == StripSubdetector::TIB ||
0068          detectorId.subdetId() == StripSubdetector::TOB || detectorId.subdetId() == StripSubdetector::TEC)) {
0069       detIds_.push_back(*iter);
0070     } else {
0071       edm::LogWarning(mlCabling_) << "[SiStripHashedDetId::" << __func__ << "]"
0072                                   << " DetId 0x" << std::hex << std::setw(8) << std::setfill('0') << *iter
0073                                   << " is not from the strip tracker!";
0074     }
0075   }
0076   if (!detIds_.empty()) {
0077     std::sort(detIds_.begin(), detIds_.end());
0078     id_ = detIds_.front();
0079     iter_ = detIds_.begin();
0080   }
0081 }
0082 
0083 // -----------------------------------------------------------------------------
0084 //
0085 std::ostream &operator<<(std::ostream &os, const SiStripHashedDetId &input) {
0086   std::stringstream ss;
0087   ss << "[SiStripHashedDetId::" << __func__ << "]"
0088      << " Found " << input.end() - input.begin() << " entries in DetId hash map:" << std::endl;
0089   SiStripHashedDetId::const_iterator iter = input.begin();
0090   for (; iter != input.end(); ++iter) {
0091     ss << " Index: " << std::dec << std::setw(5) << std::setfill(' ') << iter - input.begin() << "  DetId: 0x"
0092        << std::hex << std::setw(8) << std::setfill('0') << *iter << std::endl;
0093   }
0094   os << ss.str();
0095   return os;
0096 }