CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DQM/TrackerCommon/src/ME_MAP.cc

Go to the documentation of this file.
00001 #include "DQM/TrackerCommon/interface/ME_MAP.h"
00002 
00003 #include <TColor.h>
00004 #include <TVirtualPad.h>
00005 #include <math.h>
00006 #include <iostream>
00007 #include <cstdlib>
00008 
00009 void ME_MAP::add(std::string name, MonitorElement *me_p)
00010 {
00011   entry newentry(name, me_p);
00012   mymap.insert(newentry);
00013 }
00014 
00015 /*
00016   void ME_MAP::remove(std::string name)
00017   { 
00018   MonitorElement *d_ptr = mymap[name];
00019    delete d_ptr;
00020    mymap.erase(name);
00021     }
00022 */
00023 void ME_MAP::print(std::string name)
00024 {
00025   std::string gif_name = name + ".gif";
00026       
00027   clean_old(gif_name);
00028       
00029   create_gif(gif_name);
00030 }
00031 
00032 void ME_MAP::clean_old(std::string gif_name)
00033 {
00034   ::unlink(gif_name.c_str());
00035 }
00036 
00037 void ME_MAP::divide_canvas(int num_elements, TCanvas &canvas)
00038 {
00039   if (num_elements < 2) 
00040     {
00041       canvas.Divide(1, 1);
00042       return;
00043     }
00044   if (num_elements == 2) 
00045     {
00046       canvas.Divide(2, 1);
00047       return;
00048     }
00049       
00050   int columns = static_cast<int>(sqrt(static_cast<float>(num_elements)));
00051   int rows = static_cast<int>(ceil(static_cast<float>(num_elements) / columns));
00052   canvas.Divide(columns, rows); 
00053 }
00054 
00055 void ME_MAP::create_gif(std::string name)
00056 { 
00057   int num_elements = mymap.size();
00058       
00059   // If we (still) don't have anything, create empty eps
00060   if (num_elements == 0) 
00061     {
00062       std::string command = "cp empty.eps " + name; 
00063       ::system(command.c_str());
00064      // std::cout << "ME_MAP has no elements" << std::endl;
00065       return;
00066     }
00067       
00068   else
00069     {
00070       
00071      // std::cout << "ME_MAP has " << mymap.size() << " elements" << std::endl;
00072 
00073       TCanvas canvas("display");
00074                 
00075       divide_canvas(num_elements, canvas);
00076           
00077       int i = 0;
00078       me_map::iterator it;
00079       for (it = mymap.begin(); it != mymap.end(); it++)
00080         {
00081           // move to the next place in the canvas
00082           TVirtualPad * current_pad = canvas.cd(i + 1);
00083           Color_t color = TColor::GetColor("000000");
00084           if (it->second->hasOtherReport()) color = TColor::GetColor ("#FCD116");
00085           if (it->second->hasWarning()) color = TColor::GetColor ("#FF8000");
00086           if (it->second->hasError()) color = TColor::GetColor ("#CC0000");
00087           current_pad->HighLight(color, kTRUE);
00088           it->second->getRootObject()->Draw();
00089           i++;
00090         }
00091           
00092       canvas.SaveAs(name.c_str());
00093     }
00094 }
00095