CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/OnlineDB/SiStripConfigDb/interface/SiStripConfigDb.h

Go to the documentation of this file.
00001 // Last commit: $Id: SiStripConfigDb.h,v 1.79 2009/11/10 15:51:58 lowette Exp $
00002 
00003 #ifndef OnlineDB_SiStripConfigDb_SiStripConfigDb_h
00004 #define OnlineDB_SiStripConfigDb_SiStripConfigDb_h
00005 
00006 #define DATABASE // Needed by DeviceFactory API! Do not comment!
00007 //#define USING_DATABASE_MASKING
00008 
00009 #include "FWCore/Utilities/interface/Exception.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
00012 #include "DataFormats/Common/interface/MapOfVectors.h"
00013 #include "DataFormats/SiStripCommon/interface/ConstantsForRunType.h"
00014 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00015 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00016 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
00017 #include "OnlineDB/SiStripConfigDb/interface/SiStripDbParams.h"
00018 #include "DeviceFactory.h"
00019 #include "boost/range/iterator_range.hpp"
00020 #include "boost/cstdint.hpp"
00021 #include <iostream>
00022 #include <fstream>
00023 #include <sstream>
00024 #include <ostream>
00025 #include <vector>
00026 #include <string>
00027 #include <list>
00028 #include <map>
00029 
00030 #include "DbClient.h"
00031 
00032 namespace sistrip {
00033   static const uint16_t FEC_CRATE_OFFSET =  0; //@@ temporary
00034   static const uint16_t FEC_RING_OFFSET  =  0; //@@ temporary
00035 }
00036 
00037 // Friend class
00038 namespace cms { class SiStripO2O; }
00039 
00045 class SiStripConfigDb {
00046   
00047  public:
00048 
00049 
00050   // ---------- Constructors, destructors ----------
00051 
00052   
00056   SiStripConfigDb( const edm::ParameterSet&,
00057                    const edm::ActivityRegistry& );
00058   
00060   ~SiStripConfigDb();
00061   
00062 
00063   // ---------- PROTECTED INTERFACE ----------
00064 
00065   
00066  protected:
00067   
00068   /*
00069     Access to the configuration database is reserved solely for the
00070     commissioning (database) client and the online-to-offline transfer
00071     tool. If you wish to use this interface to the configuration
00072     database, then please contact one of the package administrators.
00073   */
00074   
00075   // ESSources and O2O
00076   friend class SiStripFedCablingBuilderFromDb;
00077   friend class SiStripPedestalsBuilderFromDb;
00078   friend class SiStripNoiseBuilderFromDb;
00079   friend class SiStripCondObjBuilderFromDb;
00080   friend class SiStripPsuDetIdMap;
00081   
00082   
00083   // Commissioning clients
00084   friend class SiStripCommissioningDbClient;
00085   friend class SiStripCommissioningOfflineDbClient;
00086   friend class CommissioningHistosUsingDb;
00087   friend class FastFedCablingHistosUsingDb;
00088   friend class FedCablingHistosUsingDb;
00089   friend class ApvTimingHistosUsingDb;
00090   friend class OptoScanHistosUsingDb;
00091   friend class PedestalsHistosUsingDb;
00092   friend class PedsFullNoiseHistosUsingDb;
00093   friend class PedsOnlyHistosUsingDb;
00094   friend class NoiseHistosUsingDb;
00095   friend class VpspScanHistosUsingDb;
00096   friend class LatencyHistosUsingDb;
00097   friend class FineDelayHistosUsingDb;
00098   friend class CalibrationHistosUsingDb;
00099 
00100   // Utility and tests
00101   friend class SiStripPartition;
00102   friend class testSiStripConfigDb;
00103   
00104 
00105 
00106   // ---------- Typedefs ----------
00107 
00108 
00109   // FED connections
00110   typedef ConnectionDescription FedConnection;
00111   typedef edm::MapOfVectors<std::string,FedConnection*> FedConnections;
00112   typedef FedConnections::range FedConnectionsRange;
00113   typedef std::vector<FedConnection*> FedConnectionsV;
00114   
00115   // Device descriptions
00116   typedef enumDeviceType DeviceType;
00117   typedef deviceDescription DeviceDescription;
00118   typedef edm::MapOfVectors<std::string,DeviceDescription*> DeviceDescriptions;
00119   typedef DeviceDescriptions::range DeviceDescriptionsRange;
00120   typedef std::vector<DeviceDescription*> DeviceDescriptionsV;
00121   
00122   // FED descriptions
00123   typedef Fed9U::Fed9UDescription FedDescription;
00124   typedef edm::MapOfVectors<std::string,FedDescription*> FedDescriptions;
00125   typedef FedDescriptions::range FedDescriptionsRange;
00126   typedef std::vector<FedDescription*> FedDescriptionsV;
00127 
00128   // FED ids
00129   typedef std::vector<uint16_t> FedIds;
00130   typedef boost::iterator_range<FedIds::const_iterator> FedIdsRange;
00131   
00132   // DCU-DetId map
00133   typedef Sgi::hash_map<unsigned long,TkDcuInfo*> DcuDetIdMap;
00134   typedef std::pair<uint32_t,TkDcuInfo*> DcuDetId; 
00135   typedef edm::MapOfVectors<std::string,DcuDetId> DcuDetIds; 
00136   typedef DcuDetIds::range DcuDetIdsRange; 
00137   typedef std::vector<DcuDetId> DcuDetIdsV;
00138   
00139   
00140   // Analysis descriptions
00141   typedef CommissioningAnalysisDescription::commissioningType AnalysisType;
00142   typedef CommissioningAnalysisDescription AnalysisDescription;
00143   typedef edm::MapOfVectors<std::string,AnalysisDescription*> AnalysisDescriptions;
00144   typedef AnalysisDescriptions::range AnalysisDescriptionsRange;
00145   typedef std::vector<AnalysisDescription*> AnalysisDescriptionsV;
00146 
00147 
00148   // ---------- Useful structs ----------
00149 
00150 
00153   class DeviceAddress { 
00154   public:
00155     DeviceAddress();
00156     void reset();
00157     uint16_t fecCrate_; 
00158     uint16_t fecSlot_;
00159     uint16_t fecRing_;
00160     uint16_t ccuAddr_;
00161     uint16_t ccuChan_;
00162     uint16_t lldChan_;
00163     uint16_t i2cAddr_;
00164     uint16_t fedId_;
00165     uint16_t feUnit_;
00166     uint16_t feChan_;
00167   };
00168 
00169   
00170   // ---------- Connection and useful methods ----------
00171 
00172   
00174   void openDbConnection();
00175   
00177   void closeDbConnection();
00178 
00180   inline const SiStripDbParams& dbParams() const;
00181   
00183   inline bool usingDb() const;
00184   
00186   DeviceFactory* const deviceFactory( std::string method_name = "" ) const;
00187   
00189   DbClient* const databaseCache( std::string method_name = "" ) const;
00190 
00191 
00192   // ---------- Run numbers for partitions and run types ----------
00193 
00194   
00195   class Run {
00196   public:
00197     sistrip::RunType type_;
00198     std::string      partition_;
00199     uint16_t         number_;
00200     Run() : type_(sistrip::UNDEFINED_RUN_TYPE), partition_(""), number_(0) {;}
00201   };
00202   
00203   typedef std::vector<Run> Runs;
00204   
00205   typedef std::map<sistrip::RunType,Runs> RunsByType;
00206   
00207   typedef std::map<std::string,Runs> RunsByPartition;
00208   
00210   void runs( Runs& ) const;
00211   
00213   void runs( const Runs& in,
00214              RunsByType& out,
00215              std::string optional_partition = "" ) const;
00216   
00218   void runs( const Runs& in,
00219              RunsByPartition& out,
00220              sistrip::RunType optional_type = sistrip::UNDEFINED_RUN_TYPE ) const;
00221 
00223   void partitions( std::list<std::string>& ) const;
00224   
00225   //@@ SiStripPartition::Versions ???
00226 
00227   
00228   // ---------- FED connections ----------
00229 
00230 
00232   FedConnectionsRange getFedConnections( std::string partition = "" );
00233 
00235   void addFedConnections( std::string partition, FedConnectionsV& );
00236   
00238   void uploadFedConnections( std::string partition = "" );
00239   
00241   void clearFedConnections( std::string partition = "" );
00242 
00244   void printFedConnections( std::string partition = "" );
00245   
00246 
00247   // ---------- FEC / Front-End devices ---------- 
00248 
00249   
00251   DeviceDescriptionsRange getDeviceDescriptions( std::string partition = "" ); 
00252 
00255   DeviceDescriptionsRange getDeviceDescriptions( DeviceType, std::string partition = "" );
00256   
00258   void addDeviceDescriptions( std::string partition, DeviceDescriptionsV& );
00259   
00261   void uploadDeviceDescriptions( std::string partition = "" ); 
00262   
00264   void clearDeviceDescriptions( std::string partition = "" ); 
00265   
00267   void printDeviceDescriptions( std::string partition = "" ); 
00268   
00270   DeviceAddress deviceAddress( const deviceDescription& ); //@@ uses temp offsets!
00271   
00272 
00273   // ---------- FED descriptions ----------
00274 
00275 
00277   FedDescriptionsRange getFedDescriptions( std::string partition = "" ); 
00278 
00280   void addFedDescriptions( std::string partition, FedDescriptionsV& );
00281   
00283   void uploadFedDescriptions( std::string partition = "" ); 
00284   
00286   void clearFedDescriptions( std::string partition = "" ); 
00287   
00289   void printFedDescriptions( std::string partition = "" ); 
00290   
00292   FedIdsRange getFedIds( std::string partition = "" );
00293   
00295   inline bool usingStrips() const;
00296   
00298   inline void usingStrips( bool );
00299   
00300 
00301   // ---------- DCU-DetId info ----------
00302 
00303 
00305   DcuDetIdsRange getDcuDetIds( std::string partition = "" );
00306   
00308   void addDcuDetIds( std::string partition, DcuDetIdsV& );
00309   
00311   void uploadDcuDetIds( std::string partition = "" );
00312   
00314   void clearDcuDetIds( std::string partition = "" );
00315   
00317   void printDcuDetIds( std::string partition = "" );
00318   
00320   static DcuDetIdsV::const_iterator findDcuDetId( DcuDetIdsV::const_iterator begin,
00321                                                   DcuDetIdsV::const_iterator end,
00322                                                   uint32_t dcu_id  );
00323   
00325   static DcuDetIdsV::iterator findDcuDetId( DcuDetIdsV::iterator begin,
00326                                             DcuDetIdsV::iterator end,
00327                                             uint32_t dcu_id  );
00328   
00329   
00330   // ---------- Commissioning analyses ---------- 
00331 
00332   
00334   AnalysisDescriptionsRange getAnalysisDescriptions( AnalysisType, std::string partition = "" );
00335   
00337   void addAnalysisDescriptions( std::string partition, AnalysisDescriptionsV& );
00338   
00340   void uploadAnalysisDescriptions( bool calibration_for_physics = false, std::string partition = "" );
00341   
00343   void clearAnalysisDescriptions( std::string partition = "" );
00344   
00346   void printAnalysisDescriptions( std::string partition = "" );
00347   
00349   DeviceAddress deviceAddress( const AnalysisDescription& ); //@@ uses temp offsets!
00350   
00352   std::string analysisType( AnalysisType ) const;
00353   
00354 
00355  private:
00356 
00357 
00358   // ---------- Private methods ----------
00359 
00360 
00362   void clearLocalCache();
00363 
00365   void usingDatabase();
00366 
00368   void usingDatabaseCache();
00369   
00371   void usingXmlFiles();
00372   
00374   void handleException( const std::string& method_name,
00375                         const std::string& extra_info = "" ) const;
00376   
00378   bool checkFileExists( const std::string& path );
00379   
00381   std::string deviceType( const enumDeviceType& device_type ) const;
00382   
00383   void clone( const DcuDetIdMap& in, DcuDetIdsV& out ) const;
00384   
00385   void clone( const DcuDetIdsV& in, DcuDetIdMap& out ) const;
00386   
00387   void clone( const DcuDetIdsV& in, DcuDetIdsV& out ) const;
00388   
00389   
00390   // ---------- Database connection, partitions and versions ----------
00391 
00392   
00394   DeviceFactory* factory_; 
00395 
00397   DbClient* dbCache_; 
00398 
00400   SiStripDbParams dbParams_;
00401 
00402 
00403   // ---------- Local cache of vectors ----------
00404 
00405 
00407   FedConnections connections_;
00408   
00410   DeviceDescriptions devices_;
00411 
00413   FedDescriptions feds_;
00414  
00416   DcuDetIds dcuDetIds_;
00417 
00419   AnalysisDescriptions analyses_;
00420 
00422   DeviceDescriptionsV apvDevices_;
00423 
00425   DeviceDescriptionsV muxDevices_;
00426 
00428   DeviceDescriptionsV dcuDevices_;
00429 
00431   DeviceDescriptionsV lldDevices_;
00432 
00434   DeviceDescriptionsV pllDevices_;
00435 
00437   DeviceDescriptionsV dohDevices_;
00438 
00440   DeviceDescriptionsV typedDevices_;
00441   
00443   FedIds fedIds_;
00444   
00445 
00446   // ---------- Miscellaneous ----------
00447 
00448   
00450   bool usingStrips_;
00451 
00453   bool openConnection_;
00454   
00456   static uint32_t cntr_;
00457 
00458   static bool allowCalibUpload_;
00459 
00460   
00461 };
00462 
00463 
00464 // ---------- Inline methods ----------
00465 
00466 
00468 const SiStripDbParams& SiStripConfigDb::dbParams() const { return dbParams_; }
00469 
00471 bool SiStripConfigDb::usingDb() const { return dbParams_.usingDb(); }
00472 
00474 bool SiStripConfigDb::usingStrips() const { return usingStrips_; }
00475 
00477 void SiStripConfigDb::usingStrips( bool using_strips ) { usingStrips_ = using_strips; }
00478 
00479 
00480 #endif // OnlineDB_SiStripConfigDb_SiStripConfigDb_h