CMS 3D CMS Logo

BrilClient.cc
Go to the documentation of this file.
1 #include "BrilClient.h"
2 
3 #include <boost/filesystem.hpp>
4 #include <boost/property_tree/json_parser.hpp>
5 #include <boost/property_tree/ptree.hpp>
6 
7 #include <iostream>
8 #include <vector>
9 
10 #include "TH2F.h"
11 
13  pathToken_ = consumes<std::string, edm::InLumi>(edm::InputTag("source", "sourceDataPath"));
14  jsonToken_ = consumes<std::string, edm::InLumi>(edm::InputTag("source", "sourceJsonPath"));
15 }
16 
18 
19 using boost::property_tree::ptree;
20 
21 template <typename T>
22 std::vector<T> as_vector(ptree const &pt, ptree::key_type const &key) {
23  std::vector<T> r;
24  for (auto &item : pt.get_child(key))
25  r.push_back(item.second.get_value<T>());
26  return r;
27 }
28 
30  DQMStore::IGetter &igetter_,
31  edm::LuminosityBlock const &lb,
32  edm::EventSetup const &) {
33  edm::Handle<std::string> filePath_;
34  lb.getByToken(pathToken_, filePath_);
35 
36  // edm::Handle<std::string> jsonPath_;
37  // lb.getByToken(jsonToken_, jsonPath_);
38  //
39 
40  ptree json;
41  if (!boost::filesystem::exists(*filePath_)) {
42  edm::LogWarning("BrilClient") << "BrilClient"
43  << " File missing: " << *filePath_ << std::endl;
44 
45  return;
46  } else {
47  edm::LogWarning("BrilClient") << "BrilClient"
48  << " Opening: " << *filePath_ << std::endl;
49 
50  read_json(std::string(*filePath_), json);
51  }
52 
53  // Parse the json
54  for (auto &mainTree : json.get_child("OccupancyPlots")) {
55  std::string title = mainTree.second.get<std::string>("titles");
56  std::size_t pos = title.find(",");
57  if (pos <= 0) {
58  edm::LogWarning("BrilClient") << "BrilClient::dqmEndLuminosityBlock"
59  << " Invalid title" << title << std::endl;
60 
61  continue;
62  }
63  std::string name = title.substr(0, pos);
64 
65  auto nBins = as_vector<int>(mainTree.second, "nbins"); // x, y
66  auto xrange = as_vector<int>(mainTree.second, "xrange"); // min, max
67  auto yrange = as_vector<int>(mainTree.second, "yrange"); // min, max
68 
69  TH2F *th = new TH2F(
70  name.c_str(), title.c_str(), nBins.at(0), xrange.at(0), xrange.at(1), nBins.at(1), yrange.at(0), yrange.at(1));
71 
72  for (auto &dataArray : mainTree.second.get_child("data")) {
73  int elements[3] = {0, 0, 0}; // binX, binY, binCont;
74  auto element = std::begin(elements);
75 
76  for (auto &binContent : dataArray.second) {
77  *element++ = stoi(binContent.second.get_value<std::string>());
78  if (element == std::end(elements))
79  break;
80  }
81 
82  th->SetBinContent(elements[0], elements[1], elements[2]);
83  }
84 
85  // Add it to the DQM store
86  ibooker_.setCurrentFolder("BRIL/OccupancyPlots");
87  igetter_.setCurrentFolder("BRIL/OccupancyPlots");
88 
89  MonitorElement *m = igetter_.get(name);
90  if (m == nullptr) {
91  m = ibooker_.book2D(name, th);
92  } else {
93  m->getTH1F()->Add(th);
94  }
95  }
96 }
97 
BrilClient::~BrilClient
~BrilClient() override
Definition: BrilClient.cc:17
as_vector
std::vector< T > as_vector(ptree const &pt, ptree::key_type const &key)
Definition: BrilClient.cc:22
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
pos
Definition: PixelAliasList.h:18
BrilClient::jsonToken_
edm::EDGetTokenT< std::string > jsonToken_
Definition: BrilClient.h:32
BrilClient::BrilClient
BrilClient(const edm::ParameterSet &ps)
Definition: BrilClient.cc:12
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
edm::Handle
Definition: AssociativeIterator.h:50
end
#define end
Definition: vmac.h:39
MakerMacros.h
edm::LuminosityBlock::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: LuminosityBlock.h:318
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BrilClient
Definition: BrilClient.h:17
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
seedmultiplicitymonitor_newtracking_cfi.nBins
nBins
Definition: seedmultiplicitymonitor_newtracking_cfi.py:8
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
edm::ParameterSet
Definition: ParameterSet.h:36
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::EventSetup
Definition: EventSetup.h:57
alignCSCRings.r
r
Definition: alignCSCRings.py:93
overlapproblemtsosanalyzer_cfi.title
title
Definition: overlapproblemtsosanalyzer_cfi.py:7
bookConverter.elements
elements
Definition: bookConverter.py:147
BrilClient::dqmEndLuminosityBlock
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: BrilClient.cc:29
T
long double T
Definition: Basic3DVectorLD.h:48
dqm::implementation::IGetter
Definition: DQMStore.h:484
dqm::implementation::IBooker::book2D
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:651
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
BrilClient.h
dqm::implementation::IBooker
Definition: DQMStore.h:43
BrilClient::pathToken_
edm::EDGetTokenT< std::string > pathToken_
Definition: BrilClient.h:28
crabWrapper.key
key
Definition: crabWrapper.py:19
json
nlohmann::json json
Definition: FastTimerService.cc:19
edm::InputTag
Definition: InputTag.h:15
begin
#define begin
Definition: vmac.h:32