CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/CalibFormats/SiStripObjects/src/SiStripDelay.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     SiStripObjects
00004 // Class  :     SiStripDelay
00005 // Implementation:
00006 //     <Notes on implementation>
00007 // Original Author:  M. De Mattia
00008 //         Created:  26/10/2010
00009 // $Id: SiStripDelay.cc,v 1.2 2010/11/04 14:31:55 demattia Exp $
00010 
00011 #include "FWCore/Utilities/interface/typelookup.h"
00012 #include "CalibFormats/SiStripObjects/interface/SiStripDelay.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
00015 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00016 #include <sstream>
00017 
00018 void SiStripDelay::fillNewDelay(const SiStripBaseDelay& baseDelay, const int sumSign,
00019                                 const std::pair<std::string, std::string> & recordLabelPair)
00020 {
00021   baseDelayVector_.push_back(&baseDelay);
00022   sumSignVector_.push_back(sumSign);
00023   recordLabelPair_.push_back(recordLabelPair);
00024 }
00025 
00026 float SiStripDelay::getDelay(const uint32_t detId) const
00027 {
00028   boost::unordered_map<uint32_t, double>::const_iterator it = delays_.find(detId);
00029   if( it != delays_.end() ) {
00030     return it->second;
00031   }
00032   return 0.;
00033 }
00034 
00035 bool SiStripDelay::makeDelay()
00036 {
00037   if( baseDelayVector_.empty() ) {
00038     return false;
00039   }
00040   std::vector<const SiStripBaseDelay*>::const_iterator it = baseDelayVector_.begin();
00041   // Check for consistent size in all baseDelays
00042   if( baseDelayVector_.size() > 1 ) {
00043     for( ; it != baseDelayVector_.end()-1; ++it ) {
00044       if( (*it)->delaysSize() != (*(it+1))->delaysSize() ) {
00045         std::cout << "makeDelay: Error, size of base delays is different!!" << std::endl;
00046         return false;
00047       }
00048     }
00049   }
00050   
00051 //   // All checks done, fill the boost::unoredered_map with the first one (initialization)
00052 //   int sumSignIndex = 0;
00053 //   int sumSign = 0;
00054 //   std::vector<uint32_t>::const_iterator detIdIt;
00055 //   for( it = baseDelayVector_.begin(); it != baseDelayVector_.end(); ++it, ++sumSignIndex ) {
00056 //     std::vector<uint32_t> detIds;
00057 //     (*it)->detIds(detIds);
00058 //     sumSign = sumSignVector_[sumSignIndex];
00059 //     for( detIdIt = detIds.begin(); detIdIt != detIds.end(); ++detIdIt ) {
00060 //       // Check if is alread there so that we never rely on the default initialization
00061 //       boost::unordered_map<uint32_t, double>::iterator delayIt = delays_.find(*detIdIt);
00062 //       if( delayIt != delays_.end() ) {
00063 //      std::cout << "second delay = " << (*it)->delay(*detIdIt)*sumSign << std::endl;
00064 //      delays_[*detIdIt] += (*it)->delay(*detIdIt)*sumSign;
00065 //      std::cout << "Full delay = " << delays_[*detIdIt] << std::endl;
00066 //       }
00067 //       else {
00068 //      std::cout << "first delay = " << (*it)->delay(*detIdIt)*sumSign << std::endl;
00069 //      delays_[*detIdIt] = (*it)->delay(*detIdIt)*sumSign;
00070 //       }
00071 //     }
00072 //   }
00073 
00074   // All checks done, fill the boost::unoredered_map with the first one (initialization)
00075   int sumSignIndex = 0;
00076   int sumSign = sumSignVector_[sumSignIndex];
00077   it = baseDelayVector_.begin();
00078   std::vector<uint32_t> detIds;
00079   (*it)->detIds(detIds);
00080   std::vector<uint32_t>::const_iterator detIdIt = detIds.begin();
00081   for( ; detIdIt != detIds.end(); ++detIdIt ) {
00082     delays_[*detIdIt] = (*it)->delay(*detIdIt)*sumSign;
00083   }
00084   ++it;
00085   ++sumSignIndex;
00086   // Fill all the others
00087   for( ; it != baseDelayVector_.end(); ++it, ++sumSignIndex ) {
00088     std::vector<uint32_t> detIds;
00089     (*it)->detIds(detIds);
00090     detIdIt = detIds.begin();
00091     sumSign = sumSignVector_[sumSignIndex];
00092     for( ; detIdIt != detIds.end(); ++detIdIt ) {
00093       // The same detIds should be in both maps, if not don't rely on the default initialization
00094       boost::unordered_map<uint32_t, double>::iterator delayIt = delays_.find(*detIdIt);
00095       if( delayIt != delays_.end() ) {
00096         delays_[*detIdIt] += (*it)->delay(*detIdIt)*sumSign;
00097       }
00098       else {
00099         std::cout << "makeDelay: Warning, detId = " << *detIdIt << " not present, summing to 0..." << std::cout;
00100         std::cout << "This means that the two baseDelay tags have different detIds. PLEASE, CHECK THAT THIS IS EXPECTED." << std::cout;
00101         delays_[*detIdIt] = (*it)->delay(*detIdIt)*sumSign;
00102       }
00103     }
00104   }
00105 
00106   return true;
00107 }
00108 
00109 void SiStripDelay::clear()
00110 {
00111   baseDelayVector_.clear();
00112   sumSignVector_.clear();
00113   recordLabelPair_.clear();
00114   delays_.clear();
00115 }
00116 
00117 void SiStripDelay::printDebug(std::stringstream & ss) const
00118 {
00119   boost::unordered_map<uint32_t, double>::const_iterator it = delays_.begin();
00120   for( ; it != delays_.end(); ++it ) {
00121     ss << "detId = " << it->first << " delay = " << it->second << std::endl;
00122   }
00123 }
00124 
00125 void SiStripDelay::printSummary(std::stringstream& ss) const
00126 {
00127   SiStripDetSummary summaryDelays;
00128   boost::unordered_map<uint32_t, double>::const_iterator it = delays_.begin();
00129   for( ; it != delays_.end(); ++it ) {
00130     summaryDelays.add(it->first, it->second);
00131   }
00132   summaryDelays.print(ss);
00133 }