CMS 3D CMS Logo

SiStripDetInfoFileWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripDetInfoFileWriter
4 // Class: SiStripDetInfoFileWriter
5 //
13 //
14 // Original Author: G. Bruno
15 // Created: Mon Nov 20 10:04:31 CET 2006
16 //
17 //
18 
19 // C++ includes
20 #include <string>
21 #include <iostream>
22 #include <fstream>
23 
24 // User includes
34 
35 class SiStripDetInfoFileWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
36 public:
38  ~SiStripDetInfoFileWriter() override;
39 
40 private:
41  void beginRun(const edm::Run&, const edm::EventSetup& iSetup) override;
42  void analyze(const edm::Event&, const edm::EventSetup&) override{};
43  void endRun(const edm::Run&, const edm::EventSetup& iSetup) override{};
44 
45 private:
46  std::ofstream outputFile_;
49 };
50 
51 using namespace cms;
52 using namespace std;
53 
55  edm::LogInfo("SiStripDetInfoFileWriter::SiStripDetInfoFileWriter");
56 
57  filePath_ = iConfig.getUntrackedParameter<std::string>("FilePath", std::string("SiStripDetInfo.dat"));
58  tkGeomToken_ = esConsumes<edm::Transition::BeginRun>();
59 }
60 
62  edm::LogInfo("SiStripDetInfoFileWriter::~SiStripDetInfoFileWriter");
63 }
64 
66  outputFile_.open(filePath_.c_str());
67 
68  if (outputFile_.is_open()) {
69  const auto& dd = iSetup.getData(tkGeomToken_);
70 
71  edm::LogInfo("SiStripDetInfoFileWriter::beginRun - got geometry ") << std::endl;
72 
73  edm::LogInfo("SiStripDetInfoFileWriter") << " There are " << dd.detUnits().size() << " detectors" << std::endl;
74 
75  for (const auto& it : dd.detUnits()) {
76  const StripGeomDetUnit* mit = dynamic_cast<StripGeomDetUnit const*>(it);
77 
78  if (mit != nullptr) {
79  uint32_t detid = (mit->geographicalId()).rawId();
80  double stripLength = mit->specificTopology().stripLength();
81  unsigned short numberOfAPVs = mit->specificTopology().nstrips() / 128;
82  float thickness = mit->specificSurface().bounds().thickness();
83 
84  if (numberOfAPVs < 1 || numberOfAPVs > 6) {
85  edm::LogError("SiStripDetInfoFileWriter")
86  << " Problem with Number of strips in detector.. " << mit->specificTopology().nstrips()
87  << "Will not write this entry to file" << endl;
88  continue;
89  }
90 
91  outputFile_ << detid << " " << numberOfAPVs << " " << stripLength << " " << thickness << "\n";
92  }
93  }
94  outputFile_.close();
95  } else {
96  edm::LogError("SiStripDetInfoFileWriter::beginRun - Unable to open file") << endl;
97  return;
98  }
99 }
100 
virtual int nstrips() const =0
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void analyze(const edm::Event &, const edm::EventSetup &) override
Log< level::Error, false > LogError
string dd
Definition: createTree.py:154
T getUntrackedParameter(std::string const &, T const &) const
virtual float thickness() const =0
virtual float stripLength() const =0
SiStripDetInfoFileWriter(const edm::ParameterSet &)
void endRun(const edm::Run &, const edm::EventSetup &iSetup) override
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void beginRun(const edm::Run &, const edm::EventSetup &iSetup) override
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
Namespace of DDCMS conversion namespace.
Log< level::Info, false > LogInfo
const Plane & specificSurface() const
Same as surface(), kept for backward compatibility.
Definition: GeomDet.h:40
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
Definition: Run.h:45
const Bounds & bounds() const
Definition: Surface.h:87