diff --git a/CalibTracker/Records/interface/SiPixelFEDChannelContainerESProducerRcd.h b/CalibTracker/Records/interface/SiPixelFEDChannelContainerESProducerRcd.h new file mode 100644 index 0000000000000..9967db6231baf --- /dev/null +++ b/CalibTracker/Records/interface/SiPixelFEDChannelContainerESProducerRcd.h @@ -0,0 +1,11 @@ +#ifndef CALIBTRACKER_RECORDS_SIPIXELFEDCHANNELCONTAINERESPRODUCERRCD_H +#define CALIBTRACKER_RECORDS_SIPIXELFEDCHANNELCONTAINERESPRODUCERRCD_H + +#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" +#include "FWCore/Framework/interface/DependentRecordImplementation.h" +#include "boost/mpl/vector.hpp" +#include "CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h" + +class SiPixelFEDChannelContainerESProducerRcd : public edm::eventsetup::DependentRecordImplementation > {}; + +#endif diff --git a/CalibTracker/Records/src/SiPixelFEDChannelContainerESProducerRcd.cc b/CalibTracker/Records/src/SiPixelFEDChannelContainerESProducerRcd.cc new file mode 100644 index 0000000000000..2944bbb2a2541 --- /dev/null +++ b/CalibTracker/Records/src/SiPixelFEDChannelContainerESProducerRcd.cc @@ -0,0 +1,5 @@ +#include "CalibTracker/Records/interface/SiPixelFEDChannelContainerESProducerRcd.h" +#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" +#include "FWCore/Utilities/interface/typelookup.h" + +EVENTSETUP_RECORD_REG(SiPixelFEDChannelContainerESProducerRcd); diff --git a/CalibTracker/SiPixelESProducers/plugins/PixelFEDChannelCollectionProducer.cc b/CalibTracker/SiPixelESProducers/plugins/PixelFEDChannelCollectionProducer.cc new file mode 100644 index 0000000000000..584659d1db8ca --- /dev/null +++ b/CalibTracker/SiPixelESProducers/plugins/PixelFEDChannelCollectionProducer.cc @@ -0,0 +1,100 @@ +// -*- C++ -*- +// +// Package: CalibTracker/PixelFEDChannelCollectionProducer +// Class: PixelFEDChannelCollectionProducer +// +/**\class PixelFEDChannelCollectionProducer + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Marco Musich +// Created: Thu, 13 Dec 2018 08:48:22 GMT +// +// + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ModuleFactory.h" +#include "FWCore/Framework/interface/ESProducer.h" + +#include "FWCore/Framework/interface/ESHandle.h" +#include "CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h" +#include "CalibTracker/Records/interface/SiPixelFEDChannelContainerESProducerRcd.h" + +// Need to add #include statements for definitions of +// the data type and record type here + +// +// class declaration +// + +class PixelFEDChannelCollectionProducer : public edm::ESProducer { + public: + PixelFEDChannelCollectionProducer(const edm::ParameterSet&); + ~PixelFEDChannelCollectionProducer() override; + + typedef std::unordered_map PixelFEDChannelCollectionMap; + using ReturnType = std::unique_ptr; + + ReturnType produce(const SiPixelFEDChannelContainerESProducerRcd &); + private: + // ----------member data --------------------------- +}; + + +PixelFEDChannelCollectionProducer::PixelFEDChannelCollectionProducer(const edm::ParameterSet& iConfig) +{ + //the following line is needed to tell the framework what + // data is being produced + setWhatProduced(this); + + //now do what ever other initialization is needed +} + + +PixelFEDChannelCollectionProducer::~PixelFEDChannelCollectionProducer() +{ + + // do anything here that needs to be done at destruction time + // (e.g. close files, deallocate resources etc.) + +} + +// +// member functions +// + +// ------------ method called to produce the data ------------ +PixelFEDChannelCollectionProducer::ReturnType +PixelFEDChannelCollectionProducer::produce(const SiPixelFEDChannelContainerESProducerRcd& iRecord) +{ + edm::ESHandle qualityCollectionHandle; + iRecord.getRecord().get(qualityCollectionHandle); + + PixelFEDChannelCollectionMap out; + + for(const auto& it : qualityCollectionHandle->getScenarioMap()){ + + std::string scenario = it.first; + PixelFEDChannelCollection disabled_channelcollection; + auto SiPixelBadFedChannels = it.second; + for(const auto &entry : SiPixelBadFedChannels){ + disabled_channelcollection.insert(entry.first, entry.second.data(), entry.second.size()); + } + out.emplace(scenario,disabled_channelcollection); + } + + auto product = std::make_unique(out); + return product; +} + +//define this as a plug-in +DEFINE_FWK_EVENTSETUP_MODULE(PixelFEDChannelCollectionProducer); diff --git a/CalibTracker/SiPixelESProducers/python/PixelFEDChannelCollectionProducer_cfi.py b/CalibTracker/SiPixelESProducers/python/PixelFEDChannelCollectionProducer_cfi.py new file mode 100644 index 0000000000000..284d2f5b060fd --- /dev/null +++ b/CalibTracker/SiPixelESProducers/python/PixelFEDChannelCollectionProducer_cfi.py @@ -0,0 +1,3 @@ +import FWCore.ParameterSet.Config as cms + +SiPixelFEDChannelContainerESProducer = cms.ESProducer("PixelFEDChannelCollectionProducer") diff --git a/CalibTracker/SiPixelESProducers/test/PixelFEDChannelCollectionMapTestReader.cc b/CalibTracker/SiPixelESProducers/test/PixelFEDChannelCollectionMapTestReader.cc new file mode 100644 index 0000000000000..1dd8e48b09e0a --- /dev/null +++ b/CalibTracker/SiPixelESProducers/test/PixelFEDChannelCollectionMapTestReader.cc @@ -0,0 +1,84 @@ +#include +#include +#include +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h" +#include "CalibTracker/Records/interface/SiPixelFEDChannelContainerESProducerRcd.h" + +class PixelFEDChannelCollectionMapTestReader : public edm::one::EDAnalyzer<> { +public: + + typedef std::unordered_map PixelFEDChannelCollectionMap; + explicit PixelFEDChannelCollectionMapTestReader(edm::ParameterSet const& p); + ~PixelFEDChannelCollectionMapTestReader(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + + virtual void analyze(const edm::Event& e, const edm::EventSetup& c) override; + + // ----------member data --------------------------- + const bool printdebug_; + const std::string formatedOutput_; + +}; + +PixelFEDChannelCollectionMapTestReader::PixelFEDChannelCollectionMapTestReader(edm::ParameterSet const& p): + printdebug_(p.getUntrackedParameter("printDebug",true)), + formatedOutput_(p.getUntrackedParameter("outputFile","")) +{ + edm::LogInfo("PixelFEDChannelCollectionMapTestReader")<<"PixelFEDChannelCollectionMapTestReader"< PixelFEDChannelCollectionMapHandle; + edm::LogInfo("PixelFEDChannelCollectionMapTestReader") <<"got eshandle"<().get(PixelFEDChannelCollectionMapHandle); + edm::LogInfo("PixelFEDChannelCollectionMapTestReader") <<"got context"<size() << std::endl; + edm::LogInfo("PixelFEDChannelCollectionMapTestReader") <<"Content of myQuality_Map "<("printDebug",true); + desc.addUntracked("outputFile",""); + descriptions.add("PixelFEDChannelCollectionMapTestReader",desc); +} + +DEFINE_FWK_MODULE(PixelFEDChannelCollectionMapTestReader); diff --git a/CalibTracker/SiPixelESProducers/test/PixelFEDChannelCollectionMapTestReader_cfg.py b/CalibTracker/SiPixelESProducers/test/PixelFEDChannelCollectionMapTestReader_cfg.py new file mode 100644 index 0000000000000..c00a534013e74 --- /dev/null +++ b/CalibTracker/SiPixelESProducers/test/PixelFEDChannelCollectionMapTestReader_cfg.py @@ -0,0 +1,79 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("ProcessOne") + +## +## MessageLogger +## +process.load('FWCore.MessageService.MessageLogger_cfi') +process.MessageLogger.categories.append("SiPixelFEDChannelContainer") +process.MessageLogger.categories.append("PixelFEDChannelCollectionMapTestReader") +process.MessageLogger.destinations = cms.untracked.vstring("cout") +process.MessageLogger.cout = cms.untracked.PSet( + threshold = cms.untracked.string("INFO"), + default = cms.untracked.PSet(limit = cms.untracked.int32(0)), + FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1), + reportEvery = cms.untracked.int32(1000) + ), + SiPixelFEDChannelContainer = cms.untracked.PSet( limit = cms.untracked.int32(-1)), + PixelFEDChannelCollectionMapTestReader = cms.untracked.PSet( limit = cms.untracked.int32(-1)) + ) +process.MessageLogger.statistics.append('cout') + +## +## Empty Source +## +process.source = cms.Source("EmptyIOVSource", + timetype = cms.string('runnumber'), + firstValue = cms.uint64(1), + lastValue = cms.uint64(1), + interval = cms.uint64(1) + ) +## +## Get the payload +## +from CondCore.CondDB.CondDB_cfi import * +CondDBQualityCollection = CondDB.clone(connect = cms.string("sqlite_file:SiPixelStatusScenarios_v1.db")) + +process.dbInput = cms.ESSource("PoolDBESSource", + CondDBQualityCollection, + toGet = cms.VPSet(cms.PSet(record = cms.string('SiPixelStatusScenariosRcd'), + tag = cms.string('SiPixelFEDChannelContainer_StuckTBM_2018_v1_mc') # choose tag you want + ) + ) + ) + +#from CalibTracker.SiPixelESProducers.PixelFEDChannelCollectionProducer_cfi import * +process.load("CalibTracker.SiPixelESProducers.PixelFEDChannelCollectionProducer_cfi") +#process.SiPixelFEDChannelContainerESProducer = cms.ESProducer("PixelFEDChannelCollectionProducer") + + +## Retrieve it and check it's available in the ES +## +process.get = cms.EDAnalyzer("EventSetupRecordDataGetter", + toGet = cms.VPSet(cms.PSet(record = cms.string('SiPixelFEDChannelContainerESProducerRcd'), + data = cms.vstring('PixelFEDChannelCollectionMap') + ) + ), + verbose = cms.untracked.bool(True) + ) + +## +## Retrieve it and check it's available in the ES +## +# process.get = cms.EDAnalyzer("EventSetupRecordDataGetter", +# toGet = cms.VPSet(cms.PSet(record = cms.string('SiPixelStatusScenariosRcd'), +# data = cms.vstring('SiPixelFEDChannelContainer') +# ) +# ), +# verbose = cms.untracked.bool(True) +# ) + +## +## Read it back +## +process.ReadDB = cms.EDAnalyzer("PixelFEDChannelCollectionMapTestReader") +process.ReadDB.printDebug = cms.untracked.bool(True) +process.ReadDB.outputFile = cms.untracked.string('PixelFEDChannelCollectionMap.log') + +process.p = cms.Path(process.get+process.ReadDB) diff --git a/CondCore/SiPixelPlugins/src/plugin.cc b/CondCore/SiPixelPlugins/src/plugin.cc index ec115267b7c92..338ac89920939 100644 --- a/CondCore/SiPixelPlugins/src/plugin.cc +++ b/CondCore/SiPixelPlugins/src/plugin.cc @@ -19,6 +19,10 @@ #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h" #include "CondFormats/DataRecord/interface/SiPixelQualityFromDbRcd.h" #include "CondFormats/DataRecord/interface/SiPixelQualityRcd.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h" +#include "CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h" +#include "CondFormats/DataRecord/interface/SiPixelStatusScenarioProbabilityRcd.h" #include "CondFormats/SiPixelObjects/interface/SiPixelCPEGenericErrorParm.h" #include "CondFormats/DataRecord/interface/SiPixelCPEGenericErrorParmRcd.h" @@ -61,6 +65,8 @@ REGISTER_PLUGIN(SiPixelDynamicInefficiencyRcd,SiPixelDynamicInefficiency); REGISTER_PLUGIN(SiPixelCalibConfigurationRcd,SiPixelCalibConfiguration); REGISTER_PLUGIN(SiPixelPerformanceSummaryRcd,SiPixelPerformanceSummary); REGISTER_PLUGIN(SiPixelQualityFromDbRcd,SiPixelQuality); +REGISTER_PLUGIN(SiPixelStatusScenariosRcd,SiPixelFEDChannelContainer); +REGISTER_PLUGIN(SiPixelStatusScenarioProbabilityRcd,SiPixelQualityProbabilities); REGISTER_PLUGIN(SiPixelCPEGenericErrorParmRcd,SiPixelCPEGenericErrorParm); REGISTER_PLUGIN(SiPixelTemplateDBObjectRcd,SiPixelTemplateDBObject); REGISTER_PLUGIN(SiPixelTemplateDBObject38TRcd,SiPixelTemplateDBObject); diff --git a/CondCore/Utilities/plugins/Module_2XML.cc b/CondCore/Utilities/plugins/Module_2XML.cc index 1dc07f23ad0bd..a9de48b269022 100644 --- a/CondCore/Utilities/plugins/Module_2XML.cc +++ b/CondCore/Utilities/plugins/Module_2XML.cc @@ -245,6 +245,8 @@ PAYLOAD_2XML_MODULE( pluginUtilities_payload2xml ){ PAYLOAD_2XML_CLASS( SiPixelGenErrorDBObject ); PAYLOAD_2XML_CLASS( SiPixelLorentzAngle ); PAYLOAD_2XML_CLASS( SiPixelQuality ); + PAYLOAD_2XML_CLASS( SiPixelFEDChannelContainer ); + PAYLOAD_2XML_CLASS( SiPixelQualityProbabilities ); PAYLOAD_2XML_CLASS( SiPixelTemplateDBObject ); PAYLOAD_2XML_CLASS( SiStripApvGain ); PAYLOAD_2XML_CLASS( SiStripBackPlaneCorrection ); diff --git a/CondCore/Utilities/src/CondDBFetch.cc b/CondCore/Utilities/src/CondDBFetch.cc index ae5589f9af04b..30ee6e1ffd280 100644 --- a/CondCore/Utilities/src/CondDBFetch.cc +++ b/CondCore/Utilities/src/CondDBFetch.cc @@ -276,6 +276,8 @@ namespace cond { FETCH_PAYLOAD_CASE( SiPixelLorentzAngle ) FETCH_PAYLOAD_CASE( SiPixelDynamicInefficiency ) FETCH_PAYLOAD_CASE( SiPixelQuality ) + FETCH_PAYLOAD_CASE( SiPixelFEDChannelContainer ) + FETCH_PAYLOAD_CASE( SiPixelQualityProbabilities ) FETCH_PAYLOAD_CASE( SiPixelTemplateDBObject ) FETCH_PAYLOAD_CASE( SiPixel2DTemplateDBObject ) FETCH_PAYLOAD_CASE( SiStripApvGain ) diff --git a/CondCore/Utilities/src/CondDBImport.cc b/CondCore/Utilities/src/CondDBImport.cc index 4d9a91ab575e6..eb6f2ec56d0bf 100644 --- a/CondCore/Utilities/src/CondDBImport.cc +++ b/CondCore/Utilities/src/CondDBImport.cc @@ -296,6 +296,8 @@ namespace cond { IMPORT_PAYLOAD_CASE( SiPixelLorentzAngle ) IMPORT_PAYLOAD_CASE( SiPixelDynamicInefficiency ) IMPORT_PAYLOAD_CASE( SiPixelQuality ) + IMPORT_PAYLOAD_CASE( SiPixelFEDChannelContainer ) + IMPORT_PAYLOAD_CASE( SiPixelQualityProbabilities ) IMPORT_PAYLOAD_CASE( SiPixelTemplateDBObject ) IMPORT_PAYLOAD_CASE( SiPixel2DTemplateDBObject ) IMPORT_PAYLOAD_CASE( SiStripApvGain ) diff --git a/CondCore/Utilities/src/CondFormats.h b/CondCore/Utilities/src/CondFormats.h index 413d3f4fd731d..ccac5e19c7389 100644 --- a/CondCore/Utilities/src/CondFormats.h +++ b/CondCore/Utilities/src/CondFormats.h @@ -138,6 +138,8 @@ #include "CondFormats/SiPixelObjects/interface/SiPixelLorentzAngle.h" #include "CondFormats/SiPixelObjects/interface/SiPixelDynamicInefficiency.h" #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h" #include "CondFormats/SiPixelObjects/interface/SiPixelTemplateDBObject.h" #include "CondFormats/SiPixelObjects/interface/SiPixel2DTemplateDBObject.h" #include "CondFormats/SiPixelObjects/interface/SiPixelGenErrorDBObject.h" diff --git a/CondFormats/DataRecord/interface/SiPixelStatusScenarioProbabilityRcd.h b/CondFormats/DataRecord/interface/SiPixelStatusScenarioProbabilityRcd.h new file mode 100644 index 0000000000000..62114a993a971 --- /dev/null +++ b/CondFormats/DataRecord/interface/SiPixelStatusScenarioProbabilityRcd.h @@ -0,0 +1,19 @@ +#ifndef SiPixelStatusScenarioProbabilityRcd_SiPixelStatusScenarioProbabilityRcd_h +#define SiPixelStatusScenarioProbabilityRcd_SiPixelStatusScenarioProbabilityRcd_h +// -*- C++ -*- +// +// Package: CondFormats/DataRecord +// Class : SiPixelStatusScenarioProbabilityRcd +// +/**\class SiPixelStatusScenarioProbabilityRcd SiPixelStatusScenarioProbabilityRcd.h CondFormats/DataRecord/interface/SiPixelStatusScenarioProbabilityRcd.h + Description: [one line class summary] + Usage: + +*/ +// +// Author: Marco Musich +// Created: Wed, 30 Nov 2018 11:44:30 GMT +// +#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" +class SiPixelStatusScenarioProbabilityRcd : public edm::eventsetup::EventSetupRecordImplementation {}; +#endif diff --git a/CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h b/CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h new file mode 100644 index 0000000000000..4c59ddaaaebed --- /dev/null +++ b/CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h @@ -0,0 +1,19 @@ +#ifndef SiPixelStatusScenariosRcd_SiPixelStatusScenariosRcd_h +#define SiPixelStatusScenariosRcd_SiPixelStatusScenariosRcd_h +// -*- C++ -*- +// +// Package: CondFormats/DataRecord +// Class : SiPixelStatusScenariosRcd +// +/**\class SiPixelStatusScenariosRcd SiPixelStatusScenariosRcd.h CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h + Description: [one line class summary] + Usage: + +*/ +// +// Author: Marco Musich +// Created: Wed, 28 Nov 2018 10:31:30 GMT +// +#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" +class SiPixelStatusScenariosRcd : public edm::eventsetup::EventSetupRecordImplementation {}; +#endif diff --git a/CondFormats/DataRecord/src/SiPixelStatusScenarioProbabilityRcd.cc b/CondFormats/DataRecord/src/SiPixelStatusScenarioProbabilityRcd.cc new file mode 100644 index 0000000000000..875b13c09e826 --- /dev/null +++ b/CondFormats/DataRecord/src/SiPixelStatusScenarioProbabilityRcd.cc @@ -0,0 +1,13 @@ +// -*- C++ -*- +// +// Package: CondFormats/DataRecord +// Class : SiPixelStatusScenarioProbabilityRcd +// +// Implementation: +// [Notes on implementation] +// +// Author: Marco Musich +// Created: Wed, 22 Feb 2017 10:31:30 GMT +#include "CondFormats/DataRecord/interface/SiPixelStatusScenarioProbabilityRcd.h" +#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" +EVENTSETUP_RECORD_REG(SiPixelStatusScenarioProbabilityRcd); diff --git a/CondFormats/DataRecord/src/SiPixelStatusScenariosRcd.cc b/CondFormats/DataRecord/src/SiPixelStatusScenariosRcd.cc new file mode 100644 index 0000000000000..72441c447d201 --- /dev/null +++ b/CondFormats/DataRecord/src/SiPixelStatusScenariosRcd.cc @@ -0,0 +1,13 @@ +// -*- C++ -*- +// +// Package: CondFormats/DataRecord +// Class : SiPixelStatusScenariosRcd +// +// Implementation: +// [Notes on implementation] +// +// Author: Marco Musich +// Created: Wed, 22 Feb 2017 10:31:30 GMT +#include "CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h" +#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" +EVENTSETUP_RECORD_REG(SiPixelStatusScenariosRcd); diff --git a/CondFormats/External/interface/PixelFEDChannel.h b/CondFormats/External/interface/PixelFEDChannel.h new file mode 100644 index 0000000000000..ec84227b97611 --- /dev/null +++ b/CondFormats/External/interface/PixelFEDChannel.h @@ -0,0 +1,69 @@ +#ifndef CondFormats_External_PIXELFEDCHANNEL_H +#define CondFormats_External_PIXELFEDCHANNEL_H + +#include +#include +#include + +#include +#include +#include + +#include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h" + +// struct PixelFEDChannel { +// unsigned int fed, link, roc_first, roc_last; +// }; + +namespace boost { + namespace serialization { + + /* + * Note regarding object tracking: all autos used here + * must resolve to untracked types, since we use local + * variables in the stack which could end up with the same + * address. For the moment, all types resolved by auto here + * are primitive types, which are untracked by default + * by Boost Serialization. + */ + + template + void save(Archive & ar, const PixelFEDChannel & obj, const unsigned int) + { + auto fed = obj.fed; + auto link = obj.link; + auto roc_first = obj.roc_first; + auto roc_last = obj.roc_last; + ar & boost::serialization::make_nvp("fed_" , fed ); + ar & boost::serialization::make_nvp("link_" , link ); + ar & boost::serialization::make_nvp("roc_first_" , roc_first ); + ar & boost::serialization::make_nvp("roc_last_" , roc_last ); + } + + template + void load(Archive & ar, PixelFEDChannel & obj, const unsigned int) + { + unsigned int fed_; + unsigned int link_; + unsigned int roc_first_; + unsigned int roc_last_; + + ar & boost::serialization::make_nvp("fed_" , fed_ ); + ar & boost::serialization::make_nvp("link_" , link_ ); + ar & boost::serialization::make_nvp("roc_first_" , roc_first_ ); + ar & boost::serialization::make_nvp("roc_last_" , roc_last_ ); + PixelFEDChannel tmp{fed_, link_, roc_first_, roc_last_}; + obj = tmp; + + } + + template + void serialize(Archive & ar, PixelFEDChannel & obj, const unsigned int v) + { + split_free(ar, obj, v); + } + + } // namespace serialization +} // namespace boost + +#endif diff --git a/CondFormats/External/test/testSerializationExternal.cpp b/CondFormats/External/test/testSerializationExternal.cpp index b56f3f88a6863..4cf38d6f77d8b 100644 --- a/CondFormats/External/test/testSerializationExternal.cpp +++ b/CondFormats/External/test/testSerializationExternal.cpp @@ -7,6 +7,7 @@ #include "CondFormats/External/interface/L1GtLogicParser.h" #include "CondFormats/External/interface/SMatrix.h" #include "CondFormats/External/interface/Timestamp.h" +#include "CondFormats/External/interface/PixelFEDChannel.h" int main() { @@ -19,6 +20,7 @@ int main() testSerialization(); testSerialization(); testSerialization>(); + testSerialization(); return 0; } diff --git a/CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h b/CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h new file mode 100644 index 0000000000000..3389b94009a3e --- /dev/null +++ b/CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h @@ -0,0 +1,50 @@ +#ifndef CondFormats_SiPixelObjects_SiPixelFEDChannelContainer_h +#define CondFormats_SiPixelObjects_SiPixelFEDChannelContainer_h + +#include "CondFormats/Serialization/interface/Serializable.h" +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h" // N.B. a DataFormat is serialized here (need for dedicated serialization rules, see CondFormats/External/interface/PixelFEDChannel.h) + +#include +#include +#include + +class SiPixelFEDChannelContainer{ +public: + typedef std::map > SiPixelFEDChannelCollection; + typedef std::unordered_map SiPixelBadFEDChannelsScenarioMap; + + SiPixelFEDChannelContainer(){} + SiPixelFEDChannelContainer( const SiPixelFEDChannelContainer& rhs ){ m_scenarioMap = rhs.getScenarioMap(); }; + virtual ~SiPixelFEDChannelContainer(){} + + void setScenario(const std::string &theScenarioId, const SiPixelFEDChannelCollection &theBadFEDChannels); + + const SiPixelBadFEDChannelsScenarioMap& getScenarioMap () const {return m_scenarioMap;} + + SiPixelFEDChannelCollection getSiPixelBadFedChannels(const std::string &ScenarioId) const; + const SiPixelFEDChannelCollection & getSiPixelBadFedChannels(const std::string &ScenarioId); + + const std::vector& getSiPixelBadFedChannelsInDetId(const std::string &theScenarioId,DetId theDetId); + + std::unique_ptr getDetSetBadPixelFedChannels(const std::string &ScenarioId) const; + + double size()const {return m_scenarioMap.size();} + std::vector getScenarioList() const; + + void printAll() const; + + //dumping values on output stream + void print(std::ostream & os) const; + +private: + + SiPixelBadFEDChannelsScenarioMap m_scenarioMap; + + COND_SERIALIZABLE; + +}; + +std::ostream & operator<<( std::ostream &, SiPixelFEDChannelContainer FEDChannels); + +#endif //CondFormats_SiPixelObjects_SiPixelFEDChannelContainer_h diff --git a/CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h b/CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h new file mode 100644 index 0000000000000..4bba6d54d1761 --- /dev/null +++ b/CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h @@ -0,0 +1,45 @@ +#ifndef CondFormats_SiPixelObjects_SiPixelQualityProbabilities_h +#define CondFormats_SiPixelObjects_SiPixelQualityProbabilities_h + +#include "CondFormats/Serialization/interface/Serializable.h" + +#include +#include +#include + +class SiPixelQualityProbabilities{ +public: + typedef std::vector > probabilityVec; + typedef std::map probabilityMap; + + SiPixelQualityProbabilities(){} + SiPixelQualityProbabilities( const SiPixelQualityProbabilities& rhs ){ m_probabilities = rhs.getProbability_Map(); }; + virtual ~SiPixelQualityProbabilities(){} + + void setProbabilities(const unsigned int puBin, const probabilityVec &theProbabilities); + + const probabilityMap& getProbability_Map () const {return m_probabilities;} + + probabilityVec getProbabilities(const unsigned int puBin) const; + const probabilityVec & getProbabilities(const unsigned int puBin); + + double size()const {return m_probabilities.size();} + double nelements(const int puBin)const {return m_probabilities.at(puBin).size();} + std::vector getPileUpBins() const; + + void printAll() const; + + //dumping values on output stream + void print(std::ostream & os) const; + +private: + + probabilityMap m_probabilities; + + COND_SERIALIZABLE; + +}; + +std::ostream & operator<<( std::ostream &, SiPixelQualityProbabilities theProbabilities); + +#endif //CondFormats_SiPixelObjects_SiPixelQualityProbabilities_h diff --git a/CondFormats/SiPixelObjects/src/SiPixelFEDChannelContainer.cc b/CondFormats/SiPixelObjects/src/SiPixelFEDChannelContainer.cc new file mode 100644 index 0000000000000..aeb233bc00ab9 --- /dev/null +++ b/CondFormats/SiPixelObjects/src/SiPixelFEDChannelContainer.cc @@ -0,0 +1,134 @@ +#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include +#include // std::setw + +//****************************************************************************// +void SiPixelFEDChannelContainer::setScenario(const std::string &theScenarioId, const SiPixelFEDChannelCollection &theBadFEDChannels) { + if( m_scenarioMap.find(theScenarioId) != m_scenarioMap.end()){ + edm::LogWarning("SiPixelFEDChannelContainer") << "Scenario: " <second; + } else { + throw cms::Exception("SiPixelFEDChannelContainer")<< "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n"; + } +} + +//****************************************************************************// +const SiPixelFEDChannelContainer::SiPixelFEDChannelCollection& SiPixelFEDChannelContainer::getSiPixelBadFedChannels(const std::string &theScenarioId) { + SiPixelBadFEDChannelsScenarioMap::const_iterator it = m_scenarioMap.find(theScenarioId); + + if (it != m_scenarioMap.end()){ + return it->second; + } else { + throw cms::Exception("SiPixelFEDChannelContainer")<< "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n"; + } +} + +//****************************************************************************// +const std::vector& SiPixelFEDChannelContainer::getSiPixelBadFedChannelsInDetId(const std::string &theScenarioId,DetId theDetId) { + + SiPixelBadFEDChannelsScenarioMap::const_iterator it = m_scenarioMap.find(theScenarioId); + + if(it == m_scenarioMap.end()){ + throw cms::Exception("SiPixelFEDChannelContainer")<< "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n"; + } else { + + SiPixelFEDChannelCollection::const_iterator it2 = (it->second).find(theDetId); + + if(it2 == (it->second).end()){ + throw cms::Exception("SiPixelFEDChannelContainer")<< "No Bad Pixel FEDChannels defined for DetId:" <second; + } +} + +//****************************************************************************// +std::unique_ptr SiPixelFEDChannelContainer::getDetSetBadPixelFedChannels(const std::string &theScenarioId) const { + + SiPixelBadFEDChannelsScenarioMap::const_iterator it = m_scenarioMap.find(theScenarioId); + + if(it == m_scenarioMap.end()){ + throw cms::Exception("SiPixelFEDChannelContainer")<< "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n"; + } + + std::unique_ptr disabled_channelcollection = std::make_unique >(); + auto SiPixelBadFedChannels = it->second; + for(const auto &entry : SiPixelBadFedChannels){ + disabled_channelcollection->insert(entry.first, entry.second.data(), entry.second.size()); + } + return disabled_channelcollection; +} + + +//****************************************************************************// +void SiPixelFEDChannelContainer::printAll() const { + + edm::LogVerbatim("SiPixelFEDChannelContainer")<<"SiPixelFEDChannelContainer::printAll()"; + edm::LogVerbatim("SiPixelFEDChannelContainer")<<" ==================================================================================================================="; + for(auto it = m_scenarioMap.begin(); it != m_scenarioMap.end() ; ++it){ + edm::LogVerbatim("SiPixelFEDChannelContainer")<< "run :"<< it->first << " \n "; + for (const auto& thePixelFEDChannel : it->second){ + + DetId detId = thePixelFEDChannel.first; + + edm::LogVerbatim("SiPixelFEDChannelContainer")<< "DetId :"<< detId << " \n "; + + for(const auto& entry: thePixelFEDChannel.second) { + //unsigned int fed, link, roc_first, roc_last; + edm::LogVerbatim("SiPixelFEDChannelContainer")<< " fed : "<< entry.fed + << " link : "<< entry.link + << " roc_first : "<< entry.roc_first + << " roc_last: : "<< entry.roc_last; + } + } + } +} + +//****************************************************************************// +void SiPixelFEDChannelContainer::print(std::ostream & os) const { + for(auto it = m_scenarioMap.begin(); it != m_scenarioMap.end() ; ++it){ + os<< "run :"<< it->first << " \n "; + for (const auto& thePixelFEDChannel : it->second){ + + DetId detId = thePixelFEDChannel.first; + os<< "DetId :"<< detId << " \n "; + for(const auto& entry: thePixelFEDChannel.second) { + os<< " fed : "<< entry.fed + << " link : "<< entry.link + << " roc_first : "<< entry.roc_first + << " roc_last: : "<< entry.roc_last; + } + } + } +} + +//****************************************************************************// +std::vector SiPixelFEDChannelContainer::getScenarioList() const { + std::vector scenarios; + scenarios.reserve(m_scenarioMap.size()); + + for(auto it = m_scenarioMap.begin(); it != m_scenarioMap.end() ; ++it){ + scenarios.push_back(it->first); + } + return scenarios; +} + +//****************************************************************************// +std::ostream & operator<<( std::ostream & os, SiPixelFEDChannelContainer FEDChannels) { + std::stringstream ss; + FEDChannels.print( ss ); + os << ss.str(); + return os; +} diff --git a/CondFormats/SiPixelObjects/src/SiPixelQualityProbabilities.cc b/CondFormats/SiPixelObjects/src/SiPixelQualityProbabilities.cc new file mode 100644 index 0000000000000..e4c90d898acec --- /dev/null +++ b/CondFormats/SiPixelObjects/src/SiPixelQualityProbabilities.cc @@ -0,0 +1,86 @@ +#include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include +#include // std::setw + +//****************************************************************************// +void SiPixelQualityProbabilities::setProbabilities(const unsigned int puBin, const probabilityVec &theProbabilities) { + + if( m_probabilities.find(puBin) != m_probabilities.end()){ + edm::LogWarning("SiPixelQualityProbabilities") << "PU bin: " << puBin <<" is already in the map!"<second; + } else { + throw cms::Exception("SiPixelQualityProbabilities")<< "No Probabilities are defined for PU bin " << puBin << "\n"; + } +} + +//****************************************************************************// +const SiPixelQualityProbabilities::probabilityVec& SiPixelQualityProbabilities::getProbabilities(const unsigned int puBin) { + probabilityMap::const_iterator it = m_probabilities.find(puBin); + + if (it != m_probabilities.end()){ + return it->second; + } else { + throw cms::Exception("SiPixelQualityProbabilities")<< "No Probabilities are defined for PU bin " << puBin << "\n"; + } + +} + + +//****************************************************************************// +void SiPixelQualityProbabilities::printAll() const { + + edm::LogVerbatim("SiPixelQualityProbabilities")<<"SiPixelQualityProbabilities::printAll()"; + edm::LogVerbatim("SiPixelQualityProbabilities")<<" ==================================================================================================================="; + for(auto it = m_probabilities.begin(); it != m_probabilities.end() ; ++it){ + edm::LogVerbatim("SiPixelQualityProbabilities")<< "PU :"<< it->first << " \n "; + for (const auto &entry : it->second){ + edm::LogVerbatim("SiPixelQualityProbabilities")<<"SiPixelQuality snapshot: " << entry.first << " |probability: " << entry.second << std::endl; + } + } + +} + +//****************************************************************************// +void SiPixelQualityProbabilities::print(std::ostream & os) const { + + for(auto it = m_probabilities.begin(); it != m_probabilities.end() ; ++it){ + os<< "PU :"<< it->first << " \n "; + for (const auto &entry : it->second){ + os<<"SiPixelQuality snapshot: " << entry.first << " |probability: " << entry.second << std::endl; + } + } + +} + + +//****************************************************************************// +std::vector SiPixelQualityProbabilities::getPileUpBins() const { + std::vector bins; + bins.reserve(m_probabilities.size()); + + for(auto it = m_probabilities.begin(); it != m_probabilities.end() ; ++it){ + bins.push_back(it->first); + } + return bins; +} + +//****************************************************************************// +std::ostream & operator<<( std::ostream & os, SiPixelQualityProbabilities theProbabilities) { + std::stringstream ss; + theProbabilities.print( ss ); + os << ss.str(); + return os; +} diff --git a/CondFormats/SiPixelObjects/src/T_EventSetup_SiPixelFEDChannelContainer.cc b/CondFormats/SiPixelObjects/src/T_EventSetup_SiPixelFEDChannelContainer.cc new file mode 100644 index 0000000000000..7a958accacd71 --- /dev/null +++ b/CondFormats/SiPixelObjects/src/T_EventSetup_SiPixelFEDChannelContainer.cc @@ -0,0 +1,7 @@ +// system include files + +// user include files +#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h" +#include "FWCore/Utilities/interface/typelookup.h" + +TYPELOOKUP_DATA_REG(SiPixelFEDChannelContainer); diff --git a/CondFormats/SiPixelObjects/src/T_EventSetup_SiPixelQualityProbabilities.cc b/CondFormats/SiPixelObjects/src/T_EventSetup_SiPixelQualityProbabilities.cc new file mode 100644 index 0000000000000..30437db9e146f --- /dev/null +++ b/CondFormats/SiPixelObjects/src/T_EventSetup_SiPixelQualityProbabilities.cc @@ -0,0 +1,5 @@ +// system include files +// user include files +#include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h" +#include "FWCore/Utilities/interface/typelookup.h" +TYPELOOKUP_DATA_REG(SiPixelQualityProbabilities); diff --git a/CondFormats/SiPixelObjects/src/classes.h b/CondFormats/SiPixelObjects/src/classes.h index 2b4e64b14ccfe..006eacf2c6ec0 100644 --- a/CondFormats/SiPixelObjects/src/classes.h +++ b/CondFormats/SiPixelObjects/src/classes.h @@ -15,6 +15,8 @@ #include "CondFormats/SiPixelObjects/interface/SiPixelPerformanceSummary.h" #include "CondFormats/SiPixelObjects/interface/SiPixelCalibConfiguration.h" #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h" #include "CondFormats/SiPixelObjects/interface/PixelDCSObject.h" template struct PixelDCSObject; @@ -45,6 +47,10 @@ namespace CondFormats_SiPixelObjects { std::vector::iterator p9; std::vector::const_iterator p10; std::vector p11; + + std::map myProbabilityMap; + std::map myPixelFEDChannelCollection; + }; } diff --git a/CondFormats/SiPixelObjects/src/classes_def.xml b/CondFormats/SiPixelObjects/src/classes_def.xml index 83b85d209955f..50b75f035a0aa 100644 --- a/CondFormats/SiPixelObjects/src/classes_def.xml +++ b/CondFormats/SiPixelObjects/src/classes_def.xml @@ -67,6 +67,13 @@ + + + + + + + diff --git a/CondFormats/SiPixelObjects/src/headers.h b/CondFormats/SiPixelObjects/src/headers.h index ce8cc1a84704e..034eb6df5885b 100644 --- a/CondFormats/SiPixelObjects/src/headers.h +++ b/CondFormats/SiPixelObjects/src/headers.h @@ -16,7 +16,10 @@ #include "CondFormats/SiPixelObjects/interface/SiPixelPerformanceSummary.h" #include "CondFormats/SiPixelObjects/interface/SiPixelCalibConfiguration.h" #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h" #include "CondFormats/SiPixelObjects/interface/PixelDCSObject.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h" #include "CondFormats/External/interface/DetID.h" +#include "CondFormats/External/interface/PixelFEDChannel.h" diff --git a/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestReader.cc b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestReader.cc new file mode 100644 index 0000000000000..a07eae336e742 --- /dev/null +++ b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestReader.cc @@ -0,0 +1,110 @@ +#include +#include +#include +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h" +#include "CondFormats/DataRecord/interface/SiPixelQualityFromDbRcd.h" +#include "CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h" + +class SiPixelFEDChannelContainerTestReader : public edm::one::EDAnalyzer<> { +public: + explicit SiPixelFEDChannelContainerTestReader(edm::ParameterSet const& p); + ~SiPixelFEDChannelContainerTestReader(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + + virtual void analyze(const edm::Event& e, const edm::EventSetup& c) override; + + // ----------member data --------------------------- + const bool printdebug_; + const std::string formatedOutput_; + +}; + +SiPixelFEDChannelContainerTestReader::SiPixelFEDChannelContainerTestReader(edm::ParameterSet const& p): + printdebug_(p.getUntrackedParameter("printDebug",true)), + formatedOutput_(p.getUntrackedParameter("outputFile","")) +{ + edm::LogInfo("SiPixelFEDChannelContainerTestReader")<<"SiPixelFEDChannelContainerTestReader"< qualityCollectionHandle; + edm::LogInfo("SiPixelFEDChannelContainerTestReader") <<"got eshandle"<().get(qualityCollectionHandle); + edm::LogInfo("SiPixelFEDChannelContainerTestReader") <<"got context"<size() << std::endl; + edm::LogInfo("SiPixelFEDChannelContainerTestReader") <<"Content of myQuality_Map "<printAll(); + } + + FILE* pFile=NULL; + if(formatedOutput_!="")pFile=fopen(formatedOutput_.c_str(), "w"); + if(pFile){ + + fprintf(pFile,"SiPixelFEDChannelContainer::printAll() \n"); + fprintf(pFile," =================================================================================================================== \n"); + + SiPixelFEDChannelContainer::SiPixelBadFEDChannelsScenarioMap m_qualities = quality_map-> getScenarioMap(); + + for(auto it = m_qualities.begin(); it != m_qualities.end() ; ++it){ + fprintf(pFile," =================================================================================================================== \n"); + fprintf(pFile,"run : %s \n ",(it->first).c_str()); + for (const auto& thePixelFEDChannel : it->second){ + DetId detId = thePixelFEDChannel.first; + fprintf(pFile,"DetId : %i \n",detId.rawId()); + for(const auto& entry: thePixelFEDChannel.second) { + //unsigned int fed, link, roc_first, roc_last; + fprintf(pFile,"fed : %i | link : %i | roc_first : %i | roc_last: %i: \n",entry.fed, entry.link, entry.roc_first, entry.roc_last); + } + } + } + } +} + +void +SiPixelFEDChannelContainerTestReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.setComment("Reads payloads of type SiPixelFEDChannelContainer"); + desc.addUntracked("printDebug",true); + desc.addUntracked("outputFile",""); + descriptions.add("SiPixelFEDChannelContainerTestReader",desc); +} + +DEFINE_FWK_MODULE(SiPixelFEDChannelContainerTestReader); diff --git a/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestReader_cfg.py b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestReader_cfg.py new file mode 100644 index 0000000000000..6cd08e5be9a09 --- /dev/null +++ b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestReader_cfg.py @@ -0,0 +1,62 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("ProcessOne") + +## +## MessageLogger +## +process.load('FWCore.MessageService.MessageLogger_cfi') +process.MessageLogger.categories.append("SiPixelFEDChannelContainerTestReader") +process.MessageLogger.categories.append("SiPixelFEDChannelContainer") +process.MessageLogger.destinations = cms.untracked.vstring("cout") +process.MessageLogger.cout = cms.untracked.PSet( + threshold = cms.untracked.string("INFO"), + default = cms.untracked.PSet(limit = cms.untracked.int32(0)), + FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1), + reportEvery = cms.untracked.int32(1000) + ), + SiPixelFEDChannelContainerTestReader = cms.untracked.PSet( limit = cms.untracked.int32(-1)), + SiPixelFEDChannelContainer = cms.untracked.PSet( limit = cms.untracked.int32(-1)) + ) +process.MessageLogger.statistics.append('cout') + +## +## Empty Source +## +process.source = cms.Source("EmptyIOVSource", + timetype = cms.string('runnumber'), + firstValue = cms.uint64(315708), + lastValue = cms.uint64(315708), + interval = cms.uint64(1) + ) +## +## Get the payload +## +from CondCore.CondDB.CondDB_cfi import * +CondDBQualityCollection = CondDB.clone(connect = cms.string("sqlite_file:SiPixelStatusScenarios_v1.db")) + +process.dbInput = cms.ESSource("PoolDBESSource", + CondDBQualityCollection, + toGet = cms.VPSet(cms.PSet(record = cms.string('SiPixelStatusScenariosRcd'), + tag = cms.string('SiPixelFEDChannelContainer_StuckTBM_2018_v1_mc') # choose tag you want + ) + ) + ) +## +## Retrieve it and check it's available in the ES +## +process.get = cms.EDAnalyzer("EventSetupRecordDataGetter", + toGet = cms.VPSet(cms.PSet(record = cms.string('SiPixelStatusScenariosRcd'), + data = cms.vstring('SiPixelFEDChannelContainer') + ) + ), + verbose = cms.untracked.bool(True) + ) +## +## Read it back +## +process.ReadDB = cms.EDAnalyzer("SiPixelFEDChannelContainerTestReader") +process.ReadDB.printDebug = cms.untracked.bool(True) +process.ReadDB.outputFile = cms.untracked.string('SiPixelFEDChannelContainer.log') + +process.p = cms.Path(process.get+process.ReadDB) diff --git a/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestWriter.cc b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestWriter.cc new file mode 100644 index 0000000000000..90b1ea77beec0 --- /dev/null +++ b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestWriter.cc @@ -0,0 +1,247 @@ +// -*- C++ -*- +// +// Package: CondFormats/SiPixelObjects +// Class: SiPixelFEDChannelContainerTestWriter +// +/**\class SiPixelFEDChannelContainerTestWriter SiPixelFEDChannelContainerTestWriter.cc CondFormats/SiPixelObjects/plugins/SiPixelFEDChannelContainerTestWriter.cc + Description: class to build the SiPixelFEDChannelContainer payloads +*/ +// +// Original Author: Marco Musich +// Created: Wed, 27 Nov 2018 12:04:36 GMT +// +// + +// system include files +#include + +// user include files +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" +#include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h" +#include "CondFormats/DataRecord/interface/SiPixelQualityFromDbRcd.h" +#include "CondFormats/SiPixelObjects/interface/CablingPathToDetUnit.h" +#include "CondFormats/SiPixelObjects/interface/PixelROC.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/ESWatcher.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +// +// class declaration +// + +class SiPixelFEDChannelContainerTestWriter : public edm::one::EDAnalyzer<> { + public: + explicit SiPixelFEDChannelContainerTestWriter(const edm::ParameterSet&); + ~SiPixelFEDChannelContainerTestWriter(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + SiPixelFEDChannelContainer::SiPixelFEDChannelCollection createFromSiPixelQuality(const SiPixelQuality & theQuality, const SiPixelFedCablingMap& theFedCabling); + + private: + virtual void beginJob() override; + virtual void analyze(const edm::Event&, const edm::EventSetup&) override; + virtual void endJob() override; + + // ----------member data --------------------------- + const std::string m_record; + const bool printdebug_; + const bool isMC_; + SiPixelFEDChannelContainer* myQualities; + + int IOVcount_; + edm::ESWatcher SiPixelQualityWatcher_; + +}; + +// +// constructors and destructor +// +SiPixelFEDChannelContainerTestWriter::SiPixelFEDChannelContainerTestWriter(const edm::ParameterSet& iConfig): + m_record(iConfig.getParameter("record")), + printdebug_(iConfig.getUntrackedParameter("printDebug",false)), + isMC_(iConfig.getUntrackedParameter("isMC",true)) +{ + //now do what ever initialization is needed + myQualities = new SiPixelFEDChannelContainer(); +} + + +SiPixelFEDChannelContainerTestWriter::~SiPixelFEDChannelContainerTestWriter() +{ + delete myQualities; +} + +// +// member functions +// + +// ------------ method called for each event ------------ +void +SiPixelFEDChannelContainerTestWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + + unsigned int RunNumber_= iEvent.eventAuxiliary().run(); + unsigned int LuminosityBlockNumber_ = iEvent.eventAuxiliary().luminosityBlock(); + + bool hasQualityIOV = SiPixelQualityWatcher_.check(iSetup); + + if(hasQualityIOV){ + + //Retrieve the strip quality from conditions + edm::ESHandle siPixelQuality_; + iSetup.get().get(siPixelQuality_); + + edm::ESHandle cablingMapHandle; + iSetup.get().get(cablingMapHandle); + + std::string scenario = std::to_string(RunNumber_)+"_"+std::to_string(LuminosityBlockNumber_); + + edm::LogInfo("SiPixelFEDChannelContainerTestWriter")<<"Found IOV:" << RunNumber_ <<"("<< LuminosityBlockNumber_ <<")"<createFromSiPixelQuality(*(siPixelQuality_.product()),*(cablingMapHandle.product())); + myQualities->setScenario(scenario,theSiPixelFEDChannelCollection); + + IOVcount_++; + + } +} + +// ------------ method called once each job just before starting event loop ------------ +SiPixelFEDChannelContainer::SiPixelFEDChannelCollection +SiPixelFEDChannelContainerTestWriter::createFromSiPixelQuality(const SiPixelQuality & theQuality, const SiPixelFedCablingMap& theFedCabling) +{ + auto fedid_ = theFedCabling.det2fedMap(); + + SiPixelFEDChannelContainer::SiPixelFEDChannelCollection theBadChannelCollection; + + auto theDisabledModules = theQuality.getBadComponentList(); + for (const auto &mod : theDisabledModules){ + //mod.DetID, mod.errorType,mod.BadRocs + + int coded_badRocs = mod.BadRocs; + std::vector disabledChannelsDetSet; + std::vector path = theFedCabling.pathToDetUnit(mod.DetID); + auto cabling_ = theFedCabling.cablingTree(); + unsigned int nrocs_inLink(0); + if (path.size() != 0){ + const sipixelobjects::PixelFEDCabling * aFed = cabling_->fed(path.at(0).fed); + const sipixelobjects::PixelFEDLink * link = aFed->link(path.at(0).link); + nrocs_inLink = link->numberOfROCs(); + } + + std::bitset<16> bad_rocs(coded_badRocs); + unsigned int n_ch = bad_rocs.size()/nrocs_inLink; + + for (unsigned int i_roc = 0; i_roc < n_ch; ++i_roc){ + + unsigned int first_idx = nrocs_inLink*i_roc; + unsigned int sec_idx = nrocs_inLink*(i_roc+1)-1; + unsigned int mask = pow(2,nrocs_inLink)-1; + unsigned int n_setbits = (coded_badRocs >> (i_roc*nrocs_inLink)) & mask; + + if (n_setbits==0){ + continue; + } + + if(n_setbits != mask){ + edm::LogWarning("SiPixelFEDChannelContainerTestWriter") << "Mismatch! DetId: "<< mod.DetID << " " << n_setbits << " " << mask << std::endl; + continue; + } + + if(printdebug_){ + edm::LogVerbatim("SiPixelFEDChannelContainerTestWriter") << "passed" << std::endl; + } + + unsigned int link_id = 99999; + unsigned int fed_id = 99999; + + for (auto const& p: path){ + const sipixelobjects::PixelFEDCabling * aFed = cabling_->fed(p.fed); + const sipixelobjects::PixelFEDLink * link = aFed->link(p.link); + const sipixelobjects::PixelROC * roc = link->roc(p.roc); + unsigned int first_roc = roc->idInDetUnit(); + + if (first_roc == first_idx){ + link_id = p.link; + fed_id = p.fed; + break; + } + } + + if(printdebug_){ + edm::LogVerbatim("SiPixelFEDChannelContainerTestWriter") << " " << fed_id << " " << link_id << " " << first_idx << " " << sec_idx << std::endl; + } + + PixelFEDChannel ch = {fed_id, link_id, first_idx, sec_idx}; + disabledChannelsDetSet.push_back(ch); + + if(printdebug_){ + edm::LogVerbatim("SiPixelFEDChannelContainerTestWriter") << i_roc << " " << coded_badRocs << " " << first_idx << " " << sec_idx << std::endl; + edm::LogVerbatim("SiPixelFEDChannelContainerTestWriter") << "=======================================" << std::endl; + } + } + + if (!disabledChannelsDetSet.empty()) { + theBadChannelCollection[mod.DetID] = disabledChannelsDetSet; + } + } + return theBadChannelCollection; +} + +void +SiPixelFEDChannelContainerTestWriter::beginJob() +{ + IOVcount_=0; +} + +// ------------ method called once each job just after ending the event loop ------------ +void +SiPixelFEDChannelContainerTestWriter::endJob() +{ + + edm::LogInfo("SiPixelFEDChannelContainerTestWriter")<<"Analyzed "<size() <printAll(); + } + + // Form the data here + edm::Service poolDbService; + if( poolDbService.isAvailable() ){ + cond::Time_t valid_time = poolDbService->currentTime(); + // this writes the payload to begin in current run defined in cfg + if(!isMC_){ + poolDbService->writeOne(myQualities,valid_time, m_record); + } else { + // for MC IOV since=1 + poolDbService->writeOne(myQualities,1, m_record); + } + } +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +SiPixelFEDChannelContainerTestWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.setComment("Writes payloads of type SiPixelFEDChannelContainer"); + desc.addUntracked("printDebug",false); + desc.add("record","SiPixelStatusScenariosRcd"); + descriptions.add("SiPixelFEDChannelContainerTestWriter",desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(SiPixelFEDChannelContainerTestWriter); diff --git a/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestWriter_cfg.py b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestWriter_cfg.py new file mode 100644 index 0000000000000..576969b4c8a07 --- /dev/null +++ b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerTestWriter_cfg.py @@ -0,0 +1,69 @@ +import FWCore.ParameterSet.Config as cms +process = cms.Process("ProcessOne") + +## +## MessageLogger +## +process.load('FWCore.MessageService.MessageLogger_cfi') +process.MessageLogger.categories.append("SiPixelFEDChannelContainerTestWriter") +process.MessageLogger.categories.append("SiPixelFEDChannelContainer") +process.MessageLogger.destinations = cms.untracked.vstring("cout") +process.MessageLogger.cout = cms.untracked.PSet( + threshold = cms.untracked.string("INFO"), + default = cms.untracked.PSet(limit = cms.untracked.int32(0)), + FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1), + reportEvery = cms.untracked.int32(1000) + ), + SiPixelFEDChannelContainerTestWriter = cms.untracked.PSet( limit = cms.untracked.int32(-1)), + SiPixelFEDChannelContainer = cms.untracked.PSet( limit = cms.untracked.int32(-1)) + ) +process.MessageLogger.statistics.append('cout') + +## +## Empty source +## +process.source = cms.Source("EmptySource", + firstRun = cms.untracked.uint32(315704), + numberEventsInRun = cms.untracked.uint32(2000), + firstLuminosityBlock = cms.untracked.uint32(1), + numberEventsInLuminosityBlock = cms.untracked.uint32(1), + ) + +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(25000000)) +#process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(10000)) + +## +## Database output service +## +process.load("CondCore.CondDB.CondDB_cfi") + +# DB input service: +process.CondDB.connect = "frontier://FrontierProd/CMS_CONDITIONS" +process.dbInput = cms.ESSource("PoolDBESSource", + process.CondDB, + toGet = cms.VPSet(cms.PSet(record = cms.string("SiPixelQualityFromDbRcd"), + tag = cms.string("SiPixelQuality_byPCL_stuckTBM_v1") + ), + cms.PSet(record = cms.string("SiPixelFedCablingMapRcd"), + tag = cms.string("SiPixelFedCablingMap_phase1_v7") + ) + ) + ) +## +## Output database (in this case local sqlite file) +## +process.CondDB.connect = 'sqlite_file:SiPixelStatusScenarios_v1.db' +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + process.CondDB, + timetype = cms.untracked.string('runnumber'), + toPut = cms.VPSet(cms.PSet(record = cms.string('SiPixelStatusScenariosRcd'), + tag = cms.string('SiPixelFEDChannelContainer_StuckTBM_2018_v1_mc') + ) + ) + ) + +process.WriteInDB = cms.EDAnalyzer("SiPixelFEDChannelContainerTestWriter", + record= cms.string('SiPixelStatusScenariosRcd'), + ) + +process.p = cms.Path(process.WriteInDB) diff --git a/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerWriteFromASCII.cc b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerWriteFromASCII.cc new file mode 100644 index 0000000000000..404ec8a2770e0 --- /dev/null +++ b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerWriteFromASCII.cc @@ -0,0 +1,170 @@ +// -*- C++ -*- +// +// Package: CondFormats/SiPixelObjects +// Class: SiPixelFEDChannelContainerTestWriter +// +/**\class SiPixelFEDChannelContainerTestWriter SiPixelFEDChannelContainerTestWriter.cc CondFormats/SiPixelObjects/plugins/SiPixelFEDChannelContainerTestWriter.cc + Description: class to build the SiPixelFEDChannelContainer payloads +*/ +// +// Original Author: Marco Musich +// Created: Wed, 27 Nov 2018 12:04:36 GMT +// +// + +// system include files +#include +#include + +// user include files +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h" +#include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h" +#include "CondFormats/DataRecord/interface/SiPixelQualityFromDbRcd.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/ESWatcher.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +// +// class declaration +// + +class SiPixelFEDChannelContainerWriteFromASCII : public edm::one::EDAnalyzer<> { + public: + explicit SiPixelFEDChannelContainerWriteFromASCII(const edm::ParameterSet&); + ~SiPixelFEDChannelContainerWriteFromASCII(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + + private: + virtual void beginJob() override; + virtual void analyze(const edm::Event&, const edm::EventSetup&) override; + virtual void endJob() override; + + // ----------member data --------------------------- + const std::string m_record; + const std::string m_SnapshotInputs; + const bool printdebug_; + SiPixelFEDChannelContainer* myQualities; + +}; + +// +// constructors and destructor +// +SiPixelFEDChannelContainerWriteFromASCII::SiPixelFEDChannelContainerWriteFromASCII(const edm::ParameterSet& iConfig): + m_record(iConfig.getParameter("record")), + m_SnapshotInputs(iConfig.getParameter("snapshots")), + printdebug_(iConfig.getUntrackedParameter("printDebug",false)) +{ + //now do what ever initialization is needed + myQualities = new SiPixelFEDChannelContainer(); +} + + +SiPixelFEDChannelContainerWriteFromASCII::~SiPixelFEDChannelContainerWriteFromASCII() +{ + delete myQualities; +} + +// +// member functions +// + +// ------------ method called for each event ------------ +void +SiPixelFEDChannelContainerWriteFromASCII::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + + std::ifstream mysnapshots(m_SnapshotInputs); + std::string line; + + std::string scenario =""; + unsigned int thedetid(0); + + SiPixelFEDChannelContainer::SiPixelFEDChannelCollection theBadFEDChannels; + + if(mysnapshots.is_open()){ + while (getline (mysnapshots, line)) { + //edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII") << line << std::endl; + std::istringstream iss (line); + unsigned int run, ls, detid, fed, link, roc_first, roc_last; + iss >> run >> ls >> detid >> fed >> link >> roc_first >> roc_last; + + PixelFEDChannel theBadChannel{fed,link,roc_first,roc_last}; + + auto newscenario=std::to_string(run)+"_"+std::to_string(ls); + if(newscenario!=scenario){ + edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII")<< "================================" << std::endl; + edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII")<< "found a new scenario: " << newscenario << std::endl; + if(scenario!=""){ + edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII")<< "size of the fed channel vector: " << theBadFEDChannels.size() << std::endl; + edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII")<< "================================" << std::endl; + myQualities->setScenario(scenario,theBadFEDChannels); + theBadFEDChannels.clear(); + } + scenario=newscenario; + } + + if(detid!=thedetid){ + if(printdebug_) edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII")<< "found a new detid!" << detid << std::endl; + thedetid=detid; + } + theBadFEDChannels[thedetid].push_back(theBadChannel); + } + } + + myQualities->setScenario(scenario,theBadFEDChannels); + + if(printdebug_){ + edm::LogInfo("SiPixelFEDChannelContainerWriteFromASCII")<<"Content of SiPixelFEDChannelContainer "<printAll(); + } +} + +// ------------ method called once each job just before starting event loop ------------ +void +SiPixelFEDChannelContainerWriteFromASCII::beginJob() +{ +} + +// ------------ method called once each job just after ending the event loop ------------ +void +SiPixelFEDChannelContainerWriteFromASCII::endJob() +{ + + edm::LogInfo("SiPixelFEDChannelContainerWriteFromASCII")<<"Size of SiPixelFEDChannelContainer object "<< myQualities->size() < poolDbService; + if( poolDbService.isAvailable() ){ + cond::Time_t valid_time = poolDbService->currentTime(); + // this writes the payload to begin in current run defined in cfg + poolDbService->writeOne(myQualities,valid_time, m_record); + } +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +SiPixelFEDChannelContainerWriteFromASCII::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.setComment("Writes payloads of type SiPixelFEDChannelContainer from input ASCII files"); + desc.addUntracked("printDebug",true); + desc.add("snapshots",""); + desc.add("record","SiPixelStatusScenariosRcd"); + descriptions.add("SiPixelFEDChannelContainerWriteFromASCII",desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(SiPixelFEDChannelContainerWriteFromASCII); diff --git a/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerWriteFromASCII_cfg.py b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerWriteFromASCII_cfg.py new file mode 100644 index 0000000000000..7a0437d682a53 --- /dev/null +++ b/CondFormats/SiPixelObjects/test/SiPixelFEDChannelContainerWriteFromASCII_cfg.py @@ -0,0 +1,70 @@ +import FWCore.ParameterSet.Config as cms +process = cms.Process("ProcessOne") + +## +## MessageLogger +## +process.load('FWCore.MessageService.MessageLogger_cfi') +process.MessageLogger.categories.append("SiPixelFEDChannelContainerWriteFromASCII") +process.MessageLogger.categories.append("SiPixelFEDChannelContainer") +process.MessageLogger.destinations = cms.untracked.vstring("cout") +process.MessageLogger.cout = cms.untracked.PSet( + threshold = cms.untracked.string("INFO"), + default = cms.untracked.PSet(limit = cms.untracked.int32(0)), + FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1), + reportEvery = cms.untracked.int32(100) + ), + SiPixelFEDChannelContainerWriteFromASCII = cms.untracked.PSet( limit = cms.untracked.int32(-1)), + SiPixelFEDChannelContainer = cms.untracked.PSet( limit = cms.untracked.int32(-1)) + ) +process.MessageLogger.statistics.append('cout') + +## +## Empty source +## +process.source = cms.Source("EmptySource", + firstRun = cms.untracked.uint32(1), + numberEventsInRun = cms.untracked.uint32(1), + firstLuminosityBlock = cms.untracked.uint32(1), + numberEventsInLuminosityBlock = cms.untracked.uint32(1), + ) + +#process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(25000000)) +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1)) + +## +## Database output service +## +process.load("CondCore.CondDB.CondDB_cfi") + +# DB input service: +process.CondDB.connect = "frontier://FrontierProd/CMS_CONDITIONS" +process.dbInput = cms.ESSource("PoolDBESSource", + process.CondDB, + toGet = cms.VPSet(cms.PSet(record = cms.string("SiPixelQualityFromDbRcd"), + tag = cms.string("SiPixelQuality_byPCL_stuckTBM_v1") + ), + cms.PSet(record = cms.string("SiPixelFedCablingMapRcd"), + tag = cms.string("SiPixelFedCablingMap_phase1_v7") + ) + ) + ) +## +## Output database (in this case local sqlite file) +## +process.CondDB.connect = 'sqlite_file:SiPixelStatusScenarios_fromFED25.db' +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + process.CondDB, + timetype = cms.untracked.string('runnumber'), + toPut = cms.VPSet(cms.PSet(record = cms.string('SiPixelStatusScenariosRcd'), + tag = cms.string('SiPixelFEDChannelContainer_StuckTBM_2018_v1_mc') + ) + ) + ) + +process.WriteInDB = cms.EDAnalyzer("SiPixelFEDChannelContainerWriteFromASCII", + record= cms.string('SiPixelStatusScenariosRcd'), + snapshots = cms.string('snapshots_fromFED25.txt') + ) + +process.p = cms.Path(process.WriteInDB) diff --git a/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestReader.cc b/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestReader.cc new file mode 100644 index 0000000000000..fe9c63dbe0e63 --- /dev/null +++ b/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestReader.cc @@ -0,0 +1,103 @@ +#include +#include +#include +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h" +#include "CondFormats/DataRecord/interface/SiPixelStatusScenarioProbabilityRcd.h" + +class SiPixelQualityProbabilitiesTestReader : public edm::one::EDAnalyzer<> { +public: + explicit SiPixelQualityProbabilitiesTestReader(edm::ParameterSet const& p); + ~SiPixelQualityProbabilitiesTestReader(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + + virtual void analyze(const edm::Event& e, const edm::EventSetup& c) override; + + // ----------member data --------------------------- + const bool printdebug_; + const std::string formatedOutput_; + +}; + +SiPixelQualityProbabilitiesTestReader::SiPixelQualityProbabilitiesTestReader(edm::ParameterSet const& p): + printdebug_(p.getUntrackedParameter("printDebug",true)), + formatedOutput_(p.getUntrackedParameter("outputFile","")) +{ + edm::LogInfo("SiPixelQualityProbabilitiesTestReader")<<"SiPixelQualityProbabilitiesTestReader"< scenarioProbabilityHandle; + edm::LogInfo("SiPixelQualityProbabilitiesTestReader") <<"got eshandle"<().get(scenarioProbabilityHandle); + edm::LogInfo("SiPixelQualityProbabilitiesTestReader") <<"got context"<size() << std::endl; + edm::LogInfo("SiPixelQualityProbabilitiesTestReader") <<"Content of my Probabilities "<printAll(); + } + + FILE* pFile=NULL; + if(formatedOutput_!="")pFile=fopen(formatedOutput_.c_str(), "w"); + if(pFile){ + + fprintf(pFile,"SiPixelQualityProbabilities::printAll() \n"); + fprintf(pFile," =================================================================================================================== \n"); + + SiPixelQualityProbabilities:: probabilityMap m_probabilities = myProbabilities->getProbability_Map(); + + for(auto it = m_probabilities.begin(); it != m_probabilities.end() ; ++it){ + fprintf(pFile," =================================================================================================================== \n"); + fprintf(pFile,"PU bin : %i \n ",(it->first)); + for (const auto &entry : it->second){ + fprintf(pFile,"Quality snapshot %s, probability %f \n",(entry.first).c_str(),entry.second); + } + } + } +} + +void +SiPixelQualityProbabilitiesTestReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.setComment("Reads payloads of type SiPixelQualityProbabilities"); + desc.addUntracked("printDebug",true); + desc.addUntracked("outputFile",""); + descriptions.add("SiPixelQualityProbabilitiesTestReader",desc); +} + +DEFINE_FWK_MODULE(SiPixelQualityProbabilitiesTestReader); diff --git a/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestReader_cfg.py b/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestReader_cfg.py new file mode 100644 index 0000000000000..c23b308f35527 --- /dev/null +++ b/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestReader_cfg.py @@ -0,0 +1,62 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("ProcessOne") + +## +## MessageLogger +## +process.load('FWCore.MessageService.MessageLogger_cfi') +process.MessageLogger.categories.append("SiPixelQualityProbabilitiesTestReader") +process.MessageLogger.categories.append("SiPixelQualityProbabilities") +process.MessageLogger.destinations = cms.untracked.vstring("cout") +process.MessageLogger.cout = cms.untracked.PSet( + threshold = cms.untracked.string("INFO"), + default = cms.untracked.PSet(limit = cms.untracked.int32(0)), + FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1), + reportEvery = cms.untracked.int32(1000) + ), + SiPixelQualityProbabilitiesTestReader = cms.untracked.PSet( limit = cms.untracked.int32(-1)), + SiPixelQualityProbabilities = cms.untracked.PSet( limit = cms.untracked.int32(-1)) + ) +process.MessageLogger.statistics.append('cout') + +## +## Empty Source +## +process.source = cms.Source("EmptyIOVSource", + timetype = cms.string('runnumber'), + firstValue = cms.uint64(1), + lastValue = cms.uint64(1), + interval = cms.uint64(1) + ) +## +## Get the payload +## +from CondCore.CondDB.CondDB_cfi import * +CondDBQualityProbabilities = CondDB.clone(connect = cms.string("sqlite_file:SiPixelStatusScenarioProbabilities.db")) + +process.dbInput = cms.ESSource("PoolDBESSource", + CondDBQualityProbabilities, + toGet = cms.VPSet(cms.PSet(record = cms.string('SiPixelStatusScenarioProbabilityRcd'), + tag = cms.string('SiPixelQualityProbabilities_v0_mc') # choose tag you want + ) + ) + ) +## +## Retrieve it and check it's available in the ES +## +process.get = cms.EDAnalyzer("EventSetupRecordDataGetter", + toGet = cms.VPSet(cms.PSet(record = cms.string('SiPixelStatusScenarioProbabilityRcd'), + data = cms.vstring('SiPixelQualityProbabilities') + ) + ), + verbose = cms.untracked.bool(True) + ) +## +## Read it back +## +process.ReadDB = cms.EDAnalyzer("SiPixelQualityProbabilitiesTestReader") +process.ReadDB.printDebug = cms.untracked.bool(True) +process.ReadDB.outputFile = cms.untracked.string('SiPixelQualityProbabilities.log') + +process.p = cms.Path(process.get+process.ReadDB) diff --git a/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestWriter.cc b/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestWriter.cc new file mode 100644 index 0000000000000..9e0393b9dece3 --- /dev/null +++ b/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestWriter.cc @@ -0,0 +1,167 @@ +// -*- C++ -*- +// +// Package: CondFormats/SiPixelObjects +// Class: SiPixelQualityProbabilitiesTestWriter +// +/**\class SiPixelQualityProbabilitiesTestWriter SiPixelQualityProbabilitiesTestWriter.cc CondFormats/SiPixelObjects/plugins/SiPixelQualityProbabilitiesTestWriter.cc + Description: class to build the SiPixel Quality probabilities +*/ +// +// Original Author: Marco Musich +// Created: Wed, 30 Nov 2018 13:22:00 GMT +// +// + +// system include files +#include +#include + +// user include files +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h" +#include "CondFormats/DataRecord/interface/SiPixelQualityFromDbRcd.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/ESWatcher.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +// +// class declaration +// + +class SiPixelQualityProbabilitiesTestWriter : public edm::one::EDAnalyzer<> { + public: + explicit SiPixelQualityProbabilitiesTestWriter(const edm::ParameterSet&); + ~SiPixelQualityProbabilitiesTestWriter(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + + private: + virtual void beginJob() override; + virtual void analyze(const edm::Event&, const edm::EventSetup&) override; + virtual void endJob() override; + + // ----------member data --------------------------- + const std::string m_ProbInputs; + const std::string m_SnapshotInputs; + const std::string m_record; + const bool printdebug_; + SiPixelQualityProbabilities* myProbabilities; + +}; + +// +// constructors and destructor +// +SiPixelQualityProbabilitiesTestWriter::SiPixelQualityProbabilitiesTestWriter(const edm::ParameterSet& iConfig): + m_ProbInputs(iConfig.getParameter("probabilities")), + m_SnapshotInputs(iConfig.getParameter("snapshots")), + m_record(iConfig.getParameter("record")), + printdebug_(iConfig.getUntrackedParameter("printDebug",false)) +{ + //now do what ever initialization is needed + myProbabilities = new SiPixelQualityProbabilities(); +} + + +SiPixelQualityProbabilitiesTestWriter::~SiPixelQualityProbabilitiesTestWriter() +{ + delete myProbabilities; +} + +// +// member functions +// + +// ------------ method called for each event ------------ +void +SiPixelQualityProbabilitiesTestWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + std::ifstream myfile(m_ProbInputs); + std::ifstream mysnapshots(m_SnapshotInputs); + std::string line1,line2; + std::map snapshotIdToString; + + if(mysnapshots.is_open()){ + while (getline (mysnapshots, line1)) { + //edm::LogInfo("SiPixelQualityProbabilitiesTestWriter") << line1 << std::endl; + std::istringstream iss (line1); + int id, run, ls; + iss >> id >> run >> ls; + snapshotIdToString[id]=std::to_string(run)+"_"+std::to_string(ls); + } + } + + SiPixelQualityProbabilities::probabilityVec myProbVector; + + if (myfile.is_open()){ + while (getline (myfile, line2)) { + edm::LogInfo("SiPixelQualityProbabilitiesTestWriter") << line2 << std::endl; + std::istringstream iss (line2); + int pileupBinId, nEntries; + iss >> pileupBinId >> nEntries; + edm::LogInfo("SiPixelQualityProbabilitiesTestWriter") << "PILEUP BIN/ENTRIES: " << pileupBinId << " " << nEntries << std::endl; + std::vector ids(nEntries, 0); + std::vector probs(nEntries, 0.0); + for (int i=0;i< nEntries; ++i){ + iss >> ids.at(i) >> probs.at(i); + //edm::LogInfo("SiPixelQualityProbabilitiesTestWriter") << ids.at(i) << " " << probs.at(i)<< std::endl; + auto idAndProb = std::make_pair(snapshotIdToString.at(ids.at(i)),probs.at(i)); + myProbVector.push_back(idAndProb); + } + if(nEntries>0) myProbabilities->setProbabilities(pileupBinId,myProbVector); + myProbVector.clear(); + } + myfile.close(); + } + + if(printdebug_){ + edm::LogInfo("SiPixelQualityProbabilitiesTestWriter")<<"Content of SiPixelQualityProbabilities "<printAll(); + } +} + +// ------------ method called once each job just before starting event loop ------------ +void +SiPixelQualityProbabilitiesTestWriter::beginJob() +{ +} + +// ------------ method called once each job just after ending the event loop ------------ +void +SiPixelQualityProbabilitiesTestWriter::endJob() +{ + + edm::LogInfo("SiPixelQualityProbabilitiesTestWriter")<<"Size of SiPixelQualityProbabilities object "<< myProbabilities->size() < poolDbService; + if( poolDbService.isAvailable() ){ + cond::Time_t valid_time = poolDbService->currentTime(); + // this writes the payload to begin in current run defined in cfg + poolDbService->writeOne(myProbabilities,valid_time, m_record); + } +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +SiPixelQualityProbabilitiesTestWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.setComment("Writes payloads of type SiPixelQualityProbabilities"); + desc.addUntracked("printDebug",true); + desc.add("record","SiPixelStatusScenarioProbabilityRcd"); + desc.add("snapshots",""); + desc.add("probabilities",""); + descriptions.add("SiPixelQualityProbabilitiesTestWriter",desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(SiPixelQualityProbabilitiesTestWriter); diff --git a/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestWriter_cfg.py b/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestWriter_cfg.py new file mode 100644 index 0000000000000..2a6fdcb25743b --- /dev/null +++ b/CondFormats/SiPixelObjects/test/SiPixelQualityProbabilitiesTestWriter_cfg.py @@ -0,0 +1,60 @@ +import FWCore.ParameterSet.Config as cms +process = cms.Process("ProcessOne") + +## +## MessageLogger +## +process.load('FWCore.MessageService.MessageLogger_cfi') +process.MessageLogger.categories.append("SiPixelQualityProbabilitiesTestWriter") +process.MessageLogger.categories.append("SiPixelQualityProbabilities") +process.MessageLogger.destinations = cms.untracked.vstring("cout") +process.MessageLogger.cout = cms.untracked.PSet( + threshold = cms.untracked.string("INFO"), + default = cms.untracked.PSet(limit = cms.untracked.int32(0)), + FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1), + reportEvery = cms.untracked.int32(1000) + ), + SiPixelQualityProbabilitiesTestWriter = cms.untracked.PSet( limit = cms.untracked.int32(-1)), + SiPixelQualityProbabilities = cms.untracked.PSet( limit = cms.untracked.int32(-1)) + ) +process.MessageLogger.statistics.append('cout') + +## +## Empty source +## +process.source = cms.Source("EmptySource", + firstRun = cms.untracked.uint32(1), + numberEventsInRun = cms.untracked.uint32(1), + firstLuminosityBlock = cms.untracked.uint32(1), + numberEventsInLuminosityBlock = cms.untracked.uint32(1), + ) + +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1)) + +## +## Database output service +## +process.load("CondCore.CondDB.CondDB_cfi") + +## +## Output database (in this case local sqlite file) +## +process.CondDB.connect = 'sqlite_file:SiPixelStatusScenarioProbabilities.db' +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + process.CondDB, + timetype = cms.untracked.string('runnumber'), + toPut = cms.VPSet(cms.PSet(record = cms.string('SiPixelStatusScenarioProbabilityRcd'), + tag = cms.string('SiPixelQualityProbabilities_v0_mc') + ) + ) + ) + + +process.WriteInDB = cms.EDAnalyzer("SiPixelQualityProbabilitiesTestWriter", + printDebug = cms.untracked.bool(True), + record = cms.string('SiPixelStatusScenarioProbabilityRcd'), + probabilities = cms.string('snapshotProb_322633.txt'), + snapshots = cms.string('snapshot_ids.txt') + ) + +process.p = cms.Path(process.WriteInDB) diff --git a/CondFormats/SiPixelObjects/test/testSerializationSiPixelObjects.cpp b/CondFormats/SiPixelObjects/test/testSerializationSiPixelObjects.cpp index c181ffe63df18..3ec997e20c421 100644 --- a/CondFormats/SiPixelObjects/test/testSerializationSiPixelObjects.cpp +++ b/CondFormats/SiPixelObjects/test/testSerializationSiPixelObjects.cpp @@ -28,7 +28,11 @@ int main() testSerialization(); testSerialization(); testSerialization(); + testSerialization(); + testSerialization(); + //testSerialization(); testSerialization(); + testSerialization(); testSerialization(); testSerialization(); testSerialization>(); diff --git a/DataFormats/SiPixelDetId/BuildFile.xml b/DataFormats/SiPixelDetId/BuildFile.xml index b5789e0ef2a2a..1971f79b51625 100644 --- a/DataFormats/SiPixelDetId/BuildFile.xml +++ b/DataFormats/SiPixelDetId/BuildFile.xml @@ -1,4 +1,5 @@ + diff --git a/DataFormats/SiPixelDetId/src/ES_PixelFEDChannelCollectionMap.cc b/DataFormats/SiPixelDetId/src/ES_PixelFEDChannelCollectionMap.cc new file mode 100644 index 0000000000000..3cc237783e027 --- /dev/null +++ b/DataFormats/SiPixelDetId/src/ES_PixelFEDChannelCollectionMap.cc @@ -0,0 +1,6 @@ +#include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h" +#include "FWCore/Utilities/interface/typelookup.h" + +typedef std::unordered_map PixelFEDChannelCollectionMap; + +TYPELOOKUP_DATA_REG(PixelFEDChannelCollectionMap); diff --git a/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.cc b/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.cc index dc3c9e4c68f68..8f140bac095e8 100644 --- a/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.cc +++ b/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.cc @@ -48,7 +48,7 @@ SiPixelRawToDigi::SiPixelRawToDigi( const edm::ParameterSet& conf ) regions_(nullptr), hCPU(nullptr), hDigi(nullptr) { - + includeErrors = config_.getParameter("IncludeErrors"); useQuality = config_.getParameter("UseQualityInfo"); if (config_.exists("ErrorList")) { @@ -58,7 +58,8 @@ SiPixelRawToDigi::SiPixelRawToDigi( const edm::ParameterSet& conf ) usererrorlist = config_.getParameter > ("UserErrorList"); } tFEDRawDataCollection = consumes (config_.getParameter("InputLabel")); - + theBadPixelFEDChannelsLabel = consumes(config_.getParameter("BadPixelFEDChannelsInputLabel")); + //start counters ndigis = 0; nwords = 0; @@ -71,7 +72,7 @@ SiPixelRawToDigi::SiPixelRawToDigi( const edm::ParameterSet& conf ) produces("UserErrorModules"); produces >(); } - + // regions if (config_.exists("Regions")) { if(!config_.getParameter("Regions").getParameterNames().empty()) @@ -152,7 +153,9 @@ SiPixelRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descriptions) desc.add("UsePhase1",false)->setComment("## Use phase1"); desc.add("CablingMapLabel","")->setComment("CablingMap label"); //Tav desc.addOptional("CheckPixelOrder"); // never used, kept for back-compatibility + desc.add("BadPixelFEDChannelsInputLabel",edm::InputTag("mix")); descriptions.add("siPixelRawToDigi",desc); + } // ----------------------------------------------------------------------------- @@ -184,7 +187,7 @@ void SiPixelRawToDigi::produce( edm::Event& ev, edm::LogError("SiPixelQualityNotPresent")<<" Configured to use SiPixelQuality, but SiPixelQuality not present"< buffers; ev.getByToken(tFEDRawDataCollection, buffers); @@ -288,11 +291,10 @@ void SiPixelRawToDigi::produce( edm::Event& ev, } } // loop on DetSet of errors - + if (!disabledChannelsDetSet.empty()) { disabled_channelcollection->insert(errordetid, disabledChannelsDetSet.data(), disabledChannelsDetSet.size()); - } - + } } // if error assigned to a real DetId } // loop on errors in event for this FED } // if errors to be included in the event @@ -314,17 +316,32 @@ void SiPixelRawToDigi::produce( edm::Event& ev, hCPU->Fill( theTimer->realTime() ); hDigi->Fill(formatter.nDigis()); } + + //------------------------------------ //send digis and errors back to framework + + edm::Handle pixelFEDChannelCollectionHandle; + std::unique_ptr PixelFEDChannelCollection_ = nullptr; + if (ev.getByToken(theBadPixelFEDChannelsLabel, pixelFEDChannelCollectionHandle)){ + + const PixelFEDChannelCollection * pfcc= pixelFEDChannelCollectionHandle.product(); + PixelFEDChannelCollection_ = std::make_unique(*pfcc); + } + ev.put(std::move(collection)); if(includeErrors){ ev.put(std::move(errorcollection)); ev.put(std::move(tkerror_detidcollection)); - ev.put(std::move(usererror_detidcollection), "UserErrorModules"); - ev.put(std::move(disabled_channelcollection)); + ev.put(std::move(usererror_detidcollection), "UserErrorModules"); + if (PixelFEDChannelCollection_ == nullptr){ + ev.put(std::move(disabled_channelcollection)); + } + else{ + ev.put(std::move(PixelFEDChannelCollection_)); + } } } - // declare this as a framework plugin #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(SiPixelRawToDigi); diff --git a/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.h b/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.h index 8ab5a2647a563..a558ba872101f 100644 --- a/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.h +++ b/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.h @@ -16,6 +16,7 @@ #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" #include "FWCore/Framework/interface/ConsumesCollector.h" #include "FWCore/Utilities/interface/CPUTimer.h" +#include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h" class SiPixelFedCablingTree; class SiPixelFedCabling; @@ -38,13 +39,13 @@ class SiPixelRawToDigi : public edm::stream::EDProducer<> { void produce( edm::Event&, const edm::EventSetup& ) override; private: - + edm::ParameterSet config_; std::unique_ptr cabling_; const SiPixelQuality* badPixelInfo_; PixelUnpackingRegions* regions_; edm::EDGetTokenT tFEDRawDataCollection; - + edm::EDGetTokenT theBadPixelFEDChannelsLabel; TH1D *hCPU, *hDigi; std::unique_ptr theTimer; bool includeErrors; @@ -56,6 +57,7 @@ class SiPixelRawToDigi : public edm::stream::EDProducer<> { edm::ESWatcher recordWatcher; edm::ESWatcher qualityWatcher; edm::InputTag label; + int ndigis; int nwords; bool usePilotBlade; diff --git a/EventFilter/SiPixelRawToDigi/python/SiPixelRawToDigi_cfi.py b/EventFilter/SiPixelRawToDigi/python/SiPixelRawToDigi_cfi.py index fda0b69fa46a1..d56f03a59d9e8 100644 --- a/EventFilter/SiPixelRawToDigi/python/SiPixelRawToDigi_cfi.py +++ b/EventFilter/SiPixelRawToDigi/python/SiPixelRawToDigi_cfi.py @@ -20,3 +20,5 @@ from Configuration.Eras.Modifier_phase1Pixel_cff import phase1Pixel phase1Pixel.toModify(siPixelDigis, UsePhase1=True) +from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2 +premix_stage2.toModify(siPixelDigis, BadPixelFEDChannelsInputLabel = "mixData") diff --git a/SimGeneral/MixingModule/python/SiPixelSimParameters_cfi.py b/SimGeneral/MixingModule/python/SiPixelSimParameters_cfi.py index f097248d5f157..dbc6de73422c1 100644 --- a/SimGeneral/MixingModule/python/SiPixelSimParameters_cfi.py +++ b/SimGeneral/MixingModule/python/SiPixelSimParameters_cfi.py @@ -36,9 +36,10 @@ def _modifyPixelDigitizerForPhase1Pixel( digitizer ) : digitizer.ElectronsPerVcal_Offset = cms.double(-60) # L2-4: -60 +- 130 digitizer.ElectronsPerVcal_L1_Offset = cms.double(-670) # L1: -670 +- 220 digitizer.UseReweighting = cms.bool(True) - + SiPixelSimBlock = cms.PSet( + KillBadFEDChannels = cms.bool(False), UseReweighting = cms.bool(False), PrintClusters = cms.bool(False), PrintTemplates = cms.bool(False), @@ -107,6 +108,7 @@ def _modifyPixelDigitizerForPhase1Pixel( digitizer ) : AddNoise = True, AddNoisyPixels = False, AddPixelInefficiency = False, #done in second step + KillBadFEDChannels = False, #done in second step ) # Threshold in electrons are the Official CRAFT09 numbers: diff --git a/SimGeneral/MixingModule/python/pixelDigitizer_cfi.py b/SimGeneral/MixingModule/python/pixelDigitizer_cfi.py index af37a4d19d301..f6b64cac19a97 100644 --- a/SimGeneral/MixingModule/python/pixelDigitizer_cfi.py +++ b/SimGeneral/MixingModule/python/pixelDigitizer_cfi.py @@ -28,3 +28,4 @@ # imported also to DataMixer configuration, and the original version # is needed there in stage2. (premix_stage2 & phase2_tracker).toModify(pixelDigitizer, **_premixStage1ModifyDict) +from CalibTracker.SiPixelESProducers.PixelFEDChannelCollectionProducer_cfi import * diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc index 314bed10f1d5a..5709f878cff4c 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc @@ -63,7 +63,7 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h" - +#include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h" //Random Number #include "FWCore/ServiceRegistry/interface/Service.h" #include "FWCore/Utilities/interface/RandomNumberGenerator.h" @@ -102,6 +102,8 @@ namespace cms mixMod.produces >().setBranchAlias(alias); mixMod.produces >().setBranchAlias(alias + "siPixelDigiSimLink"); + + for(auto const& trackerContainer : trackerContainers) { edm::InputTag tag(hitsProducer, trackerContainer); iC.consumes >(edm::InputTag(hitsProducer, trackerContainer)); @@ -115,13 +117,16 @@ namespace cms } _pixeldigialgo.reset(new SiPixelDigitizerAlgorithm(iConfig)); + if (_pixeldigialgo->killBadFEDChannels()){ + mixMod.produces(); + } } SiPixelDigitizer::~SiPixelDigitizer(){ edm::LogInfo ("PixelDigitizer ") <<"Destruct the Pixel Digitizer"; } - + // // member functions // @@ -250,20 +255,29 @@ namespace cms std::vector > theDigiVector; std::vector > theDigiLinkVector; - + if (firstFinalizeEvent_) { const unsigned int bunchspace = PileupInfo_->getMix_bunchSpacing(); _pixeldigialgo->init_DynIneffDB(iSetup, bunchspace); firstFinalizeEvent_ = false; } _pixeldigialgo->calculateInstlumiFactor(PileupInfo_.get()); - + + if (_pixeldigialgo->killBadFEDChannels()){ + std::unique_ptr PixelFEDChannelCollection_ = _pixeldigialgo->chooseScenario(PileupInfo_.get(), randomEngine_); + if (PixelFEDChannelCollection_ == nullptr){ + throw cms::Exception("NullPointerError") << "PixelFEDChannelCollection not set in chooseScenario function.\n"; + } + iEvent.put(std::move(PixelFEDChannelCollection_)); + } + + for( const auto& iu : pDD->detUnits()) { if(iu->type().isTrackerPixel()) { - + // - + edm::DetSet collector(iu->geographicalId().rawId()); edm::DetSet linkcollector(iu->geographicalId().rawId()); diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc index f1c19ea7c1b11..8f6dde28a9b4f 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc @@ -55,6 +55,7 @@ #include "FWCore/Utilities/interface/RandomNumberGenerator.h" #include "CLHEP/Random/RandGaussQ.h" #include "CLHEP/Random/RandFlat.h" +#include "CLHEP/Random/RandGeneral.h" //#include "PixelIndices.h" #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h" @@ -76,7 +77,8 @@ #include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h" #include "CondFormats/DataRecord/interface/SiPixelLorentzAngleSimRcd.h" #include "CondFormats/DataRecord/interface/SiPixelDynamicInefficiencyRcd.h" - +#include "CondFormats/DataRecord/interface/SiPixelStatusScenarioProbabilityRcd.h" +#include "CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h" #include "CondFormats/DataRecord/interface/SiPixel2DTemplateDBObjectRcd.h" #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h" @@ -89,7 +91,8 @@ #include "CondFormats/SiPixelObjects/interface/LocalPixel.h" #include "CondFormats/SiPixelObjects/interface/CablingPathToDetUnit.h" #include "CondFormats/SiPixelObjects/interface/SiPixelDynamicInefficiency.h" - +#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h" #include "CondFormats/SiPixelObjects/interface/SiPixel2DTemplateDBObject.h" #include "CondFormats/SiPixelObjects/interface/SiPixelFrameReverter.h" @@ -106,8 +109,6 @@ #include "CondFormats/SiPixelObjects/interface/PixelROC.h" - - using namespace edm; using namespace sipixelobjects; @@ -127,6 +128,12 @@ void SiPixelDigitizerAlgorithm::init(const edm::EventSetup& es) { es.get().get(map_); es.get().get(geom_); + if (KillBadFEDChannels){ + es.get().get(scenarioProbabilityHandle); + es.get().get(PixelFEDChannelCollectionMapHandle); + quality_map = PixelFEDChannelCollectionMapHandle.product(); + } + // Read template files for charge reweighting if (UseReweighting){ edm::ESHandle SiPixel2DTemp_den; @@ -253,7 +260,8 @@ SiPixelDigitizerAlgorithm::SiPixelDigitizerAlgorithm(const edm::ParameterSet& co // Control the pixel inefficiency AddPixelInefficiency(conf.getParameter("AddPixelInefficiency")), - + KillBadFEDChannels(conf.getParameter("KillBadFEDChannels")), + // Add threshold gaussian smearing: addThresholdSmearing(conf.getParameter("AddThresholdSmearing")), @@ -261,7 +269,7 @@ SiPixelDigitizerAlgorithm::SiPixelDigitizerAlgorithm(const edm::ParameterSet& co doMissCalibrate(conf.getParameter("MissCalibrate")), // Enable miss-calibration theGainSmearing(conf.getParameter("GainSmearing")), // sigma of the gain smearing theOffsetSmearing(conf.getParameter("OffsetSmearing")), //sigma of the offset smearing - + // Add pixel radiation damage for upgrade studies AddPixelAging(conf.getParameter("DoPixelAging")), UseReweighting(conf.getParameter("UseReweighting")), @@ -778,6 +786,54 @@ void SiPixelDigitizerAlgorithm::calculateInstlumiFactor(const std::vector SiPixelDigitizerAlgorithm::chooseScenario(PileupMixingContent* puInfo, CLHEP::HepRandomEngine *engine){ + + //Determine scenario to use for the current event based on pileup information + + std::unique_ptr PixelFEDChannelCollection_ = nullptr; + pixelEfficiencies_.PixelFEDChannelCollection_ = nullptr; + if (puInfo) { + const std::vector& bunchCrossing = puInfo->getMix_bunchCrossing(); + const std::vector& TrueInteractionList = puInfo->getMix_TrueInteractions(); + + int pui = 0, p = 0; + std::vector::const_iterator pu; + std::vector::const_iterator pu0 = bunchCrossing.end(); + + for (pu=bunchCrossing.begin(); pu!=bunchCrossing.end(); ++pu) { + if (*pu==0) { + pu0 = pu; + p = pui; + } + pui++; + } + + if (pu0!=bunchCrossing.end()) { + + unsigned int PUBin = TrueInteractionList.at(p); // case delta PU=1, fix me + const auto& theProbabilitiesPerScenario = scenarioProbabilityHandle->getProbabilities(PUBin); + std::vector probabilities; + probabilities.reserve(theProbabilitiesPerScenario.size()); + for (auto it = theProbabilitiesPerScenario.begin(); it != theProbabilitiesPerScenario.end(); it++){ + probabilities.push_back(it->second); + } + + CLHEP::RandGeneral randGeneral(*engine, &(probabilities.front()), probabilities.size()); + double x = randGeneral.shoot(); + unsigned int index = x * probabilities.size() - 1; + const std::string& scenario = theProbabilitiesPerScenario.at(index).first; + + PixelFEDChannelCollection_ = std::make_unique(quality_map->at(scenario)); + pixelEfficiencies_.PixelFEDChannelCollection_ = std::make_unique(quality_map->at(scenario)); + } + } + return PixelFEDChannelCollection_; +} + //============================================================================ void SiPixelDigitizerAlgorithm::setSimAccumulator(const std::map >& signalMap) { for(const auto& det: signalMap) { @@ -1588,6 +1644,32 @@ void SiPixelDigitizerAlgorithm::pixel_inefficiency(const PixelEfficiencies& eff, std::vector pixelEfficiencyROCStdPixels(16,1); std::vector pixelEfficiencyROCBigPixels(16,1); + auto pIndexConverter = PixelIndices(numColumns,numRows); + + std::vector badRocsFromFEDChannels(16,0); + if (eff.PixelFEDChannelCollection_ != nullptr){ + PixelFEDChannelCollection::const_iterator it = eff.PixelFEDChannelCollection_->find(detID); + + if (it != eff.PixelFEDChannelCollection_->end()){ + const std::vector &path = map_->pathToDetUnit(detID); + for(const auto& ch: *it) { + for (unsigned int i_roc = ch.roc_first; i_roc <= ch.roc_last; ++i_roc){ + for(const auto p : path){ + const PixelROC* myroc = map_.product()->findItem(p); + if( myroc->idInDetUnit() == static_cast(i_roc)) { + LocalPixel::RocRowCol local = {39, 25};//corresponding to center of ROC row,col + GlobalPixel global = myroc->toGlobal( LocalPixel(local) ); + int chipIndex(0), colROC(0), rowROC(0); + pIndexConverter.transformToROC(global.col,global.row,chipIndex,colROC,rowROC); + badRocsFromFEDChannels.at(chipIndex) = 1; + } + } + } + } // loop over channels + } // detID in PixelFEDChannelCollection_ + } // has PixelFEDChannelCollection_ + + if (eff.FromConfig) { // setup the chip indices conversion if (pixdet->subDetector()==GeomDetEnumerators::SubDetector::PixelBarrel || @@ -1661,7 +1743,6 @@ void SiPixelDigitizerAlgorithm::pixel_inefficiency(const PixelEfficiencies& eff, // Initilize the index converter //PixelIndices indexConverter(numColumns,numRows); - std::unique_ptr pIndexConverter(new PixelIndices(numColumns,numRows)); int chipIndex = 0; int rowROC = 0; @@ -1678,10 +1759,10 @@ void SiPixelDigitizerAlgorithm::pixel_inefficiency(const PixelEfficiencies& eff, int row = ip.first; // X in row int col = ip.second; // Y is in col //transform to ROC index coordinates - pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC); - int dColInChip = pIndexConverter->DColumn(colROC); // get ROC dcol from ROC col + pIndexConverter.transformToROC(col,row,chipIndex,colROC,rowROC); + int dColInChip = pIndexConverter.DColumn(colROC); // get ROC dcol from ROC col //dcol in mod - int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex); + int dColInDet = pIndexConverter.DColumnInModule(dColInChip,chipIndex); chips[chipIndex]++; columns[dColInDet]++; @@ -1729,10 +1810,10 @@ void SiPixelDigitizerAlgorithm::pixel_inefficiency(const PixelEfficiencies& eff, int row = ip.first; // X in row int col = ip.second; // Y is in col //transform to ROC index coordinates - pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC); - int dColInChip = pIndexConverter->DColumn(colROC); //get ROC dcol from ROC col + pIndexConverter.transformToROC(col,row,chipIndex,colROC,rowROC); + int dColInChip = pIndexConverter.DColumn(colROC); //get ROC dcol from ROC col //dcol in mod - int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex); + int dColInDet = pIndexConverter.DColumnInModule(dColInChip,chipIndex); //float rand = RandFlat::shoot(); float rand = CLHEP::RandFlat::shoot(engine); @@ -1745,11 +1826,17 @@ void SiPixelDigitizerAlgorithm::pixel_inefficiency(const PixelEfficiencies& eff, } // end if if (isPhase1){ if((pixelStd.count(chipIndex) && pixelStd[chipIndex] == 0) - || (pixelBig.count(chipIndex) && pixelBig[chipIndex] == 0)) { - // make pixel amplitude =0, pixel will be lost at clusterization - i->second.set(0.); // reset amplitude, - } // end if + || (pixelBig.count(chipIndex) && pixelBig[chipIndex] == 0) + || (badRocsFromFEDChannels.at(chipIndex) == 1)) + { + //============================================================ + // make pixel amplitude =0, pixel will be lost at clusterization + i->second.set(0.); // reset amplitude, + } // end if } // is Phase 1 + if (KillBadFEDChannels && badRocsFromFEDChannels.at(chipIndex) == 1){ + i->second.set(0.); + } } // end pixel loop } // end pixel_indefficiency diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h index 9afd731c839f9..87c1abbb00e0a 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h @@ -17,6 +17,8 @@ #include "Geometry/CommonTopologies/interface/PixelTopology.h" #include "CondFormats/SiPixelTransient/interface/SiPixelTemplate2D.h" #include "CondFormats/SiPixelObjects/interface/SiPixel2DTemplateDBObject.h" +#include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h" +#include "CalibTracker/Records/interface/SiPixelFEDChannelContainerESProducerRcd.h" #include "boost/multi_array.hpp" typedef boost::multi_array array_2d; @@ -47,6 +49,8 @@ class SiPixelQuality; class SiPixelDynamicInefficiency; class TrackerGeometry; class TrackerTopology; +class SiPixelFEDChannelContainer; +class SiPixelQualityProbabilities; class SiPixelDigitizerAlgorithm { public: @@ -81,6 +85,11 @@ class SiPixelDigitizerAlgorithm { void calculateInstlumiFactor(const std::vector &ps, int bunchSpacing); // TODO: try to remove the duplication of logic... void setSimAccumulator(const std::map >& signalMap); + std::unique_ptr chooseScenario(PileupMixingContent* puInfo, CLHEP::HepRandomEngine *); + bool killBadFEDChannels() const; + typedef std::unordered_map PixelFEDChannelCollectionMap; + const PixelFEDChannelCollectionMap* quality_map; + private: //Accessing Lorentz angle from DB: @@ -95,7 +104,10 @@ class SiPixelDigitizerAlgorithm { // Get Dynamic Inefficiency scale factors from DB edm::ESHandle SiPixelDynamicInefficiency_; - + + // For BadFEDChannel simulation + edm::ESHandle scenarioProbabilityHandle; + edm::ESHandle PixelFEDChannelCollectionMapHandle; // Define internal classes // definition class @@ -268,7 +280,8 @@ class SiPixelDigitizerAlgorithm { enum shiftEnumerator {FPixRocIdShift = 3, BPixRocIdShift = 6}; static const int rocIdMaskBits = 0x1F; void init_from_db(const edm::ESHandle&, const edm::ESHandle&); - bool matches(const DetId&, const DetId&, const std::vector&); + bool matches(const DetId&, const DetId&, const std::vector&); + std::unique_ptr PixelFEDChannelCollection_; }; // @@ -380,9 +393,10 @@ class SiPixelDigitizerAlgorithm { const bool addChargeVCALSmearing; const bool addNoisyPixels; const bool fluctuateCharge; + //-- pixel efficiency const bool AddPixelInefficiency; // bool to read in inefficiencies - + const bool KillBadFEDChannels; const bool addThresholdSmearing; //-- calibration smearing