Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

Displayer.cpp

00001 #include "Displayer.h"
00002 #include "SctData/DefectList.h"
00003 #include "DisplayManager.h"
00004 #include <cmath>
00005 #include <TCanvas.h>
00006 #include <TROOT.h>
00007 #include <TStyle.h>
00008 #include <iostream>
00009 #include <iomanip>
00010 #include <boost/lexical_cast.hpp>
00011 
00012 using namespace std;
00013 using namespace boost;
00014 using namespace SctData;
00015 
00016 namespace SctDataDisplay {
00017 
00018 struct null_deleter
00019 {
00020     void operator()(void const *) const
00021     {
00022     }
00023 };
00024 
00025 shared_ptr<TCanvas> Displayer::createCanvas(string name, string title) {
00026     unsigned int i=0;
00027     string rname;
00028     TCanvas* old = 0;
00029     do {
00030         ++i;
00031         rname = name + "_" + lexical_cast<string>(i);
00032     old = dynamic_cast<TCanvas*>(gROOT->GetListOfCanvases()->FindObject(rname.c_str()));
00033     } while(old != 0);
00034     int offset=gROOT->GetListOfCanvases()->GetSize()*20%200;
00035     gROOT->SetStyle("Plain");
00036     gStyle->SetOptStat(0);
00037     gStyle->SetTitleX(0.5);
00038     gStyle->SetTitleY(0.99);
00039     gStyle->SetTitleFontSize(0.07);
00040    
00041     shared_ptr<TCanvas> canvas = shared_ptr<TCanvas>(new TCanvas(rname.c_str(), title.c_str(), 
00042                                  offset, offset, 900, 650));
00043     if ( DisplayManager::batchMode() ) canvas->SetBatch();
00044     return canvas;
00045 }
00046 
00047 void Displayer::divideCanvas(unsigned int n, TCanvas& canvas) {
00048     unsigned int x = (unsigned int)(ceil(sqrt((double)n)));
00049     unsigned int y = (unsigned int)(ceil((double)n/x));
00050     canvas.Divide(x, y, 0.0001, 0.0001);
00051 }
00052 
00053 void Displayer::displayHistogram(shared_ptr<TH1> hist, std::string option){
00054   if (DisplayManager::rootMode()){
00055     hist.reset(hist.get(),null_deleter());
00056   }
00057   displayHistogram(*hist, option);
00058 }
00059 
00060 void Displayer::displayHistogram(TH1& hist, std::string option){
00061   if (DisplayManager::rootMode()){
00062     shared_ptr<TDirectory> file=DisplayManager::getTDirectory();
00063     if (file) { 
00064       hist.SetDirectory(file.get());
00065       file->cd();
00066       // Make sure name starts with non-numberic character for root!
00067       std::string name ="h_";
00068       name += hist.GetName();
00069       hist.Write(name.c_str());
00070     }
00071   }else{
00072     hist.Draw(option.c_str());
00073   }
00074 }
00075 
00076 void Displayer::printDefectList(const DefectList& list, std::ostream& os) {
00077   const DefectList::DefectCollection& defects = list.getAllDefects();
00078     
00079   for (DefectList::DefectCollection::const_iterator i=defects.begin(); i!=defects.end(); ++i) {
00080     os << setfill(' ') << setw(20) << i->getPrototype().getName()
00081        <<  "\tStart channel: " << i->getModuleElement().getFirst()
00082        << "\t# of channels: " << i->getModuleElement().getNChannels()
00083        << "\t" << i->getPrototype().getDescription() << std::endl;
00084   }
00085   os << "[ total number of defects = " <<  defects.size() << " ]" << std::endl;
00086   os << std::endl;
00087 }
00088 
00089 }

Generated on Thu Feb 3 17:37:35 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5