00001 #include "DcsInterface.h"
00002 #include "ConfigurationInterface.h"
00003 #include "SctData/DcsData.h"
00004 #include "Sct/SctNames.h"
00005 #include "Sct/IoExceptions.h"
00006 #include "Sct/LogicErrors.h"
00007 #include "sctConfIPC/configipc.h"
00008
00009 #include <is/isinfoany.h>
00010 #include <iostream>
00011 #include <memory>
00012
00013 namespace SctAnalysis{
00014 DcsInterface::DcsInterface() {}
00015
00016 DcsInterface::DcsInterface(boost::shared_ptr<ConfigurationInterface> config)
00017 : m_config(config), m_call_count(0), m_val_count(0), m_error_count(0)
00018 {
00019 }
00020
00021 DcsInterface::~DcsInterface(){
00022 }
00023
00024 const ConfigurationInterface& DcsInterface::getConfigurationInterface() const {
00025 if (!m_config.get()) throw Sct::LogicError("No ConfigurationInterface available", __FILE__, __LINE__);
00026 return *m_config;
00027 }
00028
00029 void DcsInterface::printStatus(std::ostringstream& os) const {
00030 std::cout << "DcsInterface::printStatus " << std::endl;
00031 os << "DcsInterface: Returned " << m_call_count << " DcsData objects"
00032 << " with total of " << m_val_count << " values." << std::endl;
00033 if (m_error_count) {
00034 os << "DcsInterface: Recorded " << m_error_count << " errors." << std::endl;
00035 }
00036 if (m_config.get()){
00037 try{
00038 m_config->print(os);
00039 }catch(std::exception& e){
00040 os << "DcsInterface has no configuration information" << std::endl;
00041 }
00042 }else{
00043 os << "DcsInterface has no configuration information" << std::endl;
00044 }
00045 }
00046
00047 boost::shared_ptr<SctData::DcsData> DcsInterface::getData(const std::string& modulename) const{
00048
00049 ++ m_call_count;
00050 using SctData::DcsData;
00051 shared_ptr<DcsData> dcsdata;
00052
00053 if (!m_config.get() || m_config->empty()){
00054 std::cerr << __FILE__ << ":" << __LINE__
00055 << " No DCS mapping information available ... "
00056 << std::endl;
00057 return dcsdata;
00058 }
00059
00060 string id = m_config->getDcsId(modulename);
00061 if (id=="") return dcsdata;
00062
00063 string regexp;
00064 regexp = ".*"; regexp += id; regexp += ".*";
00065
00066 ISInfoIterator it( Sct::SctNames::getPartition(), Sct::SctNames::getDcsServerName().c_str(), regexp.c_str() );
00067
00068 while ( it() ){
00069 ++ m_val_count;
00070 ISInfoAny isa;
00071 it.value(isa);
00072 string name=it.name();
00073
00074
00075
00076 if (isa.countAttributes()!=2) {
00077 std::cerr << "Error : DcsInterface:" << __LINE__
00078 << " Received IS information `"
00079 << name << "' with " << isa.countAttributes()
00080 << " attributes. (Expected 2)" << std::endl;
00081 ++ m_error_count;
00082 continue;
00083 }
00084 int dot1=name.rfind('.');
00085 if (dot1==string::npos || dot1<2){
00086
00087 }
00088 int dot2=name.rfind('.',dot1-1);
00089 if (dot2==string::npos){
00090 std::cerr << "Error : DcsInterface:" << __LINE__
00091 << " Received IS information `"
00092 << name << std::endl;
00093 ++m_error_count;
00094 continue;
00095 }
00096 std::string parname(name, dot2+1, dot1-dot2-1);
00097 if (parname==""){
00098 std::cerr << "Error: DcsInterface" << __LINE__
00099 << " Received IS information `"
00100 << name << "' parname = `" << parname
00101 << "' " << __FILE__ << ":" << __LINE__ << std::endl;
00102 ++m_error_count;
00103 continue;
00104 }
00105
00106 try {
00107 OWLTime value_time;
00108 isa>>value_time;
00109
00110 float val;
00111 switch(isa.getAttributeType()){
00112 case ISType::S8:
00113 case ISType::U8:
00114 case ISType::S16:
00115 {
00116 short temp;
00117 isa >> temp;
00118 val=temp;
00119 break;
00120 }
00121 case ISType::U16:
00122 {
00123 unsigned short temp;
00124 isa >> temp;
00125 val=temp;
00126 break;
00127 }
00128 case ISType::Float:
00129 {
00130 isa >> val;
00131 break;
00132 }
00133 case ISType::Double:
00134 {
00135 double temp;
00136 isa >> temp;
00137 val=temp;
00138 break;
00139 }
00140 default:
00141 {
00142 std::cerr << __FILE__ << ":" << __LINE__ << "Unexpected attribute type:"
00143 << isa.getAttributeType() << std::endl;
00144 continue;
00145 }
00146 }
00147
00148 if (!dcsdata.get()) dcsdata = shared_ptr<DcsData>( new DcsData() );
00149 dcsdata->setParameter(parname, val, value_time);
00150
00151 }catch(std::exception& e){
00152 std::cerr << e.what() << " " << __FILE__ << ":" << __LINE__ << std::endl;
00153 ++m_error_count;
00154 break;
00155 }
00156 }
00157
00158 if (!dcsdata.get()){
00159 std::cerr << "Failed to match pattern `" << regexp << "'" << " in server `"
00160 << Sct::SctNames::getDcsServerName() << "'" << std::endl;
00161 }
00162 return dcsdata;
00163 }
00164 }
00165