TF1Streamer_v1.cpp

00001 #include "Sct/VersionNotSupportedException.h"
00002 #include "Sct/UnsupportedOperationError.h"
00003 #include "TF1Streamer_v1.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 /* READ NOTES ON STREAMERS AND VERSIONS BEFORE EDITING THIS FILE! */
00017 unsigned TF1Streamer_v1::s_version=1;
00018 
00019     
00020 bool TF1Streamer_v1::inMap = IOManager::addToMap(TF1::Class()->GetName(),  auto_ptr<Streamer>(new TF1Streamer_v1()));
00021 
00022 TF1Streamer_v1::TF1Streamer_v1() throw() {}
00023 
00024 void TF1Streamer_v1::write(OStream& out, const Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00025     const RootStreamableAdapter& f1is = dynamic_cast<const RootStreamableAdapter&>(ob);
00026     TF1& f = *(TF1*)f1is.getObject();
00027 
00028     out << f.GetNpar() << f.GetChisquare() << f.GetNDF();
00029     for (int i=0; i<f.GetNpar(); ++i) {
00030         out << f.GetParameter(i) << f.GetParError(i) << f.GetParName(i);
00031     }
00032     double xmin, xmax;
00033     f.GetRange(xmin, xmax);
00034     out << xmin << xmax;
00035 }
00036 
00037 void TF1Streamer_v1::read(IStream& in, Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00038     RootStreamableAdapter& f1is = dynamic_cast<RootStreamableAdapter&>(ob);
00039     TF1& f = *(TF1*)f1is.getObject();
00040 
00041     double chisq;
00042     int npar, ndf;
00043     in >> npar >> chisq >> ndf;
00044     //Ignore number of parameters - defined by formula! @todo check it and throw?
00045     f.SetNDF(ndf);
00046     f.SetChisquare(chisq);
00047 
00048     for (int i=0; i<f.GetNpar(); ++i) {
00049         double parameter, error;
00050         string parname;
00051         in >> parameter >> error >> parname;
00052         f.SetParameter(i, parameter);
00053         f.SetParError(i, error) ;
00054         f.SetParName(i, parname.c_str());
00055     }
00056     double xmin, xmax;
00057     in >> xmin >> xmax;
00058     f.SetRange(xmin, xmax);
00059 }
00060 
00061 //Can't stream like this as we have no way of creating the right object
00062 shared_ptr<Streamable> TF1Streamer_v1::read(IStream& in, const IOManager& manager) const throw(LogicError, IoError) {
00063     throw UnsupportedOperationError("TF1IS::refreshGuts has no way of creating creating the right TF1", __FILE__, __LINE__);
00064 }
00065 
00066 }
00067 }

Generated on Mon Feb 6 14:01:35 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6