Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-17 04:57:59

0001 // -*- C++ -*-
0002 // Package:    CalibTracker/SiPixelESProducers
0003 // Class:      SiPixelDetInfoFileWriter
0004 // Original Author:  V.Chiochia (adapted from the Strip version by G.Bruno)
0005 //         Created:  Mon May 20 10:04:31 CET 2007
0006 
0007 // system includes
0008 #include <string>
0009 #include <iostream>
0010 #include <fstream>
0011 
0012 // user includes
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014 #include "FWCore/Framework/interface/ModuleFactory.h"
0015 #include "FWCore/Framework/interface/SourceFactory.h"
0016 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0020 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0021 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0022 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0023 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0024 
0025 class SiPixelDetInfoFileWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0026 public:
0027   explicit SiPixelDetInfoFileWriter(const edm::ParameterSet &);
0028   ~SiPixelDetInfoFileWriter() override;
0029 
0030 private:
0031   void beginJob() override;
0032   void beginRun(const edm::Run &, const edm::EventSetup &) override;
0033   void analyze(const edm::Event &, const edm::EventSetup &) override;
0034   void endRun(const edm::Run &, const edm::EventSetup &) override {}
0035 
0036 private:
0037   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeomTokenBeginRun_;
0038   std::ofstream outputFile_;
0039   std::string filePath_;
0040 };
0041 
0042 using namespace cms;
0043 using namespace std;
0044 
0045 SiPixelDetInfoFileWriter::SiPixelDetInfoFileWriter(const edm::ParameterSet &iConfig) {
0046   edm::LogInfo("SiPixelDetInfoFileWriter::SiPixelDetInfoFileWriter");
0047 
0048   trackerGeomTokenBeginRun_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>();
0049   filePath_ = iConfig.getUntrackedParameter<std::string>("FilePath", std::string("SiPixelDetInfo.dat"));
0050 }
0051 
0052 SiPixelDetInfoFileWriter::~SiPixelDetInfoFileWriter() {
0053   edm::LogInfo("SiPixelDetInfoFileWriter::~SiPixelDetInfoFileWriter");
0054 }
0055 
0056 void SiPixelDetInfoFileWriter::beginRun(const edm::Run &run, const edm::EventSetup &iSetup) {
0057   outputFile_.open(filePath_.c_str());
0058 
0059   if (outputFile_.is_open()) {
0060     edm::ESHandle<TrackerGeometry> pDD = iSetup.getHandle(trackerGeomTokenBeginRun_);
0061 
0062     edm::LogInfo("SiPixelDetInfoFileWriter::beginJob - got geometry  ") << std::endl;
0063     edm::LogInfo("SiPixelDetInfoFileWriter") << " There are " << pDD->detUnits().size() << " detectors" << std::endl;
0064 
0065     int nPixelDets = 0;
0066 
0067     for (const auto &it : pDD->detUnits()) {
0068       const PixelGeomDetUnit *mit = dynamic_cast<PixelGeomDetUnit const *>(it);
0069 
0070       if (mit != nullptr) {
0071         nPixelDets++;
0072         const PixelTopology &topol = mit->specificTopology();
0073         // Get the module sizes.
0074         int nrows = topol.nrows();     // rows in x
0075         int ncols = topol.ncolumns();  // cols in y
0076         uint32_t detid = (mit->geographicalId()).rawId();
0077 
0078         outputFile_ << detid << " " << ncols << " " << nrows << "\n";
0079       }
0080     }
0081     outputFile_.close();
0082     edm::LogInfo("SiPixelDetInfoFileWriter::beginJob - Loop finished. ")
0083         << nPixelDets << " Pixel DetUnits found " << std::endl;
0084   }
0085 
0086   else {
0087     edm::LogError("SiPixelDetInfoFileWriter::beginJob - Unable to open file") << endl;
0088     return;
0089   }
0090 }
0091 
0092 void SiPixelDetInfoFileWriter::beginJob() {}
0093 
0094 void SiPixelDetInfoFileWriter::analyze(const edm::Event &, const edm::EventSetup &) {}
0095 
0096 DEFINE_FWK_MODULE(SiPixelDetInfoFileWriter);