Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CalibTracker/Records/interface/SiPixelMappingSoARecord.h"
0002 #include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h"
0003 #include "CondFormats/DataRecord/interface/SiPixelQualityRcd.h"
0004 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
0005 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
0006 #include "CondFormats/SiPixelObjects/interface/SiPixelMappingHost.h"
0007 #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
0008 #include "CondFormats/SiPixelObjects/interface/alpaka/SiPixelMappingDevice.h"
0009 #include "DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0014 #include "FWCore/Utilities/interface/ESGetToken.h"
0015 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0016 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0017 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
0018 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0019 #include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
0020 
0021 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0022 
0023   using namespace cms::alpakatools;
0024 
0025   class SiPixelCablingSoAESProducer : public ESProducer {
0026   public:
0027     SiPixelCablingSoAESProducer(edm::ParameterSet const& iConfig)
0028         : ESProducer(iConfig), useQuality_(iConfig.getParameter<bool>("UseQualityInfo")) {
0029       auto cc = setWhatProduced(this);
0030       cablingMapToken_ = cc.consumes(edm::ESInputTag{"", iConfig.getParameter<std::string>("CablingMapLabel")});
0031       if (useQuality_) {
0032         qualityToken_ = cc.consumes();
0033       }
0034       geometryToken_ = cc.consumes();
0035     }
0036 
0037     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0038       edm::ParameterSetDescription desc;
0039       desc.add<std::string>("CablingMapLabel", "")->setComment("CablingMap label");
0040       desc.add<bool>("UseQualityInfo", false);
0041       descriptions.addWithDefaultLabel(desc);
0042     }
0043 
0044     std::optional<SiPixelMappingHost> produce(const SiPixelMappingSoARecord& iRecord) {
0045       auto cablingMap = iRecord.getTransientHandle(cablingMapToken_);
0046       const SiPixelQuality* quality = nullptr;
0047       if (useQuality_) {
0048         auto qualityInfo = iRecord.getTransientHandle(qualityToken_);
0049         quality = qualityInfo.product();
0050       }
0051 
0052       auto geom = iRecord.getTransientHandle(geometryToken_);
0053       SiPixelMappingHost product(pixelgpudetails::MAX_SIZE, cms::alpakatools::host());
0054       std::vector<unsigned int> const& fedIds = cablingMap->fedIds();
0055       std::unique_ptr<SiPixelFedCablingTree> const& cabling = cablingMap->cablingTree();
0056 
0057       unsigned int startFed = fedIds.front();
0058       unsigned int endFed = fedIds.back();
0059 
0060       sipixelobjects::CablingPathToDetUnit path;
0061       int index = 1;
0062 
0063       auto mapView = product.view();
0064 
0065       mapView.hasQuality() = useQuality_;
0066       for (unsigned int fed = startFed; fed <= endFed; fed++) {
0067         for (unsigned int link = 1; link <= pixelgpudetails::MAX_LINK; link++) {
0068           for (unsigned int roc = 1; roc <= pixelgpudetails::MAX_ROC; roc++) {
0069             path = {fed, link, roc};
0070             const sipixelobjects::PixelROC* pixelRoc = cabling->findItem(path);
0071             mapView[index].fed() = fed;
0072             mapView[index].link() = link;
0073             mapView[index].roc() = roc;
0074             if (pixelRoc != nullptr) {
0075               mapView[index].rawId() = pixelRoc->rawId();
0076               mapView[index].rocInDet() = pixelRoc->idInDetUnit();
0077               mapView[index].modToUnpDefault() = false;
0078               if (quality != nullptr)
0079                 mapView[index].badRocs() = quality->IsRocBad(pixelRoc->rawId(), pixelRoc->idInDetUnit());
0080               else
0081                 mapView[index].badRocs() = false;
0082             } else {  // store some dummy number
0083               mapView[index].rawId() = pixelClustering::invalidModuleId;
0084               mapView[index].rocInDet() = pixelClustering::invalidModuleId;
0085               mapView[index].badRocs() = true;
0086               mapView[index].modToUnpDefault() = true;
0087             }
0088             index++;
0089           }
0090         }
0091       }  // end of FED loop
0092       // Given FedId, Link and idinLnk; use the following formula
0093       // to get the rawId and idinDU
0094       // index = (FedID-1200) * MAX_LINK* MAX_ROC + (Link-1)* MAX_ROC + idinLnk;
0095       // where, MAX_LINK = 48, MAX_ROC = 8
0096       // FedID varies between 1200 to 1338 (In total 108 FED's)
0097       // Link varies between 1 to 48
0098       // idinLnk varies between 1 to 8
0099 
0100       auto trackerGeom = iRecord.getTransientHandle(geometryToken_);
0101 
0102       for (int i = 1; i < index; i++) {
0103         if (mapView[i].rawId() == pixelClustering::invalidModuleId) {
0104           mapView[i].moduleId() = pixelClustering::invalidModuleId;
0105         } else {
0106           auto gdet = trackerGeom->idToDetUnit(mapView[i].rawId());
0107           if (!gdet) {
0108             LogDebug("SiPixelCablingSoAESProducer") << " Not found: " << mapView[i].rawId() << std::endl;
0109             continue;
0110           }
0111           mapView[i].moduleId() = gdet->index();
0112         }
0113         LogDebug("SiPixelCablingSoAESProducer")
0114             << "----------------------------------------------------------------------------" << std::endl;
0115         LogDebug("SiPixelCablingSoAESProducer") << i << std::setw(20) << mapView[i].fed() << std::setw(20)
0116                                                 << mapView[i].link() << std::setw(20) << mapView[i].roc() << std::endl;
0117         LogDebug("SiPixelCablingSoAESProducer")
0118             << i << std::setw(20) << mapView[i].rawId() << std::setw(20) << mapView[i].rocInDet() << std::setw(20)
0119             << mapView[i].moduleId() << std::endl;
0120         LogDebug("SiPixelCablingSoAESProducer")
0121             << i << std::setw(20) << mapView[i].badRocs() << std::setw(20) << std::endl;
0122         LogDebug("SiPixelCablingSoAESProducer")
0123             << "----------------------------------------------------------------------------" << std::endl;
0124       }
0125 
0126       mapView.size() = index - 1;
0127 
0128       return product;
0129     }
0130 
0131   private:
0132     edm::ESGetToken<SiPixelFedCablingMap, SiPixelFedCablingMapRcd> cablingMapToken_;
0133     edm::ESGetToken<SiPixelQuality, SiPixelQualityRcd> qualityToken_;
0134     edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geometryToken_;
0135     const bool useQuality_;
0136   };
0137 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0138 
0139 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
0140 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(SiPixelCablingSoAESProducer);