Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:18

0001 
0002 #ifndef OnlineDB_SiStripESSources_SiStripCondObjBuilderFromDb_H
0003 #define OnlineDB_SiStripESSources_SiStripCondObjBuilderFromDb_H
0004 
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0007 #include "OnlineDB/SiStripConfigDb/interface/SiStripConfigDb.h"
0008 #include "OnlineDB/SiStripConfigDb/interface/SiStripDbParams.h"
0009 #include "CondFormats/SiStripObjects/interface/SiStripBadStrip.h"
0010 
0011 #include "OnlineDB/SiStripESSources/interface/SiStripCondObjBuilderFromDb.h"
0012 #include "OnlineDB/SiStripESSources/interface/SiStripFedCablingBuilderFromDb.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
0015 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0016 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
0017 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
0018 #include "CondFormats/SiStripObjects/interface/SiStripThreshold.h"
0019 #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
0020 #include "CondFormats/SiStripObjects/interface/SiStripLatency.h"
0021 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0022 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0023 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
0024 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0025 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
0026 #include "CalibFormats/SiStripObjects/interface/SiStripDetInfo.h"
0027 
0028 #include <memory>
0029 #include <vector>
0030 #include <string>
0031 #include <typeinfo>
0032 #include <cstdint>
0033 
0034 class SiStripFecCabling;
0035 class SiStripDetCabling;
0036 class SiStripPedestals;
0037 class SiStripNoises;
0038 class SiStripQuality;
0039 class SiStripThreshold;
0040 class DcuDetIdMap;
0041 class SiStripApvGain;
0042 class SiStripLatency;
0043 class TrackerTopology;
0044 
0045 class SiStripCondObjBuilderFromDb {
0046 public:
0047   // Typedefs
0048   typedef std::pair<uint32_t, FedChannelConnection> pair_apvpairconn;
0049   typedef std::vector<pair_apvpairconn> v_apvpairconn;
0050   typedef std::pair<uint32_t, v_apvpairconn> pair_detcon;
0051   typedef std::vector<pair_detcon> trackercon;
0052 
0053   typedef std::vector<pair_detcon>::iterator i_trackercon;
0054   typedef std::vector<pair_apvpairconn>::iterator i_apvpairconn;
0055 
0056   class SkipDeviceDescription {
0057     /* Class to hold the addresses of the devices to be skipped from gain update.
0058      * 0 stands for all devices at this level.
0059      * sistrip::invalid means this coordinate is not used. */
0060   public:
0061     SkipDeviceDescription();
0062     SkipDeviceDescription(const edm::ParameterSet& pset);
0063     bool isConsistent(const FedChannelConnection& fc) const;
0064     std::string dump() const;
0065 
0066   private:
0067     SiStripFecKey fec_;
0068     SiStripFedKey fed_;
0069     uint32_t detid_;
0070   };
0071 
0072   SiStripCondObjBuilderFromDb();
0073   SiStripCondObjBuilderFromDb(const edm::ParameterSet&, const edm::ActivityRegistry&);
0074   virtual ~SiStripCondObjBuilderFromDb();
0075 
0076   TrackerTopology* buildTrackerTopology();
0077 
0078   /** Returns database connection parameters. */
0079   inline const SiStripDbParams& dbParams() const { return db_->dbParams(); }
0080 
0081   /** Builds pedestals using FED descriptions and cabling info
0082       retrieved from configuration database. */
0083   void buildCondObj();
0084   void buildStripRelatedObjects(SiStripConfigDb* const db, const SiStripDetCabling& det_cabling);
0085   void buildAnalysisRelatedObjects(SiStripConfigDb* const db, const trackercon& tc);
0086   void buildFECRelatedObjects(SiStripConfigDb* const db, const trackercon& tc);
0087   void buildFEDRelatedObjects(SiStripConfigDb* const db, const trackercon& tc);
0088 
0089   bool checkForCompatibility(std::stringstream& input, std::stringstream& output, std::string& label);
0090   std::string getConfigString(const std::type_info& typeInfo);
0091 
0092   SiStripFedCabling* getFedCabling() {
0093     checkUpdate();
0094     return fed_cabling_;
0095   }
0096   SiStripPedestals* getPedestals() {
0097     checkUpdate();
0098     return pedestals_;
0099   }
0100   SiStripNoises* getNoises() {
0101     checkUpdate();
0102     return noises_;
0103   }
0104   SiStripThreshold* getThreshold() {
0105     checkUpdate();
0106     return threshold_;
0107   }
0108   SiStripQuality* getQuality() {
0109     checkUpdate();
0110     return quality_;
0111   }
0112   SiStripApvGain* getApvGain() {
0113     checkUpdate();
0114     return gain_;
0115   }
0116   SiStripLatency* getApvLatency() {
0117     checkUpdate();
0118     return latency_;
0119   }
0120 
0121   void getValue(SiStripFedCabling*& val) { val = getFedCabling(); }
0122   void getValue(SiStripPedestals*& val) { val = getPedestals(); }
0123   void getValue(SiStripNoises*& val) { val = getNoises(); }
0124   void getValue(SiStripThreshold*& val) { val = getThreshold(); }
0125   void getValue(SiStripQuality*& val) { val = getQuality(); }
0126   void getValue(SiStripBadStrip*& val) { val = new SiStripBadStrip(*(const SiStripBadStrip*)getQuality()); }
0127   void getValue(SiStripApvGain*& val) { val = getApvGain(); }
0128   void getValue(SiStripLatency*& val) { val = getApvLatency(); }
0129 
0130   void setLastIovGain(std::shared_ptr<SiStripApvGain> gain) { gain_last_ = gain; }
0131 
0132 protected:
0133   void checkUpdate();
0134 
0135   /** Access to the configuration DB interface class. */
0136   // Build and retrieve SiStripConfigDb object using service
0137   edm::Service<SiStripConfigDb> db_;
0138 
0139   /** Container for DB connection parameters. */
0140   SiStripDbParams dbParams_;
0141   SiStripFedCabling* fed_cabling_;
0142   SiStripPedestals* pedestals_;
0143   SiStripNoises* noises_;
0144   SiStripThreshold* threshold_;
0145   SiStripQuality* quality_;
0146   SiStripApvGain* gain_;
0147   SiStripLatency* latency_;
0148 
0149   std::shared_ptr<SiStripApvGain> gain_last_;         // last gain object in DB
0150   std::vector<SkipDeviceDescription> skippedDevices;  // devices to be skipped for gain update
0151   std::vector<uint32_t> skippedDetIds;
0152   std::vector<SkipDeviceDescription>
0153       whitelistedDevices;  // devices whitelist for gain update: will NOT be skipped, even if in the 'skip list'
0154   std::vector<uint32_t> whitelistedDetIds;
0155 
0156   //methods used by BuildStripRelatedObjects
0157   bool setValuesApvLatency(SiStripLatency& latency_,
0158                            SiStripConfigDb* const db,
0159                            FedChannelConnection& ipair,
0160                            uint32_t detid,
0161                            uint16_t apvnr,
0162                            SiStripConfigDb::DeviceDescriptionsRange apvs);
0163   bool setValuesApvTiming(SiStripConfigDb* const db, FedChannelConnection& ipair);
0164   //  bool setValuesCabling(SiStripConfigDb* const db, FedChannelConnection &ipair, uint32_t detid);
0165   bool setValuesCabling(SiStripConfigDb::FedDescriptionsRange& descriptions,
0166                         FedChannelConnection& ipair,
0167                         uint32_t detid);
0168   bool retrieveFedDescriptions(SiStripConfigDb* const db);
0169   bool retrieveTimingAnalysisDescriptions(SiStripConfigDb* const db);
0170   vector<uint32_t> retrieveActiveDetIds(const SiStripDetCabling& det_cabling);
0171   vector<const FedChannelConnection*> buildConnections(const SiStripDetCabling& det_cabling, uint32_t det_id);
0172   uint16_t retrieveNumberAPVPairs(uint32_t det_id);
0173 
0174   //set and store data
0175   void setDefaultValuesCabling(uint16_t apvPair);
0176   void setDefaultValuesApvTiming(uint32_t detid, uint32_t apvPair);
0177   void setDefaultValuesApvLatency(SiStripLatency& latency_,
0178                                   const FedChannelConnection& ipair,
0179                                   uint32_t detid,
0180                                   uint16_t apvnr);
0181   void storePedestals(uint32_t det_id);
0182   void storeNoise(uint32_t det_id);
0183   void storeThreshold(uint32_t det_id);
0184   void storeQuality(uint32_t det_id);
0185   void storeTiming(uint32_t det_id);
0186 
0187   // cfi input parameters
0188   edm::VParameterSet m_skippedDevices;  // VPset of devices to be skipped in tickmark update
0189   edm::VParameterSet
0190       m_whitelistedDevices;  // VPset of whitelisted devices: will NOT be skipped in tickmark update (even if in the 'skip list')
0191   float m_tickmarkThreshold;  // threshold to accept the tickmark measurement
0192   float m_gaincalibrationfactor;
0193   float m_defaultpedestalvalue;
0194   float m_defaultnoisevalue;
0195   float m_defaultthresholdhighvalue;
0196   float m_defaultthresholdlowvalue;
0197   uint16_t m_defaultapvmodevalue;
0198   uint16_t m_defaultapvlatencyvalue;
0199   float m_defaulttickheightvalue;
0200   bool m_useanalysis;
0201   bool m_usefed;
0202   bool m_usefec;
0203   bool m_debug;
0204   SiStripDetInfo m_detInfo;
0205 
0206   //Data containers
0207   TrackerTopology* tTopo;
0208   SiStripPedestals::InputVector inputPedestals;
0209   SiStripNoises::InputVector inputNoises;
0210   SiStripThreshold::InputVector inputThreshold;
0211   SiStripQuality::InputVector inputQuality;
0212   SiStripApvGain::InputVector inputApvGain;
0213 
0214   // Tracker Cabling objects
0215   pair_apvpairconn p_apvpcon;
0216   v_apvpairconn v_apvpcon;
0217   pair_detcon p_detcon;
0218   trackercon v_trackercon;
0219 };
0220 #endif  // OnlineDB_SiStripESSources_SiStripCondObjBuilderFromDb_H