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