Crate.cpp

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

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