Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-01 03:53:23

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiPixelQualityESProducer
0004 // Class:      SiPixelQualityESProducer
0005 //
0006 /**\class SiPixelQualityESProducer SiPixelQualityESProducer.h CalibTracker/SiPixelESProducer/src/SiPixelQualityESProducer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author: Gemma Tinti
0015 //         Created:  Jan 13 2011
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <cassert>
0022 
0023 // user include files
0024 #include "CalibTracker/Records/interface/SiStripDependentRecords.h"
0025 #include "CalibTracker/SiPixelESProducers/interface/SiPixelDetInfoFileReader.h"
0026 #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
0027 #include "CondFormats/SiStripObjects/interface/SiStripDetVOff.h"
0028 #include "CondFormats/DataRecord/interface/SiPixelQualityRcd.h"
0029 #include "CondFormats/DataRecord/interface/SiPixelQualityFromDbRcd.h"
0030 #include "CalibTracker/Records/interface/SiStripDependentRecords.h"
0031 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0032 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034 #include "FWCore/Framework/interface/EventSetup.h"
0035 #include "FWCore/Framework/interface/ESProducer.h"
0036 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0037 #include "FWCore/Framework/interface/ModuleFactory.h"
0038 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0039 
0040 using namespace edm;
0041 
0042 class SiPixelQualityESProducer : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0043 public:
0044   SiPixelQualityESProducer(const edm::ParameterSet& iConfig);
0045   ~SiPixelQualityESProducer() override;
0046 
0047   std::unique_ptr<SiPixelQuality> produce(const SiPixelQualityRcd& iRecord);
0048   std::unique_ptr<SiPixelQuality> produceWithLabel(const SiPixelQualityRcd& iRecord);
0049 
0050 private:
0051   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0052                       const edm::IOVSyncValue&,
0053                       edm::ValidityInterval&) override;
0054 
0055   struct Tokens {
0056     Tokens() = default;
0057     explicit Tokens(edm::ESConsumesCollector cc, const std::string& label) {
0058       voffToken_ = cc.consumes();
0059       dbobjectToken_ = cc.consumes(edm::ESInputTag{"", label});
0060     }
0061     edm::ESGetToken<SiStripDetVOff, SiPixelDetVOffRcd> voffToken_;
0062     edm::ESGetToken<SiPixelQuality, SiPixelQualityFromDbRcd> dbobjectToken_;
0063   };
0064 
0065   std::unique_ptr<SiPixelQuality> get_pointer(const SiPixelQualityRcd& iRecord, const Tokens& tokens);
0066 
0067   const Tokens defaultTokens_;
0068   Tokens labelTokens_;
0069 };
0070 
0071 //
0072 // constructors and destructor
0073 //
0074 
0075 SiPixelQualityESProducer::SiPixelQualityESProducer(const edm::ParameterSet& conf_)
0076     : defaultTokens_(setWhatProduced(this), "") {
0077   edm::LogInfo("SiPixelQualityESProducer::SiPixelQualityESProducer");
0078 
0079   auto label =
0080       conf_.exists("siPixelQualityLabel") ? conf_.getParameter<std::string>("siPixelQualityLabel") : std::string{};
0081 
0082   if (label == "forDigitizer" || label == "forRawToDigi") {
0083     labelTokens_ =
0084         Tokens(setWhatProduced(this, &SiPixelQualityESProducer::produceWithLabel, edm::es::Label(label)), label);
0085   }
0086   findingRecord<SiPixelQualityRcd>();
0087 }
0088 
0089 SiPixelQualityESProducer::~SiPixelQualityESProducer() {
0090   // do anything here that needs to be done at desctruction time
0091   // (e.g. close files, deallocate resources etc.)
0092 }
0093 
0094 std::unique_ptr<SiPixelQuality> SiPixelQualityESProducer::get_pointer(const SiPixelQualityRcd& iRecord,
0095                                                                       const Tokens& tokens) {
0096   ///////////////////////////////////////////////////////
0097   //  errortype "whole" = int 0 in DB  BadRocs = 65535 //
0098   //  errortype "tbmA" = int 1 in DB  BadRocs = 255    //
0099   //  errortype "tbmB" = int 2 in DB  Bad Rocs = 65280 //
0100   //  errortype "none" = int 3 in DB                   //
0101   ///////////////////////////////////////////////////////
0102 
0103   //if I have understood this is the one got from the DB or file, but in any case the ORIGINAL(maybe i need to get the record for it)
0104   //SiPixelQuality * obj = new SiPixelQuality();
0105   //SiPixelQuality::disabledModuleType BadModule;
0106   //BadModule.DetID = 1; BadModule.errorType = 0; BadModule.BadRocs = 65535; obj->addDisabledModule(BadModule);
0107 
0108   //now the dbobject is the one copied from the db
0109   auto dbptr = std::make_unique<SiPixelQuality>(iRecord.get(tokens.dbobjectToken_));
0110 
0111   //here is the magic line in which it switches off Bad Modules
0112   dbptr->add(&(iRecord.get(tokens.voffToken_)));
0113   return dbptr;
0114 }
0115 
0116 std::unique_ptr<SiPixelQuality> SiPixelQualityESProducer::produce(const SiPixelQualityRcd& iRecord) {
0117   return get_pointer(iRecord, defaultTokens_);
0118 }
0119 std::unique_ptr<SiPixelQuality> SiPixelQualityESProducer::produceWithLabel(const SiPixelQualityRcd& iRecord) {
0120   return get_pointer(iRecord, labelTokens_);
0121 }
0122 
0123 void SiPixelQualityESProducer::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0124                                               const edm::IOVSyncValue& iosv,
0125                                               edm::ValidityInterval& oValidity) {
0126   edm::ValidityInterval infinity(iosv.beginOfTime(), iosv.endOfTime());
0127   oValidity = infinity;
0128 }
0129 
0130 DEFINE_FWK_EVENTSETUP_MODULE(SiPixelQualityESProducer);