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
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 latIt lat = latencies_.begin();
00055 while( lat != latencies_.end() ) {
00056
00057 if( ((lat+1) != latencies_.end()) && ((lat+1)->mode == lat->mode) && ((lat+1)->latency == lat->latency) ) {
00058 lat = latencies_.erase(lat);
00059 }
00060 else {
00061 ++lat;
00062 }
00063 }
00064
00065
00066
00067
00068
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 uint16_t SiStripLatency::latency(const uint32_t detId, const uint16_t apv) const
00083 {
00084 const latConstIt & pos = position(detId, apv);
00085 if( pos == latencies_.end() ) {
00086 return 255;
00087 }
00088 return pos->latency;
00089 }
00090
00091 uint16_t SiStripLatency::mode(const uint32_t detId, const uint16_t apv) const
00092 {
00093 const latConstIt & pos = position(detId, apv);
00094 if( pos == latencies_.end() ) {
00095 return 0;
00096 }
00097 return pos->mode;
00098 }
00099
00100 std::pair<uint16_t, uint16_t> SiStripLatency::latencyAndMode(const uint32_t detId, const uint16_t apv) const
00101 {
00102 const latConstIt & pos = position(detId, apv);
00103 if( pos == latencies_.end() ) {
00104 return std::make_pair(255, 0);
00105 }
00106 return std::make_pair(pos->latency, pos->mode);
00107 }
00108
00109 uint16_t SiStripLatency::singleLatency() const
00110 {
00111 if( latencies_.size() == 1 ) {
00112 return latencies_[0].latency;
00113 }
00114 int differentLatenciesNum = 0;
00115
00116 for( latConstIt it = latencies_.begin(); it != latencies_.end()-1; ++it ) {
00117 if( it->latency != (it+1)->latency ) {
00118 ++differentLatenciesNum;
00119 }
00120 }
00121 if( differentLatenciesNum == 0 ) {
00122 return latencies_[0].latency;
00123 }
00124 return 255;
00125 }
00126
00127 uint16_t SiStripLatency::singleMode() const
00128 {
00129 if( latencies_.size() == 1 ) {
00130 return latencies_[0].mode;
00131 }
00132 int differentModesNum = 0;
00133
00134 for( latConstIt it = latencies_.begin(); it != latencies_.end()-1; ++it ) {
00135 if( it->mode != (it+1)->mode ) {
00136 ++differentModesNum;
00137 }
00138 }
00139 if( differentModesNum == 0 ) {
00140 return latencies_[0].mode;
00141 }
00142 return 0;
00143 }
00144
00145 void SiStripLatency::allModes(std::vector<uint16_t> & allModesVector) const
00146 {
00147 for( latConstIt it = latencies_.begin(); it != latencies_.end(); ++it ) {
00148 allModesVector.push_back(it->mode);
00149 }
00150
00151 sort( allModesVector.begin(), allModesVector.end() );
00152 allModesVector.erase( unique( allModesVector.begin(), allModesVector.end() ), allModesVector.end() );
00153 }
00154
00155 int16_t SiStripLatency::singleReadOutMode() const
00156 {
00157 uint16_t mode = singleMode();
00158 if(mode != 0 ) {
00159 if( (mode & READMODEMASK) == READMODEMASK ) return 1;
00160 if( (mode & READMODEMASK) == 0 ) return 0;
00161 }
00162 else {
00163
00164 bool allInPeakMode = true;
00165 bool allInDecoMode = true;
00166 std::vector<uint16_t> allModesVector;
00167 allModes(allModesVector);
00168 std::vector<uint16_t>::const_iterator it = allModesVector.begin();
00169 for( ; it != allModesVector.end(); ++it ) {
00170 if( ((*it) & READMODEMASK) == READMODEMASK ) allInDecoMode = false;
00171 if( ((*it) & READMODEMASK) == 0 ) allInPeakMode = false;
00172 }
00173 if( allInPeakMode ) return 1;
00174 if( allInDecoMode ) return 0;
00175 }
00176 return -1;
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 void SiStripLatency::allLatencies(std::vector<uint16_t> & allLatenciesVector) const
00194 {
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 for( latConstIt it = latencies_.begin(); it != latencies_.end(); ++it ) {
00211 allLatenciesVector.push_back(it->latency);
00212 }
00213
00214 sort( allLatenciesVector.begin(), allLatenciesVector.end() );
00215 allLatenciesVector.erase( unique( allLatenciesVector.begin(), allLatenciesVector.end() ), allLatenciesVector.end() );
00216 }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 std::vector<SiStripLatency::Latency> SiStripLatency::allUniqueLatencyAndModes()
00227 {
00228 std::vector<Latency> latencyCopy(latencies_);
00229 sort( latencyCopy.begin(), latencyCopy.end(), OrderByLatencyAndMode() );
00230 latencyCopy.erase( unique( latencyCopy.begin(), latencyCopy.end(), SiStripLatency::EqualByLatencyAndMode() ), latencyCopy.end() );
00231 return latencyCopy;
00232 }
00233
00234 void SiStripLatency::printSummary(std::stringstream & ss) const
00235 {
00236 uint16_t lat = singleLatency();
00237 uint16_t mode = singleMode();
00238 if( lat != 255 ) {
00239 ss << "All the Tracker has the same latency = " << lat << std::endl;
00240 }
00241 else {
00242 std::vector<uint16_t> allLatenciesVector;
00243 allLatencies(allLatenciesVector);
00244 if( allLatenciesVector.size() > 1 ) {
00245 ss << "There is more than one latency value in the Tracker" << std::endl;
00246 }
00247 else {
00248 ss << "Latency value is " << lat << " that means invalid" << std::endl;
00249 }
00250 }
00251
00252 if( mode != 0 ) {
00253 ss << "All the Tracker has the same mode = " << mode << std::endl;
00254 }
00255 else {
00256 std::vector<uint16_t> allModesVector;
00257 allModes(allModesVector);
00258 if( allModesVector.size() > 1 ) {
00259 ss << "There is more than one mode in the Tracker" << std::endl;
00260 }
00261 else {
00262 ss << "Mode value is " << mode << " that means invalid" << std::endl;
00263 }
00264 }
00265
00266 ss << "Total number of ranges = " << latencies_.size() << std::endl;
00267 }
00268
00269 void SiStripLatency::printDebug(std::stringstream & ss) const
00270 {
00271 ss << "List of all the latencies and modes for the " << latencies_.size() << " ranges in the object:" << std::endl;
00272 for( latConstIt it = latencies_.begin(); it != latencies_.end(); ++it ) {
00273 int detId = it->detIdAndApv >> 3;
00274 int apv = it->detIdAndApv & 7;
00275 ss << "for detId = " << detId << " and apv pair = " << apv << " latency = " << int(it->latency) << " and mode = " << int(it->mode) << std::endl;
00276 }
00277 }
00278
00279 #undef READMODEMASK