00001 #include "TGraphStreamer_v1.h"
00002 #include "TGraph.h"
00003 #include "../RootStreamableAdapter.h"
00004
00005 using std::auto_ptr;
00006
00007 using namespace Sct;
00008
00009 namespace SctData {
00010 namespace IO {
00011
00012
00013 unsigned TGraphStreamer_v1::s_version=1;
00014
00015 bool TGraphStreamer_v1::inMap = IOManager::addToMap(TGraph::Class()->GetName(), auto_ptr<Streamer>(new TGraphStreamer_v1()));
00016
00017 TGraphStreamer_v1::TGraphStreamer_v1() throw() {}
00018
00019 void TGraphStreamer_v1::write(OStream& out, const Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00020 const RootStreamableAdapter& ad = dynamic_cast<const RootStreamableAdapter&>(ob);
00021 TGraph* graph = (TGraph*)ad.getObject();
00022 out << static_cast<unsigned int> ( graph->GetN() );
00023 out.put(graph->GetX(), graph->GetN() );
00024 out.put(graph->GetY(), graph->GetN() );
00025 }
00026
00027 shared_ptr<Streamable> TGraphStreamer_v1::read(IStream& in, const IOManager& manager) const throw(LogicError, IoError) {
00028 shared_ptr<Streamable> ad (new RootStreamableAdapter(*new TGraph()));
00029 read(in, *ad, manager);
00030 return ad;
00031 }
00032
00033 void TGraphStreamer_v1::read(IStream& in, Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00034 RootStreamableAdapter& ad = dynamic_cast<RootStreamableAdapter&>(ob);
00035 TGraph* graph = (TGraph*)ad.getObject();
00036 unsigned int n = 0;
00037 in >> n;
00038 double x[n], y[n];
00039 in.get(x, n);
00040 in.get(y, n);
00041 if (n>0) graph->Set(n);
00042 for (unsigned int i=0; i<n; ++i)
00043 graph->SetPoint(i, x[i], y[i]);
00044 }
00045 }
00046 }