Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:48

0001 #ifndef SISTRIPPSUDETIDMAP_H
0002 #define SISTRIPPSUDETIDMAP_H
0003 
0004 #include <memory>
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "DataFormats/Common/interface/MapOfVectors.h"
0010 
0011 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0012 #include "OnlineDB/SiStripConfigDb/interface/SiStripConfigDb.h"
0013 #include "OnlineDB/SiStripConfigDb/interface/SiStripDbParams.h"
0014 #include "DeviceFactory.h"
0015 
0016 #include <vector>
0017 #include <string>
0018 #include <iostream>
0019 #include <fstream>
0020 #include <sstream>
0021 #include <ostream>
0022 #include <cstdint>
0023 
0024 class SiStripConfigDb;
0025 
0026 /** 
0027    \class SiStripPsuDetIdMap
0028    \brief Extension to SiStripConfigDb to map PSU channels to DetIDs using DCU-PSU map and DCU-DetID map
0029    \author J.Cole
0030 */
0031 
0032 class SiStripPsuDetIdMap {
0033 public:
0034   /** Constructor */
0035   SiStripPsuDetIdMap();
0036   /** Destructor */
0037   ~SiStripPsuDetIdMap();
0038 
0039   std::vector<uint32_t> getLvDetID(std::string psu);
0040   void getHvDetID(std::string psuchannel,
0041                   std::vector<uint32_t> &ids,
0042                   std::vector<uint32_t> &unmapped_ids,
0043                   std::vector<uint32_t> &crosstalking_ids);
0044 
0045   //Produces 3 list of detIDs:
0046   //1-detids (positively matching the PSUChannel for HV case, positively matching the PSU for the LV case)
0047   //2-unmapped_detids (matching the PSUChannel000 for the HV case, empty for LV case)
0048   //3-crosstalking_detids (matching the PSUChannel999 for the HV case, empty for the LV case)
0049   void getDetID(std::string pvss,
0050                 bool,
0051                 std::vector<uint32_t> &detids,
0052                 std::vector<uint32_t> &unmapped_detids,
0053                 std::vector<uint32_t> &crosstalking_detids);
0054   /** Returns the PSU channel name for the specified Det ID, for power groups only. */
0055   std::string getPSUName(uint32_t detid);
0056   /** Returns the PSU channel name for the specified Det ID. */
0057   std::string getPSUName(uint32_t detid, std::string group);
0058   /** Returns the detector location for the specified Det ID, for power groups only. */
0059   std::string getDetectorLocation(uint32_t detid);
0060   /** Returns the detector location for the specified PSU channel. */
0061   std::string getDetectorLocation(std::string pvss);
0062   /** Returns the detector location for the specified Det ID and specified group type (PG or CG). */
0063   std::string getDetectorLocation(uint32_t detid, std::string group);
0064   /** Returns the DCU ID for the specified PSU channel - checks power and control groups. */
0065   uint32_t getDcuId(std::string pvss);
0066   /** Returns the DCU ID associated to the specified Det ID.  NB.  This checks power groups only, by definition. */
0067   uint32_t getDcuId(uint32_t detid);
0068 
0069   //Return the HVUnmapped PSU channels as a map initialized to all channels (002/003) OFF (false):
0070   std::map<std::string, std::vector<uint32_t> > getHVUnmappedMap() { return HVUnmapped_Map; }
0071   //Return the HVCrosstalking PSU channels as a map initialized to all channels (002/003) OFF (false):
0072   std::map<std::string, std::vector<uint32_t> > getHVCrosstalkingMap() { return HVCrosstalking_Map; }
0073   //PsuDetIdMap getHVUnmappedDetIdMap() {return HVUnmapped_Map}
0074   //Return the HVUnmapped PSUchannel to (HV status) map initialized to all OFF:
0075   //PsuDetIdMap getHVUnmappedChannelMap() {return HVUnmapped_ChanStatus}
0076   //PsuDetIdMap getHVCrosstalkingChannelMap() {return HVCrossTalking_ChanStatus}
0077   /** Return the PG PSU-DETID map as a vector. */
0078   std::vector<std::pair<uint32_t, std::string> > getPsuDetIdMap() { return pgMap; }
0079   /** Return the PG detector locations as a vector - one-to-one correspondance with the contents of the PSU-DetID map vector. */
0080   std::vector<std::string> getDetectorLocations() { return detectorLocations; }
0081   /** Return the DCU IDs associated to the PG map. */
0082   std::vector<uint32_t> getDcuIds() { return dcuIds; }
0083   /** Return the CG PSU-DETID map as a vector. */
0084   std::vector<std::pair<uint32_t, std::string> > getControlPsuDetIdMap() { return cgMap; }
0085   /** Return the CG detector locations as a vector - one-to-one correspondance with the contents of the PSU-DetID map vector. */
0086   std::vector<std::string> getControlDetectorLocations() { return controlLocations; }
0087   /** Return the module DCU IDs associated to the CG map. */
0088   std::vector<uint32_t> getCgDcuIds() { return cgDcuIds; }
0089   /** Return the CCU DCU IDs associated to the CG map. */
0090   std::vector<uint32_t> getCcuDcuIds() { return ccuDcuIds; }
0091 
0092   /** Produces a formatted printout of the PSU-DETID map. */
0093   void printMap();
0094   /** Produces a formatted printout of the control PSU-DETID map. */
0095   void printControlMap();
0096   /** Main routine that accesses the DB and builds the PSU-DETID map. */
0097   //void BuildMap();
0098   /**
0099    * Build the map from given file.
0100    * ATTENTION: this will only build the pgMap, not the cgMap.
0101    */
0102   void BuildMap(const std::string &mapFile, const bool debug);
0103   //Old "rawmap" (vector of pairs) method to be used by excludeddetids:
0104   void BuildMap(const std::string &mapFile, std::vector<std::pair<uint32_t, std::string> > &rawmap);
0105   /// Overloaded method that does the buidling
0106   void BuildMap(const std::string &mapFile,
0107                 const bool debug,
0108                 std::map<std::string, std::vector<uint32_t> > &LVmap,
0109                 std::map<std::string, std::vector<uint32_t> > &HVmap,
0110                 std::map<std::string, std::vector<uint32_t> > &HVUnmappedmap,
0111                 std::map<std::string, std::vector<uint32_t> > &HVCrosstalkingmap);
0112 
0113   //Service function to remove duplicated from vectors of detids:
0114   void RemoveDuplicateDetIDs(std::vector<uint32_t> &detids);
0115 
0116   /** Returns the DCU-PSU map as a vector. */
0117   std::vector<std::pair<uint32_t, std::string> > getDcuPsuMap();
0118   /** Returns 1 if the specified PSU channel is a HV channel, 0 if it is a LV channel.  -1 means error. */
0119   int IsHVChannel(std::string pvss);
0120 
0121 private:
0122   // typedefs
0123   typedef std::vector<TkDcuPsuMap *> DcuPsuVector;
0124   typedef std::map<std::string, std::vector<uint32_t> > PsuDetIdMap;
0125   typedef edm::MapOfVectors<std::string, TkDcuPsuMap *> DcuPsus;
0126   typedef DcuPsus::range DcuPsusRange;
0127   /** Extracts the DCU-PSU map from the DB. */
0128   void getDcuPsuMap(DcuPsusRange &pRange, DcuPsusRange &cRange, std::string partition);
0129   /** Extracts the DCU device descriptions and stores them for further use. Only used for control groups. */
0130   //  std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> >  retrieveDcuDeviceAddresses(std::string partition);
0131   std::vector<std::pair<std::vector<uint16_t>, std::vector<uint32_t> > > retrieveDcuDeviceAddresses(
0132       std::string partition);
0133   /** Searches the DCU device descriptions for the specified DCU ID. Needed for control groups. */
0134   std::vector<uint32_t> findDcuIdFromDeviceAddress(uint32_t dcuid_);
0135   /** Utility to clone a DCU-PSU map. */
0136   void clone(DcuPsuVector &input, DcuPsuVector &output);
0137   /** Produces a detailed debug of the input values. */
0138   // for debugging
0139   void checkMapInputValues(const SiStripConfigDb::DcuDetIdsV &dcuDetIds_, const DcuPsuVector &dcuPsus_);
0140 
0141   // member variables
0142   edm::Service<SiStripConfigDb> db_;
0143   PsuDetIdMap LVMap, HVMap, HVUnmapped_Map, HVCrosstalking_Map;
0144   std::vector<std::pair<uint32_t, std::string> > pgMap, cgMap;
0145   std::vector<std::string> detectorLocations, controlLocations;
0146   std::vector<uint32_t> dcuIds, cgDcuIds, ccuDcuIds;
0147   DcuPsus DcuPsuMapPG_, DcuPsuMapCG_;
0148   //  std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> > dcu_device_addr_vector;
0149   std::vector<std::pair<std::vector<uint16_t>, std::vector<uint32_t> > > dcu_device_addr_vector;
0150 };
0151 #endif