Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:52

0001 #include "CalibFormats/SiStripObjects/interface/SiStripHashedDetId.h"
0002 #include "CalibTracker/Records/interface/SiStripHashedDetIdRcd.h"
0003 #include "FWCore/Framework/interface/ESProducer.h"
0004 #include "FWCore/Framework/interface/ModuleFactory.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0008 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0009 
0010 using namespace sistrip;
0011 
0012 /**
0013    @class SiStripHashedDetIdESModule
0014    @author R.Bainbridge
0015    @brief Builds hashed DetId map based on DetIds read from geometry database
0016 */
0017 class SiStripHashedDetIdESModule : public edm::ESProducer {
0018 public:
0019   SiStripHashedDetIdESModule(const edm::ParameterSet&);
0020   ~SiStripHashedDetIdESModule() override;
0021 
0022   /** Builds hashed DetId map based on geometry. */
0023   std::unique_ptr<SiStripHashedDetId> produce(const SiStripHashedDetIdRcd&);
0024 
0025 private:
0026   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0027 };
0028 
0029 // -----------------------------------------------------------------------------
0030 //
0031 SiStripHashedDetIdESModule::SiStripHashedDetIdESModule(const edm::ParameterSet& pset)
0032     : geomToken_(setWhatProduced(this, &SiStripHashedDetIdESModule::produce).consumes()) {
0033   edm::LogVerbatim("HashedDetId") << "[SiStripHashedDetIdESSourceFromGeom::" << __func__ << "]"
0034                                   << " Constructing object...";
0035 }
0036 
0037 // -----------------------------------------------------------------------------
0038 //
0039 SiStripHashedDetIdESModule::~SiStripHashedDetIdESModule() {
0040   edm::LogVerbatim("HashedDetId") << "[SiStripHashedDetIdESSourceFromGeom::" << __func__ << "]"
0041                                   << " Destructing object...";
0042 }
0043 
0044 // -----------------------------------------------------------------------------
0045 //
0046 std::unique_ptr<SiStripHashedDetId> SiStripHashedDetIdESModule::produce(const SiStripHashedDetIdRcd& rcd) {
0047   edm::LogVerbatim("HashedDetId") << "[SiStripHashedDetIdFakeESSource::" << __func__ << "]"
0048                                   << " Building \"fake\" hashed DetId map from geometry";
0049 
0050   const auto& geom = rcd.get(geomToken_);
0051 
0052   std::vector<uint32_t> dets;
0053   dets.reserve(16000);
0054 
0055   for (const auto& iter : geom.detUnits()) {
0056     const auto strip = dynamic_cast<StripGeomDetUnit const*>(iter);
0057     if (strip) {
0058       dets.push_back((strip->geographicalId()).rawId());
0059     }
0060   }
0061   edm::LogVerbatim(mlDqmCommon_) << "[SiStripHashedDetIdESModule::" << __func__ << "]"
0062                                  << " Retrieved " << dets.size() << " sistrip DetIds from geometry!";
0063 
0064   // Create hash map object
0065   auto hash = std::make_unique<SiStripHashedDetId>(dets);
0066   LogTrace(mlDqmCommon_) << "[SiStripHashedDetIdESModule::" << __func__ << "]"
0067                          << " DetId hash map: " << std::endl
0068                          << *hash;
0069 
0070   return hash;
0071 }
0072 
0073 DEFINE_FWK_EVENTSETUP_MODULE(SiStripHashedDetIdESModule);