ScanPointsStreamer_v1.cpp

00001 #include "ScanPointsStreamer_v1.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 /* READ NOTES ON STREAMERS AND VERSIONS BEFORE EDITING THIS FILE! */
00013 unsigned ScanPointsStreamer_v1::s_version=1;
00014 
00015 ScanPointsStreamer_v1::ScanPointsStreamer_v1() throw() {}
00016 
00017 bool ScanPointsStreamer_v1::inMap = IOManager::addToMap("SctData::ScanPoints",  std::auto_ptr<Streamer>(new ScanPointsStreamer_v1()));
00018 
00019 
00020 shared_ptr<Streamable> ScanPointsStreamer_v1::read(IStream& in, const IOManager& manager) const throw(Sct::LogicError, Sct::IoError) {
00021     std::auto_ptr<Streamable> m (new ScanPoints());
00022     read(in, *m, manager);
00023     return shared_ptr<Streamable>(m);
00024 }
00025 
00026 void ScanPointsStreamer_v1::write(OStream& out, const Streamable& ob, const IOManager& manager) const throw(Sct::LogicError, Sct::IoError) {
00027     //Downcast should always work!
00028     const ScanPoints& points = dynamic_cast<const ScanPoints&>(ob);
00029 
00030     unsigned short npoints = points.getNPoints();
00031 
00032     //Copy into array
00033     float pts[npoints];
00034     unsigned int nEvents[npoints];
00035     unsigned int nErrorEvents[npoints];
00036     for (int i=0; i<npoints; ++i) {
00037         pts[i] = (float)points[i];
00038         nEvents[i] = points.getNEvents(i);
00039         nErrorEvents[i] = points.getNErrorEvents(i);
00040     }
00041 
00042     out << npoints;
00043     out.put(pts, npoints);
00044     out.put(nEvents, npoints);
00045     out.put(nErrorEvents, npoints);
00046 }
00047 
00048 void ScanPointsStreamer_v1::read(IStream& in, Streamable& ob, const IOManager& manager) const throw(Sct::LogicError, Sct::IoError) {
00049     //Downcast should always work!
00050     ScanPoints& points = dynamic_cast<ScanPoints&>(ob);
00051 
00052     unsigned short npoints;
00053     unsigned int size;
00054     float* pts;
00055     unsigned int* nEvents;
00056     unsigned int* nErrorEvents;
00057 
00058     in >> npoints;
00059     in.get(&pts, size);
00060     if (size != npoints) {  
00061         return;
00062     }
00063     in.get(&nEvents, size);
00064     if (size != npoints) {  
00065         return;
00066     }
00067     in.get(&nErrorEvents, size);
00068     if (size != npoints) {  
00069         return;
00070     }
00071 
00072     //Put it all into the ScanPoints class
00073     for (unsigned int i=0; i<npoints; ++i) {
00074         points.addPoint(pts[i], nEvents[i], nErrorEvents[i]);
00075     }
00076     delete[] pts;
00077     delete[] nEvents;
00078     delete[] nErrorEvents;
00079 }
00080 }
00081 }

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