Gaudi Framework, version v20r4

Generated: 8 Jan 2009

DataListenerSvc Class Reference

#include <bking/DataListenerSvc.h>

Inheritance diagram for DataListenerSvc:

Inheritance graph
[legend]
Collaboration diagram for DataListenerSvc:

Collaboration graph
[legend]

List of all members.


Detailed Description

DataListenerSvc inherits from IMonitorSvc and allows the GAUDI user to monitor variables declared in an algorithm.

DataListenerSvc generates XML files on the individual machines where the algorithm is run, which can then be parsed by e.g. GANGA and sent to a monitoring server such as MonALISA. XML files are written at a frequency specified by the user and are consumed as they are created when used within GANGA.

Usage

In Algorithm header file
In Algorithm cpp file
Supports declaration of variables of type: int, long, bool, double, string

In GAUDI options file
Job options available
Parameters:
EventFrequency How data is sent to - default is every 100 events

XML file format
XML tag format is the following:

Opening parent tags of the form:

<?xml version="1.0" encoding="ASCII" standalone="yes"?>
<Results Time="Tue Aug 22 10:17:22 2006">
        <Run>

With then an entry for each monitored variable of the form:

        <Incident>
                <IncType>EndEvent </IncType>
<IncSource>EventLoopMgr </IncSource>
<VarName>Psi ID </VarName>
<Value Result="8">443</Value>
        </Incident>

Parameters:
IncType What type of incident triggered the handle method
IncSource What triggered the IIncident handle method
VarName Name of the variable monitored
Value Value of the variable
Result Number of times the variable already read
Author:
Ben KING
Date:
2006-08-24

Definition at line 112 of file DataListenerSvc.h.


Public Member Functions

 DataListenerSvc (const std::string &name, ISvcLocator *sl)
 need the next declaration ? compiler seems to find the static var
virtual ~DataListenerSvc ()
StatusCode queryInterface (const InterfaceID &riid, void **ppvIF)
 Query interfaces of Interface.
StatusCode initialize ()
 Initialization (from CONFIGURED to INITIALIZED).
StatusCode finalize ()
 Finalize (from INITIALIZED to CONFIGURED).
void declareInfo (const std::string &name, const bool &var, const std::string &desc, const IInterface *owner)
 Declare monitoring information.
void declareInfo (const std::string &name, const int &var, const std::string &desc, const IInterface *owner)
void declareInfo (const std::string &name, const long &var, const std::string &desc, const IInterface *owner)
void declareInfo (const std::string &name, const double &var, const std::string &desc, const IInterface *owner)
void declareInfo (const std::string &name, const std::string &var, const std::string &desc, const IInterface *owner)
void declareInfo (const std::string &name, const std::pair< double, double > &var, const std::string &desc, const IInterface *owner)
void declareInfo (const std::string &name, const AIDA::IBaseHistogram *var, const std::string &desc, const IInterface *owner)
void declareInfo (const std::string &name, const std::string &format, const void *var, int size, const std::string &desc, const IInterface *owner)
void undeclareInfo (const std::string &name, const IInterface *owner)
 Undeclare monitoring information.
void undeclareAll (const IInterface *owner)
 Undeclare monitoring information.
virtual void handle (const Incident &)
 Implementation of the IIncidentListener.h virtual method.
std::set< std::string > * getInfos (const IInterface *owner=0)
 Get the names for all declared monitoring informations for a given owner.
void apmSend (char *clusterName, char *moduleName, char *key, double val)
 Send (key,value) pairs to MonALISA server.
void apmSend (char *clusterName, char *moduleName, char *key, int val)
 Send a (char*,int) pair to MonALISA.
void apmSend (char *clusterName, char *moduleName, char *key, long val)
 Send a (char*,long) pair to MonALISA.
void apmSend (char *clusterName, char *moduleName, char *key, bool val)
 Send a (char*,bool) pair to MonALISA.
void apmSend (char *clusterName, char *moduleName, char *key, char *val)
 Send a (char*,char*) pair to MonALISA.

Private Types

typedef std::pair< std::string,
ValueMap
Entry
typedef std::map< const
IInterface *, std::set
< std::string > > 
InfoNamesMap
typedef std::map< std::string,
ValueMap
ValNamesMap

Private Member Functions

void writeMap (ValNamesMap *, const Incident &, std::ofstream *)
void writeXML (ValNamesMap *, const Incident &, std::ofstream *)
std::string resizeString (const std::string, const unsigned int)
std::string stringConverter (const int convertee)
std::string stringConverter (const double convertee)
std::string stringConverter (const bool convertee)
std::string stringConverter (const long convertee)
void sendData (ValNamesMap *)
 MonALISA sender method to send Data to MonALISA server.
std::string infoOwnerName (const IInterface *owner)

Private Attributes

ApMonapm
ValueMap m_ValueMap
ValueMap m_ValueMapTemp
time_t rawTime
time_t rawTime2
char buffer [50]
char buffer2 [50]
std::string timeDate
std::string timeDate2
std::string valToWrite
InfoNamesMap m_InfoNamesMap
InfoNamesMap::iterator m_InfoNamesMapIt
ValNamesMap m_ValNamesMap
ValNamesMap::iterator m_ValNamesMapIt
XmlCode xml
IIncidentSvcm_incidentSvc
FILEMonitorLog
std::ofstream Log4
std::ofstream XMLLog
int FreqCriterion
int m_EventFrequency
std::map< std::string,
std::string > 
m_infoDescriptions
int m_MLjobID
int m_MLEventFrequency
std::string m_MLClusterName
std::string m_ApMonSettingsFile
std::string jobIDString
int m_MonALISAMonitoring
int m_XMLMonitoring
int m_FileMonitoring
char * keyToSend

Member Typedef Documentation

typedef std::pair< std::string, ValueMap > DataListenerSvc::Entry [private]

Definition at line 216 of file DataListenerSvc.h.

typedef std::map<const IInterface*, std::set<std::string> > DataListenerSvc::InfoNamesMap [private]

Definition at line 217 of file DataListenerSvc.h.

typedef std::map< std::string, ValueMap > DataListenerSvc::ValNamesMap [private]

Definition at line 219 of file DataListenerSvc.h.


Constructor & Destructor Documentation

DataListenerSvc::DataListenerSvc ( const std::string &  name,
ISvcLocator sl 
)

need the next declaration ? compiler seems to find the static var

Definition at line 65 of file DataListenerSvc.cpp.

00066   : Service(name, sl) {
00067 
00068   declareProperty ("EventFrequency", m_EventFrequency=defaultFrequency);
00069   declareProperty ("MLEventFrequency", m_MLEventFrequency=defaultMLFrequency);
00070   declareProperty ("MLjobID", m_MLjobID=defaultjobID);
00071   declareProperty ("MLClusterName", m_MLClusterName=defaultClusterName);
00072   declareProperty ("MonALISAMonitoring", m_MonALISAMonitoring=defaultMonALISAMonitoring);
00073   declareProperty ("ApMonSource", m_ApMonSettingsFile=defaultApMonSettingsFile);
00074 
00075   declareProperty ("XMLMonitoring", m_XMLMonitoring=defaultXMLMonitoring);
00076   declareProperty ("FileMonitoring", m_FileMonitoring=defaultFileMonitoring);
00077 
00078 }

virtual DataListenerSvc::~DataListenerSvc (  )  [inline, virtual]

Definition at line 119 of file DataListenerSvc.h.

00119 {}


Member Function Documentation

StatusCode DataListenerSvc::queryInterface ( const InterfaceID riid,
void **  ppvUnknown 
) [virtual]

Query interfaces of Interface.

Parameters:
riid ID of Interface to be retrieved
ppvUnknown Pointer to Location for interface pointer

Reimplemented from Service.

Definition at line 84 of file DataListenerSvc.cpp.

00086 {
00087   if(IID_IMonitorSvc == riid) {
00088     *ppvIF = dynamic_cast<IMonitorSvc*> (this);
00089   }
00090   else {
00091     return Service::queryInterface(riid, ppvIF);
00092   }
00093   addRef();
00094   return StatusCode::SUCCESS;
00095 }

StatusCode DataListenerSvc::initialize (  )  [virtual]

Initialization (from CONFIGURED to INITIALIZED).

Reimplemented from Service.

Definition at line 98 of file DataListenerSvc.cpp.

00099 {
00100 
00101   m_ApMonSettingsFile = defaultApMonSettingsFile;
00102   StatusCode sc = Service::initialize();
00103   MsgStream msg(msgSvc(),name());
00104 
00105   jobIDString = "jobID: " + stringConverter(m_MLjobID);
00106 
00107   if ( !sc.isSuccess() )   {
00108     msg << MSG::ERROR << "Failed to initialize Service base class." << endmsg;
00109     return StatusCode::FAILURE;
00110   }
00111 
00112   sc = service("IncidentSvc", m_incidentSvc, true);
00113   if (!sc.isSuccess()) {
00114     msg << MSG::ERROR << "Failed to access incident service." << endmsg;
00115     return StatusCode::FAILURE;
00116   }
00117   m_incidentSvc->addListener(this, IncidentType::EndEvent);
00118 
00119 
00120   if (m_MonALISAMonitoring){
00121     // Initialise MonALISA
00122     apm = new ApMon(const_cast<char*>(m_ApMonSettingsFile.c_str()));
00123   }
00124 
00125 
00126   // DEBUG info on job options specified in GAUDI
00127   if (m_MLEventFrequency == defaultMLFrequency) {
00128     msg << MSG::DEBUG
00129         << "Frequency to send data to MonALISA not specified, taken as the default value: "
00130         << defaultMLFrequency << endreq;
00131   } else {
00132     msg << MSG::INFO
00133         << "Data sent to MonALISA every "
00134         << m_MLEventFrequency << " events" << endreq;
00135   }
00136 
00137   if (m_MLjobID == defaultjobID){
00138     msg << MSG::DEBUG
00139         << "DataListenerSvc MonALISA Job ID not specified, taken as the default value: "
00140         << defaultjobID << endreq;
00141   }
00142 
00143   if (m_MLClusterName == defaultClusterName){
00144     msg << MSG::DEBUG
00145         << "DataListenerSvc MonALISA cluster name not specified, taken as the default value: "
00146         << defaultClusterName << endreq;
00147   }
00148 
00149   if (m_ApMonSettingsFile == defaultApMonSettingsFile){
00150     msg << MSG::DEBUG
00151         << "MonALISA ApMon configuration file destination not specified,  will be read from: "
00152         << defaultClusterName << endreq;
00153   }
00154 
00155   if (m_EventFrequency == defaultFrequency){
00156     msg << MSG::INFO
00157         << "XML Log file frequency not specified, taken as the default value: "
00158         << defaultFrequency << endreq;
00159   } else {
00160     msg << MSG::INFO
00161         << "Frequency XML logs are written at: "
00162         << m_EventFrequency << endreq;
00163   }
00164 
00165 
00166   if (m_MonALISAMonitoring) {
00167     msg << MSG::INFO
00168         << "Data will be published to a MonALISA server"
00169         << endreq;
00170   }
00171 
00172   if (m_XMLMonitoring) {
00173     msg << MSG::INFO
00174         << "Data will be written to XML log files"
00175         << endreq;
00176   }
00177   if (m_FileMonitoring) {
00178     msg << MSG::INFO
00179         << "Data will be updated in a Text log file"
00180         << endreq;
00181   }
00182 
00183   return StatusCode::SUCCESS;
00184 
00185 }

StatusCode DataListenerSvc::finalize (  )  [virtual]

Finalize (from INITIALIZED to CONFIGURED).

Reimplemented from Service.

Definition at line 188 of file DataListenerSvc.cpp.

00189 {
00190   MsgStream msg(msgSvc(),"DataListenerSvc");
00191 
00192   m_infoDescriptions.clear();
00193   m_ValNamesMap.clear();
00194 
00195   if (m_MonALISAMonitoring){
00196         if ( 0!= apm ) {
00197                 delete apm;
00198                 apm = 0 ;
00199         }
00200   }
00201 
00202   msg << MSG::DEBUG << "ApMon deleted" << endreq;
00203   msg << MSG::INFO << "finalized successfully" << endreq;
00204 
00205  if( m_incidentSvc ) m_incidentSvc->release();
00206 
00207   return Service::finalize();
00208 }

void DataListenerSvc::declareInfo ( const std::string &  name,
const bool &  var,
const std::string &  desc,
const IInterface owner 
) [virtual]

Declare monitoring information.

Parameters:
name Monitoring information name known to the external system
var Monitoring Listener address
desc Textual description
owner Owner identifier of the monitoring information (needed to peform clean up

Implements IMonitorSvc.

Definition at line 274 of file DataListenerSvc.cpp.

00277 {
00278 
00279   ValueMap::m_type vartype;
00280   vartype = ValueMap::m_bool;
00281 
00282   MsgStream msg(msgSvc(),"DataListenerSvc");
00283 
00284   m_ValueMap.set_ptr(  static_cast <void*> (const_cast <bool*> (&var) )  );
00285   m_ValueMap.set_ptrType(vartype);
00286 
00287   Entry p1(name, m_ValueMap);
00288 
00289   m_ValNamesMap.insert(p1);
00290 
00291 }

void DataListenerSvc::declareInfo ( const std::string &  name,
const int &  var,
const std::string &  desc,
const IInterface owner 
) [virtual]

Implements IMonitorSvc.

Definition at line 256 of file DataListenerSvc.cpp.

00259 {
00260   ValueMap::m_type vartype;
00261   vartype = ValueMap::m_int;
00262 
00263   MsgStream msg(msgSvc(),"DataListenerSvc");
00264 
00265   m_ValueMap.set_ptr(  static_cast <void*> (const_cast <int*> (&var) )  );
00266   m_ValueMap.set_ptrType(vartype);
00267 
00268   Entry p1(name, m_ValueMap);
00269 
00270   m_ValNamesMap.insert(p1);
00271 
00272 }

void DataListenerSvc::declareInfo ( const std::string &  name,
const long &  var,
const std::string &  desc,
const IInterface owner 
) [virtual]

Implements IMonitorSvc.

Definition at line 237 of file DataListenerSvc.cpp.

00240 {
00241 
00242   ValueMap::m_type vartype;
00243   vartype = ValueMap::m_long;
00244 
00245   MsgStream msg(msgSvc(),"DataListenerSvc");
00246 
00247   m_ValueMap.set_ptr(  static_cast <void*> (const_cast <long*> (&var) )  );
00248   m_ValueMap.set_ptrType(vartype);
00249 
00250   Entry p1(name, m_ValueMap);
00251 
00252   m_ValNamesMap.insert(p1);
00253 
00254 }

void DataListenerSvc::declareInfo ( const std::string &  name,
const double &  var,
const std::string &  desc,
const IInterface owner 
) [virtual]

Implements IMonitorSvc.

Definition at line 214 of file DataListenerSvc.cpp.

00217 {
00218   ValueMap::m_type vartype;
00219   vartype = ValueMap::m_double;
00220 
00221   MsgStream msg(msgSvc(),"DataListenerSvc");
00222 
00223   // In the ValueMap, store the pointer to the data (converted to void*)
00224   // and also store the pointer type (with an enum) so it can be converted back
00225   m_ValueMap.set_ptr(  static_cast <void*> (const_cast <double*> (&var) )  );
00226   m_ValueMap.set_ptrType(vartype);
00227 
00228   Entry p1(name, m_ValueMap);
00229 
00230   // m_ValNamesMap is then composed of n (variable Name: ValueMap) pairs
00231   m_ValNamesMap.insert(p1);
00232 
00233 }

void DataListenerSvc::declareInfo ( const std::string &  name,
const std::string &  var,
const std::string &  desc,
const IInterface owner 
) [virtual]

Implements IMonitorSvc.

Definition at line 293 of file DataListenerSvc.cpp.

00297 {
00298   ValueMap::m_type vartype;
00299   vartype = ValueMap::m_string;
00300 
00301   MsgStream msg(msgSvc(),"DataListenerSvc");
00302 
00303   m_ValueMap.set_ptr(  static_cast <void*> (const_cast <std::string*> (&var) )  );  m_ValueMap.set_ptrType(vartype);
00304 
00305   Entry p1(name, m_ValueMap);
00306 
00307   m_ValNamesMap.insert(p1);
00308 
00309 }

void DataListenerSvc::declareInfo ( const std::string &  name,
const std::pair< double, double > &  var,
const std::string &  desc,
const IInterface owner 
) [virtual]

Implements IMonitorSvc.

Definition at line 312 of file DataListenerSvc.cpp.

00316 {
00317 }

void DataListenerSvc::declareInfo ( const std::string &  name,
const AIDA::IBaseHistogram *  var,
const std::string &  desc,
const IInterface owner 
) [virtual]

Implements IMonitorSvc.

Definition at line 318 of file DataListenerSvc.cpp.

00322 {
00323 }

void DataListenerSvc::declareInfo ( const std::string &  name,
const std::string &  format,
const void *  var,
int  size,
const std::string &  desc,
const IInterface owner 
) [virtual]

Implements IMonitorSvc.

Definition at line 325 of file DataListenerSvc.cpp.

00331 {
00332 }

void DataListenerSvc::undeclareInfo ( const std::string &  name,
const IInterface owner 
) [virtual]

Undeclare monitoring information.

Parameters:
name Monitoring information name known to the external system
owner Owner identifier of the monitoring information

Implements IMonitorSvc.

Definition at line 336 of file DataListenerSvc.cpp.

00338 {
00339 }

void DataListenerSvc::undeclareAll ( const IInterface owner  )  [virtual]

Undeclare monitoring information.

Parameters:
owner Owner identifier of the monitoring information

Implements IMonitorSvc.

Definition at line 341 of file DataListenerSvc.cpp.

00342 {
00343 }

void DataListenerSvc::handle ( const Incident Inc  )  [virtual]

Implementation of the IIncidentListener.h virtual method.

Implements IIncidentListener.

Definition at line 358 of file DataListenerSvc.cpp.

00359 {
00360 
00361   MsgStream msg(msgSvc(),"DataListenerSvc");
00362   numIncidents++;
00363 
00364 
00365   if (numIncidents % m_EventFrequency == 0){
00366 
00367     try {
00368       Log4.open("MonitorLog.txt", std::ios::trunc);
00369       XMLLog.open(("./log" + stringConverter(fileCounter)  + ".xml").c_str() , std::ios::trunc);
00370     } catch(std::exception /*&e*/) {
00371       msg << MSG::INFO
00372           << "Log File could not be opened, no monitoring available"
00373           << endreq;
00374     }
00375 
00376     if (m_MonALISAMonitoring){
00377       // Send Data to MonALISA
00378       sendData(&m_ValNamesMap);
00379     }
00380 
00381     if (m_FileMonitoring){
00382       // Write simple text log
00383       writeMap(&m_ValNamesMap, Inc, &Log4 );
00384       Log4.close();
00385     }
00386 
00387     if (m_XMLMonitoring){
00388       // Write XML files
00389       writeXML(&m_ValNamesMap, Inc, &XMLLog );
00390       XMLLog.close();
00391     }
00392 
00393     fileCounter++;
00394   }
00395 
00396 }

std::set< std::string > * DataListenerSvc::getInfos ( const IInterface owner = 0  )  [virtual]

Get the names for all declared monitoring informations for a given owner.

If the owner is NULL, then it returns for all owners

Implements IMonitorSvc.

Definition at line 345 of file DataListenerSvc.cpp.

00346 {
00347   std::set<std::string> * returnData = NULL;
00348   return returnData;
00349 }

void DataListenerSvc::apmSend ( char *  clusterName,
char *  moduleName,
char *  key,
double  val 
)

Send (key,value) pairs to MonALISA server.

Parameters:
clusterName Name of cluster where information will be stored
moduleName Name of module where information will be stored
key Key of the (key,value) pair sent to MonALISA
value Value of the (key,value) pair sent to MonALISA Send a (char*,double) pair to MonALISA

Definition at line 641 of file DataListenerSvc.cpp.

00643 {
00644   MsgStream msg(msgSvc(),"DataListenerSvc");
00645   msg << MSG::DEBUG << "ApMon instantiated" << endreq;
00646 
00647   try {
00648     DataListenerSvc::apm->sendParameter( clusterName, clusterNode, key, val);
00649     msg << MSG::DEBUG << "ApMon instantiated" << endreq;
00650     msg << MSG::INFO << "Sent parameters to MonALISA sever:"
00651         << m_MLClusterName << "->"
00652         << jobIDString.c_str() << "->"
00653         << key << ":" << val << endreq;
00654   } catch(std::runtime_error &e) {
00655     msg << MSG::WARNING << "WARNING sending to ApMon:\t" << e.what() << endreq;
00656   }
00657 }

void DataListenerSvc::apmSend ( char *  clusterName,
char *  moduleName,
char *  key,
int  val 
)

Send a (char*,int) pair to MonALISA.

Definition at line 659 of file DataListenerSvc.cpp.

00661 {
00662   MsgStream msg(msgSvc(),"DataListenerSvc");
00663   msg << MSG::DEBUG << "ApMon instantiated" << endreq;
00664   try {
00665     DataListenerSvc::apm->sendParameter( clusterName, clusterNode, key, val);
00666     msg << MSG::DEBUG << "ApMon instantiated" << endreq;
00667     msg << MSG::INFO << "Sent parameters to MonALISA sever:"
00668         << m_MLClusterName << "->"
00669         << jobIDString.c_str() << "->"
00670         << key << ":" << val << endreq;
00671   } catch(std::runtime_error &e) {
00672     msg << MSG::WARNING << "WARNING sending to ApMon:\t" << e.what() << endreq;
00673   }
00674 }

void DataListenerSvc::apmSend ( char *  clusterName,
char *  moduleName,
char *  key,
long  val 
)

Send a (char*,long) pair to MonALISA.

Definition at line 676 of file DataListenerSvc.cpp.

00678 {
00679   MsgStream msg(msgSvc(),"DataListenerSvc");
00680   msg << MSG::DEBUG << "ApMon instantiated" << endreq;
00681   double temp;
00682   temp = *(double*)val;
00683 
00684   try {
00685     DataListenerSvc::apm->sendParameter( clusterName, clusterNode, key, temp);
00686     msg << MSG::DEBUG << "ApMon instantiated" << endreq;
00687     msg << MSG::INFO << "Sent parameters to MonALISA sever:"
00688         << m_MLClusterName << "->"
00689         << jobIDString.c_str() << "->"
00690         << key << ":" << val << endreq;
00691   } catch (std::runtime_error &e){
00692     msg << MSG::WARNING << "WARNING sending to ApMon:\t" << e.what() << endreq;
00693   }
00694 }

void DataListenerSvc::apmSend ( char *  clusterName,
char *  moduleName,
char *  key,
bool  val 
)

Send a (char*,bool) pair to MonALISA.

Definition at line 696 of file DataListenerSvc.cpp.

00698 {
00699   MsgStream msg(msgSvc(),"DataListenerSvc");
00700   msg << MSG::DEBUG << "ApMon instantiated" << endreq;
00701   try {
00702     DataListenerSvc::apm->sendParameter( clusterName, clusterNode, key, val);
00703     msg << MSG::DEBUG << "ApMon instantiated" << endreq;
00704     msg << MSG::INFO << "Sent parameters to MonALISA sever:"
00705         << m_MLClusterName << "->"
00706         << jobIDString.c_str() << "->"
00707         << key << ":" << val << endreq;
00708   } catch (std::runtime_error &e){
00709     msg << MSG::WARNING << "WARNING sending to ApMon:\t" << e.what() << endreq;
00710   }
00711 }

void DataListenerSvc::apmSend ( char *  clusterName,
char *  moduleName,
char *  key,
char *  val 
)

Send a (char*,char*) pair to MonALISA.

Definition at line 713 of file DataListenerSvc.cpp.

00715 {
00716   MsgStream msg(msgSvc(),"DataListenerSvc");
00717   msg << MSG::DEBUG << "ApMon instantiated" << endreq;
00718   try {
00719     DataListenerSvc::apm->sendParameter( clusterName, clusterNode, key, val);
00720     msg << MSG::DEBUG << "ApMon instantiated" << endreq;
00721     msg << MSG::INFO << "Sent parameters to MonALISA sever:"
00722         << m_MLClusterName << "->"
00723         << jobIDString.c_str() << "->"
00724         << key << ":" << val << endreq;
00725   } catch (std::runtime_error &e){
00726     msg << MSG::WARNING << "WARNING sending to ApMon:\t" << e.what() << endreq;
00727   }
00728 }

void DataListenerSvc::writeMap ( ValNamesMap m_ValNamesMap,
const Incident Inc,
std::ofstream *  MyFile 
) [private]

Definition at line 546 of file DataListenerSvc.cpp.

00548 {
00549   // prepare time ctime.h and remove trailing carriage return
00550   time ( &rawTime2 );
00551   sprintf (buffer2, "%s", ctime(&rawTime2));
00552   timeDate2 = buffer2;
00553   timeDate2.erase(timeDate2.size()-1, 1);
00554 
00555   // headings for the text file with spacing numbers
00556   std::string space = "   ";
00557   std::string heading0 = "Time                       "; // 27
00558   std::string heading1 = "No      "; // 8 chars long
00559   std::string heading2 = "Incident Type     "; // 18
00560   std::string heading3 = "Incident Source   "; // 18
00561   std::string heading4 = "Name            ";  // 16
00562   std::string heading5 = "Value               "; // 20
00563 
00564   *MyFile << heading0 + heading1 + heading2 + heading3 + heading4 + heading5
00565           << std::endl;
00566 
00567   for (m_ValNamesMapIt = m_ValNamesMap->begin();
00568        m_ValNamesMapIt != m_ValNamesMap->end();
00569        ++m_ValNamesMapIt){
00570 
00571     m_ValueMapTemp = m_ValNamesMapIt->second;
00572 
00573     *MyFile << timeDate2 << space
00574 
00575             << resizeString(stringConverter(numIncidents),8) // Counts # incidents
00576             << resizeString(Inc.type(),18)                 // Incident Type
00577             << resizeString(Inc.source(),18)               // Source of the Incident
00578             << resizeString(m_ValNamesMapIt->first,20);    // Variable Name
00579 
00580     // Check the variable type and in each case, cast accordingly
00581     if (m_ValueMapTemp.get_ptrType() == ValueMap::m_double){
00582       *MyFile << resizeString(stringConverter(*(double*)m_ValueMapTemp.get_ptr()), 12)
00583               << std::endl;
00584     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_int){
00585       *MyFile << resizeString(stringConverter(*(int*)m_ValueMapTemp.get_ptr()), 12)
00586               << std::endl;
00587     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_long){
00588       *MyFile << resizeString(stringConverter(*(long*)m_ValueMapTemp.get_ptr()), 12)
00589               << std::endl;
00590     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_bool){
00591       *MyFile << resizeString(stringConverter(*(bool*)m_ValueMapTemp.get_ptr()), 12)
00592               << std::endl;
00593     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_string){
00594       *MyFile << resizeString((*(std::string*)m_ValueMapTemp.get_ptr()), 12)
00595               << std::endl;
00596       }
00597 
00598       }
00599 
00600 }

void DataListenerSvc::writeXML ( ValNamesMap m_ValNamesMap,
const Incident Inc,
std::ofstream *  MyFile 
) [private]

Definition at line 467 of file DataListenerSvc.cpp.

00470 {
00471 
00472   MsgStream msg(msgSvc(),"DataListenerSvc");
00473 
00474   // prepare time ctime.h and remove trailing carriage return
00475   time ( &rawTime );
00476   sprintf (buffer, "%s", ctime(&rawTime));
00477   timeDate = buffer;
00478   timeDate.erase(timeDate.size()-1, 1);
00479 
00480 
00481   msg << MSG::INFO << "XML written to file: " << MyFile << endreq;
00482 
00483 
00484   *MyFile << xml.declaration("1.0", "ASCII", "yes") << std::endl;
00485 
00486   *MyFile << xml.tagBegin("Results", 0, "Time", timeDate)
00487           << xml.tagBegin("Run",1);
00488 
00489 
00490   for (m_ValNamesMapIt = m_ValNamesMap->begin();
00491        m_ValNamesMapIt != m_ValNamesMap->end();
00492        ++m_ValNamesMapIt) {
00493 
00494     m_ValueMapTemp = m_ValNamesMapIt->second;
00495 
00496     *MyFile << xml.tagBegin("Incident",2);
00497 
00498     *MyFile << xml.tagBegin("IncType", 3)
00499             << xml.data(resizeString(Inc.type(),18))
00500             << xml.tagEnd("IncType", 0);
00501 
00502     *MyFile << xml.tagBegin("IncSource", 3)
00503             << xml.data(resizeString(Inc.source(),18))
00504             << xml.tagEnd("IncSource", 0);
00505 
00506     *MyFile << xml.tagBegin("VarName", 3)
00507             << xml.data(resizeString(m_ValNamesMapIt->first,20))
00508             << xml.tagEnd("VarName", 0);
00509 
00510     *MyFile << xml.tagBegin("Value", 3, "Result", stringConverter(numIncidents));
00511     // Check the variable type and in each case, cast accordingly
00512 
00513 
00514 
00515     // re-convert pointers to their original form and then to strings
00516     // so that they can be written with XMLCode.h
00517     if (m_ValueMapTemp.get_ptrType() == ValueMap::m_double){
00518       valToWrite = stringConverter(*(double*)m_ValueMapTemp.get_ptr());
00519     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_int){
00520       valToWrite = stringConverter(*(int*)m_ValueMapTemp.get_ptr());
00521     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_long){
00522       valToWrite = stringConverter(*(long*)m_ValueMapTemp.get_ptr());
00523     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_bool){
00524       valToWrite = stringConverter(*(bool*)m_ValueMapTemp.get_ptr());
00525     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_string){
00526       valToWrite = *(std::string*)m_ValueMapTemp.get_ptr();
00527     }
00528 
00529 
00530     *MyFile << xml.data(valToWrite);
00531     msg << MSG::DEBUG << "XML written: " << m_ValNamesMapIt->first << " , "
00532         << valToWrite << endreq;
00533 
00534     *MyFile << xml.tagEnd("Value", 0);
00535     *MyFile << xml.tagEnd("Incident",2);
00536   }
00537 
00538 
00539   *MyFile << xml.tagEnd("Run",1)
00540           << xml.tagEnd("Results", 0);
00541 
00542 }

std::string DataListenerSvc::resizeString ( const std::string  text,
const unsigned int  length 
) [private]

Definition at line 401 of file DataListenerSvc.cpp.

00403 {
00404   std::string temp;
00405   unsigned int counter=0;
00406 
00407   do {
00408 
00409     if (text.length() > length) {
00410       temp = text.substr(0,(length-1));
00411     } else {
00412       if (counter==0) {
00413         temp = text;
00414         counter++;
00415       }
00416       temp.append(" ");
00417     }
00418 
00419   } while (temp.length() != length);
00420 
00421   return temp;
00422 }

std::string DataListenerSvc::stringConverter ( const int  convertee  )  [private]

Definition at line 426 of file DataListenerSvc.cpp.

00427 {
00428   std::stringstream s;
00429   std::string temp;
00430   s << convertee;
00431   s >> temp;
00432   s.flush();
00433   return temp;
00434 }

std::string DataListenerSvc::stringConverter ( const double  convertee  )  [private]

Definition at line 436 of file DataListenerSvc.cpp.

00437 {
00438   std::stringstream s;
00439   std::string temp;
00440   s << convertee;
00441   s >> temp;
00442   s.flush();
00443   return temp;
00444 }

std::string DataListenerSvc::stringConverter ( const bool  convertee  )  [private]

Definition at line 455 of file DataListenerSvc.cpp.

00456 {
00457   std::stringstream s;
00458   std::string temp;
00459   s << convertee;
00460   s >> temp;
00461   s.flush();
00462   return temp;
00463 }

std::string DataListenerSvc::stringConverter ( const long  convertee  )  [private]

Definition at line 445 of file DataListenerSvc.cpp.

00446 {
00447   std::stringstream s;
00448   std::string temp;
00449   s << convertee;
00450   s >> temp;
00451   s.flush();
00452   return temp;
00453 }

void DataListenerSvc::sendData ( ValNamesMap m_ValNamesMap  )  [private]

MonALISA sender method to send Data to MonALISA server.

Definition at line 603 of file DataListenerSvc.cpp.

00604 {
00605 
00606   for (m_ValNamesMapIt = m_ValNamesMap->begin();
00607        m_ValNamesMapIt != m_ValNamesMap->end();
00608        ++m_ValNamesMapIt){
00609 
00610     m_ValueMapTemp = m_ValNamesMapIt->second;
00611     keyToSend = const_cast<char*>((m_ValNamesMapIt->first).c_str());
00612 
00613 
00614     if (m_ValueMapTemp.get_ptrType() == ValueMap::m_double){
00615       apmSend(const_cast <char*>(m_MLClusterName.c_str()),
00616               const_cast <char*> (jobIDString.c_str()),
00617               keyToSend, *(double*)m_ValueMapTemp.get_ptr());
00618     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_int){
00619       apmSend(const_cast <char*>(m_MLClusterName.c_str()),
00620               const_cast <char*> (jobIDString.c_str()),
00621               keyToSend, *(int*)m_ValueMapTemp.get_ptr());
00622     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_long){
00623       apmSend(const_cast <char*>(m_MLClusterName.c_str()),
00624               const_cast <char*> (jobIDString.c_str()),
00625               keyToSend, *(long*)m_ValueMapTemp.get_ptr());
00626     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_bool){
00627       apmSend(const_cast <char*>(m_MLClusterName.c_str()),
00628               const_cast <char*> (jobIDString.c_str()),
00629               keyToSend, *(bool*)m_ValueMapTemp.get_ptr());
00630     } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_string){
00631       apmSend(const_cast <char*>(m_MLClusterName.c_str()),
00632               const_cast <char*> (jobIDString.c_str()),
00633               keyToSend, const_cast <char*>((*(std::string*)m_ValueMapTemp.get_ptr()).c_str()));
00634     }
00635   }
00636 
00637 }

std::string DataListenerSvc::infoOwnerName ( const IInterface owner  )  [private]

Definition at line 351 of file DataListenerSvc.cpp.

00352   {
00353     std::string returnData = "";
00354     return returnData;
00355   }


Member Data Documentation

Definition at line 198 of file DataListenerSvc.h.

Definition at line 202 of file DataListenerSvc.h.

Definition at line 203 of file DataListenerSvc.h.

Definition at line 205 of file DataListenerSvc.h.

Definition at line 206 of file DataListenerSvc.h.

char DataListenerSvc::buffer[50] [private]

Definition at line 208 of file DataListenerSvc.h.

char DataListenerSvc::buffer2[50] [private]

Definition at line 209 of file DataListenerSvc.h.

std::string DataListenerSvc::timeDate [private]

Definition at line 210 of file DataListenerSvc.h.

std::string DataListenerSvc::timeDate2 [private]

Definition at line 211 of file DataListenerSvc.h.

std::string DataListenerSvc::valToWrite [private]

Definition at line 212 of file DataListenerSvc.h.

Definition at line 233 of file DataListenerSvc.h.

InfoNamesMap::iterator DataListenerSvc::m_InfoNamesMapIt [private]

Definition at line 234 of file DataListenerSvc.h.

Definition at line 236 of file DataListenerSvc.h.

ValNamesMap::iterator DataListenerSvc::m_ValNamesMapIt [private]

Definition at line 237 of file DataListenerSvc.h.

Definition at line 238 of file DataListenerSvc.h.

Definition at line 243 of file DataListenerSvc.h.

Definition at line 244 of file DataListenerSvc.h.

std::ofstream DataListenerSvc::Log4 [private]

Definition at line 245 of file DataListenerSvc.h.

std::ofstream DataListenerSvc::XMLLog [private]

Definition at line 246 of file DataListenerSvc.h.

Definition at line 249 of file DataListenerSvc.h.

Definition at line 250 of file DataListenerSvc.h.

std::map<std::string,std::string> DataListenerSvc::m_infoDescriptions [private]

Definition at line 260 of file DataListenerSvc.h.

Definition at line 264 of file DataListenerSvc.h.

Definition at line 265 of file DataListenerSvc.h.

std::string DataListenerSvc::m_MLClusterName [private]

Definition at line 266 of file DataListenerSvc.h.

std::string DataListenerSvc::m_ApMonSettingsFile [private]

Definition at line 267 of file DataListenerSvc.h.

std::string DataListenerSvc::jobIDString [private]

Definition at line 268 of file DataListenerSvc.h.

Definition at line 269 of file DataListenerSvc.h.

Definition at line 270 of file DataListenerSvc.h.

Definition at line 271 of file DataListenerSvc.h.

char* DataListenerSvc::keyToSend [private]

Definition at line 274 of file DataListenerSvc.h.


The documentation for this class was generated from the following files:

Generated at Thu Jan 8 17:50:51 2009 for Gaudi Framework, version v20r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004