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