00001 #include "../OpeResult.h"
00002 #include "../RootStreamableAdapter.h"
00003 #include "OpeStreamer_v1.h"
00004 #include "../OpeResultIOHelper.h"
00005 #include "Sct/SctParameters.h"
00006 #include "Sct/LogicErrors.h"
00007
00008 #include <TGraph.h>
00009 #include <TH1.h>
00010
00011 using namespace Sct;
00012
00013 namespace SctData {
00014 namespace IO {
00015
00016
00017 unsigned OpeStreamer_v1::s_version=1;
00018
00019 OpeStreamer_v1::OpeStreamer_v1() throw() {}
00020
00021 bool OpeStreamer_v1::inMap = IOManager::addToMap("SctData::OpeResult", auto_ptr<Streamer>(new OpeStreamer_v1()));
00022
00023 shared_ptr<Streamable> OpeStreamer_v1::read(IStream& in, const IOManager& manager) const throw(LogicError, IoError) {
00024 OpeResultIOHelper helper;
00025 auto_ptr<SctData::OpeResult> ope = helper.create();
00026 shared_ptr<Sct::Streamable> ad(ope);
00027 read(in, *ad, manager);
00028 return ad;
00029 }
00030
00031 void OpeStreamer_v1::write(OStream& out, const Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00032 const OpeResult& myope = dynamic_cast<const OpeResult&>(ob);
00033 out << myope.getUniqueID();
00034 for (unsigned int ichip=0; ichip<nChipModule; ichip++) {
00035 writeChipResult(out, myope.getChipResult(ichip), manager);
00036 }
00037 }
00038
00039 void OpeStreamer_v1::read(IStream& in, Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00040 OpeResult& myope = dynamic_cast<OpeResult&>(ob);
00041 std::string uniqueid;
00042 in >> uniqueid;
00043 OpeResultIOHelper help;
00044 help.set(myope);
00045 help.setUniqueID(UniqueID(uniqueid));
00046 for (unsigned int ichip=0; ichip<nChipModule; ichip++) {
00047 readChipResult(in, myope.getChipResult(ichip), manager);
00048 }
00049 }
00050
00051 void OpeStreamer_v1::writeChipResult(OStream& out, const ChipOpeResult& c, const IOManager& manager) const throw (LogicError, IoError) {
00052 out << (bool) c.hist.get();
00053 if (c.hist.get()){
00054 manager.writeImpl(out, RootStreamableAdapter( *c.hist ), true);
00055 out << c.badmax << c.threshold;
00056 }
00057 }
00058
00059 void OpeStreamer_v1::readChipResult(IStream& in, ChipOpeResult& c, const IOManager& manager) const throw(LogicError, IoError) {
00060 bool available;
00061 in >> available;
00062 if (available){
00063 shared_ptr<Streamable> ob = manager.readImpl(in);
00064 shared_ptr<RootStreamableAdapter> ad = boost::dynamic_pointer_cast<RootStreamableAdapter>(ob);
00065 c.hist = shared_ptr<TH1> ( dynamic_cast<TH1*>(ad->getObject()));
00066 in >> c.badmax >> c.threshold;
00067 }
00068 }
00069
00070 }
00071 }