00001 #include "TH1DStreamer_v1.h"
00002 #include "TH1.h"
00003 #include "../RootStreamableAdapter.h"
00004
00005 using namespace Sct;
00006
00007 namespace SctData {
00008 namespace IO {
00009
00010
00011 unsigned TH1DStreamer_v1::s_version=1;
00012
00013 bool TH1DStreamer_v1::inMap = IOManager::addToMap(TH1D::Class()->GetName(), auto_ptr<Streamer>(new TH1DStreamer_v1()));
00014
00015 TH1DStreamer_v1::TH1DStreamer_v1() throw() {}
00016
00017 void TH1DStreamer_v1::write(OStream& out, const Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00018 const RootStreamableAdapter& ad = dynamic_cast<const RootStreamableAdapter&>(ob);
00019 TH1D* hist = (TH1D*)ad.getObject();
00020 out << hist->GetName();
00021 out << hist->GetTitle();
00022 out << hist->GetNbinsX();
00023 out.put(hist->GetArray(), hist->GetNbinsX()+2 );
00024 out.put(hist->GetXaxis()->GetXbins()->GetArray(), hist->GetNbinsX()+1 );
00025 }
00026
00027 shared_ptr<Streamable> TH1DStreamer_v1::read(IStream& in, const IOManager& manager) const throw(LogicError, IoError) {
00028 shared_ptr<Streamable> ad (new RootStreamableAdapter(*new TH1D()));
00029 read(in, *ad, manager);
00030 return ad;
00031 }
00032
00033 void TH1DStreamer_v1::read(IStream& in, Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00034 RootStreamableAdapter& ad = dynamic_cast<RootStreamableAdapter&>(ob);
00035 TH1D* hist = (TH1D*)ad.getObject();
00036 std::string name, title;
00037 unsigned int n =0;
00038 in >> name >> title;
00039 hist->SetName(name.c_str());
00040 hist->SetTitle(title.c_str());
00041 in >> n;
00042 double data[n+2], bins[n+1];
00043 in.get(data, n+2);
00044 in.get(bins, n+1);
00045
00046 hist->SetBinsLength(n+2);
00047 hist->GetXaxis()->Set(n,bins);
00048
00049 for (unsigned int i=0; i<n+2; ++i) {
00050 hist->SetBinContent(i,data[i]);
00051 }
00052 }
00053 }
00054 }