PowerCrate.cpp

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

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