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