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