00001 #include "ScanPointsStreamer.h"
00002 #include "../ScanPoints.h"
00003
00004 #include "Sct/Streamable.h"
00005 #include "Sct/IOManager.h"
00006
00007 using namespace SctData;
00008
00009 namespace SctData {
00010 namespace IO {
00011
00012 ScanPointsStreamer::ScanPointsStreamer() throw() {}
00013
00014 bool ScanPointsStreamer::inMap = IOManager::addToMap("SctData::ScanPoints", std::auto_ptr<Streamer>(new ScanPointsStreamer()));
00015
00016
00017 shared_ptr<Streamable> ScanPointsStreamer::read(IStream& in, const IOManager& manager) const throw(Sct::LogicError, Sct::IoError) {
00018 std::auto_ptr<Streamable> m (new ScanPoints());
00019 read(in, *m, manager);
00020 return shared_ptr<Streamable>(m);
00021 }
00022
00023 void ScanPointsStreamer::write(OStream& out, const Streamable& ob, const IOManager& manager) const throw(Sct::LogicError, Sct::IoError) {
00024
00025 const ScanPoints& points = dynamic_cast<const ScanPoints&>(ob);
00026
00027 unsigned short npoints = points.getNPoints();
00028
00029
00030 float pts[npoints];
00031 unsigned int nEvents[npoints];
00032 unsigned int nErrorEvents[npoints];
00033 for (int i=0; i<npoints; ++i) {
00034 pts[i] = (float)points[i];
00035 nEvents[i] = points.getNEvents(i);
00036 nErrorEvents[i] = points.getNErrorEvents(i);
00037 }
00038
00039 out << npoints;
00040 out.put(pts, npoints);
00041 out.put(nEvents, npoints);
00042 out.put(nErrorEvents, npoints);
00043 }
00044
00045 void ScanPointsStreamer::read(IStream& in, Streamable& ob, const IOManager& manager) const throw(Sct::LogicError, Sct::IoError) {
00046
00047 ScanPoints& points = dynamic_cast<ScanPoints&>(ob);
00048
00049 unsigned short npoints;
00050 unsigned int size;
00051 float* pts;
00052 unsigned int* nEvents;
00053 unsigned int* nErrorEvents;
00054
00055 in >> npoints;
00056 in.get(&pts, size);
00057 if (size != npoints) {
00058 return;
00059 }
00060 in.get(&nEvents, size);
00061 if (size != npoints) {
00062 return;
00063 }
00064 in.get(&nErrorEvents, size);
00065 if (size != npoints) {
00066 return;
00067 }
00068
00069
00070 for (unsigned int i=0; i<npoints; ++i) {
00071 points.addPoint(pts[i], nEvents[i], nErrorEvents[i]);
00072 }
00073 }
00074 }
00075 }