Gaudi Framework, version v22r4

Home   Generated: Fri Sep 2 2011
Public Member Functions | Private Types | Private Member Functions | Private Attributes

DataListenerSvc Class Reference

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

#include <bking/DataListenerSvc.h>

Inheritance diagram for DataListenerSvc:
Inheritance graph
[legend]
Collaboration diagram for DataListenerSvc:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DataListenerSvc (const std::string &name, ISvcLocator *sl)
virtual ~DataListenerSvc ()
StatusCode initialize ()
StatusCode finalize ()
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 StatEntity &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

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:
EventFrequencyHow 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:
IncTypeWhat type of incident triggered the handle method
IncSourceWhat triggered the IIncident handle method
VarNameName of the variable monitored
ValueValue of the variable
ResultNumber of times the variable already read
Author:
Ben KING
Date:
2006-08-24

Definition at line 112 of file DataListenerSvc.h.


Member Typedef Documentation

Definition at line 213 of file DataListenerSvc.h.

Definition at line 214 of file DataListenerSvc.h.

Definition at line 216 of file DataListenerSvc.h.


Constructor & Destructor Documentation

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

Definition at line 59 of file DataListenerSvc.cpp.

  : base_class(name, sl) {

  declareProperty ("EventFrequency", m_EventFrequency=defaultFrequency);
  declareProperty ("MLEventFrequency", m_MLEventFrequency=defaultMLFrequency);
  declareProperty ("MLjobID", m_MLjobID=defaultjobID);
  declareProperty ("MLClusterName", m_MLClusterName=defaultClusterName);
  declareProperty ("MonALISAMonitoring", m_MonALISAMonitoring=defaultMonALISAMonitoring);
  declareProperty ("ApMonSource", m_ApMonSettingsFile=defaultApMonSettingsFile);

  declareProperty ("XMLMonitoring", m_XMLMonitoring=defaultXMLMonitoring);
  declareProperty ("FileMonitoring", m_FileMonitoring=defaultFileMonitoring);

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

Definition at line 116 of file DataListenerSvc.h.

{}

Member Function Documentation

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

Send (key,value) pairs to MonALISA server.

Parameters:
clusterNameName of cluster where information will be stored
moduleNameName of module where information will be stored
keyKey of the (key,value) pair sent to MonALISA
valueValue of the (key,value) pair sent to MonALISA Send a (char*,double) pair to MonALISA

Definition at line 608 of file DataListenerSvc.cpp.

{
  MsgStream msg(msgSvc(),"DataListenerSvc");
  msg << MSG::DEBUG << "ApMon instantiated" << endmsg;

  try {
    DataListenerSvc::apm->sendParameter( clusterName, clusterNode, key, val);
    msg << MSG::DEBUG << "ApMon instantiated" << endmsg;
    msg << MSG::INFO << "Sent parameters to MonALISA sever:"
        << m_MLClusterName << "->"
        << jobIDString.c_str() << "->"
        << key << ":" << val << endmsg;
  } catch(std::runtime_error &e) {
    msg << MSG::WARNING << "WARNING sending to ApMon:\t" << e.what() << endmsg;
  }
}
void DataListenerSvc::apmSend ( char *  clusterName,
char *  moduleName,
char *  key,
int  val 
)

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

Definition at line 626 of file DataListenerSvc.cpp.

{
  MsgStream msg(msgSvc(),"DataListenerSvc");
  msg << MSG::DEBUG << "ApMon instantiated" << endmsg;
  try {
    DataListenerSvc::apm->sendParameter( clusterName, clusterNode, key, val);
    msg << MSG::DEBUG << "ApMon instantiated" << endmsg;
    msg << MSG::INFO << "Sent parameters to MonALISA sever:"
        << m_MLClusterName << "->"
        << jobIDString.c_str() << "->"
        << key << ":" << val << endmsg;
  } catch(std::runtime_error &e) {
    msg << MSG::WARNING << "WARNING sending to ApMon:\t" << e.what() << endmsg;
  }
}
void DataListenerSvc::apmSend ( char *  clusterName,
char *  moduleName,
char *  key,
long  val 
)

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

Definition at line 643 of file DataListenerSvc.cpp.

{
  MsgStream msg(msgSvc(),"DataListenerSvc");
  msg << MSG::DEBUG << "ApMon instantiated" << endmsg;
  double temp;
  temp = *(double*)val;

  try {
    DataListenerSvc::apm->sendParameter( clusterName, clusterNode, key, temp);
    msg << MSG::DEBUG << "ApMon instantiated" << endmsg;
    msg << MSG::INFO << "Sent parameters to MonALISA sever:"
        << m_MLClusterName << "->"
        << jobIDString.c_str() << "->"
        << key << ":" << val << endmsg;
  } catch (std::runtime_error &e){
    msg << MSG::WARNING << "WARNING sending to ApMon:\t" << e.what() << endmsg;
  }
}
void DataListenerSvc::apmSend ( char *  clusterName,
char *  moduleName,
char *  key,
bool  val 
)

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

Definition at line 663 of file DataListenerSvc.cpp.

{
  MsgStream msg(msgSvc(),"DataListenerSvc");
  msg << MSG::DEBUG << "ApMon instantiated" << endmsg;
  try {
    DataListenerSvc::apm->sendParameter( clusterName, clusterNode, key, val);
    msg << MSG::DEBUG << "ApMon instantiated" << endmsg;
    msg << MSG::INFO << "Sent parameters to MonALISA sever:"
        << m_MLClusterName << "->"
        << jobIDString.c_str() << "->"
        << key << ":" << val << endmsg;
  } catch (std::runtime_error &e){
    msg << MSG::WARNING << "WARNING sending to ApMon:\t" << e.what() << endmsg;
  }
}
void DataListenerSvc::apmSend ( char *  clusterName,
char *  moduleName,
char *  key,
char *  val 
)

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

Definition at line 680 of file DataListenerSvc.cpp.

{
  MsgStream msg(msgSvc(),"DataListenerSvc");
  msg << MSG::DEBUG << "ApMon instantiated" << endmsg;
  try {
    DataListenerSvc::apm->sendParameter( clusterName, clusterNode, key, val);
    msg << MSG::DEBUG << "ApMon instantiated" << endmsg;
    msg << MSG::INFO << "Sent parameters to MonALISA sever:"
        << m_MLClusterName << "->"
        << jobIDString.c_str() << "->"
        << key << ":" << val << endmsg;
  } catch (std::runtime_error &e){
    msg << MSG::WARNING << "WARNING sending to ApMon:\t" << e.what() << endmsg;
  }
}
void DataListenerSvc::declareInfo ( const std::string name,
const int &  var,
const std::string desc,
const IInterface owner 
)

Definition at line 223 of file DataListenerSvc.cpp.

{
  ValueMap::m_type vartype;
  vartype = ValueMap::m_int;

  MsgStream msg(msgSvc(),"DataListenerSvc");

  m_ValueMap.set_ptr(  static_cast <void*> (const_cast <int*> (&var) )  );
  m_ValueMap.set_ptrType(vartype);

  Entry p1(name, m_ValueMap);

  m_ValNamesMap.insert(p1);

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

Definition at line 278 of file DataListenerSvc.cpp.

{
}
void DataListenerSvc::declareInfo ( const std::string name,
const AIDA::IBaseHistogram *  var,
const std::string desc,
const IInterface owner 
)

Definition at line 292 of file DataListenerSvc.cpp.

{
}
void DataListenerSvc::declareInfo ( const std::string name,
const bool var,
const std::string desc,
const IInterface owner 
)

Declare monitoring information.

Parameters:
nameMonitoring information name known to the external system
varMonitoring Listener address
descTextual description
ownerOwner identifier of the monitoring information (needed to perform clean up

Definition at line 241 of file DataListenerSvc.cpp.

{

  ValueMap::m_type vartype;
  vartype = ValueMap::m_bool;

  MsgStream msg(msgSvc(),"DataListenerSvc");

  m_ValueMap.set_ptr(  static_cast <void*> (const_cast <bool*> (&var) )  );
  m_ValueMap.set_ptrType(vartype);

  Entry p1(name, m_ValueMap);

  m_ValNamesMap.insert(p1);

}
void DataListenerSvc::declareInfo ( const std::string name,
const long var,
const std::string desc,
const IInterface owner 
)

Definition at line 204 of file DataListenerSvc.cpp.

{

  ValueMap::m_type vartype;
  vartype = ValueMap::m_long;

  MsgStream msg(msgSvc(),"DataListenerSvc");

  m_ValueMap.set_ptr(  static_cast <void*> (const_cast <long*> (&var) )  );
  m_ValueMap.set_ptrType(vartype);

  Entry p1(name, m_ValueMap);

  m_ValNamesMap.insert(p1);

}
void DataListenerSvc::declareInfo ( const std::string name,
const StatEntity var,
const std::string desc,
const IInterface owner 
)

Definition at line 285 of file DataListenerSvc.cpp.

{
}
void DataListenerSvc::declareInfo ( const std::string name,
const std::string format,
const void *  var,
int  size,
const std::string desc,
const IInterface owner 
)

Definition at line 299 of file DataListenerSvc.cpp.

{
}
void DataListenerSvc::declareInfo ( const std::string name,
const double &  var,
const std::string desc,
const IInterface owner 
)

Definition at line 183 of file DataListenerSvc.cpp.

{
  ValueMap::m_type vartype;
  vartype = ValueMap::m_double;

  MsgStream msg(msgSvc(),"DataListenerSvc");

  // In the ValueMap, store the pointer to the data (converted to void*)
  // and also store the pointer type (with an enum) so it can be converted back
  m_ValueMap.set_ptr(  static_cast <void*> (const_cast <double*> (&var) )  );
  m_ValueMap.set_ptrType(vartype);

  Entry p1(name, m_ValueMap);

  // m_ValNamesMap is then composed of n (variable Name: ValueMap) pairs
  m_ValNamesMap.insert(p1);

}
void DataListenerSvc::declareInfo ( const std::string name,
const std::string var,
const std::string desc,
const IInterface owner 
)

Definition at line 260 of file DataListenerSvc.cpp.

{
  ValueMap::m_type vartype;
  vartype = ValueMap::m_string;

  MsgStream msg(msgSvc(),"DataListenerSvc");

  m_ValueMap.set_ptr(  static_cast <void*> (const_cast <std::string*> (&var) )  );  m_ValueMap.set_ptrType(vartype);

  Entry p1(name, m_ValueMap);

  m_ValNamesMap.insert(p1);

}
StatusCode DataListenerSvc::finalize ( void   ) [virtual]

Reimplemented from Service.

Definition at line 161 of file DataListenerSvc.cpp.

{
  MsgStream msg(msgSvc(),"DataListenerSvc");

  m_infoDescriptions.clear();
  m_ValNamesMap.clear();

  if (m_MonALISAMonitoring){
    if ( 0!= apm ) {
      delete apm;
      apm = 0 ;
    }
  }

  msg << MSG::DEBUG << "ApMon deleted" << endmsg;
  msg << MSG::INFO << "finalized successfully" << endmsg;

  if( m_incidentSvc ) m_incidentSvc->release();

  return Service::finalize();
}
std::set< std::string > * DataListenerSvc::getInfos ( const IInterface owner = 0 )

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

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

Definition at line 317 of file DataListenerSvc.cpp.

{
  std::set<std::string> * returnData = NULL;
  return returnData;
}
void DataListenerSvc::handle ( const Incident Inc ) [virtual]

Implementation of the IIncidentListener.h virtual method.

Definition at line 329 of file DataListenerSvc.cpp.

{

  MsgStream msg(msgSvc(),"DataListenerSvc");
  numIncidents++;


  if (numIncidents % m_EventFrequency == 0){

    try {
      Log4.open("MonitorLog.txt", std::ios::trunc);
      XMLLog.open(("./log" + stringConverter(fileCounter)  + ".xml").c_str() , std::ios::trunc);
    } catch(std::exception &/*e*/) {
      msg << MSG::INFO
          << "Log File could not be opened, no monitoring available"
          << endmsg;
    }

    if (m_MonALISAMonitoring){
      // Send Data to MonALISA
      sendData(&m_ValNamesMap);
    }

    if (m_FileMonitoring){
      // Write simple text log
      writeMap(&m_ValNamesMap, Inc, &Log4 );
      Log4.close();
    }

    if (m_XMLMonitoring){
      // Write XML files
      writeXML(&m_ValNamesMap, Inc, &XMLLog );
      XMLLog.close();
    }

    fileCounter++;
  }

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

Definition at line 323 of file DataListenerSvc.cpp.

{
  std::string returnData = "";
  return returnData;
}
StatusCode DataListenerSvc::initialize ( void   ) [virtual]

Reimplemented from Service.

Definition at line 75 of file DataListenerSvc.cpp.

{

  m_ApMonSettingsFile = defaultApMonSettingsFile;
  StatusCode sc = Service::initialize();
  MsgStream msg(msgSvc(),name());

  jobIDString = "jobID: " + stringConverter(m_MLjobID);

  if ( !sc.isSuccess() )   {
    msg << MSG::ERROR << "Failed to initialize Service base class." << endmsg;
    return StatusCode::FAILURE;
  }

  sc = service("IncidentSvc", m_incidentSvc, true);
  if (!sc.isSuccess()) {
    msg << MSG::ERROR << "Failed to access incident service." << endmsg;
    return StatusCode::FAILURE;
  }
  m_incidentSvc->addListener(this, IncidentType::EndEvent);

  if (m_MonALISAMonitoring){
    // Initialise MonALISA
    apm = new ApMon(const_cast<char*>(m_ApMonSettingsFile.c_str()));
  }

  // DEBUG info on job options specified in GAUDI
  if (m_MLEventFrequency == defaultMLFrequency) {
    msg << MSG::DEBUG
        << "Frequency to send data to MonALISA not specified, taken as the default value: "
        << defaultMLFrequency << endmsg;
  } else {
    msg << MSG::INFO
        << "Data sent to MonALISA every "
        << m_MLEventFrequency << " events" << endmsg;
  }

  if (m_MLjobID == defaultjobID){
    msg << MSG::DEBUG
        << "DataListenerSvc MonALISA Job ID not specified, taken as the default value: "
        << defaultjobID << endmsg;
  }

  if (m_MLClusterName == defaultClusterName){
    msg << MSG::DEBUG
        << "DataListenerSvc MonALISA cluster name not specified, taken as the default value: "
        << defaultClusterName << endmsg;
  }

  if (m_ApMonSettingsFile == defaultApMonSettingsFile){
    msg << MSG::DEBUG
        << "MonALISA ApMon configuration file destination not specified,  will be read from: "
        << defaultClusterName << endmsg;
  }

  if (m_EventFrequency == defaultFrequency){
    msg << MSG::INFO
        << "XML Log file frequency not specified, taken as the default value: "
        << defaultFrequency << endmsg;
  } else {
    msg << MSG::INFO
        << "Frequency XML logs are written at: "
        << m_EventFrequency << endmsg;
  }

  if (m_MonALISAMonitoring) {
    msg << MSG::INFO
        << "Data will be published to a MonALISA server"
        << endmsg;
  }

  if (m_XMLMonitoring) {
    msg << MSG::INFO
        << "Data will be written to XML log files"
        << endmsg;
  }
  if (m_FileMonitoring) {
    msg << MSG::INFO
        << "Data will be updated in a Text log file"
        << endmsg;
  }

  return StatusCode::SUCCESS;
}
std::string DataListenerSvc::resizeString ( const std::string  text,
const unsigned int  length 
) [private]

Definition at line 370 of file DataListenerSvc.cpp.

{
  std::string temp;
  unsigned int counter=0;

  do {

    if (text.length() > length) {
      temp = text.substr(0,(length-1));
    } else {
      if (counter==0) {
        temp = text;
        counter++;
      }
      temp.append(" ");
    }

  } while (temp.length() != length);

  return temp;
}
void DataListenerSvc::sendData ( ValNamesMap m_ValNamesMap ) [private]

MonALISA sender method to send Data to MonALISA server.

Definition at line 571 of file DataListenerSvc.cpp.

{

  for (m_ValNamesMapIt = m_ValNamesMap->begin();
       m_ValNamesMapIt != m_ValNamesMap->end();
       ++m_ValNamesMapIt){

    m_ValueMapTemp = m_ValNamesMapIt->second;
    keyToSend = const_cast<char*>((m_ValNamesMapIt->first).c_str());


    if (m_ValueMapTemp.get_ptrType() == ValueMap::m_double){
      apmSend(const_cast <char*>(m_MLClusterName.c_str()),
              const_cast <char*> (jobIDString.c_str()),
              keyToSend, *(double*)m_ValueMapTemp.get_ptr());
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_int){
      apmSend(const_cast <char*>(m_MLClusterName.c_str()),
              const_cast <char*> (jobIDString.c_str()),
              keyToSend, *(int*)m_ValueMapTemp.get_ptr());
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_long){
      apmSend(const_cast <char*>(m_MLClusterName.c_str()),
              const_cast <char*> (jobIDString.c_str()),
              keyToSend, *(long*)m_ValueMapTemp.get_ptr());
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_bool){
      apmSend(const_cast <char*>(m_MLClusterName.c_str()),
              const_cast <char*> (jobIDString.c_str()),
              keyToSend, *(bool*)m_ValueMapTemp.get_ptr());
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_string){
      apmSend(const_cast <char*>(m_MLClusterName.c_str()),
              const_cast <char*> (jobIDString.c_str()),
              keyToSend, const_cast <char*>((*(std::string*)m_ValueMapTemp.get_ptr()).c_str()));
    }
  }

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

Definition at line 424 of file DataListenerSvc.cpp.

{
  std::stringstream s;
  std::string temp;
  s << convertee;
  s >> temp;
  s.flush();
  return temp;
}
std::string DataListenerSvc::stringConverter ( const long  convertee ) [private]

Definition at line 414 of file DataListenerSvc.cpp.

{
  std::stringstream s;
  std::string temp;
  s << convertee;
  s >> temp;
  s.flush();
  return temp;
}
std::string DataListenerSvc::stringConverter ( const double  convertee ) [private]

Definition at line 404 of file DataListenerSvc.cpp.

{
  std::stringstream s;
  std::string temp;
  s << convertee;
  s >> temp;
  s.flush();
  return temp;
}
std::string DataListenerSvc::stringConverter ( const int  convertee ) [private]

Definition at line 394 of file DataListenerSvc.cpp.

{
  std::stringstream s;
  std::string temp;
  s << convertee;
  s >> temp;
  s.flush();
  return temp;
}
void DataListenerSvc::undeclareAll ( const IInterface owner )

Undeclare monitoring information.

Parameters:
ownerOwner identifier of the monitoring information

Definition at line 313 of file DataListenerSvc.cpp.

{
}
void DataListenerSvc::undeclareInfo ( const std::string name,
const IInterface owner 
)

Undeclare monitoring information.

Parameters:
nameMonitoring information name known to the external system
ownerOwner identifier of the monitoring information

Definition at line 308 of file DataListenerSvc.cpp.

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

Definition at line 514 of file DataListenerSvc.cpp.

{
  // prepare time ctime.h and remove trailing carriage return
  time ( &rawTime2 );
  sprintf (buffer2, "%s", ctime(&rawTime2));
  timeDate2 = buffer2;
  timeDate2.erase(timeDate2.size()-1, 1);

  // headings for the text file with spacing numbers
  std::string space = "   ";
  std::string heading0 = "Time                       "; // 27
  std::string heading1 = "No      "; // 8 chars long
  std::string heading2 = "Incident Type     "; // 18
  std::string heading3 = "Incident Source   "; // 18
  std::string heading4 = "Name            ";  // 16
  std::string heading5 = "Value               "; // 20

  *MyFile << heading0 + heading1 + heading2 + heading3 + heading4 + heading5
          << std::endl;

  for (m_ValNamesMapIt = m_ValNamesMap->begin();
       m_ValNamesMapIt != m_ValNamesMap->end();
       ++m_ValNamesMapIt){

    m_ValueMapTemp = m_ValNamesMapIt->second;

    *MyFile << timeDate2 << space

            << resizeString(stringConverter(numIncidents),8) // Counts # incidents
            << resizeString(Inc.type(),18)                 // Incident Type
            << resizeString(Inc.source(),18)               // Source of the Incident
            << resizeString(m_ValNamesMapIt->first,20);    // Variable Name

    // Check the variable type and in each case, cast accordingly
    if (m_ValueMapTemp.get_ptrType() == ValueMap::m_double){
      *MyFile << resizeString(stringConverter(*(double*)m_ValueMapTemp.get_ptr()), 12)
              << std::endl;
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_int){
      *MyFile << resizeString(stringConverter(*(int*)m_ValueMapTemp.get_ptr()), 12)
              << std::endl;
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_long){
      *MyFile << resizeString(stringConverter(*(long*)m_ValueMapTemp.get_ptr()), 12)
              << std::endl;
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_bool){
      *MyFile << resizeString(stringConverter(*(bool*)m_ValueMapTemp.get_ptr()), 12)
              << std::endl;
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_string){
      *MyFile << resizeString((*(std::string*)m_ValueMapTemp.get_ptr()), 12)
              << std::endl;
      }

      }

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

Definition at line 435 of file DataListenerSvc.cpp.

{

  MsgStream msg(msgSvc(),"DataListenerSvc");

  // prepare time ctime.h and remove trailing carriage return
  time ( &rawTime );
  sprintf (buffer, "%s", ctime(&rawTime));
  timeDate = buffer;
  timeDate.erase(timeDate.size()-1, 1);


  msg << MSG::INFO << "XML written to file: " << MyFile << endmsg;


  *MyFile << xml.declaration("1.0", "ASCII", "yes") << std::endl;

  *MyFile << xml.tagBegin("Results", 0, "Time", timeDate)
          << xml.tagBegin("Run",1);


  for (m_ValNamesMapIt = m_ValNamesMap->begin();
       m_ValNamesMapIt != m_ValNamesMap->end();
       ++m_ValNamesMapIt) {

    m_ValueMapTemp = m_ValNamesMapIt->second;

    *MyFile << xml.tagBegin("Incident",2);

    *MyFile << xml.tagBegin("IncType", 3)
            << xml.data(resizeString(Inc.type(),18))
            << xml.tagEnd("IncType", 0);

    *MyFile << xml.tagBegin("IncSource", 3)
            << xml.data(resizeString(Inc.source(),18))
            << xml.tagEnd("IncSource", 0);

    *MyFile << xml.tagBegin("VarName", 3)
            << xml.data(resizeString(m_ValNamesMapIt->first,20))
            << xml.tagEnd("VarName", 0);

    *MyFile << xml.tagBegin("Value", 3, "Result", stringConverter(numIncidents));
    // Check the variable type and in each case, cast accordingly



    // re-convert pointers to their original form and then to strings
    // so that they can be written with XMLCode.h
    if (m_ValueMapTemp.get_ptrType() == ValueMap::m_double){
      valToWrite = stringConverter(*(double*)m_ValueMapTemp.get_ptr());
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_int){
      valToWrite = stringConverter(*(int*)m_ValueMapTemp.get_ptr());
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_long){
      valToWrite = stringConverter(*(long*)m_ValueMapTemp.get_ptr());
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_bool){
      valToWrite = stringConverter(*(bool*)m_ValueMapTemp.get_ptr());
    } else if (m_ValueMapTemp.get_ptrType() == ValueMap::m_string){
      valToWrite = *(std::string*)m_ValueMapTemp.get_ptr();
    }


    *MyFile << xml.data(valToWrite);
    msg << MSG::DEBUG << "XML written: " << m_ValNamesMapIt->first << " , "
        << valToWrite << endmsg;

    *MyFile << xml.tagEnd("Value", 0);
    *MyFile << xml.tagEnd("Incident",2);
  }


  *MyFile << xml.tagEnd("Run",1)
          << xml.tagEnd("Results", 0);

}

Member Data Documentation

Definition at line 195 of file DataListenerSvc.h.

char DataListenerSvc::buffer[50] [private]

Definition at line 205 of file DataListenerSvc.h.

char DataListenerSvc::buffer2[50] [private]

Definition at line 206 of file DataListenerSvc.h.

Definition at line 246 of file DataListenerSvc.h.

Definition at line 265 of file DataListenerSvc.h.

char* DataListenerSvc::keyToSend [private]

Definition at line 271 of file DataListenerSvc.h.

Definition at line 242 of file DataListenerSvc.h.

Definition at line 264 of file DataListenerSvc.h.

Definition at line 247 of file DataListenerSvc.h.

Definition at line 268 of file DataListenerSvc.h.

Definition at line 240 of file DataListenerSvc.h.

Definition at line 257 of file DataListenerSvc.h.

Definition at line 230 of file DataListenerSvc.h.

Definition at line 231 of file DataListenerSvc.h.

Definition at line 263 of file DataListenerSvc.h.

Definition at line 262 of file DataListenerSvc.h.

Definition at line 261 of file DataListenerSvc.h.

Definition at line 266 of file DataListenerSvc.h.

Definition at line 233 of file DataListenerSvc.h.

Definition at line 234 of file DataListenerSvc.h.

Definition at line 199 of file DataListenerSvc.h.

Definition at line 200 of file DataListenerSvc.h.

Definition at line 267 of file DataListenerSvc.h.

Definition at line 241 of file DataListenerSvc.h.

Definition at line 202 of file DataListenerSvc.h.

Definition at line 203 of file DataListenerSvc.h.

Definition at line 207 of file DataListenerSvc.h.

Definition at line 208 of file DataListenerSvc.h.

Definition at line 209 of file DataListenerSvc.h.

Definition at line 235 of file DataListenerSvc.h.

Definition at line 243 of file DataListenerSvc.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Fri Sep 2 2011 16:25:16 for Gaudi Framework, version v22r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004