This page is deprecated in favour of documentation provided at http://xdaq.web.cern.ch

Creating a Monitorable Application

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_;
};

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r2 - 2010-01-14 - RolandMoser
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    XdaqWiki/XMAS All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback