IsPutCommand.cpp

00001 #include "IsPutCommand.h"
00002 #include "Archiver.h"
00003 #include "Sct/IS/IOManagerIS.h"
00004 #include "Sct/LogicErrors.h"
00005 #include "Sct/IoExceptions.h"
00006 #include "Sct/ISProxy/IOManagerISProxy.h"
00007 #include "Sct/ISUtilities.h"
00008 #include "CalibrationController/Serialization/IsInfoWrapper.h"
00009 // Summary stuff:
00010 #include "SummaryWriter/TestSummaryIS.h"
00011 #include "SummaryWriter/SummaryManager.h"
00012 #include "SctData/TestResult.h"
00013 #include <is/info.h>
00014 #include <is/infodictionary.h>
00015 #include <is/infoiterator.h>
00016 #include <is/inforeceiver.h>
00017 #include <is/infoT.h>
00018 #include <boost/timer.hpp>
00019 #include <sstream>
00020 
00021 namespace SctArchiving{
00022   IsPutCommand::IsPutCommand(boost::shared_ptr<Sct::Serializable> ob)
00023     : PutCommand(ob)  {
00024   }
00025 
00026   IsPutCommand::IsPutCommand() {}
00027 
00028   IsPutCommand::~IsPutCommand() {}
00029 
00030   void IsPutCommand::setServer(const string& name){
00031     m_server=name;
00032   }
00033 
00034   boost::shared_ptr<ArchivingCommand> IsPutCommand::create()const{
00035     boost::shared_ptr<ArchivingCommand> cmd(new IsPutCommand() );
00036     return cmd;
00037   }
00038   
00039   void IsPutCommand::execute(){
00040     using namespace SctCalibrationController;
00041     boost::timer t;
00042 
00043     if (!m_ob.get()) throw Sct::IllegalStateError("Null pointer", __FILE__, __LINE__);
00044 
00045     if (m_server=="") m_server = Archiver::instance().getRetrieveIsServer();
00046 
00047     if (m_ob->getClassName()=="TestData" || m_ob->getClassName()=="SequenceData") {
00048       shared_ptr<IsInfoWrapper> wrapper = boost::dynamic_pointer_cast<IsInfoWrapper>(m_ob);
00049       if (!wrapper.get()) throw Sct::IllegalStateError(m_ob->getClassName() + 
00050                                " couldnt be cast as a ISSerializableWrapperI", __FILE__, __LINE__);
00051       wrapper->publishWrappedObject(m_server);
00052     }else{
00053       Sct::IS::IOParamsIS params( m_server );
00054       Sct::ISProxy::IOManagerISProxy::instance().write(*m_ob, &params);      
00055     }
00056 
00057      // if TestResult publish summary too.
00058     if (m_ob->getClassName().find("TestResult")!=std::string::npos){
00059       try{
00060     shared_ptr<SctData::TestResult> r = boost::dynamic_pointer_cast<SctData::TestResult>(m_ob);
00061     if (!r.get()) throw Sct::IllegalStateError(string("Bad cast of TestResult ") + (string)m_ob->getUniqueID(), __FILE__, __LINE__);
00062     TestSummaryIS t;
00063     t.dataString = SctData::TestSummary::SummaryManager::instance().write(*r);
00064     std::string name = m_server;
00065     name += ".";
00066     name += "Summary.";
00067     name += (string) m_ob->getUniqueID();
00068     
00069     Sct::ISUtilities::addOrUpdateOrThrow(name, t, __FILE__, __LINE__, MRS_ERROR);
00070       }catch(Sct::IsException& e){
00071     if (e.getStatus()==ISInfo::AlreadyExist){
00072       std::cerr << e.what() << std::endl;
00073     }else{
00074       throw;
00075     }
00076       }catch(Sct::Throwable& e){
00077     e.sendToMrs(MRS_DIAGNOSTIC);
00078       }
00079       
00080       Archiver::instance().addISTime(t.elapsed());
00081     }
00082   }
00083 }

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