Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-17 01:40:50

0001 // system includes
0002 #include <sys/time.h>
0003 #include <memory>
0004 
0005 // CLHEP
0006 #include "CLHEP/Random/RandGauss.h"
0007 
0008 // user includes
0009 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0010 #include "CondFormats/SiPixelObjects/interface/SiPixelPerformanceSummary.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/Frameworkfwd.h"
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/ServiceRegistry/interface/Service.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 namespace cms {
0026   class SiPixelPerformanceSummaryBuilder : public edm::one::EDAnalyzer<> {
0027   public:
0028     explicit SiPixelPerformanceSummaryBuilder(const edm::ParameterSet&);
0029     ~SiPixelPerformanceSummaryBuilder() override;
0030     void analyze(const edm::Event&, const edm::EventSetup&) override;
0031 
0032   private:
0033     edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0034     std::vector<uint32_t> detectorModules_;
0035   };
0036 }  // namespace cms
0037 
0038 using namespace cms;
0039 
0040 SiPixelPerformanceSummaryBuilder::SiPixelPerformanceSummaryBuilder(const edm::ParameterSet& iConfig)
0041     : tkGeomToken_(esConsumes()) {}
0042 
0043 SiPixelPerformanceSummaryBuilder::~SiPixelPerformanceSummaryBuilder() = default;
0044 
0045 void SiPixelPerformanceSummaryBuilder::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0046   const TrackerGeometry* pDD = &iSetup.getData(tkGeomToken_);
0047   edm::LogInfo("SiPixelPerformanceSummaryBuilder") << pDD->detUnits().size() << " detectors" << std::endl;
0048 
0049   for (const auto& it : pDD->detUnits()) {
0050     if (dynamic_cast<PixelGeomDetUnit const*>(it) != nullptr) {
0051       detectorModules_.push_back(it->geographicalId().rawId());
0052     }
0053   }
0054   edm::LogInfo("Modules") << "detectorModules_.size() = " << detectorModules_.size();
0055 
0056   SiPixelPerformanceSummary performanceSummary;
0057 
0058   for (std::vector<uint32_t>::const_iterator iDet = detectorModules_.begin();  // fill object
0059        iDet != detectorModules_.end();
0060        ++iDet) {
0061     float nDigisMean = (float)CLHEP::RandGauss::shoot(50., 20.);  // generate random values for each detId
0062     float nDigisRMS = (float)CLHEP::RandGauss::shoot(20., 4.);
0063     float emptyFraction = (float)CLHEP::RandGauss::shoot(.5, .2);
0064 
0065     performanceSummary.setNumberOfDigis(*iDet, nDigisMean, nDigisRMS, emptyFraction);  // set values
0066   }
0067   clock_t presentTime = clock();
0068   performanceSummary.setTimeStamp((unsigned long long)presentTime);
0069   performanceSummary.print();
0070 
0071   edm::Service<cond::service::PoolDBOutputService> poolDBService;  // write to DB
0072   if (poolDBService.isAvailable()) {
0073     try {
0074       if (poolDBService->isNewTagRequest("SiPixelPerformanceSummaryRcd")) {
0075         edm::LogInfo("Tag") << " is a new tag request.";
0076         poolDBService->createOneIOV<SiPixelPerformanceSummary>(
0077             performanceSummary, poolDBService->beginOfTime(), "SiPixelPerformanceSummaryRcd");
0078       } else {
0079         edm::LogInfo("Tag") << " tag exists already";
0080         poolDBService->appendOneIOV<SiPixelPerformanceSummary>(
0081             performanceSummary, poolDBService->currentTime(), "SiPixelPerformanceSummaryRcd");
0082       }
0083     } catch (const cond::Exception& err) {
0084       edm::LogError("DBWriting") << err.what() << std::endl;
0085     } catch (const std::exception& err) {
0086       edm::LogError("DBWriting") << "caught std::exception " << err.what() << std::endl;
0087     } catch (...) {
0088       edm::LogError("DBWriting") << "unknown error" << std::endl;
0089     }
0090   } else
0091     edm::LogError("PoolDBOutputService") << "service unavailable" << std::endl;
0092 }
0093 DEFINE_FWK_MODULE(SiPixelPerformanceSummaryBuilder);