CMS 3D CMS Logo

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

#include <SiStripHistoPlotter.h>

Classes

struct  PlotParameter
 

Public Member Functions

bool condDBPlotsToMake ()
 
void createCondDBPlots (DQMStore *dqm_store)
 
void createPlots (DQMStore *dqm_store)
 
void createStaticPlot (MonitorElement *me, const std::string &file_name)
 
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 17 of file SiStripHistoPlotter.h.

Constructor & Destructor Documentation

SiStripHistoPlotter::SiStripHistoPlotter ( )

Definition at line 26 of file SiStripHistoPlotter.cc.

26  {
27  edm::LogInfo("SiStripHistoPlotter") << " Creating SiStripHistoPlotter "
28  << "\n";
29 }
SiStripHistoPlotter::~SiStripHistoPlotter ( )

Definition at line 33 of file SiStripHistoPlotter.cc.

33  {
34  edm::LogInfo("SiStripHistoPlotter") << " Deleting SiStripHistoPlotter "
35  << "\n";
36 }

Member Function Documentation

bool SiStripHistoPlotter::condDBPlotsToMake ( )
inline

Definition at line 41 of file SiStripHistoPlotter.h.

References condDBPlotList_.

42  {
43  return !condDBPlotList_.empty();
44  }
std::vector< PlotParameter > condDBPlotList_
void SiStripHistoPlotter::createCondDBPlots ( DQMStore dqm_store)

Definition at line 334 of file SiStripHistoPlotter.cc.

References condDBPlotList_, createDummyImage(), hasNamedImage(), makeCondDBPlots(), dataset::name, and AlCaHLTBitMon_QueryRunRegistry::string.

335 {
336  if (condDBPlotList_.empty()) return;
337  std::string name = "Dummy";
338  if (!hasNamedImage(name)) createDummyImage(name);
339 
340  for (std::vector<PlotParameter>::iterator it = condDBPlotList_.begin();
341  it != condDBPlotList_.end();
342  it++) {
343  makeCondDBPlots(dqm_store, (*it));
344  }
345  condDBPlotList_.clear();
346 }
bool hasNamedImage(const std::string &name)
std::vector< PlotParameter > condDBPlotList_
void makeCondDBPlots(DQMStore *dqm_store, const PlotParameter &par)
void createDummyImage(const std::string &name)
void SiStripHistoPlotter::createDummyImage ( const std::string &  name)
private

Definition at line 206 of file SiStripHistoPlotter.cc.

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

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

206  {
207  std::string image;
208  getDummyImage(image);
209  namedPictureBuffer_.insert(std::pair<std::string, std::string>(name, image));
210 }
std::map< std::string, std::string > namedPictureBuffer_
void getDummyImage(std::string &image)
void SiStripHistoPlotter::createPlots ( DQMStore dqm_store)

Definition at line 54 of file SiStripHistoPlotter.cc.

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

54  {
55  if (plotList_.empty()) return;
56  std::string name = "Dummy";
57  if (!hasNamedImage(name)) createDummyImage(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_
void SiStripHistoPlotter::createStaticPlot ( MonitorElement me,
const std::string &  file_name 
)

Definition at line 288 of file SiStripHistoPlotter.cc.

References svgfig::canvas(), mps_check::command, cmsPerfSuiteHarvest::file_name, MonitorElement::getRefRootObject(), MonitorElement::getRefTH1(), MonitorElement::getTH1(), dataset::name, setDrawingOption(), and AlCaHLTBitMon_QueryRunRegistry::string.

288  {
289  TH1* hist1 = me->getTH1();
290  auto canvas = new TCanvas("TKCanvas", "TKCanvas", 600, 400);
291  if (hist1) {
292  TText tTitle;
293  tTitle.SetTextFont(64);
294  tTitle.SetTextSizePixels(20);
295 
296  setDrawingOption(hist1);
297  hist1->Draw();
298  std::string name = hist1->GetName();
299  if (me->getRefRootObject()) {
300  TH1* hist1_ref = me->getRefTH1();
301  if (hist1_ref) {
302  hist1_ref->SetLineColor(3);
303  hist1_ref->SetMarkerColor(3);
304  if (name.find("Summary") != std::string::npos)
305  hist1_ref->Draw("same");
306  else
307  hist1_ref->DrawNormalized("same", hist1->GetEntries());
308  }
309  }
310  }
311  canvas->Update();
312  std::string command = "rm -f " + file_name;
313  gSystem->Exec(command.c_str());
314  canvas->Print(file_name.c_str(),"png");
315  canvas->Clear();
316  delete canvas;
317 }
TH1 * getTH1() const
void setDrawingOption(TH1 *hist)
TH1 * getRefTH1() const
TObject * getRefRootObject() const
list command
Definition: mps_check.py:25
def canvas(sub, attr)
Definition: svgfig.py:482
void SiStripHistoPlotter::fillNamedImageBuffer ( TCanvas *  c1,
const std::string &  name 
)
private

(Documentation under construction).

This method

Definition at line 153 of file SiStripHistoPlotter.cc.

References gather_cfg::cout, hasNamedImage(), mps_fire::i, dataset::name, namedPictureBuffer_, and mathSSE::return().

Referenced by makeCondDBPlots(), and makePlot().

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

Definition at line 214 of file SiStripHistoPlotter.cc.

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

Referenced by createDummyImage().

214  {
216  std::ostringstream local_str;
217  // Read back the file line by line and temporarily store it in a stringstream
218  std::string localPath = std::string("DQM/TrackerCommon/test/images/EmptyPlot.png");
219  std::ifstream * imagefile = new std::ifstream((edm::FileInPath(localPath).fullPath()).c_str(),std::ios::in);
220  if(imagefile->is_open()) {
221  while (getline( *imagefile, line )) {
222  local_str << line << std::endl ;
223  }
224  }
225  imagefile->close();
226  image = local_str.str();
227 }
void SiStripHistoPlotter::getNamedImageBuffer ( const std::string &  path,
std::string &  image 
)

Definition at line 129 of file SiStripHistoPlotter.cc.

References gather_cfg::cout, and namedPictureBuffer_.

129  {
130  std::map<std::string, std::string>::iterator cPos;
131  if (path == "dummy_path") {
132  std::cout << " Sending Dummy Image for : "
133  << path << std::endl;
134  cPos = namedPictureBuffer_.find("Dummy");
135  image = cPos->second;
136  } else {
137  cPos = namedPictureBuffer_.find(path);
138  if (cPos != namedPictureBuffer_.end()) {
139  image = cPos->second;
140  if (namedPictureBuffer_.size() > 99 ) namedPictureBuffer_.erase(cPos);
141  } else {
142  std::cout << " Sending Dummy Image for : " << path << std::endl;
143  cPos = namedPictureBuffer_.find("Dummy");
144  image = cPos->second;
145  }
146  }
147 }
std::map< std::string, std::string > namedPictureBuffer_
void SiStripHistoPlotter::getProjection ( MonitorElement me,
TH1F *  tp 
)
private

Definition at line 247 of file SiStripHistoPlotter.cc.

References MonitorElement::DQM_KIND_TH1F, MonitorElement::DQM_KIND_TH2F, MonitorElement::DQM_KIND_TPROFILE, MonitorElement::getTH1F(), MonitorElement::getTH2F(), MonitorElement::getTitle(), MonitorElement::getTProfile(), mps_fire::i, MonitorElement::kind(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by makePlot().

247  {
248 
249  std::string ptit = me->getTitle();
250  ptit += "-Yprojection";
251 
252  if (me->kind() == MonitorElement::DQM_KIND_TH2F) {
253  TH2F* hist2 = me->getTH2F();
254  tp = new TH1F(ptit.c_str(),
255  ptit.c_str(),
256  hist2->GetNbinsY(),
257  hist2->GetYaxis()->GetXmin(),
258  hist2->GetYaxis()->GetXmax());
259  tp->GetXaxis()->SetTitle(ptit.c_str());
260  for (int j = 1; j < hist2->GetNbinsY()+1; j++) {
261  float tot_count = 0.0;
262  for (int i = 1; i < hist2->GetNbinsX()+1; i++) {
263  tot_count += hist2->GetBinContent(i, j);
264  }
265  tp->SetBinContent(j, tot_count);
266  }
267  } else if (me->kind() == MonitorElement::DQM_KIND_TPROFILE) {
268  TProfile* prof = me->getTProfile();
269  tp =
270  new TH1F(ptit.c_str(), ptit.c_str(), 100, 0.0, prof->GetMaximum() * 1.2);
271  tp->GetXaxis()->SetTitle(ptit.c_str());
272  for (int i = 1; i < prof->GetNbinsX()+1; i++) {
273  tp->Fill(prof->GetBinContent(i));
274  }
275  } else if (me->kind() == MonitorElement::DQM_KIND_TH1F) {
276  TH1F* hist1 = me->getTH1F();
277  tp =
278  new TH1F(ptit.c_str(), ptit.c_str(), 100, 0.0, hist1->GetMaximum() * 1.2);
279  tp->GetXaxis()->SetTitle(ptit.c_str());
280  for (int i = 1; i < hist1->GetNbinsX()+1; i++) {
281  tp->Fill(hist1->GetBinContent(i));
282  }
283  }
284 }
TProfile * getTProfile() const
TH1F * getTH1F() const
std::string getTitle() const
get MonitorElement title
TH2F * getTH2F() const
Kind kind() const
Get the type of the monitor element.
bool SiStripHistoPlotter::hasNamedImage ( const std::string &  name)
private

Definition at line 197 of file SiStripHistoPlotter.cc.

References namedPictureBuffer_.

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

197  {
198  std::map<std::string, std::string>::const_iterator cPos = namedPictureBuffer_.find(name);
199  if (cPos == namedPictureBuffer_.end()) {
200  return false;
201  } else return true;
202 }
std::map< std::string, std::string > namedPictureBuffer_
void SiStripHistoPlotter::makeCondDBPlots ( DQMStore dqm_store,
const PlotParameter par 
)
private

Definition at line 350 of file SiStripHistoPlotter.cc.

References svgfig::canvas(), SiStripHistoPlotter::PlotParameter::CHeight, SiStripHistoPlotter::PlotParameter::CWidth, fillNamedImageBuffer(), DQMStore::getContents(), MonitorElement::getName(), MonitorElement::getTH1(), trackerHits::histo, TSGForRoadSearch_cfi::option, SiStripHistoPlotter::PlotParameter::Option, SiStripHistoPlotter::PlotParameter::Path, SiStripUtility::split(), AlCaHLTBitMon_QueryRunRegistry::string, and GlobalPosition_Frontier_DevDB_cff::tag.

Referenced by createCondDBPlots().

350  {
351  TCanvas * canvas = new TCanvas("TKCanvas", "TKCanvas", par.CWidth, par.CHeight);
352 
353  std::vector<std::string> htypes;
354  std::string option = par.Option;
355  SiStripUtility::split(option, htypes, ",");
356 
358  std::vector<MonitorElement*> all_mes = dqm_store->getContents(par.Path);
359 
360  for (std::vector<std::string>::const_iterator ih = htypes.begin();
361  ih!= htypes.end(); ih++) {
362  std::string type = (*ih);
363  if (type.empty()) continue;
364  std::string tag = par.Path + "/";
365  for (std::vector<MonitorElement*>::const_iterator it = all_mes.begin();
366  it != all_mes.end();
367  it++) {
368  MonitorElement * me = (*it);
369  if (!me) continue;
370  std::string hname = me->getName();
371  if (hname.find(type) != std::string::npos) {
372  TH1* histo = me->getTH1();
373  histo->Draw();
374  tag += type;
375  fillNamedImageBuffer(canvas, tag);
376  canvas->Clear();
377  }
378  }
379  }
380  delete canvas;
381 }
type
Definition: HCALResponse.h:21
std::vector< MonitorElement * > getContents(std::string const &path) const
Definition: DQMStore.cc:1640
TH1 * getTH1() const
const std::string & getName() const
get name of ME
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).
void SiStripHistoPlotter::makePlot ( DQMStore const *  dqm_store,
const PlotParameter par 
)
private

Definition at line 67 of file SiStripHistoPlotter.cc.

References svgfig::canvas(), SiStripHistoPlotter::PlotParameter::CHeight, SiStripHistoPlotter::PlotParameter::CWidth, MonitorElement::DQM_KIND_TH1F, MonitorElement::DQM_KIND_TH2F, MonitorElement::DQM_KIND_TPROFILE, MonitorElement::DQM_KIND_TPROFILE2D, fillNamedImageBuffer(), DQMStore::get(), SiStripUtility::getMEStatus(), SiStripUtility::getMEStatusColor(), getProjection(), MonitorElement::getTH1(), trackerHits::histo, MonitorElement::kind(), dataset::name, SiStripHistoPlotter::PlotParameter::Option, SiStripHistoPlotter::PlotParameter::Path, AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, and groupFilesInBlocks::tt.

Referenced by createPlots().

69 {
70  TCanvas* canvas =
71  new TCanvas("TKCanvas", "TKCanvas", par.CWidth, par.CHeight);
72 
73  MonitorElement* me = dqm_store->get(par.Path);
74  if (me) {
75 
76  int istat = SiStripUtility::getMEStatus(me);
77 
78  std::string dopt = par.Option;
80  int icol;
81  SiStripUtility::getMEStatusColor(istat, icol, tag);
82  if (me->kind() == MonitorElement::DQM_KIND_TH1F ||
86  TH1* histo = me->getTH1();
87  TH1F* tproject = nullptr;
88  if (dopt == "projection") {
89  getProjection(me, tproject);
90  if (tproject)
91  tproject->Draw();
92  else
93  histo->Draw();
94  } else {
95  dopt = "";
96  std::string name = histo->GetName();
98  dopt = "colz";
99  histo->SetStats( kFALSE );
100  } else {
101  if (name.find("Summary_Mean") != std::string::npos) {
102  histo->SetStats(kFALSE);
103  } else {
104  histo->SetFillColor(1);
105  }
106  }
107  histo->Draw(dopt.c_str());
108  }
109  }
110  TText tTitle;
111  tTitle.SetTextFont(64);
112  tTitle.SetTextSizePixels(20);
113  // tTitle.DrawTextNDC(0.1, 0.92, histo->GetName());
114 
115  if (icol != 1) {
116  TText tt;
117  tt.SetTextSize(0.12);
118  tt.SetTextColor(icol);
119  tt.DrawTextNDC(0.5, 0.5, tag.c_str());
120  }
121  fillNamedImageBuffer(canvas, par.Path);
122  canvas->Clear();
123  }
124  delete canvas;
125 }
TH1 * getTH1() const
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)
Kind kind() const
Get the type of the monitor element.
bool SiStripHistoPlotter::plotsToMake ( )
inline

Definition at line 36 of file SiStripHistoPlotter.h.

References plotList_.

37  {
38  return !plotList_.empty();
39  }
std::vector< PlotParameter > plotList_
void SiStripHistoPlotter::setDrawingOption ( TH1 *  hist)
private

Definition at line 230 of file SiStripHistoPlotter.cc.

Referenced by createStaticPlot().

230  {
231  if (!hist) return;
232 
233  TAxis* xa = hist->GetXaxis();
234  TAxis* ya = hist->GetYaxis();
235 
236  xa->SetTitleOffset(0.7);
237  xa->SetTitleSize(0.05);
238  xa->SetLabelSize(0.04);
239 
240  ya->SetTitleOffset(0.7);
241  ya->SetTitleSize(0.05);
242  ya->SetLabelSize(0.04);
243 
244 }
void SiStripHistoPlotter::setNewCondDBPlot ( std::string const &  path,
std::string const &  option,
int  width,
int  height 
)

Definition at line 322 of file SiStripHistoPlotter.cc.

References condDBPlotList_, eostools::move(), TSGForRoadSearch_cfi::option, callgraph::path, and ApeEstimator_cff::width.

326 {
327  PlotParameter local_par{path, option, width, height};
328  condDBPlotList_.push_back(std::move(local_par));
329 }
std::vector< PlotParameter > condDBPlotList_
def move(src, dest)
Definition: eostools.py:511
void SiStripHistoPlotter::setNewPlot ( std::string const &  path,
std::string const &  option,
int  width,
int  height 
)

Definition at line 41 of file SiStripHistoPlotter.cc.

References createDummyImage(), hasNamedImage(), eostools::move(), dataset::name, TSGForRoadSearch_cfi::option, callgraph::path, plotList_, AlCaHLTBitMon_QueryRunRegistry::string, and ApeEstimator_cff::width.

45 {
46  std::string name = "Dummy";
47  if (!hasNamedImage(name)) createDummyImage(name);
48  PlotParameter local_par{path, option, width, height};
49  plotList_.push_back(std::move(local_par));
50 }
bool hasNamedImage(const std::string &name)
void createDummyImage(const std::string &name)
std::vector< PlotParameter > plotList_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

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

Definition at line 66 of file SiStripHistoPlotter.h.

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

std::map<std::string, std::string> SiStripHistoPlotter::namedPictureBuffer_
private
std::vector<PlotParameter> SiStripHistoPlotter::plotList_
private

Definition at line 65 of file SiStripHistoPlotter.h.

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