Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:     SiStripObjects
0004 // Class  :     SiStripDelay
0005 // Implementation:
0006 //     <Notes on implementation>
0007 // Original Author:  M. De Mattia
0008 //         Created:  26/10/2010
0009 
0010 #include "CalibFormats/SiStripObjects/interface/SiStripDelay.h"
0011 #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/Utilities/interface/typelookup.h"
0014 #include <cassert>
0015 #include <sstream>
0016 
0017 void SiStripDelay::fillNewDelay(const SiStripBaseDelay &baseDelay,
0018                                 const int sumSign,
0019                                 const std::pair<std::string, std::string> &recordLabelPair) {
0020   baseDelayVector_.push_back(&baseDelay);
0021   sumSignVector_.push_back(sumSign);
0022   recordLabelPair_.push_back(recordLabelPair);
0023 }
0024 
0025 float SiStripDelay::getDelay(const uint32_t detId) const {
0026   std::unordered_map<uint32_t, double>::const_iterator it = delays_.find(detId);
0027   if (it != delays_.end()) {
0028     return it->second;
0029   }
0030   return 0.;
0031 }
0032 
0033 bool SiStripDelay::makeDelay() {
0034   if (baseDelayVector_.empty()) {
0035     return false;
0036   }
0037   std::vector<const SiStripBaseDelay *>::const_iterator it = baseDelayVector_.begin();
0038   // Check for consistent size in all baseDelays
0039   if (baseDelayVector_.size() > 1) {
0040     for (; it != baseDelayVector_.end() - 1; ++it) {
0041       if ((*it)->delaysSize() != (*(it + 1))->delaysSize()) {
0042         std::cout << "makeDelay: Error, size of base delays is different!!" << std::endl;
0043         return false;
0044       }
0045     }
0046   }
0047 
0048   //   // All checks done, fill the boost::unoredered_map with the first one
0049   //   (initialization) int sumSignIndex = 0; int sumSign = 0;
0050   //   std::vector<uint32_t>::const_iterator detIdIt;
0051   //   for( it = baseDelayVector_.begin(); it != baseDelayVector_.end(); ++it,
0052   //   ++sumSignIndex ) {
0053   //     std::vector<uint32_t> detIds;
0054   //     (*it)->detIds(detIds);
0055   //     sumSign = sumSignVector_[sumSignIndex];
0056   //     for( detIdIt = detIds.begin(); detIdIt != detIds.end(); ++detIdIt ) {
0057   //       // Check if is alread there so that we never rely on the default
0058   //       initialization boost::unordered_map<uint32_t, double>::iterator
0059   //       delayIt = delays_.find(*detIdIt); if( delayIt != delays_.end() ) {
0060   //    std::cout << "second delay = " << (*it)->delay(*detIdIt)*sumSign <<
0061   // std::endl;     delays_[*detIdIt] += (*it)->delay(*detIdIt)*sumSign;
0062   // std::cout
0063   // << "Full delay = " << delays_[*detIdIt] << std::endl;
0064   //       }
0065   //       else {
0066   //    std::cout << "first delay = " << (*it)->delay(*detIdIt)*sumSign <<
0067   // std::endl;     delays_[*detIdIt] = (*it)->delay(*detIdIt)*sumSign;
0068   //       }
0069   //     }
0070   //   }
0071 
0072   // All checks done, fill the boost::unoredered_map with the first one
0073   // (initialization)
0074   int sumSignIndex = 0;
0075   int sumSign = sumSignVector_[sumSignIndex];
0076   it = baseDelayVector_.begin();
0077   std::vector<uint32_t> detIds;
0078   (*it)->detIds(detIds);
0079   std::vector<uint32_t>::const_iterator detIdIt = detIds.begin();
0080   for (; detIdIt != detIds.end(); ++detIdIt) {
0081     delays_[*detIdIt] = (*it)->delay(*detIdIt) * sumSign;
0082   }
0083   ++it;
0084   ++sumSignIndex;
0085   // Fill all the others
0086   for (; it != baseDelayVector_.end(); ++it, ++sumSignIndex) {
0087     std::vector<uint32_t> detIds;
0088     (*it)->detIds(detIds);
0089     detIdIt = detIds.begin();
0090     sumSign = sumSignVector_[sumSignIndex];
0091     for (; detIdIt != detIds.end(); ++detIdIt) {
0092       // The same detIds should be in both maps, if not don't rely on the
0093       // default initialization
0094       std::unordered_map<uint32_t, double>::iterator delayIt = delays_.find(*detIdIt);
0095       if (delayIt != delays_.end()) {
0096         delays_[*detIdIt] += (*it)->delay(*detIdIt) * sumSign;
0097       } else {
0098         std::cout << "makeDelay: Warning, detId = " << *detIdIt << " not present, summing to 0..." << std::endl;
0099         std::cout << "This means that the two baseDelay tags have different "
0100                      "detIds. PLEASE, CHECK THAT THIS IS EXPECTED."
0101                   << std::endl;
0102         delays_[*detIdIt] = (*it)->delay(*detIdIt) * sumSign;
0103       }
0104     }
0105   }
0106 
0107   return true;
0108 }
0109 
0110 void SiStripDelay::clear() {
0111   baseDelayVector_.clear();
0112   sumSignVector_.clear();
0113   recordLabelPair_.clear();
0114   delays_.clear();
0115 }
0116 
0117 void SiStripDelay::printDebug(std::stringstream &ss, const TrackerTopology * /*trackerTopo*/) const {
0118   std::unordered_map<uint32_t, double>::const_iterator it = delays_.begin();
0119   for (; it != delays_.end(); ++it) {
0120     ss << "detId = " << it->first << " delay = " << it->second << std::endl;
0121   }
0122 }
0123 
0124 void SiStripDelay::printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const {
0125   SiStripDetSummary summaryDelays{trackerTopo};
0126   std::unordered_map<uint32_t, double>::const_iterator it = delays_.begin();
0127   for (; it != delays_.end(); ++it) {
0128     summaryDelays.add(it->first, it->second);
0129   }
0130   summaryDelays.print(ss);
0131 }