Gaudi Framework, version v20r2

Generated: 18 Jul 2008

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 a (char*,double) pair to MonALISA.
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
FILE * MonitorLog
std::ofstream Log4
std::ofstream XMLLog
int FreqCriterion
int m_EventFrequency
std::map< std::string, std::stringm_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 66 of file DataListenerSvc.cpp.

References Service::declareProperty(), defaultApMonSettingsFile, defaultClusterName, defaultFileMonitoring, defaultFrequency, defaultjobID, defaultMLFrequency, defaultMonALISAMonitoring, defaultXMLMonitoring, m_ApMonSettingsFile, m_EventFrequency, m_FileMonitoring, m_MLClusterName, m_MLEventFrequency, m_MLjobID, m_MonALISAMonitoring, and m_XMLMonitoring.

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

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

Definition at line 119 of file DataListenerSvc.h.

00119 {}


Member Function Documentation

StatusCode DataListenerSvc::queryInterface ( const InterfaceID riid,
void **  ppvIF 
) [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 85 of file DataListenerSvc.cpp.

References Service::addRef(), IID_IMonitorSvc, Service::queryInterface(), and StatusCode::SUCCESS.

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

StatusCode DataListenerSvc::initialize (  )  [virtual]

Initialization (from CONFIGURED to INITIALIZED).

Reimplemented from Service.

Definition at line 99 of file DataListenerSvc.cpp.

References IIncidentSvc::addListener(), apm, std::basic_string< _CharT, _Traits, _Alloc >::c_str(), MSG::DEBUG, defaultApMonSettingsFile, defaultClusterName, defaultFrequency, defaultjobID, defaultMLFrequency, IncidentType::EndEvent, endmsg(), endreq(), MSG::ERROR, StatusCode::FAILURE, MSG::INFO, Service::initialize(), StatusCode::isSuccess(), jobIDString, m_ApMonSettingsFile, m_EventFrequency, m_FileMonitoring, m_incidentSvc, m_MLClusterName, m_MLEventFrequency, m_MLjobID, m_MonALISAMonitoring, m_XMLMonitoring, Service::msgSvc(), Service::name(), Service::service(), stringConverter(), and StatusCode::SUCCESS.

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

StatusCode DataListenerSvc::finalize (  )  [virtual]

Finalize (from INITIALIZED to CONFIGURED).

Reimplemented from Service.

Definition at line 189 of file DataListenerSvc.cpp.

References apm, MSG::DEBUG, endreq(), Service::finalize(), MSG::INFO, m_incidentSvc, m_infoDescriptions, m_MonALISAMonitoring, m_ValNamesMap, Service::msgSvc(), and IInterface::release().

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

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 275 of file DataListenerSvc.cpp.

References ValueMap::m_bool, m_ValNamesMap, m_ValueMap, Service::msgSvc(), Service::name(), ValueMap::set_ptr(), and ValueMap::set_ptrType().

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

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

Implements IMonitorSvc.

Definition at line 257 of file DataListenerSvc.cpp.

References ValueMap::m_int, m_ValNamesMap, m_ValueMap, Service::msgSvc(), Service::name(), ValueMap::set_ptr(), and ValueMap::set_ptrType().

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

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

Implements IMonitorSvc.

Definition at line 238 of file DataListenerSvc.cpp.

References ValueMap::m_long, m_ValNamesMap, m_ValueMap, Service::msgSvc(), Service::name(), ValueMap::set_ptr(), and ValueMap::set_ptrType().

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

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

Implements IMonitorSvc.

Definition at line 215 of file DataListenerSvc.cpp.

References ValueMap::m_double, m_ValNamesMap, m_ValueMap, Service::msgSvc(), Service::name(), ValueMap::set_ptr(), and ValueMap::set_ptrType().

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

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

Implements IMonitorSvc.

Definition at line 294 of file DataListenerSvc.cpp.

References ValueMap::m_string, m_ValNamesMap, m_ValueMap, Service::msgSvc(), Service::name(), ValueMap::set_ptr(), and ValueMap::set_ptrType().

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

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 313 of file DataListenerSvc.cpp.

00317 {
00318 }

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

Implements IMonitorSvc.

Definition at line 319 of file DataListenerSvc.cpp.

00323 {
00324 }

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 326 of file DataListenerSvc.cpp.

00332 {
00333 }

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 337 of file DataListenerSvc.cpp.

00339 {
00340 }

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

Undeclare monitoring information.

Parameters:
owner Owner identifier of the monitoring information

Implements IMonitorSvc.

Definition at line 342 of file DataListenerSvc.cpp.

00343 {
00344 }

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

Implementation of the IIncidentListener.h virtual method.

Implements IIncidentListener.

Definition at line 359 of file DataListenerSvc.cpp.

References std::basic_ofstream< _CharT, _Traits >::close(), endreq(), fileCounter, MSG::INFO, Log4, m_EventFrequency, m_FileMonitoring, m_MonALISAMonitoring, m_ValNamesMap, m_XMLMonitoring, Service::msgSvc(), numIncidents, std::basic_ofstream< _CharT, _Traits >::open(), sendData(), stringConverter(), std::basic_ios< _CharT, _Traits >::trunc, writeMap(), writeXML(), and XMLLog.

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

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 346 of file DataListenerSvc.cpp.

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

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

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

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

Definition at line 642 of file DataListenerSvc.cpp.

References apm, std::basic_string< _CharT, _Traits, _Alloc >::c_str(), MSG::DEBUG, endreq(), MSG::INFO, jobIDString, m_MLClusterName, Service::msgSvc(), ApMon::sendParameter(), MSG::WARNING, and std::runtime_error::what().

Referenced by sendData().

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

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

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

Definition at line 660 of file DataListenerSvc.cpp.

References apm, std::basic_string< _CharT, _Traits, _Alloc >::c_str(), MSG::DEBUG, endreq(), MSG::INFO, jobIDString, m_MLClusterName, Service::msgSvc(), ApMon::sendParameter(), MSG::WARNING, and std::runtime_error::what().

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

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

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

Definition at line 677 of file DataListenerSvc.cpp.

References apm, std::basic_string< _CharT, _Traits, _Alloc >::c_str(), MSG::DEBUG, endreq(), MSG::INFO, jobIDString, m_MLClusterName, Service::msgSvc(), ApMon::sendParameter(), MSG::WARNING, and std::runtime_error::what().

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

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

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

Definition at line 697 of file DataListenerSvc.cpp.

References apm, std::basic_string< _CharT, _Traits, _Alloc >::c_str(), MSG::DEBUG, endreq(), MSG::INFO, jobIDString, m_MLClusterName, Service::msgSvc(), ApMon::sendParameter(), MSG::WARNING, and std::runtime_error::what().

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

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

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

Definition at line 714 of file DataListenerSvc.cpp.

References apm, std::basic_string< _CharT, _Traits, _Alloc >::c_str(), MSG::DEBUG, endreq(), MSG::INFO, jobIDString, m_MLClusterName, Service::msgSvc(), ApMon::sendParameter(), MSG::WARNING, and std::runtime_error::what().

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

void DataListenerSvc::writeMap ( ValNamesMap ,
const Incident ,
std::ofstream  
) [private]

Definition at line 547 of file DataListenerSvc.cpp.

References buffer2, std::endl(), std::basic_string< _CharT, _Traits, _Alloc >::erase(), ValueMap::get_ptr(), ValueMap::get_ptrType(), ValueMap::m_bool, ValueMap::m_double, ValueMap::m_int, ValueMap::m_long, ValueMap::m_string, m_ValNamesMap, m_ValNamesMapIt, m_ValueMapTemp, numIncidents, rawTime2, resizeString(), std::basic_string< _CharT, _Traits, _Alloc >::size(), Incident::source(), stringConverter(), timeDate2, and Incident::type().

Referenced by handle().

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

void DataListenerSvc::writeXML ( ValNamesMap ,
const Incident ,
std::ofstream  
) [private]

Definition at line 468 of file DataListenerSvc.cpp.

References buffer, XmlCode::data(), MSG::DEBUG, XmlCode::declaration(), std::endl(), endreq(), std::basic_string< _CharT, _Traits, _Alloc >::erase(), ValueMap::get_ptr(), ValueMap::get_ptrType(), MSG::INFO, ValueMap::m_bool, ValueMap::m_double, ValueMap::m_int, ValueMap::m_long, ValueMap::m_string, m_ValNamesMap, m_ValNamesMapIt, m_ValueMapTemp, Service::msgSvc(), numIncidents, rawTime, resizeString(), std::basic_string< _CharT, _Traits, _Alloc >::size(), Incident::source(), stringConverter(), XmlCode::tagBegin(), XmlCode::tagEnd(), timeDate, Incident::type(), valToWrite, and xml.

Referenced by handle().

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

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

Definition at line 402 of file DataListenerSvc.cpp.

References std::basic_string< _CharT, _Traits, _Alloc >::append(), counter(), std::basic_string< _CharT, _Traits, _Alloc >::length(), and std::basic_string< _CharT, _Traits, _Alloc >::substr().

Referenced by writeMap(), and writeXML().

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

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

Definition at line 427 of file DataListenerSvc.cpp.

References Gaudi::Units::s.

Referenced by handle(), initialize(), writeMap(), and writeXML().

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

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

Definition at line 437 of file DataListenerSvc.cpp.

References Gaudi::Units::s.

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

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

Definition at line 456 of file DataListenerSvc.cpp.

References Gaudi::Units::s.

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

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

Definition at line 446 of file DataListenerSvc.cpp.

References Gaudi::Units::s.

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

void DataListenerSvc::sendData ( ValNamesMap  )  [private]

MonALISA sender method to send Data to MonALISA server.

Definition at line 604 of file DataListenerSvc.cpp.

References apmSend(), std::basic_string< _CharT, _Traits, _Alloc >::c_str(), ValueMap::get_ptr(), ValueMap::get_ptrType(), jobIDString, keyToSend, ValueMap::m_bool, ValueMap::m_double, ValueMap::m_int, ValueMap::m_long, m_MLClusterName, ValueMap::m_string, m_ValNamesMap, m_ValNamesMapIt, and m_ValueMapTemp.

Referenced by handle().

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

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

Definition at line 352 of file DataListenerSvc.cpp.

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


Member Data Documentation

ApMon* DataListenerSvc::apm [private]

Definition at line 198 of file DataListenerSvc.h.

Referenced by apmSend(), finalize(), and initialize().

ValueMap DataListenerSvc::m_ValueMap [private]

Definition at line 202 of file DataListenerSvc.h.

Referenced by declareInfo().

ValueMap DataListenerSvc::m_ValueMapTemp [private]

Definition at line 203 of file DataListenerSvc.h.

Referenced by sendData(), writeMap(), and writeXML().

time_t DataListenerSvc::rawTime [private]

Definition at line 205 of file DataListenerSvc.h.

Referenced by writeXML().

time_t DataListenerSvc::rawTime2 [private]

Definition at line 206 of file DataListenerSvc.h.

Referenced by writeMap().

char DataListenerSvc::buffer[50] [private]

Definition at line 208 of file DataListenerSvc.h.

Referenced by writeXML().

char DataListenerSvc::buffer2[50] [private]

Definition at line 209 of file DataListenerSvc.h.

Referenced by writeMap().

std::string DataListenerSvc::timeDate [private]

Definition at line 210 of file DataListenerSvc.h.

Referenced by writeXML().

std::string DataListenerSvc::timeDate2 [private]

Definition at line 211 of file DataListenerSvc.h.

Referenced by writeMap().

std::string DataListenerSvc::valToWrite [private]

Definition at line 212 of file DataListenerSvc.h.

Referenced by writeXML().

InfoNamesMap DataListenerSvc::m_InfoNamesMap [private]

Definition at line 233 of file DataListenerSvc.h.

InfoNamesMap::iterator DataListenerSvc::m_InfoNamesMapIt [private]

Definition at line 234 of file DataListenerSvc.h.

ValNamesMap DataListenerSvc::m_ValNamesMap [private]

Definition at line 236 of file DataListenerSvc.h.

Referenced by declareInfo(), finalize(), handle(), sendData(), writeMap(), and writeXML().

ValNamesMap::iterator DataListenerSvc::m_ValNamesMapIt [private]

Definition at line 237 of file DataListenerSvc.h.

Referenced by sendData(), writeMap(), and writeXML().

XmlCode DataListenerSvc::xml [private]

Definition at line 238 of file DataListenerSvc.h.

Referenced by writeXML().

IIncidentSvc* DataListenerSvc::m_incidentSvc [private]

Definition at line 243 of file DataListenerSvc.h.

Referenced by finalize(), and initialize().

FILE* DataListenerSvc::MonitorLog [private]

Definition at line 244 of file DataListenerSvc.h.

std::ofstream DataListenerSvc::Log4 [private]

Definition at line 245 of file DataListenerSvc.h.

Referenced by handle().

std::ofstream DataListenerSvc::XMLLog [private]

Definition at line 246 of file DataListenerSvc.h.

Referenced by handle().

int DataListenerSvc::FreqCriterion [private]

Definition at line 249 of file DataListenerSvc.h.

int DataListenerSvc::m_EventFrequency [private]

Definition at line 250 of file DataListenerSvc.h.

Referenced by DataListenerSvc(), handle(), and initialize().

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

Definition at line 260 of file DataListenerSvc.h.

Referenced by finalize().

int DataListenerSvc::m_MLjobID [private]

Definition at line 264 of file DataListenerSvc.h.

Referenced by DataListenerSvc(), and initialize().

int DataListenerSvc::m_MLEventFrequency [private]

Definition at line 265 of file DataListenerSvc.h.

Referenced by DataListenerSvc(), and initialize().

std::string DataListenerSvc::m_MLClusterName [private]

Definition at line 266 of file DataListenerSvc.h.

Referenced by apmSend(), DataListenerSvc(), initialize(), and sendData().

std::string DataListenerSvc::m_ApMonSettingsFile [private]

Definition at line 267 of file DataListenerSvc.h.

Referenced by DataListenerSvc(), and initialize().

std::string DataListenerSvc::jobIDString [private]

Definition at line 268 of file DataListenerSvc.h.

Referenced by apmSend(), initialize(), and sendData().

int DataListenerSvc::m_MonALISAMonitoring [private]

Definition at line 269 of file DataListenerSvc.h.

Referenced by DataListenerSvc(), finalize(), handle(), and initialize().

int DataListenerSvc::m_XMLMonitoring [private]

Definition at line 270 of file DataListenerSvc.h.

Referenced by DataListenerSvc(), handle(), and initialize().

int DataListenerSvc::m_FileMonitoring [private]

Definition at line 271 of file DataListenerSvc.h.

Referenced by DataListenerSvc(), handle(), and initialize().

char* DataListenerSvc::keyToSend [private]

Definition at line 274 of file DataListenerSvc.h.

Referenced by sendData().


The documentation for this class was generated from the following files:
Generated at Fri Jul 18 12:07:00 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004