CMS 3D CMS Logo

SiPixelDetInfoFileWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Package: CalibTracker/SiPixelESProducers
3 // Class: SiPixelDetInfoFileWriter
4 // Original Author: V.Chiochia (adapted from the Strip version by G.Bruno)
5 // Created: Mon May 20 10:04:31 CET 2007
6 
7 // system includes
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 
12 // user includes
24 
25 class SiPixelDetInfoFileWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
26 public:
28  ~SiPixelDetInfoFileWriter() override;
29 
30 private:
31  void beginJob() override;
32  void beginRun(const edm::Run &, const edm::EventSetup &) override;
33  void analyze(const edm::Event &, const edm::EventSetup &) override;
34  void endRun(const edm::Run &, const edm::EventSetup &) override {}
35 
36 private:
38  std::ofstream outputFile_;
40 };
41 
42 using namespace cms;
43 using namespace std;
44 
46  edm::LogInfo("SiPixelDetInfoFileWriter::SiPixelDetInfoFileWriter");
47 
48  trackerGeomTokenBeginRun_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>();
49  filePath_ = iConfig.getUntrackedParameter<std::string>("FilePath", std::string("SiPixelDetInfo.dat"));
50 }
51 
53  edm::LogInfo("SiPixelDetInfoFileWriter::~SiPixelDetInfoFileWriter");
54 }
55 
57  outputFile_.open(filePath_.c_str());
58 
59  if (outputFile_.is_open()) {
60  edm::ESHandle<TrackerGeometry> pDD = iSetup.getHandle(trackerGeomTokenBeginRun_);
61 
62  edm::LogInfo("SiPixelDetInfoFileWriter::beginJob - got geometry ") << std::endl;
63  edm::LogInfo("SiPixelDetInfoFileWriter") << " There are " << pDD->detUnits().size() << " detectors" << std::endl;
64 
65  int nPixelDets = 0;
66 
67  for (const auto &it : pDD->detUnits()) {
68  const PixelGeomDetUnit *mit = dynamic_cast<PixelGeomDetUnit const *>(it);
69 
70  if (mit != nullptr) {
71  nPixelDets++;
72  const PixelTopology &topol = mit->specificTopology();
73  // Get the module sizes.
74  int nrows = topol.nrows(); // rows in x
75  int ncols = topol.ncolumns(); // cols in y
76  uint32_t detid = (mit->geographicalId()).rawId();
77 
78  outputFile_ << detid << " " << ncols << " " << nrows << "\n";
79  }
80  }
81  outputFile_.close();
82  edm::LogInfo("SiPixelDetInfoFileWriter::beginJob - Loop finished. ")
83  << nPixelDets << " Pixel DetUnits found " << std::endl;
84  }
85 
86  else {
87  edm::LogError("SiPixelDetInfoFileWriter::beginJob - Unable to open file") << endl;
88  return;
89  }
90 }
91 
93 
95 
void endRun(const edm::Run &, const edm::EventSetup &) override
virtual int ncolumns() const =0
virtual int nrows() const =0
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
Log< level::Error, false > LogError
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeomTokenBeginRun_
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(const edm::Event &, const edm::EventSetup &) override
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
Namespace of DDCMS conversion namespace.
void beginRun(const edm::Run &, const edm::EventSetup &) override
Log< level::Info, false > LogInfo
SiPixelDetInfoFileWriter(const edm::ParameterSet &)
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
Definition: Run.h:45