00001 #include "Sct/VersionNotSupportedException.h"
00002 #include "Sct/UnsupportedOperationError.h"
00003 #include "TF1Streamer.h"
00004 #include "../RootStreamableAdapter.h"
00005
00006 #include <TF1.h>
00007 #include <TClass.h>
00008 #include <string>
00009
00010 using namespace Sct;
00011 using namespace std;
00012
00013 namespace SctData {
00014 namespace IO {
00015
00016 bool TF1Streamer::inMap = IOManager::addToMap(TF1::Class()->GetName(), auto_ptr<Streamer>(new TF1Streamer()));
00017
00018 TF1Streamer::TF1Streamer() throw() {}
00019
00020 void TF1Streamer::write(OStream& out, const Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00021 const RootStreamableAdapter& f1is = dynamic_cast<const RootStreamableAdapter&>(ob);
00022 TF1& f = *(TF1*)f1is.getObject();
00023
00024 out << 1;
00025 out << f.GetNpar() << f.GetChisquare() << f.GetNDF();
00026 for (int i=0; i<f.GetNpar(); ++i) {
00027 out << f.GetParameter(i) << f.GetParError(i) << f.GetParName(i);
00028 }
00029 double xmin, xmax;
00030 f.GetRange(xmin, xmax);
00031 out << xmin << xmax;
00032 }
00033
00034 void TF1Streamer::read(IStream& in, Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00035 RootStreamableAdapter& f1is = dynamic_cast<RootStreamableAdapter&>(ob);
00036 TF1& f = *(TF1*)f1is.getObject();
00037
00038 int version;
00039 in >> version;
00040 if (version!=1) {
00041 throw VersionNotSupportedException("Serious version error TF1Streamer", __FILE__, __LINE__);
00042 }
00043
00044 double chisq;
00045 int npar, ndf;
00046 in >> npar >> chisq >> ndf;
00047
00048 f.SetNDF(ndf);
00049 f.SetChisquare(chisq);
00050
00051 for (int i=0; i<f.GetNpar(); ++i) {
00052 double parameter, error;
00053 string parname;
00054 in >> parameter >> error >> parname;
00055 f.SetParameter(i, parameter);
00056 f.SetParError(i, error) ;
00057 f.SetParName(i, parname.c_str());
00058 }
00059 double xmin, xmax;
00060 in >> xmin >> xmax;
00061 f.SetRange(xmin, xmax);
00062 }
00063
00064
00065 shared_ptr<Streamable> TF1Streamer::read(IStream& in, const IOManager& manager) const throw(LogicError, IoError) {
00066 throw UnsupportedOperationError("TF1IS::refreshGuts has no way of creating creating the right TF1", __FILE__, __LINE__);
00067 }
00068
00069 }
00070 }