| # Gaudi Framework, version v20r3
Generated: 24 Nov 2008

# DataListenerSvc.h

Go to the documentation of this file.

    00001 #ifndef GAUDIKERNEL_DATALISTENERSVC_H
    00002 #define GAUDIKERNEL_DATALISTENERSVC_H
    00003
    00004
    00005 #include "GaudiKernel/Service.h"
    00006 #include "GaudiKernel/IIncidentSvc.h"
    00007 #include "GaudiKernel/IMonitorSvc.h"
    00008 #include "GaudiKernel/IIncidentListener.h"
    00009 #include "ValueMap.h"
    00010 #include "XmlCode.h"
    00011 #include "ApMon.h"
    00012 #include <iostream>
    00013 #include <fstream>
    00014 #include <ctime>
    00015 #include <string>
    00016 #include <map>
    00017 #include <set>
    00018
    00019
    00020 #include <stdio.h>
    00021
    00022
    00023 // Forward declarations
    00024 class ISvcLocator;
    00025
    00112 class DataListenerSvc : public Service,
    00113                         virtual public IMonitorSvc,
    00114                         virtual public IIncidentListener {
    00115 public:
    00116   DataListenerSvc(const std::string& name, ISvcLocator* sl);
    00117
    00118
    00119   virtual ~DataListenerSvc() {}
    00120
    00121   //IInterface pure virtual member functions
    00122   StatusCode queryInterface(const InterfaceID& riid, void** ppvIF);
    00123   // Service pure virtual member functions
    00124   StatusCode initialize();
    00125   StatusCode finalize();
    00126
    00134   void declareInfo(const std::string& name, const bool&  var,
    00135                    const std::string& desc, const IInterface* owner) ;
    00136   void declareInfo(const std::string& name, const int&  var,
    00137                    const std::string& desc, const IInterface* owner) ;
    00138   void declareInfo(const std::string& name, const long&  var,
    00139                    const std::string& desc, const IInterface* owner) ;
    00140   void declareInfo(const std::string& name, const double& var,
    00141                    const std::string& desc, const IInterface* owner) ;
    00142   void declareInfo(const std::string& name, const std::string& var,
    00143                    const std::string& desc, const IInterface* owner) ;
    00144   void declareInfo(const std::string& name, const std::pair<double,double>&var,
    00145                    const std::string& desc, const IInterface* owner) ;
    00146   void declareInfo(const std::string& name, const AIDA::IBaseHistogram* var,
    00147                    const std::string& desc, const IInterface* owner) ;
    00148   void declareInfo(const std::string& name, const std::string& format,
    00149                    const void * var, int size, const std::string& desc,
    00150                    const IInterface* owner) ;
    00151
    00152   // Declaration of declareProperty which is virtual in one of my includes
    00153   // (that would be service.h)
    00154   //  StatusCode declareProperty(const std::string& name, const int& var);
    00155
    00156
    00161   void undeclareInfo( const std::string& name, const IInterface* owner ) ;
    00162
    00166   void undeclareAll( const IInterface* owner ) ;
    00167
    00169   virtual void handle(const Incident&);
    00170
    00171
    00175   std::set<std::string> * getInfos(const IInterface* owner = 0);
    00176
    00177
    00184
    00185   void apmSend(char* clusterName, char* moduleName, char* key, double val);
    00187   void apmSend(char* clusterName, char* moduleName, char* key, int val);
    00189   void apmSend(char* clusterName, char* moduleName, char* key, long val);
    00191   void apmSend(char* clusterName, char* moduleName, char* key, bool val);
    00193   void apmSend(char* clusterName, char* moduleName, char* key, char* val);
    00194
    00195 private:
    00196
    00197
    00198   ApMon *apm;
    00199
    00200
    00201   // ValueMap stores declared data information
    00202   ValueMap m_ValueMap;
    00203   ValueMap m_ValueMapTemp;
    00204
    00205   time_t rawTime;
    00206   time_t rawTime2;
    00207
    00208   char buffer[50];
    00209   char buffer2[50];
    00210   std::string timeDate;
    00211   std::string timeDate2;
    00212   std::string valToWrite;
    00213
    00214
    00215   // Used to hold variable name and data information
    00216   typedef std::pair< std::string, ValueMap > Entry;
    00217   typedef std::map<const IInterface*, std::set<std::string> > InfoNamesMap;
    00218
    00219   typedef std::map< std::string, ValueMap > ValNamesMap;
    00220
    00221   void writeMap(ValNamesMap*, const Incident&, std::ofstream*);
    00222   void writeXML(ValNamesMap*, const Incident&, std::ofstream*);
    00223   std::string resizeString ( const std::string, const unsigned int );
    00224
    00225   // Converts types INTO a string with a stringstream
    00226   std::string stringConverter ( const int convertee );
    00227   std::string stringConverter ( const double convertee );
    00228   std::string stringConverter ( const bool convertee );
    00229   std::string stringConverter ( const long convertee );
    00230
    00231
    00232
    00233   InfoNamesMap m_InfoNamesMap;
    00234   InfoNamesMap::iterator m_InfoNamesMapIt;
    00235
    00236   ValNamesMap m_ValNamesMap;
    00237   ValNamesMap::iterator m_ValNamesMapIt;
    00238   XmlCode xml;
    00239
    00240
    00241   // Map associating to each algorithm name a set with the info
    00242   // names from this algorithm
    00243   IIncidentSvc* m_incidentSvc;
    00244   FILE* MonitorLog;
    00245   std::ofstream Log4;
    00246   std::ofstream XMLLog;
    00247
    00248
    00249   int FreqCriterion;
    00250   int m_EventFrequency;
    00251
    00252
    00254   void sendData(ValNamesMap*);
    00255
    00256   // The container below is necessary because usually the descriptions of
    00257   // the services are constant strings, not variables. DimService expects
    00258   // a variable address to monitor as its second argument and we are using
    00259   // a DimService for strings to publish the descriptions.
    00260   std::map<std::string,std::string> m_infoDescriptions;
    00261   std::string infoOwnerName( const IInterface* owner );
    00262
    00263   // MonALISA optionsfile variables
    00264   int m_MLjobID;
    00265   int m_MLEventFrequency;
    00266   std::string m_MLClusterName;
    00267   std::string m_ApMonSettingsFile;
    00268   std::string jobIDString;
    00269   int m_MonALISAMonitoring;
    00270   int m_XMLMonitoring;
    00271   int m_FileMonitoring;
    00272
    00273
    00274   char *keyToSend;
    00275
    00276
    00277 };
    00278
    00279 #endif // GAUDIKERNEL_DATALISTENERSVC_H