File indexing completed on 2024-04-06 12:15:17
0001
0002
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0006 #include "FWCore/Framework/interface/ModuleFactory.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/ESProducer.h"
0009 #include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
0010 #include "Geometry/MTDCommonData/interface/MTDTopologyMode.h"
0011 #include "Geometry/Records/interface/MTDTopologyRcd.h"
0012 #include "CondFormats/GeometryObjects/interface/PMTDParameters.h"
0013 #include "Geometry/Records/interface/PMTDParametersRcd.h"
0014
0015 #include <memory>
0016
0017 class MTDTopologyEP : public edm::ESProducer {
0018 public:
0019 MTDTopologyEP(const edm::ParameterSet&);
0020
0021 using ReturnType = std::unique_ptr<MTDTopology>;
0022
0023 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0024
0025 ReturnType produce(const MTDTopologyRcd&);
0026
0027 private:
0028 void fillParameters(const PMTDParameters&, int& mtdTopologyMode, MTDTopology::ETLValues&);
0029
0030 const edm::ESGetToken<PMTDParameters, PMTDParametersRcd> token_;
0031 };
0032
0033 MTDTopologyEP::MTDTopologyEP(const edm::ParameterSet& conf)
0034 : token_{setWhatProduced(this).consumesFrom<PMTDParameters, PMTDParametersRcd>(edm::ESInputTag())} {}
0035
0036 void MTDTopologyEP::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0037 edm::ParameterSetDescription ttc;
0038 descriptions.add("mtdTopology", ttc);
0039 }
0040
0041 MTDTopologyEP::ReturnType MTDTopologyEP::produce(const MTDTopologyRcd& iRecord) {
0042 int mtdTopologyMode;
0043 MTDTopology::ETLValues etlVals;
0044
0045 fillParameters(iRecord.get(token_), mtdTopologyMode, etlVals);
0046
0047 return std::make_unique<MTDTopology>(mtdTopologyMode, etlVals);
0048 }
0049
0050 void MTDTopologyEP::fillParameters(const PMTDParameters& ptp, int& mtdTopologyMode, MTDTopology::ETLValues& etlVals) {
0051 mtdTopologyMode = ptp.topologyMode_;
0052
0053
0054
0055 if (mtdTopologyMode <= static_cast<int>(MTDTopologyMode::Mode::barphiflat)) {
0056 return;
0057 }
0058
0059
0060
0061 for (size_t it = 3; it <= 9; it++) {
0062 if (ptp.vitems_[it].vpars_.size() != ptp.vitems_[2].vpars_.size()) {
0063 throw cms::Exception("MTDTopologyEP") << "Inconsistent size of ETL structure arrays";
0064 }
0065 }
0066
0067 MTDTopology::ETLfaceLayout tmpFace;
0068
0069
0070
0071 tmpFace.idDiscSide_ = 0;
0072 tmpFace.idDetType1_ = 2;
0073
0074 tmpFace.start_copy_[0] = ptp.vitems_[3].vpars_;
0075 tmpFace.start_copy_[1] = ptp.vitems_[2].vpars_;
0076 tmpFace.offset_[0] = ptp.vitems_[7].vpars_;
0077 tmpFace.offset_[1] = ptp.vitems_[6].vpars_;
0078
0079 etlVals.emplace_back(tmpFace);
0080
0081
0082
0083 tmpFace.idDiscSide_ = 1;
0084 tmpFace.idDetType1_ = 1;
0085
0086 tmpFace.start_copy_[0] = ptp.vitems_[4].vpars_;
0087 tmpFace.start_copy_[1] = ptp.vitems_[5].vpars_;
0088 tmpFace.offset_[0] = ptp.vitems_[8].vpars_;
0089 tmpFace.offset_[1] = ptp.vitems_[9].vpars_;
0090
0091 etlVals.emplace_back(tmpFace);
0092
0093 #ifdef EDM_ML_DEBUG
0094 edm::LogVerbatim("MTDTopologyEP") << " Topology mode = " << mtdTopologyMode << "\n";
0095 auto print_array = [&](std::vector<int> vector) {
0096 std::stringstream ss;
0097 for (auto const& elem : vector) {
0098 ss << " " << elem;
0099 }
0100 ss << "\n";
0101 return ss.str();
0102 };
0103
0104 for (auto const& ilay : etlVals) {
0105 edm::LogVerbatim("MTDTopologyEP") << " disc face = " << ilay.idDiscSide_ << " start det type = " << ilay.idDetType1_
0106 << "\n start_copy[0]= " << print_array(ilay.start_copy_[0])
0107 << "\n start_copy[1]= " << print_array(ilay.start_copy_[1])
0108 << "\n offset[0]= " << print_array(ilay.offset_[0])
0109 << "\n offset[1]= " << print_array(ilay.offset_[1]);
0110 }
0111
0112 #endif
0113 }
0114
0115 DEFINE_FWK_EVENTSETUP_MODULE(MTDTopologyEP);