CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
RunNumber_t run() const
Definition: EventID.h:38
Log< level::Info, true > LogVerbatim
void setComment(std::string const &value)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
assert(be >=bs)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
void setComment(std::string const &value)
int iEvent
Definition: GenABIO.cc:224
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static constexpr auto TOB
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Info, false > LogInfo
Definition: DetId.h:17
edm::EventID id() const
Definition: EventBase.h:59
Log< level::Warning, false > LogWarning
static constexpr auto TID
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define LogDebug(id)
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46