emcTracedFEMPlotter.C

Go to the documentation of this file.
00001 // $Id: emcTracedFEMPlotter.C,v 1.6 2004/06/23 10:31:01 aphecetc Exp $
00002 
00003 #include "emcDefines.h"
00004 #include "emcTracedFEMPlotter.h"
00005 #include "emcTracedFEM.h"
00006 #include "emcTracedValue.h"
00007 #include "TGraph.h"
00008 #include <vector>
00009 
00010 using namespace std;
00011 
00012 //_____________________________________________________________________________
00013 emcTracedFEMPlotter::emcTracedFEMPlotter(const emcTracedFEM& tf,
00014                                          time_t tics0)
00015   : fTracedFEM(tf.clone()), fTics0(tics0)
00016 {
00017   fGraphs.resize(fTracedFEM->size(), 0) ;
00018 }
00019 
00020 //_____________________________________________________________________________
00021 emcTracedFEMPlotter::emcTracedFEMPlotter(const emcTracedFEM& tf,
00022                                          int tics0)
00023   : fTracedFEM(tf.clone()), fTics0(tics0)
00024 {
00025   fGraphs.resize(fTracedFEM->size(), 0) ;
00026 }
00027 
00028 //_____________________________________________________________________________
00029 emcTracedFEMPlotter::emcTracedFEMPlotter(const emcTracedFEM& tf)
00030   : fTracedFEM(tf.clone()), fTics0(tf.GetXmin())
00031 {
00032   fGraphs.resize(fTracedFEM->size(), 0) ;
00033 }
00034 
00035 //_____________________________________________________________________________
00036 emcTracedFEMPlotter::~emcTracedFEMPlotter()
00037 {
00038   size_t i ;
00039   for ( i = 0 ; i < fGraphs.size() ; ++i )
00040     {
00041       delete fGraphs[i] ;
00042     }
00043 }
00044 
00045 //_____________________________________________________________________________
00046 TGraph*
00047 emcTracedFEMPlotter::CopyGraph(int ichannel)
00048 {
00049   if ( !ValidChannel(ichannel) )
00050     return 0 ;
00051 
00052   if ( !fGraphs[ichannel] )
00053     {
00054       MakeGraph(ichannel) ;
00055     }
00056 
00057   return static_cast<TGraph*>(fGraphs[ichannel]->Clone());
00058 }
00059 
00060 
00061 //_____________________________________________________________________________
00062 bool
00063 emcTracedFEMPlotter::Draw(int ichannel, const char* option)
00064 {
00065   if ( !ValidChannel(ichannel) )
00066     return false ;
00067 
00068   if ( !fGraphs[ichannel] )
00069     {
00070       MakeGraph(ichannel) ;
00071     }
00072 
00073   fGraphs[ichannel]->Draw(option) ;
00074 
00075   return true ;
00076 }
00077 
00078 //_____________________________________________________________________________
00079 void
00080 emcTracedFEMPlotter::MakeGraph(int ichannel)
00081 {
00082   vector<double> x;
00083   vector<double> y;
00084 
00085   fTracedFEM->FirstItem(ichannel);
00086 
00087   x.push_back(0);
00088 
00089   emcTracedValue* tv1 = fTracedFEM->NextItem();
00090 
00091   y.push_back(tv1->GetConstant());
00092 
00093   emcTracedValue* tv2 = 0;
00094 
00095   while ( ( tv2 = fTracedFEM->NextItem() ) )
00096     {
00097       x.push_back(tv1->GetX());
00098       y.push_back(tv1->GetConstant());
00099       x.push_back(tv2->GetX());
00100       y.push_back(tv1->getValue(tv2->GetX()));
00101       tv1 = tv2;
00102     }
00103 
00104   x.push_back(tv1->GetX());
00105   y.push_back(tv1->GetConstant());
00106 
00107   int xrelmax = static_cast<int>(fTracedFEM->GetXmax()-fTracedFEM->GetXmin());
00108 
00109   x.push_back(xrelmax);
00110   y.push_back(tv1->getValue(xrelmax));
00111 
00112 #ifdef DEBUG  
00113   for ( size_t i = 0; i < x.size(); ++i )
00114     {
00115       x[i] += fTics0;
00116       cout << "Point(" << i << ")=(" << x[i] << "," << y[i] << ")"
00117            << endl;
00118     }
00119 #endif
00120 
00121   fGraphs[ichannel] = new TGraph(x.size(),&x[0],&y[0]) ;
00122 }
00123 
00124 //_____________________________________________________________________________
00125 bool
00126 emcTracedFEMPlotter::ValidChannel(int ichannel) const
00127 {
00128   if ( ichannel < 0 || ichannel >= static_cast<int>(fGraphs.size()) )
00129     {
00130       return false ;
00131     }
00132   else
00133     {
00134       return true ;
00135     }
00136 }
00137 
00138 //_____________________________________________________________________________
00139 bool
00140 emcTracedFEMPlotter::Write(int ichannel, const char* name)
00141 {
00142   if ( !ValidChannel(ichannel) )
00143     return false ;
00144 
00145   if ( !fGraphs[ichannel] )
00146     {
00147       MakeGraph(ichannel) ;
00148     }
00149 
00150   fGraphs[ichannel]->Write(name) ;
00151 
00152   return true ;
00153 }