Go to the documentation of this file.00001 #include "CondFormats/SiStripObjects/interface/SiStripLatency.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 #include <algorithm>
00006 #include <iterator>
00007 #include <iostream>
00008 #include <sstream>
00009
00010 bool SiStripLatency::put( const uint32_t detId, const uint16_t apv, const uint16_t latency, const uint16_t mode )
00011 {
00012 if( detId > 536870911 ) {
00013 std::stringstream error;
00014 error << "ERROR: the detId = " << detId << " is bigger than the maximum acceptable value = 2^(29) - 1 = " << 536870911 << std::endl;
00015 error << "Since we are using 29 bits for the detId and 3 bits for the apv value. The maximum tracker detId at the moment" << std::endl;
00016 error << "of the writing of this class was 47017836 as defined in CalibTracker/SiStripCommon/data/SiStripDetInfo.dat." << std::endl;
00017 error << "If the maximum value has changed a revision of this calss is needed, possibly changing the detIdAndApv value from" << std::endl;
00018 error << "from uint32_t to uint64_t." << std::endl;
00019 edm::LogError("SiStripLatency::put") << error;
00020 throw cms::Exception("InsertFailure");
00021 }
00022
00023
00024 uint32_t detIdAndApv = (detId << 3) | apv;
00025 latIt pos = lower_bound(latencies_.begin(), latencies_.end(), detIdAndApv, OrderByDetIdAndApv());
00026
00027 if( pos != latencies_.end() && pos->detIdAndApv == detIdAndApv ) {
00028 std::cout << "Value already inserted, skipping insertion" << std::endl;
00029 return false;
00030 }
00031
00032 latencies_.insert(pos, Latency(detIdAndApv, latency, mode));
00033
00034 return true;
00035 }
00036
00037 void SiStripLatency::compress()
00038 {
00039 latIt lat = latencies_.begin();
00040 while( lat != latencies_.end() ) {
00041
00042 if( ((lat+1) != latencies_.end()) && ((lat+1)->mode == lat->mode) && ((lat+1)->latency == lat->latency) ) {
00043 lat = latencies_.erase(lat);
00044 }
00045 else {
00046 ++lat;
00047 }
00048 }
00049 }
00050
00051 uint16_t SiStripLatency::latency(const uint32_t detId, const uint16_t apv) const
00052 {
00053 const latConstIt & pos = position(detId, apv);
00054 if( pos == latencies_.end() ) {
00055 return 255;
00056 }
00057 return pos->latency;
00058 }
00059
00060 uint16_t SiStripLatency::mode(const uint32_t detId, const uint16_t apv) const
00061 {
00062 const latConstIt & pos = position(detId, apv);
00063 if( pos == latencies_.end() ) {
00064 return 0;
00065 }
00066 return pos->mode;
00067 }
00068
00069 std::pair<uint16_t, uint16_t> SiStripLatency::latencyAndMode(const uint32_t detId, const uint16_t apv) const
00070 {
00071 const latConstIt & pos = position(detId, apv);
00072 if( pos == latencies_.end() ) {
00073 return std::make_pair(255, 0);
00074 }
00075 return std::make_pair(pos->latency, pos->mode);
00076 }
00077
00078 uint16_t SiStripLatency::singleLatency() const
00079 {
00080 if( latencies_.size() == 1 ) {
00081 return latencies_[0].latency;
00082 }
00083 int differentLatenciesNum = 0;
00084
00085 for( latConstIt it = latencies_.begin(); it != latencies_.end()-1; ++it ) {
00086 if( it->latency != (it+1)->latency ) {
00087 ++differentLatenciesNum;
00088 }
00089 }
00090 if( differentLatenciesNum == 0 ) {
00091 return latencies_[0].latency;
00092 }
00093 return 255;
00094 }
00095
00096 uint16_t SiStripLatency::singleMode() const
00097 {
00098 if( latencies_.size() == 1 ) {
00099 return latencies_[0].mode;
00100 }
00101 int differentModesNum = 0;
00102
00103 for( latConstIt it = latencies_.begin(); it != latencies_.end()-1; ++it ) {
00104 if( it->mode != (it+1)->mode ) {
00105 ++differentModesNum;
00106 }
00107 }
00108 if( differentModesNum == 0 ) {
00109 return latencies_[0].mode;
00110 }
00111 return 0;
00112 }
00113
00114 void SiStripLatency::allModes(std::vector<uint16_t> & allModesVector) const
00115 {
00116 for( latConstIt it = latencies_.begin(); it != latencies_.end(); ++it ) {
00117 allModesVector.push_back(it->mode);
00118 }
00119
00120 sort( allModesVector.begin(), allModesVector.end() );
00121 allModesVector.erase( unique( allModesVector.begin(), allModesVector.end() ), allModesVector.end() );
00122 }
00123
00124 int16_t SiStripLatency::singleReadOutMode() const
00125 {
00126 uint16_t mode = singleMode();
00127 if(mode != 0 ) {
00128 if( (mode & READMODEMASK) == READMODEMASK ) return 1;
00129 if( (mode & READMODEMASK) == 0 ) return 0;
00130 }
00131 else {
00132
00133 bool allInPeakMode = true;
00134 bool allInDecoMode = true;
00135 std::vector<uint16_t> allModesVector;
00136 allModes(allModesVector);
00137 std::vector<uint16_t>::const_iterator it = allModesVector.begin();
00138 if (allModesVector.size() == 1 && allModesVector[0] == 0) allInPeakMode = false;
00139 else{
00140 for( ; it != allModesVector.end(); ++it ) {
00141 if( (*it) % 2 == 0 ) continue;
00142 if( ((*it) & READMODEMASK) == READMODEMASK ) allInDecoMode = false;
00143 if( ((*it) & READMODEMASK) == 0 ) allInPeakMode = false;
00144 }
00145 }
00146 if( allInPeakMode ) return 1;
00147 if( allInDecoMode ) return 0;
00148 }
00149 return -1;
00150 }
00151
00152
00153 void SiStripLatency::allLatencies(std::vector<uint16_t> & allLatenciesVector) const
00154 {
00155
00156 for( latConstIt it = latencies_.begin(); it != latencies_.end(); ++it ) {
00157 allLatenciesVector.push_back(it->latency);
00158 }
00159
00160 sort( allLatenciesVector.begin(), allLatenciesVector.end() );
00161 allLatenciesVector.erase( unique( allLatenciesVector.begin(), allLatenciesVector.end() ), allLatenciesVector.end() );
00162 }
00163
00164
00165 std::vector<SiStripLatency::Latency> SiStripLatency::allUniqueLatencyAndModes()
00166 {
00167 std::vector<Latency> latencyCopy(latencies_);
00168 sort( latencyCopy.begin(), latencyCopy.end(), OrderByLatencyAndMode() );
00169 latencyCopy.erase( unique( latencyCopy.begin(), latencyCopy.end(), SiStripLatency::EqualByLatencyAndMode() ), latencyCopy.end() );
00170 return latencyCopy;
00171 }
00172
00173 void SiStripLatency::printSummary(std::stringstream & ss) const
00174 {
00175 ss << std::endl;
00176 if(singleReadOutMode()==1){
00177 ss << "SingleReadOut = PEAK" << std::endl;
00178 }else if(singleReadOutMode()==0){
00179 ss << "SingleReadOut = DECO" << std::endl;
00180 }else{
00181 ss << "SingleReadOut = MIXED" << std::endl;
00182 }
00183 uint16_t lat = singleLatency();
00184 if( lat != 255 ) {
00185 ss << "All the Tracker has the same latency = " << lat << std::endl;
00186 }
00187 else {
00188 std::vector<uint16_t> allLatenciesVector;
00189 allLatencies(allLatenciesVector);
00190 if( allLatenciesVector.size() > 1 ) {
00191 ss << "There is more than one latency value in the Tracker" << std::endl;
00192 }
00193 else {
00194 ss << "Latency value is " << lat << " that means invalid" << std::endl;
00195 }
00196 }
00197 ss << "Total number of ranges = " << latencies_.size() << std::endl;
00198 printDebug(ss);
00199 }
00200
00201
00202 void SiStripLatency::printDebug(std::stringstream & ss) const
00203 {
00204 ss << "List of all the latencies and modes for the " << latencies_.size() << " ranges in the object:" << std::endl;
00205 for( latConstIt it = latencies_.begin(); it != latencies_.end(); ++it ) {
00206 int detId = it->detIdAndApv >> 3;
00207 int apv = it->detIdAndApv & 7;
00208 ss << "for detId = " << detId << " and apv pair = " << apv << " latency = " << int(it->latency) << " and mode = " << int(it->mode) << std::endl;
00209 }
00210 }
00211
00212 #undef READMODEMASK