DefectListStreamer_v2.cpp

00001 #include "DefectListStreamer_v2.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_v2::s_version=2;
00012 /* READ NOTES ON STREAMERS AND VERSIONS BEFORE EDITING THIS FILE! */
00013     
00014 DefectListStreamer_v2::DefectListStreamer_v2() throw() {}
00015 
00016 bool DefectListStreamer_v2::inMap = IOManager::addToMap("SctData::DefectList",  auto_ptr<Streamer>(new DefectListStreamer_v2()));
00017 
00018 void DefectListStreamer_v2::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     // does parameter exist?
00029     out << (bool)(*i).getParameter();
00030     // what is it?
00031     if ((*i).getParameter()) out << *(*i).getParameter();
00032     }
00033 }
00034 
00035 shared_ptr<Streamable> DefectListStreamer_v2::read(IStream& in, const IOManager& manager) const throw(LogicError, IoError) {
00036     shared_ptr<Streamable> m (new DefectList());
00037     read(in, *m, manager);
00038     return m;
00039 }
00040 
00041 void DefectListStreamer_v2::read(IStream& in, Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00042     DefectList& m = dynamic_cast<DefectList&>(ob);
00043 
00044     int nDefects = -1;
00045     int rep = 1;
00046     unsigned int startChannel = 0;
00047     unsigned int nChannels = 0;
00048 
00049     in >> nDefects;
00050     for (int i=0; i<nDefects; ++i) {
00051         in >> rep >> startChannel >> nChannels;
00052     bool par_exists;
00053     in >> par_exists;
00054     boost::optional<double> par;
00055     if (par_exists) {
00056         double temporaryDouble;
00057         in >> temporaryDouble;
00058         par = boost::optional<double>(temporaryDouble);
00059     };
00060     
00061         m.addDefect(Defect(helper.getFromRep(rep), ModuleElement(startChannel, startChannel+nChannels-1),par));
00062     }
00063 }
00064 }
00065 }

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