Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 #include <memory>
0020 
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/Framework/interface/ESProducer.h"
0023 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0024 #include "FWCore/Framework/interface/ModuleFactory.h"
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0029 #include "CondFormats/DataRecord/interface/SiPixelQualityFromDbRcd.h"
0030 #include "CondFormats/DataRecord/interface/SiPixelQualityRcd.h"
0031 #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
0032 #include "CondFormats/SiStripObjects/interface/SiStripDetVOff.h"
0033 
0034 class SiPixelQualityESProducer : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0035 public:
0036   SiPixelQualityESProducer(const edm::ParameterSet& iConfig);
0037   ~SiPixelQualityESProducer() override = default;
0038 
0039   std::unique_ptr<SiPixelQuality> produce(const SiPixelQualityRcd& iRecord);
0040 
0041   static void fillDescriptions(edm::ConfigurationDescriptions&);
0042 
0043 private:
0044   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0045                       const edm::IOVSyncValue&,
0046                       edm::ValidityInterval&) override;
0047 
0048   edm::ESGetToken<SiPixelQuality, SiPixelQualityFromDbRcd> siPixelQualityFromDbToken_;
0049   edm::ESGetToken<SiStripDetVOff, SiPixelDetVOffRcd> voffToken_;
0050 };
0051 
0052 SiPixelQualityESProducer::SiPixelQualityESProducer(const edm::ParameterSet& iConfig) {
0053   // setWhatProduced internally uses "appendToDataLabel" to name the output product of this ESProducer
0054   auto const& appendToDataLabel = iConfig.getParameter<std::string>("appendToDataLabel");
0055   auto esCC = setWhatProduced(this);
0056 
0057   // "siPixelQualityFromDbLabel" corresponds to the Label of a tag with Record
0058   // "SiPixelQualityFromDbRcd" in the EventSetup (normally provided by the GlobalTag)
0059   auto const& siPixelQualityFromDbLabel = iConfig.getParameter<std::string>("siPixelQualityFromDbLabel");
0060   siPixelQualityFromDbToken_ = esCC.consumes(edm::ESInputTag{"", siPixelQualityFromDbLabel});
0061   voffToken_ = esCC.consumes();
0062 
0063   findingRecord<SiPixelQualityRcd>();
0064 
0065   edm::LogInfo("SiPixelQualityESProducer")
0066       << "Module = \"" << description().label_ << "\" (appendToDataLabel = \"" << appendToDataLabel
0067       << "\", siPixelQualityFromDbLabel = \"" << siPixelQualityFromDbLabel << "\")";
0068 }
0069 
0070 std::unique_ptr<SiPixelQuality> SiPixelQualityESProducer::produce(const SiPixelQualityRcd& iRecord) {
0071   ///////////////////////////////////////////////////////
0072   //  errortype "whole" = int 0 in DB  BadRocs = 65535 //
0073   //  errortype "tbmA" = int 1 in DB  BadRocs = 255    //
0074   //  errortype "tbmB" = int 2 in DB  Bad Rocs = 65280 //
0075   //  errortype "none" = int 3 in DB                   //
0076   ///////////////////////////////////////////////////////
0077 
0078   //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)
0079   //SiPixelQuality * obj = new SiPixelQuality();
0080   //SiPixelQuality::disabledModuleType BadModule;
0081   //BadModule.DetID = 1; BadModule.errorType = 0; BadModule.BadRocs = 65535; obj->addDisabledModule(BadModule);
0082 
0083   //now the dbobject is the one copied from the db
0084   auto dbptr = std::make_unique<SiPixelQuality>(iRecord.get(siPixelQualityFromDbToken_));
0085 
0086   //here is the magic line in which it switches off Bad Modules
0087   dbptr->add(&(iRecord.get(voffToken_)));
0088   return dbptr;
0089 }
0090 
0091 void SiPixelQualityESProducer::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0092                                               const edm::IOVSyncValue& iosv,
0093                                               edm::ValidityInterval& oValidity) {
0094   edm::ValidityInterval infinity(iosv.beginOfTime(), iosv.endOfTime());
0095   oValidity = infinity;
0096 }
0097 
0098 void SiPixelQualityESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0099   edm::ParameterSetDescription desc;
0100   desc.add<std::string>("siPixelQualityFromDbLabel", "");
0101   {
0102     edm::ParameterSetDescription desc_ps;
0103     desc_ps.add<std::string>("record", "SiPixelQualityFromDbRcd");
0104     desc_ps.add<std::string>("tag", "");
0105     std::vector<edm::ParameterSet> default_ps;
0106     default_ps.reserve(2);
0107     {
0108       edm::ParameterSet temp;
0109       temp.addParameter<std::string>("record", "SiPixelQualityFromDbRcd");
0110       temp.addParameter<std::string>("tag", "");
0111       default_ps.push_back(temp);
0112     }
0113     {
0114       edm::ParameterSet temp;
0115       temp.addParameter<std::string>("record", "SiPixelDetVOffRcd");
0116       temp.addParameter<std::string>("tag", "");
0117       default_ps.push_back(temp);
0118     }
0119     desc.addVPSet("ListOfRecordToMerge", desc_ps, default_ps);
0120   }
0121   descriptions.addWithDefaultLabel(desc);
0122 }
0123 
0124 DEFINE_FWK_EVENTSETUP_MODULE(SiPixelQualityESProducer);