CMS 3D CMS Logo

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