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