CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 &path, std::string &option, int width, int height)
 
void setNewPlot (std::string &path, std::string &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 *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") <<
28  " Creating SiStripHistoPlotter " << "\n" ;
29 }
SiStripHistoPlotter::~SiStripHistoPlotter ( )

Definition at line 33 of file SiStripHistoPlotter.cc.

References condDBPlotList_, and plotList_.

33  {
34  edm::LogInfo("SiStripHistoPlotter") <<
35  " Deleting SiStripHistoPlotter " << "\n" ;
36  plotList_.clear();
37  condDBPlotList_.clear();
38 
39 }
std::vector< PlotParameter > condDBPlotList_
std::vector< PlotParameter > plotList_

Member Function Documentation

bool SiStripHistoPlotter::condDBPlotsToMake ( )
inline

Definition at line 33 of file SiStripHistoPlotter.h.

References condDBPlotList_.

Referenced by SiStripInformationExtractor::createImages().

33 { return ((condDBPlotList_.size() > 0) ? true : false);}
std::vector< PlotParameter > condDBPlotList_
void SiStripHistoPlotter::createCondDBPlots ( DQMStore dqm_store)

Definition at line 326 of file SiStripHistoPlotter.cc.

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

Referenced by SiStripInformationExtractor::createImages().

326  {
327  if (condDBPlotList_.size() == 0) return;
328  std::string name = "Dummy";
329  if (!hasNamedImage(name)) createDummyImage(name);
330 
331  for (std::vector<PlotParameter>::iterator it = condDBPlotList_.begin();
332  it != condDBPlotList_.end(); it++) {
333  makeCondDBPlots(dqm_store, (*it));
334  }
335  condDBPlotList_.clear();
336 }
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 205 of file SiStripHistoPlotter.cc.

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

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

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

Definition at line 56 of file SiStripHistoPlotter.cc.

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

Referenced by SiStripInformationExtractor::createImages().

56  {
57  if (plotList_.size() == 0) return;
58  std::string name = "Dummy";
59  if (!hasNamedImage(name)) createDummyImage(name);
60  for (std::vector<PlotParameter>::iterator it = plotList_.begin();
61  it != plotList_.end(); it++) {
62  makePlot(dqm_store, (*it));
63  }
64  plotList_.clear();
65 }
bool hasNamedImage(const std::string &name)
void createDummyImage(const std::string &name)
std::vector< PlotParameter > plotList_
void makePlot(DQMStore *dqm_store, const PlotParameter &par)
void SiStripHistoPlotter::createStaticPlot ( MonitorElement me,
const std::string &  file_name 
)

Definition at line 284 of file SiStripHistoPlotter.cc.

References svgfig::canvas(), edmPickEvents::command, cmsHarvester::file_name, MonitorElement::getRefRootObject(), MonitorElement::getRefTH1(), MonitorElement::getTH1(), mergeVDriftHistosByStation::name, setDrawingOption(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by SiStripInformationExtractor::plotHistosFromLayout().

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

(Documentation under construction).

This method

Definition at line 150 of file SiStripHistoPlotter.cc.

References gather_cfg::cout, hasNamedImage(), i, mergeVDriftHistosByStation::name, namedPictureBuffer_, NULL, and reco::return().

Referenced by makeCondDBPlots(), and makePlot().

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

Definition at line 213 of file SiStripHistoPlotter.cc.

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

Referenced by createDummyImage().

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

Definition at line 126 of file SiStripHistoPlotter.cc.

References gather_cfg::cout, and namedPictureBuffer_.

126  {
127  std::map<std::string, std::string>::iterator cPos;
128  if (path == "dummy_path") {
129  std::cout << " Sending Dummy Image for : "
130  << path << std::endl;
131  cPos = namedPictureBuffer_.find("Dummy");
132  image = cPos->second;
133  } else {
134  cPos = namedPictureBuffer_.find(path);
135  if (cPos != namedPictureBuffer_.end()) {
136  image = cPos->second;
137  if (namedPictureBuffer_.size() > 99 ) namedPictureBuffer_.erase(cPos);
138  } else {
139  std::cout << " Sending Dummy Image for : "
140  << path << std::endl;
141  cPos = namedPictureBuffer_.find("Dummy");
142  image = cPos->second;
143  }
144  }
145 }
std::map< std::string, std::string > namedPictureBuffer_
tuple path
else: Piece not in the list, fine.
tuple cout
Definition: gather_cfg.py:121
void SiStripHistoPlotter::getProjection ( MonitorElement me,
TH1F *  tp 
)
private

Definition at line 246 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(), i, j, MonitorElement::kind(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by makePlot().

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

Definition at line 196 of file SiStripHistoPlotter.cc.

References namedPictureBuffer_.

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

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

Definition at line 340 of file SiStripHistoPlotter.cc.

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

Referenced by createCondDBPlots().

340  {
341  TCanvas * canvas = new TCanvas("TKCanvas", "TKCanvas", par.CWidth, par.CHeight);
342 
343  std::vector<std::string> htypes;
344  std::string option = par.Option;
345  SiStripUtility::split(option, htypes, ",");
346 
348  std::vector<MonitorElement*> all_mes = dqm_store->getContents(par.Path);
349 
350  for (std::vector<std::string>::const_iterator ih = htypes.begin();
351  ih!= htypes.end(); ih++) {
352  std::string type = (*ih);
353  if (type.size() == 0) continue;
354  std::string tag = par.Path + "/";
355  for (std::vector<MonitorElement *>::const_iterator it = all_mes.begin();
356  it!= all_mes.end(); it++) {
357  MonitorElement * me = (*it);
358  if (!me) continue;
359  std::string hname = me->getName();
360  if (hname.find(type) != std::string::npos) {
361  TH1* histo = me->getTH1();
362  histo->Draw();
363  tag += type;
364  fillNamedImageBuffer(canvas, tag);
365  canvas->Clear();
366  }
367  }
368  }
369  delete canvas;
370 }
type
Definition: HCALResponse.h:21
const std::string & getName(void) const
get name of ME
static void split(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
def canvas
Definition: svgfig.py:481
TH1 * getTH1(void) const
std::vector< MonitorElement * > getContents(const std::string &path) const
Definition: DQMStore.cc:1737
void fillNamedImageBuffer(TCanvas *c1, const std::string &name)
(Documentation under construction).
void SiStripHistoPlotter::makePlot ( DQMStore dqm_store,
const PlotParameter par 
)
private

Definition at line 69 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(), timingPdfMaker::histo, MonitorElement::kind(), mergeVDriftHistosByStation::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 = new TCanvas("TKCanvas", "TKCanvas", par.CWidth, par.CHeight);
71 
72  MonitorElement * me = dqm_store->get(par.Path);
73  if (me) {
74 
75  int istat = SiStripUtility::getMEStatus(me);
76 
77  std::string dopt = par.Option;
79  int icol;
80  SiStripUtility::getMEStatusColor(istat, icol, tag);
81  if (me->kind() == MonitorElement::DQM_KIND_TH1F ||
85  TH1* histo = me->getTH1();
86  TH1F* tproject = 0;
87  if (dopt == "projection") {
88  getProjection(me, tproject);
89  if (tproject) tproject->Draw();
90  else histo->Draw();
91  } else {
92  dopt = "";
93  std::string name = histo->GetName();
95  dopt = "colz";
96  histo->SetStats( kFALSE );
97  } else {
98  if (name.find("Summary_Mean") != std::string::npos) {
99  histo->SetStats( kFALSE );
100  } else {
101  histo->SetFillColor(1);
102  }
103  }
104  histo->Draw(dopt.c_str());
105  }
106  }
107  TText tTitle;
108  tTitle.SetTextFont(64);
109  tTitle.SetTextSizePixels(20);
110  // tTitle.DrawTextNDC(0.1, 0.92, histo->GetName());
111 
112  if (icol != 1) {
113  TText tt;
114  tt.SetTextSize(0.12);
115  tt.SetTextColor(icol);
116  tt.DrawTextNDC(0.5, 0.5, tag.c_str());
117  }
118  fillNamedImageBuffer(canvas, par.Path);
119  canvas->Clear();
120  }
121  delete canvas;
122 }
def canvas
Definition: svgfig.py:481
TH1 * getTH1(void) const
Kind kind(void) const
Get the type of the monitor element.
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1708
static void getMEStatusColor(int status, int &rval, int &gval, int &bval)
static int getMEStatus(MonitorElement *me)
void getProjection(MonitorElement *me, TH1F *tp)
void fillNamedImageBuffer(TCanvas *c1, const std::string &name)
(Documentation under construction).
bool SiStripHistoPlotter::plotsToMake ( )
inline

Definition at line 32 of file SiStripHistoPlotter.h.

References plotList_.

Referenced by SiStripInformationExtractor::createImages().

32 { return ((plotList_.size() > 0) ? true : false);}
std::vector< PlotParameter > plotList_
void SiStripHistoPlotter::setDrawingOption ( TH1 *  hist)
private

Definition at line 229 of file SiStripHistoPlotter.cc.

Referenced by createStaticPlot().

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

Definition at line 315 of file SiStripHistoPlotter.cc.

References SiStripHistoPlotter::PlotParameter::CHeight, condDBPlotList_, SiStripHistoPlotter::PlotParameter::CWidth, SiStripHistoPlotter::PlotParameter::Option, SiStripHistoPlotter::PlotParameter::Path, cmsHarvester::path, and create_public_lumi_plots::width.

315  {
316  PlotParameter local_par;
317  local_par.Path = path;
318  local_par.Option = option;
319  local_par.CWidth = width;
320  local_par.CHeight = height;
321  condDBPlotList_.push_back(local_par);
322 }
std::vector< PlotParameter > condDBPlotList_
tuple path
else: Piece not in the list, fine.
void SiStripHistoPlotter::setNewPlot ( std::string &  path,
std::string &  option,
int  width,
int  height 
)

Definition at line 43 of file SiStripHistoPlotter.cc.

References SiStripHistoPlotter::PlotParameter::CHeight, createDummyImage(), SiStripHistoPlotter::PlotParameter::CWidth, hasNamedImage(), mergeVDriftHistosByStation::name, SiStripHistoPlotter::PlotParameter::Option, SiStripHistoPlotter::PlotParameter::Path, cmsHarvester::path, plotList_, AlCaHLTBitMon_QueryRunRegistry::string, and create_public_lumi_plots::width.

43  {
44  std::string name = "Dummy";
45  if (!hasNamedImage(name)) createDummyImage(name);
46  PlotParameter local_par;
47  local_par.Path = path;
48  local_par.Option = option;
49  local_par.CWidth = width;
50  local_par.CHeight = height;
51  plotList_.push_back(local_par);
52 }
bool hasNamedImage(const std::string &name)
tuple path
else: Piece not in the list, fine.
void createDummyImage(const std::string &name)
std::vector< PlotParameter > plotList_

Member Data Documentation

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

Definition at line 59 of file SiStripHistoPlotter.h.

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