NPtGainTestResultStreamer_v2.cpp

00001 #include "../NPtGainTestResult.h"
00002 #include "../RootStreamableAdapter.h"
00003 #include "../ResponseCurve.h"
00004 #include "NPtGainTestResultStreamer_v2.h"
00005 
00006 #include <TF1.h>
00007 #include <vector>
00008 
00009 using namespace Sct;
00010 
00011 namespace SctData {
00012 namespace IO {
00013 
00014 /* READ NOTES ON STREAMERS AND VERSIONS BEFORE EDITING THIS FILE! */
00015 unsigned NPtGainTestResultStreamer_v2::s_version=2;
00016 
00017 
00018 NPtGainTestResultStreamer_v2::NPtGainTestResultStreamer_v2() throw() {}
00019 
00020 bool NPtGainTestResultStreamer_v2::inMap = IOManager::addToMap("SctData::NPtGainTestResult",  auto_ptr<Streamer>(new NPtGainTestResultStreamer_v2()));
00021 
00022 
00023 shared_ptr<Streamable> NPtGainTestResultStreamer_v2::read(IStream& in, const IOManager& manager) const throw(LogicError, IoError) {
00024     shared_ptr<Streamable> ad (new NPtGainTestResult());
00025     read(in, *ad, manager);
00026     return ad;
00027 }
00028 
00029 void NPtGainTestResultStreamer_v2::write(OStream& out, const Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00030     //cout << "NPtGainTestResultIS::publishGuts" << endl;
00031     //Let superclass do its work
00032     manager.writeImpl(out, ob, "SctData::TestResult");
00033 
00034     const NPtGainTestResult& mytest = dynamic_cast <const NPtGainTestResult&>(ob);
00035 
00036     out << mytest.getNChipData();
00037     for (unsigned int i = 0; i < mytest.getNChipData(); ++i) {
00038         writeData(out, mytest.getChipData(i), manager);
00039     }
00040 
00041     out << mytest.getNChannelData();
00042     for (unsigned int i = 0; i < mytest.getNChannelData(); ++i) {
00043         writeData(out, mytest.getChannelData(i), manager);
00044     }
00045 
00046     putSlope(mytest.noiseSlope, out);
00047     putSlope(mytest.gainSlope, out);
00048     putSlope(mytest.offsetSlope, out);
00049 }
00050 
00051 void NPtGainTestResultStreamer_v2::writeData(OStream& out, const NPtGainTestResultData& ob, const IOManager& manager) const throw(LogicError, IoError) {
00052     manager.writeImpl(out, *ob.rc, false);
00053     manager.writeImpl(out, RootStreamableAdapter(*ob.graph), false);
00054     out << ob.gain << ob.noise << ob.offset;
00055 }
00056 
00057 void NPtGainTestResultStreamer_v2::read(IStream& in, Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00058     manager.readImpl(in, ob, "SctData::TestResult");
00059 
00060     NPtGainTestResult& mytest = dynamic_cast < NPtGainTestResult & >(ob);
00061 
00062     unsigned int n = 0;
00063     in >> n;
00064     mytest.setChipDataSize(n);
00065 
00066     for (unsigned int i = 0; i<n; ++i) {
00067         readData(in, mytest, mytest.getChipData(i), manager);
00068     }
00069 
00070     in >> n;
00071     mytest.setChannelDataSize(n);
00072     for (unsigned int i = 0; i<n; ++i) {
00073         readData(in, mytest, mytest.getChannelData(i), manager);
00074     }
00075     
00076     getSlope(mytest.noiseSlope, in);
00077     getSlope(mytest.gainSlope, in);
00078     getSlope(mytest.offsetSlope, in);
00079 }
00080 
00081 void NPtGainTestResultStreamer_v2::getSlope(Sct::RangedVector<float>& d, Sct::IStream& is) const{
00082   size_t size=0;
00083   float* data=0;
00084   is.get(&data, size);
00085   d.resize(size);
00086   for (unsigned i=0; i<size; ++i){
00087     d[i]=data[i];
00088   }
00089   delete[] data;
00090 }
00091 
00092 void NPtGainTestResultStreamer_v2::putSlope(const Sct::RangedVector<float>& d, Sct::OStream& os) const{
00093     float data[d.size()];
00094     for (unsigned i=0; i<d.size(); ++i){
00095       data[i]=d[i];
00096     }
00097     os.put(data, d.size());
00098 }
00099 
00100 void NPtGainTestResultStreamer_v2::readData(IStream& in, NPtGainTestResult& mytest, NPtGainTestResultData& ob, const IOManager& manager) const throw(LogicError, IoError) {
00101     //Response Curve
00102     shared_ptr<Streamable> str = manager.readImpl(in, "SctData::ResponseCurve");
00103     shared_ptr<ResponseCurve> rc = boost::dynamic_pointer_cast<ResponseCurve>(str) ;
00104     ob.rc = rc;
00105 
00106     //TGraph
00107     ob.graph = shared_ptr<TGraph>(new TGraph());
00108     RootStreamableAdapter ad2(*ob.graph);
00109     manager.readImpl(in, ad2, false);
00110 
00111     //Rest
00112     in >> ob.gain >> ob.noise >> ob.offset;
00113 }
00114 
00115 }
00116 } 
00117 

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