This page is deprecated in favour of documentation provided at http://xdaq.web.cern.ch
The two example shows how to extend application to support the XMAS push and pull model for monitoring
Pull model
The following example shows how to create a simple
pull mode monitorable infospace that will contain an xdata::UnsignedLong data item myCounter_, which is to be monitored. myCounter_ is updated with the actual value from a hardware card whenever it is retrieved by means of the callback xdata::actionPerformed() method.
class MyApplication: public xdaq::Application, xdata::ActionListener
{
MyApplication()
{
// Create/Retrieve an infospace
toolbox::net::URN monitorable = this->createQualifiedInfoSpace("myInfospace");
xdata::InfoSpace * is = xdata::getInfoSpaceFactory()->get(monitorable.toString());
// Publish myCounter in monitorable infospace
is->fireItemAvailable("myCounter", &myCounter);
// attach listener to myCounter_ to detect retrieval event
is->addGroupRetrieveListener (this);
}
void actionPerformed (xdata::Event& e)
{
if ( e.type() == "urn:xdata-event:ItemGroupRetrieveEvent" )
{
xdata::ItemGroupRetrieveEvent & event = dynamic_cast<xdata::ItemGroupRetrieveEvent&>(e);
if ( event.infoSpace()->name().find("urn:myInfoSpace") = std::string::npos )
{
myCounter_ = ... get actual value from card ...
}
}
// A counter to be monitored
xdata::UnsignedLong myCounter_;
};
The infospace so created is ready to be monitored through the XMAS infrastructure.
Push Model
The next example shows how to implement a
push model monitoring. Every change of the variable myCounter_ will be notified into the system such that it can be intercepted by XMAS infrstructure. The push model can be used in configurations where XMAS is not provided by making the application independent of the XMAS infrastructure. In this case the firing of the change is ignored. The full example can be found withing the powerpack distribution under daq/xmas/tester.
class MyApplication: public xdaq::Application, public toolbox::task::TimerListener
{
MyApplication()
{
// Create/Retrieve an infospace
toolbox::net::URN monitorable = this->createQualifiedInfoSpace("myInfospace");
xdata::InfoSpace * is = xdata::getInfoSpaceFactory()->get(monitorable.toString());
// Publish myCounter in monitorable infospace
is->fireItemAvailable("myCounter", &myCounter_);
// attach listener to myCounter_ to detect retrieval event
is->addGroupRetrieveListener (this);
//
// prepare a timer thread to increment myCounter
// ....
}
void timeExpired(toolbox::task::TimerEvent& e)
{
try
{
xdata::InfoSpace * is = xdata::getInfoSpaceFactory()->get(monitorable_);
myCounter_ = myCounter_ + 1;
std::list names;
names.push_back("myCounter");
is->fireItemGroupChanged(names, this);
}
catch (xdata::exception::Exception& xe)
{
LOG4CPLUS_ERROR(getApplicationLogger(), stdformat_exception_history(xe) );
}
catch (std::exception& se)
{
std::string msg = "Caught standard exception while trying to collect: ";
msg += se.what();
LOG4CPLUS_ERROR(getApplicationLogger(), msg );
}
catch (...)
{
std::string msg = "Caught unknown exception while trying to collect";
LOG4CPLUS_ERROR(getApplicationLogger(), msg );
}
}
// A counter to be monitored
xdata::UnsignedLong myCounter_;
toolbox::net::URN monitorable_;
};