CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
SiStripLatency Class Reference

#include <SiStripLatency.h>

Classes

struct  EqualByLatencyAndMode
 
struct  Latency
 
struct  OrderByDetIdAndApv
 
struct  OrderByLatencyAndMode
 

Public Types

typedef std::vector< Latency >::const_iterator latConstIt
 
typedef std::vector< Latency >::iterator latIt
 

Public Member Functions

void allLatencies (std::vector< uint16_t > &allLatenciesVector) const
 Fills the passed vector with all the possible latencies in the Tracker. More...
 
std::vector< LatencyallLatencyAndModes () const
 
void allModes (std::vector< uint16_t > &allModesVector) const
 Fills the passed vector with all the possible modes in the Tracker. More...
 
std::vector< LatencyallUniqueLatencyAndModes ()
 
void compress ()
 
uint16_t latency (const uint32_t detId, const uint16_t apv) const
 
std::pair< uint16_t, uint16_t > latencyAndMode (const uint32_t detId, const uint16_t apv) const
 
uint16_t mode (const uint32_t detId, const uint16_t apv) const
 
void printDebug (std::stringstream &ss, const TrackerTopology *trackerTopo) const
 Prints the full list of all ranges and corresponding values of latency and mode. More...
 
void printSummary (std::stringstream &ss, const TrackerTopology *trackerTopo) const
 Prints the number of ranges as well as the value of singleLatency and singleMode. More...
 
bool put (const uint32_t detId, const uint16_t apv, const uint16_t latency, const uint16_t mode)
 
uint16_t singleLatency () const
 If all the latency values stored are equal return that value, otherwise return -1. More...
 
uint16_t singleMode () const
 
int16_t singleReadOutMode () const
 
 SiStripLatency ()
 

Private Member Functions

const latConstIt position (const uint32_t detId, const uint16_t apv) const
 Used to compute the position with the lower_bound binary search. More...
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Private Attributes

std::vector< Latencylatencies_
 

Friends

class boost::serialization::access
 
template<typename CondSerializationT , typename Enabled >
struct cond::serialization::access
 

Detailed Description

Holds the latency and the mode of the run.
The latency is stored per apv and the information is compressed by reducing sequences of apvs with the same latency to a single value plus information on the start and end of the sequence.
The mode is a single value, stored as a char. The actual operation mode bit is bit number 3 starting from 0. The bitmask to retrieve the information in the number 8 (1000).

Definition at line 59 of file SiStripLatency.h.

Member Typedef Documentation

typedef std::vector<Latency>::const_iterator SiStripLatency::latConstIt

Definition at line 86 of file SiStripLatency.h.

typedef std::vector<Latency>::iterator SiStripLatency::latIt

Definition at line 85 of file SiStripLatency.h.

Constructor & Destructor Documentation

SiStripLatency::SiStripLatency ( )
inline

Definition at line 63 of file SiStripLatency.h.

63 {}

Member Function Documentation

void SiStripLatency::allLatencies ( std::vector< uint16_t > &  allLatenciesVector) const

Fills the passed vector with all the possible latencies in the Tracker.

Definition at line 153 of file SiStripLatency.cc.

References latencies_, and tier0::unique().

Referenced by allLatencyAndModes(), and printSummary().

154 {
155 
156  for( latConstIt it = latencies_.begin(); it != latencies_.end(); ++it ) {
157  allLatenciesVector.push_back(it->latency);
158  }
159  // The Latencies are sorted by DetIdAndApv, we need to sort the latencies again and then remove duplicates
160  sort( allLatenciesVector.begin(), allLatenciesVector.end() );
161  allLatenciesVector.erase( unique( allLatenciesVector.begin(), allLatenciesVector.end() ), allLatenciesVector.end() );
162 }
def unique(seq, keepstr=True)
Definition: tier0.py:24
std::vector< Latency > latencies_
std::vector< Latency >::const_iterator latConstIt
std::vector<Latency> SiStripLatency::allLatencyAndModes ( ) const
inline
void SiStripLatency::allModes ( std::vector< uint16_t > &  allModesVector) const

Fills the passed vector with all the possible modes in the Tracker.

Definition at line 114 of file SiStripLatency.cc.

References latencies_, and tier0::unique().

Referenced by allLatencyAndModes(), and singleReadOutMode().

115 {
116  for( latConstIt it = latencies_.begin(); it != latencies_.end(); ++it ) {
117  allModesVector.push_back(it->mode);
118  }
119  // The Latencies are sorted by DetIdAndApv, we need to sort the modes again and then remove duplicates
120  sort( allModesVector.begin(), allModesVector.end() );
121  allModesVector.erase( unique( allModesVector.begin(), allModesVector.end() ), allModesVector.end() );
122 }
def unique(seq, keepstr=True)
Definition: tier0.py:24
std::vector< Latency > latencies_
std::vector< Latency >::const_iterator latConstIt
std::vector< SiStripLatency::Latency > SiStripLatency::allUniqueLatencyAndModes ( )

Definition at line 165 of file SiStripLatency.cc.

References latencies_, and tier0::unique().

Referenced by allLatencyAndModes().

166 {
167  std::vector<Latency> latencyCopy(latencies_);
168  sort( latencyCopy.begin(), latencyCopy.end(), OrderByLatencyAndMode() );
169  latencyCopy.erase( unique( latencyCopy.begin(), latencyCopy.end(), SiStripLatency::EqualByLatencyAndMode() ), latencyCopy.end() );
170  return latencyCopy;
171 }
def unique(seq, keepstr=True)
Definition: tier0.py:24
std::vector< Latency > latencies_
void SiStripLatency::compress ( )

Reduce ranges of consecutive detIdsAndApvs with the same latency and mode to one value (the latest) so that lower_bound will return the correct value for latency and mode.

Definition at line 37 of file SiStripLatency.cc.

References latencies_.

Referenced by allLatencyAndModes(), and SiStripCondObjBuilderFromDb::buildFECRelatedObjects().

38 {
39  latIt lat = latencies_.begin();
40  while( lat != latencies_.end() ) {
41  // If it is not the last and it has the same latency and mode as the next one remove it
42  if( ((lat+1) != latencies_.end()) && ((lat+1)->mode == lat->mode) && ((lat+1)->latency == lat->latency) ) {
43  lat = latencies_.erase(lat);
44  }
45  else {
46  ++lat;
47  }
48  }
49 }
Definition: DQMStore.h:29
std::vector< Latency >::iterator latIt
std::vector< Latency > latencies_
uint16_t SiStripLatency::latency ( const uint32_t  detId,
const uint16_t  apv 
) const

Definition at line 51 of file SiStripLatency.cc.

References latencies_, and position().

52 {
53  const latConstIt & pos = position(detId, apv);
54  if( pos == latencies_.end() ) {
55  return 255;
56  }
57  return pos->latency;
58 }
const latConstIt position(const uint32_t detId, const uint16_t apv) const
Used to compute the position with the lower_bound binary search.
std::vector< Latency > latencies_
std::vector< Latency >::const_iterator latConstIt
std::pair< uint16_t, uint16_t > SiStripLatency::latencyAndMode ( const uint32_t  detId,
const uint16_t  apv 
) const

Definition at line 69 of file SiStripLatency.cc.

References latencies_, and position().

70 {
71  const latConstIt & pos = position(detId, apv);
72  if( pos == latencies_.end() ) {
73  return std::make_pair(255, 0);
74  }
75  return std::make_pair(pos->latency, pos->mode);
76 }
const latConstIt position(const uint32_t detId, const uint16_t apv) const
Used to compute the position with the lower_bound binary search.
std::vector< Latency > latencies_
std::vector< Latency >::const_iterator latConstIt
uint16_t SiStripLatency::mode ( const uint32_t  detId,
const uint16_t  apv 
) const

Definition at line 60 of file SiStripLatency.cc.

References latencies_, and position().

Referenced by singleReadOutMode().

61 {
62  const latConstIt & pos = position(detId, apv);
63  if( pos == latencies_.end() ) {
64  return 0;
65  }
66  return pos->mode;
67 }
const latConstIt position(const uint32_t detId, const uint16_t apv) const
Used to compute the position with the lower_bound binary search.
std::vector< Latency > latencies_
std::vector< Latency >::const_iterator latConstIt
const latConstIt SiStripLatency::position ( const uint32_t  detId,
const uint16_t  apv 
) const
inlineprivate

Used to compute the position with the lower_bound binary search.

Definition at line 151 of file SiStripLatency.h.

References SiStripLatency::Latency::detIdAndApv, and latencies_.

Referenced by latency(), latencyAndMode(), and mode().

152  {
153  if( latencies_.empty() ) {
154  // std::cout << "SiStripLatency: Error, range is empty" << std::endl;
155  return latencies_.end();
156  }
157  uint32_t detIdAndApv = (detId << 3) | apv;
158  latConstIt pos = lower_bound(latencies_.begin(), latencies_.end(), detIdAndApv, OrderByDetIdAndApv());
159  return pos;
160  }
std::vector< Latency > latencies_
std::vector< Latency >::const_iterator latConstIt
void SiStripLatency::printDebug ( std::stringstream &  ss,
const TrackerTopology trackerTopo 
) const

Prints the full list of all ranges and corresponding values of latency and mode.

Definition at line 202 of file SiStripLatency.cc.

References createfilelist::int, and latencies_.

Referenced by allLatencyAndModes(), SiStripCondObjBuilderFromDb::buildFECRelatedObjects(), and printSummary().

203 {
204  ss << "List of all the latencies and modes for the " << latencies_.size() << " ranges in the object:" << std::endl;
205  for( latConstIt it = latencies_.begin(); it != latencies_.end(); ++it ) {
206  int detId = it->detIdAndApv >> 3;
207  int apv = it->detIdAndApv & 7; // 7 is 0...0111
208  ss << "for detId = " << detId << " and apv pair = " << apv << " latency = " << int(it->latency) << " and mode = " << int(it->mode) << std::endl;
209  }
210 }
std::vector< Latency > latencies_
std::vector< Latency >::const_iterator latConstIt
void SiStripLatency::printSummary ( std::stringstream &  ss,
const TrackerTopology trackerTopo 
) const

Prints the number of ranges as well as the value of singleLatency and singleMode.

Definition at line 173 of file SiStripLatency.cc.

References allLatencies(), latencies_, printDebug(), singleLatency(), and singleReadOutMode().

Referenced by allLatencyAndModes(), and SiStripCondObjBuilderFromDb::buildFECRelatedObjects().

174 {
175  ss << std::endl;
176  if(singleReadOutMode()==1){
177  ss << "SingleReadOut = PEAK" << std::endl;
178  }else if(singleReadOutMode()==0){
179  ss << "SingleReadOut = DECO" << std::endl;
180  }else{
181  ss << "SingleReadOut = MIXED" << std::endl;
182  }
183  uint16_t lat = singleLatency();
184  if( lat != 255 ) {
185  ss << "All the Tracker has the same latency = " << lat << std::endl;
186  }
187  else {
188  std::vector<uint16_t> allLatenciesVector;
189  allLatencies(allLatenciesVector);
190  if( allLatenciesVector.size() > 1 ) {
191  ss << "There is more than one latency value in the Tracker" << std::endl;
192  }
193  else {
194  ss << "Latency value is " << lat << " that means invalid" << std::endl;
195  }
196  }
197  ss << "Total number of ranges = " << latencies_.size() << std::endl;
198  printDebug(ss, trackerTopo);
199 }
int16_t singleReadOutMode() const
Definition: DQMStore.h:29
void allLatencies(std::vector< uint16_t > &allLatenciesVector) const
Fills the passed vector with all the possible latencies in the Tracker.
uint16_t singleLatency() const
If all the latency values stored are equal return that value, otherwise return -1.
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints the full list of all ranges and corresponding values of latency and mode.
std::vector< Latency > latencies_
bool SiStripLatency::put ( const uint32_t  detId,
const uint16_t  apv,
const uint16_t  latency,
const uint16_t  mode 
)

Saves the detIdAndApv and latency values in the vector of Latency objects. At the end of the filling phase, the compress method should be called to collapse all ranges in single values. Note that everything would work even if the compress method is not called, only the space used would be more than needed.

Definition at line 10 of file SiStripLatency.cc.

References gather_cfg::cout, relativeConstraints::error, Exception, and latencies_.

Referenced by SiStripCondObjBuilderFromDb::setDefaultValuesApvLatency(), and SiStripCondObjBuilderFromDb::setValuesApvLatency().

11 {
12  if( detId > 536870911 ) {
13  std::stringstream error;
14  error << "ERROR: the detId = " << detId << " is bigger than the maximum acceptable value = 2^(29) - 1 = " << 536870911 << std::endl;
15  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;
16  error << "of the writing of this class was 47017836 as defined in CalibTracker/SiStripCommon/data/SiStripDetInfo.dat." << std::endl;
17  error << "If the maximum value has changed a revision of this calss is needed, possibly changing the detIdAndApv value from" << std::endl;
18  error << "from uint32_t to uint64_t." << std::endl;
19  edm::LogError("SiStripLatency::put") << error.str();
20  throw cms::Exception("InsertFailure");
21  }
22 
23  // Store all the values in the vectors
24  uint32_t detIdAndApv = (detId << 3) | apv;
25  latIt pos = lower_bound(latencies_.begin(), latencies_.end(), detIdAndApv, OrderByDetIdAndApv());
26 
27  if( pos != latencies_.end() && pos->detIdAndApv == detIdAndApv ) {
28  std::cout << "Value already inserted, skipping insertion" << std::endl;
29  return false;
30  }
31  // std::cout << "Filling with: latency = " << latency << ", mode = " << mode << std::endl;
32  latencies_.insert(pos, Latency(detIdAndApv, latency, mode));
33 
34  return true;
35 }
std::vector< Latency >::iterator latIt
uint16_t mode(const uint32_t detId, const uint16_t apv) const
uint16_t latency(const uint32_t detId, const uint16_t apv) const
std::vector< Latency > latencies_
template<class Archive >
void SiStripLatency::serialize ( Archive &  ar,
const unsigned int  version 
)
private
uint16_t SiStripLatency::singleLatency ( ) const

If all the latency values stored are equal return that value, otherwise return -1.

Definition at line 78 of file SiStripLatency.cc.

References latencies_.

Referenced by allLatencyAndModes(), EventWithHistoryFilter::getAPVLatency(), and printSummary().

79 {
80  if( latencies_.size() == 1 ) {
81  return latencies_[0].latency;
82  }
83  int differentLatenciesNum = 0;
84  // Count the number of different latencies
85  for( latConstIt it = latencies_.begin(); it != latencies_.end()-1; ++it ) {
86  if( it->latency != (it+1)->latency ) {
87  ++differentLatenciesNum;
88  }
89  }
90  if( differentLatenciesNum == 0 ) {
91  return latencies_[0].latency;
92  }
93  return 255;
94 }
std::vector< Latency > latencies_
std::vector< Latency >::const_iterator latConstIt
uint16_t SiStripLatency::singleMode ( ) const

Definition at line 96 of file SiStripLatency.cc.

References latencies_.

Referenced by allLatencyAndModes(), and singleReadOutMode().

97 {
98  if( latencies_.size() == 1 ) {
99  return latencies_[0].mode;
100  }
101  int differentModesNum = 0;
102  // Count the number of different modes
103  for( latConstIt it = latencies_.begin(); it != latencies_.end()-1; ++it ) {
104  if( it->mode != (it+1)->mode ) {
105  ++differentModesNum;
106  }
107  }
108  if( differentModesNum == 0 ) {
109  return latencies_[0].mode;
110  }
111  return 0;
112 }
std::vector< Latency > latencies_
std::vector< Latency >::const_iterator latConstIt
int16_t SiStripLatency::singleReadOutMode ( ) const

Definition at line 124 of file SiStripLatency.cc.

References allModes(), mode(), READMODEMASK, and singleMode().

Referenced by allLatencyAndModes(), SiStripLorentzAngleCalibration::derivatives(), SiStripBackplaneCalibration::derivatives(), EventWithHistoryFilter::getAPVMode(), and printSummary().

125 {
126  uint16_t mode = singleMode();
127  if(mode != 0 ) {
128  if( (mode & READMODEMASK) == READMODEMASK ) return 1;
129  if( (mode & READMODEMASK) == 0 ) return 0;
130  }
131  else {
132  // If we are here the Tracker is not in single mode. Check if it is in single Read-out mode.
133  bool allInPeakMode = true;
134  bool allInDecoMode = true;
135  std::vector<uint16_t> allModesVector;
136  allModes(allModesVector);
137  std::vector<uint16_t>::const_iterator it = allModesVector.begin();
138  if (allModesVector.size() == 1 && allModesVector[0] == 0) allInPeakMode = false;
139  else{
140  for( ; it != allModesVector.end(); ++it ) {
141  if( (*it) % 2 == 0 ) continue;
142  if( ((*it) & READMODEMASK) == READMODEMASK ) allInDecoMode = false;
143  if( ((*it) & READMODEMASK) == 0 ) allInPeakMode = false;
144  }
145  }
146  if( allInPeakMode ) return 1;
147  if( allInDecoMode ) return 0;
148  }
149  return -1;
150 }
uint16_t mode(const uint32_t detId, const uint16_t apv) const
void allModes(std::vector< uint16_t > &allModesVector) const
Fills the passed vector with all the possible modes in the Tracker.
uint16_t singleMode() const
#define READMODEMASK

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 163 of file SiStripLatency.h.

template<typename CondSerializationT , typename Enabled >
friend struct cond::serialization::access
friend

Definition at line 163 of file SiStripLatency.h.

Member Data Documentation

std::vector<Latency> SiStripLatency::latencies_
private