CMS 3D CMS Logo

SiPhase2OuterTrackerLorentzAngleWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondTools/SiPhase2Tracker
4 // Class: SiPhase2OuterTrackerLorentzAngleWriter
5 //
14 //
15 // Original Author: Marco Musich
16 // Created: Mon, 18 May 2020 18:00:00 GMT
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 #include <iostream>
23 #include <string>
24 #include <unordered_map>
25 
26 // user include files
41 
42 //
43 // class declaration
44 //
45 
47 public:
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53 private:
54  void analyze(const edm::Event&, const edm::EventSetup&) override;
55 
56  // ----------member data ---------------------------
61  float m_value;
62 };
63 
64 //
65 // constructors and destructor
66 //
68  : topoToken_(esConsumes()),
69  geomToken_(esConsumes()),
70  m_record(iConfig.getParameter<std::string>("record")),
71  m_tag(iConfig.getParameter<std::string>("tag")),
72  m_value(iConfig.getParameter<double>("value")) {}
73 
75  edm::LogInfo("SiPhase2OuterTrackerLorentzAngleWriter")
76  << "SiPhase2OuterTrackerLorentzAngleWriter::~SiPhase2OuterTrackerLorentzAngleWriter" << std::endl;
77 }
78 
79 //
80 // member functions
81 //
82 
83 // ------------ method called for each event ------------
86  using namespace edm;
87  edm::LogInfo("SiPhase2OuterTrackerLorentzAngleWriter")
88  << "SiPhase2OuterTrackerLorentzAngleWriter::analyze " << std::endl;
89 
90  // Database services (write)
92  if (!mydbservice.isAvailable()) {
93  edm::LogWarning("SiPhase2OuterTrackerLorentzAngleWriter") << "Service is unavailable" << std::endl;
94  return;
95  }
96 
97  std::string tag = mydbservice->tag(m_record);
98  unsigned int irun = iEvent.id().run();
99  edm::LogVerbatim("SiPhase2OuterTrackerLorentzAngleWriter") << "Writing on tag : " << tag << std::endl;
100  edm::LogVerbatim("SiPhase2OuterTrackerLorentzAngleWriter") << "Usinng as IOV run : " << irun << std::endl;
101 
102  // map to be filled
103  std::unordered_map<unsigned int, float> detsLAtoDB;
104 
105  // Retrieve tracker topology from geometry
106  const TrackerTopology* const tTopo = &iSetup.getData(topoToken_);
107 
108  // Retrieve old style tracker geometry from geometry
109  const TrackerGeometry* pDD = &iSetup.getData(geomToken_);
110  edm::LogInfo("SiPhase2OuterTrackerLorentzAngleWriter")
111  << " There are " << pDD->detUnits().size() << " modules in this geometry." << std::endl;
112 
113  for (auto const& det_u : pDD->detUnits()) {
114  const DetId detid = det_u->geographicalId();
115  uint32_t rawId = detid.rawId();
116  int subid = detid.subdetId();
117  if (detid.det() == DetId::Detector::Tracker) {
118  const Phase2TrackerGeomDetUnit* pixdet = dynamic_cast<const Phase2TrackerGeomDetUnit*>(det_u);
119  assert(pixdet);
120  LogDebug("SiPhase2OuterTrackerLorentzAngleWriter") << rawId << " is a " << subid << " det" << std::endl;
121  if (subid == StripSubdetector::TOB || subid == StripSubdetector::TID) {
122  LogDebug("SiPhase2OuterTrackerLorentzAngleWriter")
123  << "subdetector ID:" << subid << " layer:" << tTopo->layer(detid) << std::endl;
124  detsLAtoDB[rawId] = m_value;
125  }
126  }
127  }
128 
129  edm::LogInfo("SiPhase2OuterTrackerLorentzAngleWriter")
130  << " There are " << detsLAtoDB.size() << " OT Lorentz Angle values assigned" << std::endl;
131 
132  // SiPhase2OuterTrackerLorentzAngle object
133  auto lorentzAngle = std::make_unique<SiPhase2OuterTrackerLorentzAngle>();
134  lorentzAngle->putLorentzAngles(detsLAtoDB);
135  edm::LogInfo("SiPhase2OuterTrackerLorentzAngleWriter") << "currentTime " << mydbservice->currentTime() << std::endl;
136  mydbservice->writeOneIOV(*lorentzAngle, mydbservice->currentTime(), m_record);
137 }
138 
139 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
142  desc.setComment("Module to write SiPhase2OuterTrackerLorentzAngle Payloads");
143  desc.add<std::string>("record", "SiPhase2OuterTrackerLorentzAngleRcd")->setComment("record to write");
144  desc.add<std::string>("tag", "SiPhase2OuterTrackerLorentzAngle")->setComment("tag to write");
145  desc.add<double>("value", 0.07)->setComment("value to be put in the payload");
146  descriptions.addWithDefaultLabel(desc);
147 }
148 
149 //define this as a plug-in
Log< level::Info, true > LogVerbatim
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
assert(be >=bs)
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
unsigned int layer(const DetId &id) const
std::string tag(const std::string &recordName)
int iEvent
Definition: GenABIO.cc:224
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
bool getData(T &iHolder) const
Definition: EventSetup.h:122
static constexpr auto TOB
Log< level::Info, false > LogInfo
Definition: DetId.h:17
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
HLT enums.
bool isAvailable() const
Definition: Service.h:40
Log< level::Warning, false > LogWarning
static constexpr auto TID
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define LogDebug(id)