CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ME_MAP.cc
Go to the documentation of this file.
2 
3 #include <TColor.h>
4 #include <TVirtualPad.h>
5 #include <math.h>
6 #include <iostream>
7 #include <cstdlib>
8 
9 void ME_MAP::add(std::string name, MonitorElement *me_p)
10 {
11  entry newentry(name, me_p);
12  mymap.insert(newentry);
13 }
14 
15 /*
16  void ME_MAP::remove(std::string name)
17  {
18  MonitorElement *d_ptr = mymap[name];
19  delete d_ptr;
20  mymap.erase(name);
21  }
22 */
23 void ME_MAP::print(std::string name)
24 {
25  std::string gif_name = name + ".gif";
26 
27  clean_old(gif_name);
28 
29  create_gif(gif_name);
30 }
31 
32 void ME_MAP::clean_old(std::string gif_name)
33 {
34  ::unlink(gif_name.c_str());
35 }
36 
37 void ME_MAP::divide_canvas(int num_elements, TCanvas &canvas)
38 {
39  if (num_elements < 2)
40  {
41  canvas.Divide(1, 1);
42  return;
43  }
44  if (num_elements == 2)
45  {
46  canvas.Divide(2, 1);
47  return;
48  }
49 
50  int columns = static_cast<int>(sqrt(static_cast<float>(num_elements)));
51  int rows = static_cast<int>(ceil(static_cast<float>(num_elements) / columns));
52  canvas.Divide(columns, rows);
53 }
54 
55 void ME_MAP::create_gif(std::string name)
56 {
57  int num_elements = mymap.size();
58 
59  // If we (still) don't have anything, create empty eps
60  if (num_elements == 0)
61  {
62  std::string command = "cp empty.eps " + name;
63  ::system(command.c_str());
64  // std::cout << "ME_MAP has no elements" << std::endl;
65  return;
66  }
67 
68  else
69  {
70 
71  // std::cout << "ME_MAP has " << mymap.size() << " elements" << std::endl;
72 
73  TCanvas canvas("display");
74 
75  divide_canvas(num_elements, canvas);
76 
77  int i = 0;
78  me_map::iterator it;
79  for (it = mymap.begin(); it != mymap.end(); it++)
80  {
81  // move to the next place in the canvas
82  TVirtualPad * current_pad = canvas.cd(i + 1);
83  Color_t color = TColor::GetColor("000000");
84  if (it->second->hasOtherReport()) color = TColor::GetColor ("#FCD116");
85  if (it->second->hasWarning()) color = TColor::GetColor ("#FF8000");
86  if (it->second->hasError()) color = TColor::GetColor ("#CC0000");
87  current_pad->HighLight(color, kTRUE);
88  it->second->getRootObject()->Draw();
89  i++;
90  }
91 
92  canvas.SaveAs(name.c_str());
93  }
94 }
95 
int i
Definition: DBlmapReader.cc:9
void print(std::string name)
print the map into a gif named &quot;name&quot;
Definition: ME_MAP.cc:23
void add(std::string name, MonitorElement *me_p)
add the ME named &quot;name&quot; to the map
Definition: ME_MAP.cc:9
def canvas
Definition: svgfig.py:481
T sqrt(T t)
Definition: SSEVec.h:46
void create_gif(std::string name)
create the gif file
Definition: ME_MAP.cc:55
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
void clean_old(std::string gif_name)
clean old eps and gif files by the same name
Definition: ME_MAP.cc:32
me_map mymap
a map of pointers to a subset of the MEs in contents:
Definition: ME_MAP.h:16
void divide_canvas(int num_elements, TCanvas &canvas)
divide the canvas according to the number of elements to display
Definition: ME_MAP.cc:37