CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CondFormats/SiStripObjects/interface/SiStripLatency.h

Go to the documentation of this file.
00001 #ifndef SiStripLatency_h
00002 #define SiStripLatency_h
00003 
00004 #include <vector>
00005 #include <algorithm>
00006 #include <stdint.h>
00007 #include <sstream>
00008 
00009 #define READMODEMASK 8
00010 
00055 class SiStripLatency
00056 {
00057  public:
00058 
00059   SiStripLatency() {}
00060 
00061   // Defined as public for genreflex
00062   struct Latency
00063   {
00064     Latency(const uint32_t inputDetIdAndApv, const uint16_t inputLatency, const uint16_t inputMode) :
00065       detIdAndApv(inputDetIdAndApv),
00066       latency(inputLatency),
00067       mode(inputMode)
00068     {}
00070     Latency() :
00071       detIdAndApv(0),
00072       latency(255),
00073       mode(0)
00074     {}
00075     uint32_t detIdAndApv;
00076     unsigned char latency;
00077     unsigned char mode;
00078   };
00079   typedef std::vector<Latency>::iterator latIt;
00080   typedef std::vector<Latency>::const_iterator latConstIt;
00081 
00088   bool put( const uint32_t detId, const uint16_t apv, const uint16_t latency, const uint16_t mode );
00089   uint16_t latency(const uint32_t detId, const uint16_t apv) const;
00090   uint16_t mode(const uint32_t detId, const uint16_t apv) const;
00091   std::pair<uint16_t, uint16_t> latencyAndMode(const uint32_t detId, const uint16_t apv) const;
00092   inline std::vector<Latency> allLatencyAndModes() const { return latencies_; }
00093 
00095   void allLatencies(std::vector<uint16_t> & allLatenciesVector) const;
00097   void allModes(std::vector<uint16_t> & allModesVector) const;
00098   int16_t singleReadOutMode() const;
00099   //   bool allPeak() const;
00100 
00101   std::vector<Latency> allUniqueLatencyAndModes();
00102 
00107   void compress();
00109   uint16_t singleLatency() const;
00110   uint16_t singleMode() const;
00111 
00113   void printSummary(std::stringstream & ss) const;
00115   void printDebug(std::stringstream & ss) const;
00116 
00117  private:
00118 
00119   struct OrderByDetIdAndApv
00120   {
00121     bool operator()(const Latency & lat1, const uint32_t detIdAndApv) const {
00122       return lat1.detIdAndApv < detIdAndApv;
00123     }
00124   };
00125 
00126   struct OrderByLatencyAndMode
00127   {
00128     bool operator()(const Latency & lat1, const Latency & lat2) {
00129       // latency and mode are unsigned short that cannot exceed 255.
00130       // Sum them multiplying the mode by 1000 to get a single ordering number.
00131       int latencyAndModeSortValue1 = int(lat1.latency) + 1000*int(lat1.mode);
00132       int latencyAndModeSortValue2 = int(lat2.latency) + 1000*int(lat2.mode);
00133       return( latencyAndModeSortValue1 < latencyAndModeSortValue2 );
00134     }
00135   };
00136   struct EqualByLatencyAndMode
00137   {
00138     bool operator()(const Latency & lat1, const Latency & lat2) {
00139       return( (lat1.latency == lat2.latency) && (lat1.mode == lat2.mode) );
00140     }
00141   };
00142 
00144   // If put in the cc file it will not know about the typedefs and the Latency class
00145   const latConstIt position(const uint32_t detId, const uint16_t apv) const
00146   {
00147     if( latencies_.empty() ) {
00148       // std::cout << "SiStripLatency: Error, range is empty" << std::endl;
00149       return latencies_.end();
00150     }
00151     uint32_t detIdAndApv = (detId << 3) | apv;
00152     latConstIt pos = lower_bound(latencies_.begin(), latencies_.end(), detIdAndApv, OrderByDetIdAndApv());
00153     return pos;
00154   }
00155   std::vector<Latency> latencies_;
00156 };
00157 
00158 #endif