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