00001 #include "IsGetCommand.h"
00002 #include "Archiver.h"
00003 #include "Sct/IS/IOManagerIS.h"
00004 #include "Sct/IoExceptions.h"
00005 #include <is/info.h>
00006 #include <is/infodictionary.h>
00007 #include <is/infoiterator.h>
00008 #include <is/inforeceiver.h>
00009 #include <is/infoT.h>
00010 #include "Sct/SctNames.h"
00011 #include "CalibrationController/IS/TestData.h"
00012 #include "CalibrationController/IS/SequenceData.h"
00013 #include "CalibrationController/Serialization/TestDataWrapper.h"
00014 #include "CalibrationController/Serialization/SequenceDataWrapper.h"
00015 #include <boost/timer.hpp>
00016
00017 namespace SctArchiving{
00018 IsGetCommand::IsGetCommand(boost::shared_ptr<Sct::IS::IONameIS> name)
00019 : GetCommand(name)
00020 {}
00021
00022 IsGetCommand::IsGetCommand() {}
00023
00024 IsGetCommand::~IsGetCommand(){}
00025
00026 void IsGetCommand::execute(){
00027 boost::timer t;
00028 if (m_name->getIOName().find("SctData")==std::string::npos) {
00029
00030 m_ob = retrieveISOB( m_name->getIOName() );
00031 }else{
00032
00033 m_ob = Sct::IS::IOManagerIS::instance().read(m_name->getIOName());
00034 }
00035
00036 Archiver::instance().addISTime(t.elapsed());
00037 }
00038
00039 boost::shared_ptr<ArchivingCommand> IsGetCommand::create()const{
00040 boost::shared_ptr<ArchivingCommand> cmd(new IsGetCommand() );
00041 return cmd;
00042 }
00043
00045 shared_ptr<Sct::Serializable> IsGetCommand::retrieveISOB(const std::string& name) const {
00046 ISInfoAny infoany;
00047 ISInfo::Status result = SctNames::getISDictionary().findValue(name.c_str(), infoany);
00048 if (result != ISInfo::Success) {
00049 std::ostringstream oss;
00050 oss << "Error reading from IS server. Couldn't get: "
00051 << name << " expected class TestData";
00052 throw Sct::IsException(result, oss.str(), __FILE__, __LINE__);
00053 }
00054 const std::string& classname=infoany.type().name();
00055
00056 if (classname == "TestData") {
00057 shared_ptr<TestData> td ( new TestData() );
00058 ISInfo::Status result = SctNames::getISDictionary().findValue(name.c_str(), *td);
00059 if (result != ISInfo::Success) {
00060 std::ostringstream oss;
00061 oss << "Error reading from IS server. Couldn't get: "
00062 << name << " expected class TestData";
00063 throw IsException(result, oss.str(), __FILE__, __LINE__);
00064 }
00065 return shared_ptr<Sct::Serializable> ( new ::SctCalibrationController::TestDataWrapper(td) );
00066 } else if (classname == "SequenceData"){
00067 shared_ptr<SequenceData> td ( new SequenceData() );
00068 ISInfo::Status result = SctNames::getISDictionary().findValue(name.c_str(), *td);
00069 if (result != ISInfo::Success) {
00070 std::ostringstream oss;
00071 oss << "Error reading from IS server. Couldn't get: "
00072 << name << " expected class SequenceData";
00073 throw Sct::IsException(result, oss.str(), __FILE__, __LINE__);
00074 }
00075 return shared_ptr<Sct::Serializable> ( new ::SctCalibrationController::SequenceDataWrapper(td) );
00076 } else {
00077 throw Sct::IoException(string("I don't know how to retrieve ") + name, __FILE__, __LINE__);
00078 }
00079 }
00080
00081 }