CMS 3D CMS Logo

SiPixelPerformanceSummaryBuilder.cc
Go to the documentation of this file.
1 // system includes
2 #include <sys/time.h>
3 #include <memory>
4 
5 // CLHEP
6 #include "CLHEP/Random/RandGauss.h"
7 
8 // user includes
24 
25 namespace cms {
27  public:
30  void analyze(const edm::Event&, const edm::EventSetup&) override;
31 
32  private:
34  std::vector<uint32_t> detectorModules_;
35  };
36 } // namespace cms
37 
38 using namespace cms;
39 
41  : tkGeomToken_(esConsumes()) {}
42 
44 
46  const TrackerGeometry* pDD = &iSetup.getData(tkGeomToken_);
47  edm::LogInfo("SiPixelPerformanceSummaryBuilder") << pDD->detUnits().size() << " detectors" << std::endl;
48 
49  for (const auto& it : pDD->detUnits()) {
50  if (dynamic_cast<PixelGeomDetUnit const*>(it) != nullptr) {
51  detectorModules_.push_back(it->geographicalId().rawId());
52  }
53  }
54  edm::LogInfo("Modules") << "detectorModules_.size() = " << detectorModules_.size();
55 
56  SiPixelPerformanceSummary performanceSummary;
57 
58  for (std::vector<uint32_t>::const_iterator iDet = detectorModules_.begin(); // fill object
59  iDet != detectorModules_.end();
60  ++iDet) {
61  float nDigisMean = (float)CLHEP::RandGauss::shoot(50., 20.); // generate random values for each detId
62  float nDigisRMS = (float)CLHEP::RandGauss::shoot(20., 4.);
63  float emptyFraction = (float)CLHEP::RandGauss::shoot(.5, .2);
64 
65  performanceSummary.setNumberOfDigis(*iDet, nDigisMean, nDigisRMS, emptyFraction); // set values
66  }
67  clock_t presentTime = clock();
68  performanceSummary.setTimeStamp((unsigned long long)presentTime);
69  performanceSummary.print();
70 
71  edm::Service<cond::service::PoolDBOutputService> poolDBService; // write to DB
72  if (poolDBService.isAvailable()) {
73  try {
74  if (poolDBService->isNewTagRequest("SiPixelPerformanceSummaryRcd")) {
75  edm::LogInfo("Tag") << " is a new tag request.";
77  performanceSummary, poolDBService->beginOfTime(), "SiPixelPerformanceSummaryRcd");
78  } else {
79  edm::LogInfo("Tag") << " tag exists already";
81  performanceSummary, poolDBService->currentTime(), "SiPixelPerformanceSummaryRcd");
82  }
83  } catch (const cond::Exception& err) {
84  edm::LogError("DBWriting") << err.what() << std::endl;
85  } catch (const std::exception& err) {
86  edm::LogError("DBWriting") << "caught std::exception " << err.what() << std::endl;
87  } catch (...) {
88  edm::LogError("DBWriting") << "unknown error" << std::endl;
89  }
90  } else
91  edm::LogError("PoolDBOutputService") << "service unavailable" << std::endl;
92 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Base exception class for the object to relational access.
Definition: Exception.h:11
void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setTimeStamp(unsigned long long timeStamp)
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
Log< level::Error, false > LogError
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
bool setNumberOfDigis(uint32_t detId, float mean, float rms, float emPtn)
int iEvent
Definition: GenABIO.cc:224
bool isNewTagRequest(const std::string &recordName)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
Namespace of DDCMS conversion namespace.
Log< level::Info, false > LogInfo
bool isAvailable() const
Definition: Service.h:40
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_