Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-11-29 00:56:17

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 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0040 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0041 
0042 using namespace edm;
0043 
0044 class SiPixelQualityESProducer : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0045 public:
0046   SiPixelQualityESProducer(const edm::ParameterSet& iConfig);
0047   ~SiPixelQualityESProducer() override;
0048 
0049   std::unique_ptr<SiPixelQuality> produce(const SiPixelQualityRcd& iRecord);
0050   std::unique_ptr<SiPixelQuality> produceWithLabel(const SiPixelQualityRcd& iRecord);
0051   std::unique_ptr<SiPixelQuality> produceWithLabelRawToDigi(const SiPixelQualityRcd& iRecord);
0052 
0053   static void fillDescriptions(edm::ConfigurationDescriptions&);
0054 
0055 private:
0056   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0057                       const edm::IOVSyncValue&,
0058                       edm::ValidityInterval&) override;
0059 
0060   struct Tokens {
0061     Tokens() = default;
0062     explicit Tokens(edm::ESConsumesCollector cc, const std::string& label) {
0063       voffToken_ = cc.consumes();
0064       dbobjectToken_ = cc.consumes(edm::ESInputTag{"", label});
0065     }
0066     edm::ESGetToken<SiStripDetVOff, SiPixelDetVOffRcd> voffToken_;
0067     edm::ESGetToken<SiPixelQuality, SiPixelQualityFromDbRcd> dbobjectToken_;
0068   };
0069 
0070   std::unique_ptr<SiPixelQuality> get_pointer(const SiPixelQualityRcd& iRecord, const Tokens& tokens);
0071 
0072   const Tokens defaultTokens_;
0073   Tokens labelTokens_;
0074   Tokens labelTokens_RawToDigi_;
0075 };
0076 
0077 //
0078 // constructors and destructor
0079 //
0080 
0081 SiPixelQualityESProducer::SiPixelQualityESProducer(const edm::ParameterSet& conf_)
0082     : defaultTokens_(setWhatProduced(this), "") {
0083   edm::LogInfo("SiPixelQualityESProducer::SiPixelQualityESProducer");
0084 
0085   auto label = conf_.getParameter<std::string>("siPixelQualityLabel");
0086 
0087   if (label == "forDigitizer") {
0088     labelTokens_ =
0089         Tokens(setWhatProduced(this, &SiPixelQualityESProducer::produceWithLabel, edm::es::Label(label)), label);
0090   }
0091 
0092   label = conf_.getParameter<std::string>("siPixelQualityLabel_RawToDigi");
0093 
0094   if (label == "forRawToDigi") {
0095     labelTokens_RawToDigi_ = Tokens(
0096         setWhatProduced(this, &SiPixelQualityESProducer::produceWithLabelRawToDigi, edm::es::Label(label)), label);
0097   }
0098   findingRecord<SiPixelQualityRcd>();
0099 }
0100 
0101 SiPixelQualityESProducer::~SiPixelQualityESProducer() {
0102   // do anything here that needs to be done at desctruction time
0103   // (e.g. close files, deallocate resources etc.)
0104 }
0105 
0106 std::unique_ptr<SiPixelQuality> SiPixelQualityESProducer::get_pointer(const SiPixelQualityRcd& iRecord,
0107                                                                       const Tokens& tokens) {
0108   ///////////////////////////////////////////////////////
0109   //  errortype "whole" = int 0 in DB  BadRocs = 65535 //
0110   //  errortype "tbmA" = int 1 in DB  BadRocs = 255    //
0111   //  errortype "tbmB" = int 2 in DB  Bad Rocs = 65280 //
0112   //  errortype "none" = int 3 in DB                   //
0113   ///////////////////////////////////////////////////////
0114 
0115   //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)
0116   //SiPixelQuality * obj = new SiPixelQuality();
0117   //SiPixelQuality::disabledModuleType BadModule;
0118   //BadModule.DetID = 1; BadModule.errorType = 0; BadModule.BadRocs = 65535; obj->addDisabledModule(BadModule);
0119 
0120   //now the dbobject is the one copied from the db
0121   auto dbptr = std::make_unique<SiPixelQuality>(iRecord.get(tokens.dbobjectToken_));
0122 
0123   //here is the magic line in which it switches off Bad Modules
0124   dbptr->add(&(iRecord.get(tokens.voffToken_)));
0125   return dbptr;
0126 }
0127 
0128 std::unique_ptr<SiPixelQuality> SiPixelQualityESProducer::produce(const SiPixelQualityRcd& iRecord) {
0129   return get_pointer(iRecord, defaultTokens_);
0130 }
0131 std::unique_ptr<SiPixelQuality> SiPixelQualityESProducer::produceWithLabel(const SiPixelQualityRcd& iRecord) {
0132   return get_pointer(iRecord, labelTokens_);
0133 }
0134 std::unique_ptr<SiPixelQuality> SiPixelQualityESProducer::produceWithLabelRawToDigi(const SiPixelQualityRcd& iRecord) {
0135   return get_pointer(iRecord, labelTokens_RawToDigi_);
0136 }
0137 
0138 void SiPixelQualityESProducer::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0139                                               const edm::IOVSyncValue& iosv,
0140                                               edm::ValidityInterval& oValidity) {
0141   edm::ValidityInterval infinity(iosv.beginOfTime(), iosv.endOfTime());
0142   oValidity = infinity;
0143 }
0144 
0145 void SiPixelQualityESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0146   edm::ParameterSetDescription desc;
0147   desc.add<std::string>("siPixelQualityLabel", "");
0148   desc.add<std::string>("siPixelQualityLabel_RawToDigi", "");
0149   {
0150     edm::ParameterSetDescription desc_ps;
0151     desc_ps.add<std::string>("record", "SiPixelQualityFromDbRcd");
0152     desc_ps.add<std::string>("tag", "");
0153     std::vector<edm::ParameterSet> default_ps;
0154     default_ps.reserve(2);
0155     {
0156       edm::ParameterSet temp;
0157       temp.addParameter<std::string>("record", "SiPixelQualityFromDbRcd");
0158       temp.addParameter<std::string>("tag", "");
0159       default_ps.push_back(temp);
0160     }
0161     {
0162       edm::ParameterSet temp;
0163       temp.addParameter<std::string>("record", "SiPixelDetVOffRcd");
0164       temp.addParameter<std::string>("tag", "");
0165       default_ps.push_back(temp);
0166     }
0167     desc.addVPSet("ListOfRecordToMerge", desc_ps, default_ps);
0168   }
0169   descriptions.addWithDefaultLabel(desc);
0170 }
0171 
0172 DEFINE_FWK_EVENTSETUP_MODULE(SiPixelQualityESProducer);