DefectListStreamer_v1.cpp

00001 #include "DefectListStreamer_v1.h"
00002 #include "../DefectList.h"
00003 #include "Sct/LogicErrors.h"
00004 #include "Sct/IoExceptions.h"
00005 
00006 using namespace Sct;
00007 
00008 namespace SctData {
00009 namespace IO {
00010 
00011 unsigned DefectListStreamer_v1::s_version=1;
00012 /* READ NOTES ON STREAMERS AND VERSIONS BEFORE EDITING THIS FILE! */
00013     
00014 DefectListStreamer_v1::DefectListStreamer_v1() throw() {}
00015 
00016 bool DefectListStreamer_v1::inMap = IOManager::addToMap("SctData::DefectList",  auto_ptr<Streamer>(new DefectListStreamer_v1()));
00017 
00018 void DefectListStreamer_v1::write(OStream& out, const Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00019     //cast should always be safe
00020     const DefectList& m = dynamic_cast<const DefectList&>(ob);
00021 
00022     const std::list<Defect>& mylist = m.getAllDefects();
00023     out << mylist.size();
00024     for (std::list<Defect>::const_iterator i = mylist.begin(); 
00025      i != mylist.end() ; ++i) {
00026         ModuleElement el=(*i).getModuleElement();
00027         out << helper.getRepresentation((*i).getPrototype()) << el.getFirst() << el.getNChannels();
00028     }
00029 }
00030 
00031 shared_ptr<Streamable> DefectListStreamer_v1::read(IStream& in, const IOManager& manager) const throw(LogicError, IoError) {
00032     shared_ptr<Streamable> m (new DefectList());
00033     read(in, *m, manager);
00034     return m;
00035 }
00036 
00037 void DefectListStreamer_v1::read(IStream& in, Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00038     DefectList& m = dynamic_cast<DefectList&>(ob);
00039 
00040     int nDefects = -1;
00041     int rep = 1;
00042     unsigned int startChannel = 0;
00043     unsigned int nChannels = 0;
00044 
00045     in >> nDefects;
00046     for (int i=0; i<nDefects; ++i) {
00047         in >> rep >> startChannel >> nChannels;
00048         m.addDefect(Defect(helper.getFromRep(rep), ModuleElement(startChannel, startChannel+nChannels-1)));
00049     }
00050 }
00051 }
00052 }

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