Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

ConfigurationInterface.cpp

00001 #include "ConfigurationInterface.h"
00002 #include "Sct/SctNames.h"
00003 #include "Sct/IoExceptions.h"
00004 #include "Sct/StdExceptionWrapper.h"
00005 #include "Sct/ConfigurationException.h"
00006 #include <iomanip>
00007 
00008 using namespace SctConfiguration;
00009 
00010 namespace SctAnalysis{
00011 
00012 ConfigurationInterface::ConfigurationInterface(boost::shared_ptr<Configuration> c) : m_config(c)
00013 {
00014   m_infoReceiver = boost::shared_ptr<ISInfoReceiver>(new ISInfoReceiver(Sct::SctNames::getPartition()));
00015   m_infoReceiver->subscribe("ConfigurationServer", "SystemStructureChangeCount", updateCallback, this);
00016   m_infoReceiver->subscribe("ConfigurationServer", "ModuleMappingChangeCount", updateCallback, this);
00017 }
00018 
00019 ConfigurationInterface::~ConfigurationInterface(){
00020 }
00021 
00022 std::string ConfigurationInterface::getDcsId(const std::string& modulename) const {
00023   std::cout << "ConfigurationInterface getDcsId " << modulename << std::endl;
00024   std::map<std::string, std::string>::const_iterator it = m_map.find(modulename );
00025   if (it==m_map.end()) { 
00026     //std::cout << "(none)" << std::endl;
00027     return "";
00028   } else {
00029     //std::cout << "`" << (*it).second << "'" << std::endl;
00030     return (*it).second;
00031   }
00032 }
00033 
00034 bool ConfigurationInterface::empty() const{
00035   return m_map.empty();
00036 }
00037 
00038 void ConfigurationInterface::update(){
00039   boost::recursive_mutex::scoped_lock lock(m_access);
00040   m_map.clear();
00041   std::list<std::string> modules;
00042   try{
00043     modules = m_config->listAllModules();
00044   }catch(Sct::Throwable& e){
00045     Sct::ConfigurationException("Error getting power mappings", e, __FILE__, __LINE__).sendToMrs(MRS_INFORMATION);
00046   }catch(SctConfiguration::ConfigurationException& e){
00047     std::ostringstream oss;
00048     oss << "Error getting power mappings " << e.what();
00049     Sct::ConfigurationException(oss.str(), __FILE__, __LINE__).sendToMrs(MRS_INFORMATION);
00050   }catch(std::exception& e){
00051     Sct::StdExceptionWrapper err(e);
00052     Sct::ConfigurationException("Error getting power mappings", err, __FILE__, __LINE__).sendToMrs(MRS_INFORMATION);
00053   }
00054   
00055   unsigned nprob=0;
00056   for (std::list<std::string>::const_iterator i=modules.begin(); i!= modules.end(); ++i){
00057     unsigned crate, channel, partition, mur, mod;
00058     try{
00059       m_config->translateFromSN(*i, mur, mod);
00060       m_config->translateToPowerSupply(mur, mod, partition, crate, channel);
00061       m_map[*i]=encode(partition, crate, channel);
00062       std::cout << "Mapped module " << *i << " to " << encode(partition, crate, channel) << std::endl;
00063     }catch(SctConfiguration::ConfigurationException& e){
00064       if (nprob<10) std::cerr << e.what() << std::endl;
00065       if (nprob==0) std::cerr << "[No more error messages will be printed for this update]" << std::endl;
00066       nprob++;
00067     }
00068   }
00069   print(std::cout);
00070 }
00071 
00072 std::string ConfigurationInterface::encode(unsigned partition, unsigned crate, unsigned channel){
00073   std::ostringstream oss;
00074   oss << "Crate" << std::setw(2) << std::setfill('0') << crate 
00075       << ".Channel" << std::setw(2) << std::setfill('0') << channel;
00076   return oss.str();
00077 }
00078 
00079 void ConfigurationInterface::print(std::ostream& os) const{
00080   boost::recursive_mutex::scoped_lock lock(m_access);
00081   std::cout << "ConfigurationInterface::print" << std::endl;
00082   os << "Configuration Interface has power maps for " 
00083      << m_map.size() << " modules" << std::endl;
00084 }
00085 
00086 void ConfigurationInterface::updateCallback(ISCallbackInfo* isc){
00087   if (isc->reason() == ISInfoCreated || isc->reason() == ISInfoUpdated ){
00088     ConfigurationInterface* rock=static_cast<ConfigurationInterface*>(isc->parameter());
00089     rock->update();
00090   }
00091 }
00092 
00093 }

Generated on Fri Jan 14 12:47:02 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5