PowerCard.cpp

00001 #include <config/ConfigObject.h>
00002 #include <config/Change.h>
00003 #include "PowerCard.h"
00004 
00005 // include files for classes used in relationships
00006 
00007 #include "PowerParam.h"
00008 
00009 
00010 namespace SCTDAL {
00011   const std::string PowerCard::s_class_name("PowerCard");
00012 
00013     // the constructor
00014 
00015   PowerCard::PowerCard(::Configuration& db, ::ConfigObject& o) :
00016     DalObject(db, o)  {
00017   }
00018 
00019 
00020   void PowerCard::print(unsigned int indent, bool print_header, std::ostream& s) const
00021   {
00022     std::string str(indent, ' ');
00023 
00024     if(print_header) {
00025       s
00026         << str << "SCTDAL PowerCard object:\n"
00027         << str << "  id: \'" << UID() << "\', class name: \'" << class_name() << "\'\n";
00028     }
00029 
00030 
00031       // print direct attributes
00032 
00033     s << str << "  id: " << id() << std::endl;
00034     s << str << "  type: " << type() << std::endl;
00035 
00036 
00037       // print direct relationships
00038 
00039     if( m_params.empty() ) {
00040       s << str << "  params value is empty\n";
00041     }
00042     else {
00043       s << str << "  " << m_params.size() << " object(s) in params:\n";
00044       for(std::vector<const SCTDAL::PowerParam*>::const_iterator i = m_params.begin(); i != m_params.end(); ++i) {
00045         (*i)->print(indent + 4, true, s);
00046       }
00047       }
00048   }
00049 
00050 
00051   std::ostream&
00052   operator<<(std::ostream& s, const PowerCard * obj)
00053   {
00054     s << '\'';
00055 
00056     if(obj == 0) {
00057       s << "(null)";
00058     }
00059     else {
00060       obj->config_object().print_ptr(s);
00061     }
00062     s << '\'';
00063 
00064     return s;
00065   }
00066 
00067 
00068   std::ostream&
00069   operator<<(std::ostream& s, const PowerCard & obj)
00070   {
00071     if(&obj == 0) {
00072       s << "(null)";
00073     }
00074     else {
00075       obj.print(0, true, s);
00076     }
00077 
00078     return s;
00079   }
00080 
00081 
00082   void PowerCard::update(::Configuration& conf, const ::ConfigurationChange * change)
00083   {
00084     conf.update<PowerCard>(change->get_modified_objs(), change->get_removed_objs());
00085   }
00086 
00087 
00088   void PowerCard::reset(::Configuration& conf, bool re_initialise_obj)
00089   {
00090     conf.reset_objects<PowerCard>(re_initialise_obj);
00091   }
00092 
00093 
00094   void PowerCard::init(bool init_children)
00095   {
00096     p_was_read = true;
00097     increment_read();
00098     static const char * env = ::getenv("TDAQ_REPORT_DAL_OBJECT_READ");
00099     if(env) { std::cout << "DEBUG: read object " << this << std::endl; }
00100 
00101     if(!p_obj.get("id",m_id)) {
00102       std::cerr << "ERROR: could not find attribute 'id'\n";
00103     }
00104     else {
00105       p_db.convert(m_id, p_obj, "id");
00106     }
00107 
00108     if(!p_obj.get("type",m_type)) {
00109       std::cerr << "ERROR: could not find attribute 'type'\n";
00110     }
00111     else {
00112       p_db.convert(m_type, p_obj, "type");
00113     }
00114     p_db.ref<SCTDAL::PowerParam>(p_obj, "params", m_params, init_children);
00115 
00116     p_obj.clear(); // clear resources used by implementation
00117   }
00118 
00119   PowerCard::~PowerCard()
00120   {
00121   }
00122 
00123   bool PowerCard::set_params(const std::vector<const SCTDAL::PowerParam*>& a) {
00124     clear();
00125     std::vector<const ConfigObject*> v;
00126     for(std::vector<const SCTDAL::PowerParam*>::const_iterator i = a.begin(); i != a.end(); ++i) {
00127       v.push_back(&((*i)->config_object()));
00128     }
00129     return p_obj.set_objs("params", v);
00130   }
00131 
00132 }

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