CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
SiStripHistoPlotter Class Reference

#include <SiStripHistoPlotter.h>

Classes

struct  PlotParameter
 

Public Types

typedef dqm::harvesting::DQMStore DQMStore
 
typedef dqm::harvesting::MonitorElement MonitorElement
 

Public Member Functions

bool condDBPlotsToMake ()
 
void createCondDBPlots (DQMStore *dqm_store)
 
void createPlots (DQMStore *dqm_store)
 
void getNamedImageBuffer (const std::string &path, std::string &image)
 
bool plotsToMake ()
 
void setNewCondDBPlot (std::string const &path, std::string const &option, int width, int height)
 
void setNewPlot (std::string const &path, std::string const &option, int width, int height)
 
 SiStripHistoPlotter ()
 
 ~SiStripHistoPlotter ()
 

Private Member Functions

void createDummyImage (const std::string &name)
 
void fillNamedImageBuffer (TCanvas *c1, const std::string &name)
 (Documentation under construction). More...
 
void getDummyImage (std::string &image)
 
void getProjection (MonitorElement *me, TH1F *tp)
 
bool hasNamedImage (const std::string &name)
 
void makeCondDBPlots (DQMStore *dqm_store, const PlotParameter &par)
 
void makePlot (DQMStore const *dqm_store, const PlotParameter &par)
 
void setDrawingOption (TH1 *hist)
 

Private Attributes

std::vector< PlotParametercondDBPlotList_
 
std::map< std::string, std::string > namedPictureBuffer_
 
std::vector< PlotParameterplotList_
 

Detailed Description

Definition at line 15 of file SiStripHistoPlotter.h.

Member Typedef Documentation

◆ DQMStore

Definition at line 18 of file SiStripHistoPlotter.h.

◆ MonitorElement

Definition at line 17 of file SiStripHistoPlotter.h.

Constructor & Destructor Documentation

◆ SiStripHistoPlotter()

SiStripHistoPlotter::SiStripHistoPlotter ( )

Definition at line 25 of file SiStripHistoPlotter.cc.

25  {
26  edm::LogInfo("SiStripHistoPlotter") << " Creating SiStripHistoPlotter "
27  << "\n";
28 }
Log< level::Info, false > LogInfo

◆ ~SiStripHistoPlotter()

SiStripHistoPlotter::~SiStripHistoPlotter ( )

Definition at line 32 of file SiStripHistoPlotter.cc.

32  {
33  edm::LogInfo("SiStripHistoPlotter") << " Deleting SiStripHistoPlotter "
34  << "\n";
35 }
Log< level::Info, false > LogInfo

Member Function Documentation

◆ condDBPlotsToMake()

bool SiStripHistoPlotter::condDBPlotsToMake ( )
inline

Definition at line 29 of file SiStripHistoPlotter.h.

References condDBPlotList_.

29 { return !condDBPlotList_.empty(); }
std::vector< PlotParameter > condDBPlotList_

◆ createCondDBPlots()

void SiStripHistoPlotter::createCondDBPlots ( DQMStore dqm_store)

Definition at line 285 of file SiStripHistoPlotter.cc.

References condDBPlotList_, createDummyImage(), hasNamedImage(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, makeCondDBPlots(), Skims_PA_cff::name, and AlCaHLTBitMon_QueryRunRegistry::string.

285  {
286  if (condDBPlotList_.empty())
287  return;
288  std::string name = "Dummy";
289  if (!hasNamedImage(name))
291 
292  for (std::vector<PlotParameter>::iterator it = condDBPlotList_.begin(); it != condDBPlotList_.end(); it++) {
293  makeCondDBPlots(dqm_store, (*it));
294  }
295  condDBPlotList_.clear();
296 }
bool hasNamedImage(const std::string &name)
std::vector< PlotParameter > condDBPlotList_
void makeCondDBPlots(DQMStore *dqm_store, const PlotParameter &par)
void createDummyImage(const std::string &name)

◆ createDummyImage()

void SiStripHistoPlotter::createDummyImage ( const std::string &  name)
private

Definition at line 199 of file SiStripHistoPlotter.cc.

References getDummyImage(), Skims_PA_cff::name, namedPictureBuffer_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by createCondDBPlots(), createPlots(), and setNewPlot().

199  {
200  std::string image;
201  getDummyImage(image);
202  namedPictureBuffer_.insert(std::pair<std::string, std::string>(name, image));
203 }
std::map< std::string, std::string > namedPictureBuffer_
void getDummyImage(std::string &image)

◆ createPlots()

void SiStripHistoPlotter::createPlots ( DQMStore dqm_store)

Definition at line 52 of file SiStripHistoPlotter.cc.

References createDummyImage(), hasNamedImage(), makePlot(), Skims_PA_cff::name, plotList_, and AlCaHLTBitMon_QueryRunRegistry::string.

52  {
53  if (plotList_.empty())
54  return;
55  std::string name = "Dummy";
56  if (!hasNamedImage(name))
58  for (auto const& par : plotList_) {
59  makePlot(dqm_store, par);
60  }
61  plotList_.clear();
62 }
bool hasNamedImage(const std::string &name)
void makePlot(DQMStore const *dqm_store, const PlotParameter &par)
void createDummyImage(const std::string &name)
std::vector< PlotParameter > plotList_

◆ fillNamedImageBuffer()

void SiStripHistoPlotter::fillNamedImageBuffer ( TCanvas *  c1,
const std::string &  name 
)
private

(Documentation under construction).

This method

Definition at line 145 of file SiStripHistoPlotter.cc.

References visDQMUpload::buf, alignmentValidation::c1, gather_cfg::cout, free(), hasNamedImage(), mps_fire::i, Skims_PA_cff::name, and namedPictureBuffer_.

Referenced by makeCondDBPlots(), and makePlot().

145  {
146  // DQMScope enter;
147  // Now extract the image
148  // 114 - stands for "no write on Close"
149  // std::cout << ACYellow << ACBold
150  // << "[SiPixelInformationExtractor::fillNamedImageBuffer()] "
151  // << ACPlain
152  // << "A canvas: "
153  // << c1->GetName()
154  // << std::endl ;
155  c1->Update();
156  c1->Modified();
157  TImageDump imgdump("tmp.png", 114);
158  c1->Paint();
159 
160  // get an internal image which will be automatically deleted
161  // in the imgdump destructor
162  TImage* image = imgdump.GetImage();
163 
164  if (image == nullptr) {
165  std::cout << "No TImage found for " << name << std::endl;
166  return;
167  }
168  char* buf;
169  int sz = 0;
170  image->GetImageBuffer(&buf, &sz);
171 
172  std::ostringstream local_str;
173  for (int i = 0; i < sz; i++)
174  local_str << buf[i];
175 
176  // delete [] buf;
177  ::free(buf); // buf is allocated via realloc() by a C language AfterStep library invoked by the
178  // default (and so far only) TImage implementation in root, TASImage.
179 
180  // clear the first element map if # of entries > 30
181  if (hasNamedImage(name))
182  namedPictureBuffer_.erase(name);
183  namedPictureBuffer_[name] = local_str.str();
184  // if (namedPictureBuffer_[name].size() > 0) std::cout << "image created " << name << std::endl;
185 }
std::map< std::string, std::string > namedPictureBuffer_
bool hasNamedImage(const std::string &name)
void free(void *ptr) noexcept

◆ getDummyImage()

void SiStripHistoPlotter::getDummyImage ( std::string &  image)
private

Definition at line 207 of file SiStripHistoPlotter.cc.

References contentValuesFiles::fullPath, recoMuon::in, mps_splice::line, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by createDummyImage().

207  {
209  std::ostringstream local_str;
210  // Read back the file line by line and temporarily store it in a stringstream
211  std::string localPath = std::string("DQM/TrackerCommon/test/images/EmptyPlot.png");
212  std::ifstream* imagefile = new std::ifstream((edm::FileInPath(localPath).fullPath()).c_str(), std::ios::in);
213  if (imagefile->is_open()) {
214  while (getline(*imagefile, line)) {
215  local_str << line << std::endl;
216  }
217  }
218  imagefile->close();
219  image = local_str.str();
220 }

◆ getNamedImageBuffer()

void SiStripHistoPlotter::getNamedImageBuffer ( const std::string &  path,
std::string &  image 
)

Definition at line 122 of file SiStripHistoPlotter.cc.

References gather_cfg::cout, namedPictureBuffer_, and castor_dqm_sourceclient_file_cfg::path.

122  {
123  std::map<std::string, std::string>::iterator cPos;
124  if (path == "dummy_path") {
125  std::cout << " Sending Dummy Image for : " << path << std::endl;
126  cPos = namedPictureBuffer_.find("Dummy");
127  image = cPos->second;
128  } else {
129  cPos = namedPictureBuffer_.find(path);
130  if (cPos != namedPictureBuffer_.end()) {
131  image = cPos->second;
132  if (namedPictureBuffer_.size() > 99)
133  namedPictureBuffer_.erase(cPos);
134  } else {
135  std::cout << " Sending Dummy Image for : " << path << std::endl;
136  cPos = namedPictureBuffer_.find("Dummy");
137  image = cPos->second;
138  }
139  }
140 }
std::map< std::string, std::string > namedPictureBuffer_

◆ getProjection()

void SiStripHistoPlotter::getProjection ( MonitorElement me,
TH1F *  tp 
)
private

Definition at line 240 of file SiStripHistoPlotter.cc.

References mps_fire::i, dqmiolumiharvest::j, hlt_dqm_clientPB-live_cfg::me, AlCaHLTBitMon_QueryRunRegistry::string, MonitorElementData::TH1F, MonitorElementData::TH2F, cmsswSequenceInfo::tp, and MonitorElementData::TPROFILE.

Referenced by makePlot().

240  {
241  std::string ptit = me->getTitle();
242  ptit += "-Yprojection";
243 
244  if (me->kind() == MonitorElement::Kind::TH2F) {
245  TH2F* hist2 = me->getTH2F();
246  tp = new TH1F(
247  ptit.c_str(), ptit.c_str(), hist2->GetNbinsY(), hist2->GetYaxis()->GetXmin(), hist2->GetYaxis()->GetXmax());
248  tp->GetXaxis()->SetTitle(ptit.c_str());
249  for (int j = 1; j < hist2->GetNbinsY() + 1; j++) {
250  float tot_count = 0.0;
251  for (int i = 1; i < hist2->GetNbinsX() + 1; i++) {
252  tot_count += hist2->GetBinContent(i, j);
253  }
254  tp->SetBinContent(j, tot_count);
255  }
256  } else if (me->kind() == MonitorElement::Kind::TPROFILE) {
257  TProfile* prof = me->getTProfile();
258  tp = new TH1F(ptit.c_str(), ptit.c_str(), 100, 0.0, prof->GetMaximum() * 1.2);
259  tp->GetXaxis()->SetTitle(ptit.c_str());
260  for (int i = 1; i < prof->GetNbinsX() + 1; i++) {
261  tp->Fill(prof->GetBinContent(i));
262  }
263  } else if (me->kind() == MonitorElement::Kind::TH1F) {
264  TH1F* hist1 = me->getTH1F();
265  tp = new TH1F(ptit.c_str(), ptit.c_str(), 100, 0.0, hist1->GetMaximum() * 1.2);
266  tp->GetXaxis()->SetTitle(ptit.c_str());
267  for (int i = 1; i < hist1->GetNbinsX() + 1; i++) {
268  tp->Fill(hist1->GetBinContent(i));
269  }
270  }
271 }

◆ hasNamedImage()

bool SiStripHistoPlotter::hasNamedImage ( const std::string &  name)
private

Definition at line 189 of file SiStripHistoPlotter.cc.

References Skims_PA_cff::name, and namedPictureBuffer_.

Referenced by createCondDBPlots(), createPlots(), fillNamedImageBuffer(), and setNewPlot().

189  {
190  std::map<std::string, std::string>::const_iterator cPos = namedPictureBuffer_.find(name);
191  if (cPos == namedPictureBuffer_.end()) {
192  return false;
193  } else
194  return true;
195 }
std::map< std::string, std::string > namedPictureBuffer_

◆ makeCondDBPlots()

void SiStripHistoPlotter::makeCondDBPlots ( DQMStore dqm_store,
const PlotParameter par 
)
private

Definition at line 300 of file SiStripHistoPlotter.cc.

References svgfig::canvas(), SiStripHistoPlotter::PlotParameter::CHeight, SiStripHistoPlotter::PlotParameter::CWidth, fillNamedImageBuffer(), dqm::implementation::IGetter::getContents(), timingPdfMaker::histo, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, hlt_dqm_clientPB-live_cfg::me, SiStripHistoPlotter::PlotParameter::Option, fileinputsource_cfi::option, SiStripHistoPlotter::PlotParameter::Path, SiStripUtility::split(), AlCaHLTBitMon_QueryRunRegistry::string, and makeGlobalPositionRcd_cfg::tag.

Referenced by createCondDBPlots().

300  {
301  TCanvas* canvas = new TCanvas("TKCanvas", "TKCanvas", par.CWidth, par.CHeight);
302 
303  std::vector<std::string> htypes;
304  std::string option = par.Option;
305  SiStripUtility::split(option, htypes, ",");
306 
308  std::vector<MonitorElement*> all_mes = dqm_store->getContents(par.Path);
309 
310  for (std::vector<std::string>::const_iterator ih = htypes.begin(); ih != htypes.end(); ih++) {
311  const std::string& type = (*ih);
312  if (type.empty())
313  continue;
314  std::string tag = par.Path + "/";
315  for (std::vector<MonitorElement*>::const_iterator it = all_mes.begin(); it != all_mes.end(); it++) {
316  MonitorElement* me = (*it);
317  if (!me)
318  continue;
319  std::string hname = me->getName();
320  if (hname.find(type) != std::string::npos) {
321  TH1* histo = me->getTH1();
322  histo->Draw();
323  tag += type;
325  canvas->Clear();
326  }
327  }
328  }
329  delete canvas;
330 }
static void split(std::string const &str, std::vector< std::string > &tokens, std::string const &delimiters=" ")
def canvas(sub, attr)
Definition: svgfig.py:482
void fillNamedImageBuffer(TCanvas *c1, const std::string &name)
(Documentation under construction).
virtual std::vector< dqm::harvesting::MonitorElement * > getContents(std::string const &path) const
Definition: DQMStore.cc:625

◆ makePlot()

void SiStripHistoPlotter::makePlot ( DQMStore const *  dqm_store,
const PlotParameter par 
)
private

Definition at line 66 of file SiStripHistoPlotter.cc.

References svgfig::canvas(), SiStripHistoPlotter::PlotParameter::CHeight, SiStripHistoPlotter::PlotParameter::CWidth, fillNamedImageBuffer(), dqm::implementation::IGetter::get(), SiStripUtility::getMEStatus(), SiStripUtility::getMEStatusColor(), getProjection(), timingPdfMaker::histo, hlt_dqm_clientPB-live_cfg::me, Skims_PA_cff::name, SiStripHistoPlotter::PlotParameter::Option, SiStripHistoPlotter::PlotParameter::Path, AlCaHLTBitMon_QueryRunRegistry::string, makeGlobalPositionRcd_cfg::tag, MonitorElementData::TH1F, MonitorElementData::TH2F, MonitorElementData::TPROFILE, MonitorElementData::TPROFILE2D, and groupFilesInBlocks::tt.

Referenced by createPlots().

66  {
67  TCanvas* canvas = new TCanvas("TKCanvas", "TKCanvas", par.CWidth, par.CHeight);
68 
69  MonitorElement* me = dqm_store->get(par.Path);
70  if (me) {
71  int istat = SiStripUtility::getMEStatus(me);
72 
73  std::string dopt = par.Option;
75  int icol;
77  if (me->kind() == MonitorElement::Kind::TH1F || me->kind() == MonitorElement::Kind::TH2F ||
79  TH1* histo = me->getTH1();
80  TH1F* tproject = nullptr;
81  if (dopt == "projection") {
82  getProjection(me, tproject);
83  if (tproject)
84  tproject->Draw();
85  else
86  histo->Draw();
87  } else {
88  dopt = "";
89  std::string name = histo->GetName();
90  if (me->kind() == MonitorElement::Kind::TPROFILE2D) {
91  dopt = "colz";
92  histo->SetStats(kFALSE);
93  } else {
94  if (name.find("Summary_Mean") != std::string::npos) {
95  histo->SetStats(kFALSE);
96  } else {
97  histo->SetFillColor(1);
98  }
99  }
100  histo->Draw(dopt.c_str());
101  }
102  }
103  TText tTitle;
104  tTitle.SetTextFont(64);
105  tTitle.SetTextSizePixels(20);
106  // tTitle.DrawTextNDC(0.1, 0.92, histo->GetName());
107 
108  if (icol != 1) {
109  TText tt;
110  tt.SetTextSize(0.12);
111  tt.SetTextColor(icol);
112  tt.DrawTextNDC(0.5, 0.5, tag.c_str());
113  }
114  fillNamedImageBuffer(canvas, par.Path);
115  canvas->Clear();
116  }
117  delete canvas;
118 }
Definition: TTTypes.h:54
static void getMEStatusColor(int status, int &rval, int &gval, int &bval)
def canvas(sub, attr)
Definition: svgfig.py:482
void getProjection(MonitorElement *me, TH1F *tp)
void fillNamedImageBuffer(TCanvas *c1, const std::string &name)
(Documentation under construction).
static int getMEStatus(MonitorElement const *me)

◆ plotsToMake()

bool SiStripHistoPlotter::plotsToMake ( )
inline

Definition at line 28 of file SiStripHistoPlotter.h.

References plotList_.

28 { return !plotList_.empty(); }
std::vector< PlotParameter > plotList_

◆ setDrawingOption()

void SiStripHistoPlotter::setDrawingOption ( TH1 *  hist)
private

Definition at line 223 of file SiStripHistoPlotter.cc.

References compareTotals::hist.

223  {
224  if (!hist)
225  return;
226 
227  TAxis* xa = hist->GetXaxis();
228  TAxis* ya = hist->GetYaxis();
229 
230  xa->SetTitleOffset(0.7);
231  xa->SetTitleSize(0.05);
232  xa->SetLabelSize(0.04);
233 
234  ya->SetTitleOffset(0.7);
235  ya->SetTitleSize(0.05);
236  ya->SetLabelSize(0.04);
237 }

◆ setNewCondDBPlot()

void SiStripHistoPlotter::setNewCondDBPlot ( std::string const &  path,
std::string const &  option,
int  width,
int  height 
)

◆ setNewPlot()

void SiStripHistoPlotter::setNewPlot ( std::string const &  path,
std::string const &  option,
int  width,
int  height 
)

Member Data Documentation

◆ condDBPlotList_

std::vector<PlotParameter> SiStripHistoPlotter::condDBPlotList_
private

Definition at line 51 of file SiStripHistoPlotter.h.

Referenced by condDBPlotsToMake(), createCondDBPlots(), and setNewCondDBPlot().

◆ namedPictureBuffer_

std::map<std::string, std::string> SiStripHistoPlotter::namedPictureBuffer_
private

◆ plotList_

std::vector<PlotParameter> SiStripHistoPlotter::plotList_
private

Definition at line 50 of file SiStripHistoPlotter.h.

Referenced by createPlots(), plotsToMake(), and setNewPlot().