CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CondFormats/SiStripObjects/interface/SiStripFedCabling.h

Go to the documentation of this file.
00001 #ifndef CondFormats_SiStripObjects_SiStripFedCabling_H
00002 #define CondFormats_SiStripObjects_SiStripFedCabling_H
00003 
00004 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00005 #include <boost/range/iterator_range.hpp>
00006 #include <boost/cstdint.hpp>
00007 #include <sstream>
00008 #include <vector>
00009 #include <string>
00010 
00011 #define SISTRIPCABLING_USING_NEW_STRUCTURE
00012 #define SISTRIPCABLING_USING_NEW_INTERFACE
00013 
00014 
00015 // -------------------------------------------------------
00016 #ifndef SISTRIPCABLING_USING_NEW_STRUCTURE // ------------
00017 // -------------------------------------------------------
00018 
00019 
00020 class SiStripFedCabling;
00021 
00023 std::ostream& operator<< ( std::ostream&, const SiStripFedCabling& );
00024 
00030 class SiStripFedCabling {
00031   
00032  public:
00033   
00034   // -------------------- Constructors, destructors --------------------
00035 
00037   SiStripFedCabling( const std::vector<FedChannelConnection>& );
00038 
00040   SiStripFedCabling( const SiStripFedCabling& ); 
00041 
00043   SiStripFedCabling();
00044 
00046   ~SiStripFedCabling();
00047 
00048   // -------------------- Utility methods --------------------
00049   
00051   void buildFedCabling( const std::vector<FedChannelConnection>& connections );
00052   
00054   void print( std::stringstream& ) const;
00055   
00057   void terse( std::stringstream& ) const;
00058   
00060   void summary( std::stringstream& ) const;
00061 
00062   // -------------------- Methods to retrieve connections --------------------
00063 
00065   const std::vector<uint16_t>& feds() const;
00066   
00068   const std::vector<FedChannelConnection>& connections( uint16_t fed_id ) const; 
00069   
00071   const FedChannelConnection& connection( uint16_t fed_id,
00072                                           uint16_t fed_chan ) const; 
00073   
00075   inline const std::vector<FedChannelConnection>& detected() const; 
00076   
00078   inline const std::vector<FedChannelConnection>& undetected() const; 
00079   
00080   // -------------------- Private member data --------------------
00081 
00082  private:
00083   
00085   std::vector<uint16_t> feds_;
00086 
00095   std::vector< std::vector<FedChannelConnection> > connected_;
00096 
00103   std::vector<FedChannelConnection> detected_;
00104 
00113   std::vector<FedChannelConnection> undetected_;
00114 
00115 };
00116 
00117 const std::vector<FedChannelConnection>& SiStripFedCabling::detected() const { return detected_; }
00118 const std::vector<FedChannelConnection>& SiStripFedCabling::undetected() const{ return undetected_; }
00119 
00120 
00121 // -------------------------------------------------------------
00122 #else // SISTRIPCABLING_USING_NEW_STRUCTURE --------------------
00123 #ifndef SISTRIPCABLING_USING_NEW_INTERFACE // ------------------
00124 // -------------------------------------------------------------
00125 
00126 
00127 class SiStripFedCabling;
00128 
00130 std::ostream& operator<< ( std::ostream&, const SiStripFedCabling& );
00131 
00137 class SiStripFedCabling {
00138   
00139  public:
00140   
00141   // -------------------- Typedefs and structs --------------------
00142 
00143   typedef std::vector<uint16_t> Feds;
00144 
00145   typedef Feds::iterator FedsIter;
00146 
00147   typedef Feds::const_iterator FedsConstIter;
00148 
00149   typedef boost::iterator_range<FedsIter> FedsIterRange;
00150 
00151   typedef boost::iterator_range<FedsConstIter> FedsConstIterRange;
00152 
00153   typedef std::vector<FedChannelConnection> Conns;
00154 
00155   typedef Conns::iterator ConnsIter;
00156 
00157   typedef Conns::const_iterator ConnsConstIter;
00158   
00159   typedef boost::iterator_range<ConnsIter> ConnsIterRange;
00160 
00161   typedef boost::iterator_range<ConnsConstIter> ConnsConstIterRange;
00162 
00163   typedef std::pair<uint32_t,uint32_t> ConnsPair;
00164   
00165   typedef std::vector<ConnsPair> Registry;
00166   
00167   // -------------------- Constructors, destructors --------------------
00168 
00170   SiStripFedCabling( const std::vector<FedChannelConnection>& );
00171 
00173   SiStripFedCabling( const SiStripFedCabling& ); 
00174 
00176   SiStripFedCabling();
00177 
00179   ~SiStripFedCabling();
00180 
00181   // -------------------- Methods to retrieve connections --------------------
00182 
00184   const std::vector<uint16_t>& feds() const;
00185   
00187   const std::vector<FedChannelConnection>& connections( uint16_t fed_id ) const; 
00188   
00190   const FedChannelConnection& connection( uint16_t fed_id,
00191                                           uint16_t fed_chan ) const; 
00192   
00194   inline const std::vector<FedChannelConnection>& detected() const; 
00195   
00197   inline const std::vector<FedChannelConnection>& undetected() const; 
00198 
00199   // -------------------- Utility methods --------------------
00200   
00202   void buildFedCabling( const std::vector<FedChannelConnection>& connections );
00203   
00205   void print( std::stringstream& ) const;
00206   
00208   void terse( std::stringstream& ) const;
00209   
00211   void summary( std::stringstream& ) const;
00212 
00214   class ConnsRange {
00215 
00216   public:
00217     
00218     ConnsRange( const Conns&, ConnsPair );
00219     ConnsRange( const Conns& );
00220     ConnsRange() {;}
00221     
00222     ConnsConstIter begin() const;
00223     ConnsConstIter end() const;
00224     ConnsConstIterRange range() const;
00225     ConnsConstIterRange invalid() const;
00226     
00227     bool empty() const;
00228     uint32_t size() const;
00229 
00230     ConnsPair connsPair() const;
00231     static ConnsPair emptyPair();
00232 
00233     void print( std::stringstream& ) const;
00234     
00235   private:
00236     
00237     ConnsConstIterRange vector_;
00238     ConnsConstIterRange range_;
00239 
00240   };
00241 
00243   ConnsRange range( ConnsPair ) const;
00244   
00245   // -------------------- Private member data --------------------
00246 
00247  private:
00248 
00250   Feds feds_;
00251   
00253   Registry registry_;
00254   
00256   Conns connections_;
00257 
00259   Conns detected_;
00260   
00262   Conns undetected_;
00263 
00264 };
00265 
00266 std::ostream& operator<<( std::ostream&, const SiStripFedCabling::ConnsRange& );
00267 
00268 inline const std::vector<FedChannelConnection>& SiStripFedCabling::detected() const { 
00269   return detected_; 
00270 }
00271 
00272 inline const std::vector<FedChannelConnection>& SiStripFedCabling::undetected() const{ 
00273   return undetected_; 
00274 }
00275 
00276 inline SiStripFedCabling::ConnsConstIter SiStripFedCabling::ConnsRange::begin() const { 
00277   return range_.begin(); 
00278 }
00279 
00280 inline SiStripFedCabling::ConnsConstIter SiStripFedCabling::ConnsRange::end() const { 
00281   return range_.end(); 
00282 }
00283 
00284 inline SiStripFedCabling::ConnsConstIterRange SiStripFedCabling::ConnsRange::range() const { 
00285   return range_;
00286 }
00287 
00288 inline SiStripFedCabling::ConnsConstIterRange SiStripFedCabling::ConnsRange::invalid() const { 
00289   return ConnsConstIterRange( vector_.end(), vector_.end() );
00290 }
00291 
00292 inline bool SiStripFedCabling::ConnsRange::empty() const { 
00293   return ( range_.begin() == range_.end() );
00294 }
00295 
00296 inline uint32_t SiStripFedCabling::ConnsRange::size() const { 
00297   return std::distance( range_.begin(), range_.end() );
00298 }
00299 
00300 inline SiStripFedCabling::ConnsPair SiStripFedCabling::ConnsRange::connsPair() const { 
00301   return ( ( range_.begin() == vector_.end() && 
00302              range_.end()   == vector_.end() ) ?
00303            ConnsPair( sistrip::invalid32_, sistrip::invalid32_ ) :
00304            ConnsPair( std::distance( vector_.begin(), range_.begin() ), 
00305                       std::distance( vector_.begin(), range_.end() ) ) );
00306 }
00307 
00308 inline SiStripFedCabling::ConnsPair SiStripFedCabling::ConnsRange::emptyPair() { 
00309   return ConnsPair( sistrip::invalid32_, sistrip::invalid32_ );
00310 }
00311 
00312 inline SiStripFedCabling::ConnsRange SiStripFedCabling::range( SiStripFedCabling::ConnsPair p ) const {
00313   return ConnsRange( connections_, p );
00314 }
00315 
00316 
00317 // -------------------------------------------------------------
00318 #else // SISTRIPCABLING_USING_NEW_INTERFACE --------------------
00319 // -------------------------------------------------------------
00320 
00321 
00322 class SiStripFedCabling;
00323 
00325 std::ostream& operator<< ( std::ostream&, const SiStripFedCabling& );
00326 
00332 class SiStripFedCabling {
00333   
00334  public:
00335   
00336   // -------------------- Typedefs and structs --------------------
00337 
00338   typedef std::vector<uint16_t> Feds;
00339 
00340   typedef Feds::iterator FedsIter;
00341 
00342   typedef Feds::const_iterator FedsConstIter;
00343 
00344   typedef boost::iterator_range<FedsIter> FedsIterRange;
00345 
00346   typedef boost::iterator_range<FedsConstIter> FedsConstIterRange;
00347 
00348   typedef std::vector<FedChannelConnection> Conns;
00349 
00350   typedef Conns::iterator ConnsIter;
00351 
00352   typedef Conns::const_iterator ConnsConstIter;
00353   
00354   typedef boost::iterator_range<ConnsIter> ConnsIterRange;
00355 
00356   typedef boost::iterator_range<ConnsConstIter> ConnsConstIterRange;
00357 
00358   typedef std::pair<uint32_t,uint32_t> ConnsPair;
00359   
00360   typedef std::vector<ConnsPair> Registry;
00361   
00362   // -------------------- TO BE DEPRECATED! --------------------
00363   
00365   SiStripFedCabling( const std::vector<FedChannelConnection>& );
00366   
00368   void buildFedCabling( const std::vector<FedChannelConnection>& );
00369   
00371   const std::vector<FedChannelConnection>& connections( uint16_t fed_id ) const; 
00372   
00374   const FedChannelConnection& connection( uint16_t fed_id, uint16_t fed_ch ) const; 
00375   
00377   const std::vector<uint16_t>& feds() const;
00378   
00380   const std::vector<FedChannelConnection>& detected() const; 
00381   
00383   const std::vector<FedChannelConnection>& undetected() const; 
00384   
00385   // -------------------- Constructors, destructors --------------------
00386   
00388   SiStripFedCabling( ConnsConstIterRange );
00389   
00391   SiStripFedCabling( const SiStripFedCabling& ); 
00392   
00394   SiStripFedCabling();
00395 
00397   ~SiStripFedCabling();
00398 
00399   // -------------------- Methods to retrieve connections --------------------
00400 
00402   FedsConstIterRange fedIds() const;
00403   
00405   ConnsConstIterRange fedConnections( uint16_t fed_id ) const; 
00406   
00408   FedChannelConnection fedConnection( uint16_t fed_id, uint16_t fed_ch ) const; 
00409   
00411   ConnsConstIterRange detectedDevices() const; 
00412   
00414   ConnsConstIterRange undetectedDevices() const; 
00415 
00416   // -------------------- Utility methods --------------------
00417   
00419   void buildFedCabling( ConnsConstIterRange connections );
00420   
00422   void printDebug( std::stringstream& ) const;
00423 
00425   void print( std::stringstream& ss ) const {
00426     printDebug(ss);
00427   }
00428   
00430   void terse( std::stringstream& ) const;
00431   
00433   void printSummary( std::stringstream& ) const;
00435   void summary( std::stringstream& ss ) const {
00436     printSummary(ss);
00437   }
00438 
00440   class ConnsRange {
00441 
00442   public:
00443     
00444     ConnsRange( const Conns&, ConnsPair );
00445     ConnsRange( const Conns& );
00446     ConnsRange() {;}
00447     
00448     ConnsConstIter begin() const;
00449     ConnsConstIter end() const;
00450     ConnsConstIterRange range() const;
00451     ConnsConstIterRange invalid() const;
00452     
00453     bool empty() const;
00454     uint32_t size() const;
00455 
00456     ConnsPair connsPair() const;
00457     static ConnsPair emptyPair();
00458 
00459     void print( std::stringstream& ) const;
00460     
00461   private:
00462     
00463     ConnsConstIterRange vector_;
00464     ConnsConstIterRange range_;
00465 
00466   };
00467 
00469   ConnsRange range( ConnsPair ) const;
00470   
00471   // -------------------- Private member data --------------------
00472 
00473  private:
00474 
00476   Feds feds_;
00477   
00479   Registry registry_;
00480   
00482   Conns connections_;
00483 
00485   Conns detected_;
00486   
00488   Conns undetected_;
00489 
00490 };
00491 
00492 std::ostream& operator<<( std::ostream&, const SiStripFedCabling::ConnsRange& );
00493 
00494 inline SiStripFedCabling::FedsConstIterRange SiStripFedCabling::fedIds() const {
00495   return FedsConstIterRange( feds_.begin(), feds_.end() );
00496 }
00497 
00498 inline SiStripFedCabling::ConnsConstIterRange SiStripFedCabling::detectedDevices() const { 
00499   return ConnsConstIterRange( detected_.begin(), detected_.end() ); 
00500 }
00501 
00502 inline SiStripFedCabling::ConnsConstIterRange SiStripFedCabling::undetectedDevices() const{ 
00503   return ConnsConstIterRange( undetected_.begin(), undetected_.end() ); 
00504 }
00505 
00506 inline SiStripFedCabling::ConnsConstIter SiStripFedCabling::ConnsRange::begin() const { 
00507   return range_.begin(); 
00508 }
00509 
00510 inline SiStripFedCabling::ConnsConstIter SiStripFedCabling::ConnsRange::end() const { 
00511   return range_.end(); 
00512 }
00513 
00514 inline SiStripFedCabling::ConnsConstIterRange SiStripFedCabling::ConnsRange::range() const { 
00515   return range_;
00516 }
00517 
00518 inline SiStripFedCabling::ConnsConstIterRange SiStripFedCabling::ConnsRange::invalid() const { 
00519   return ConnsConstIterRange( vector_.end(), vector_.end() );
00520 }
00521 
00522 inline bool SiStripFedCabling::ConnsRange::empty() const { 
00523   return ( range_.begin() == range_.end() );
00524 }
00525 
00526 inline uint32_t SiStripFedCabling::ConnsRange::size() const { 
00527   return std::distance( range_.begin(), range_.end() );
00528 }
00529 
00530 inline SiStripFedCabling::ConnsPair SiStripFedCabling::ConnsRange::connsPair() const { 
00531   return ( ( range_.begin() == vector_.end() && 
00532              range_.end()   == vector_.end() ) ?
00533            ConnsPair( sistrip::invalid32_, sistrip::invalid32_ ) :
00534            ConnsPair( std::distance( vector_.begin(), range_.begin() ), 
00535                       std::distance( vector_.begin(), range_.end() ) ) );
00536 }
00537 
00538 inline SiStripFedCabling::ConnsPair SiStripFedCabling::ConnsRange::emptyPair() { 
00539   return ConnsPair( sistrip::invalid32_, sistrip::invalid32_ );
00540 }
00541 
00542 inline SiStripFedCabling::ConnsRange SiStripFedCabling::range( SiStripFedCabling::ConnsPair p ) const {
00543   return ConnsRange( connections_, p );
00544 }
00545 
00546 
00547 // -------------------------------------------------------------
00548 #endif // SISTRIPCABLING_USING_NEW_INTERFACE -------------------
00549 #endif // SISTRIPCABLING_USING_NEW_STRUCTURE -------------------
00550 // -------------------------------------------------------------
00551 
00552 #endif // CondFormats_SiStripObjects_SiStripFedCabling_H
00553