DcsInterface.cpp

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

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