| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

StatsServerAlg Class Reference

#include <StatsServerAlg.h>

Inheritance diagram for StatsServerAlg:

[legend]
Collaboration diagram for StatsServerAlg:
[legend]
List of all members.

Public Member Functions

 StatsServerAlg (const std::string &name, ISvcLocator *pSvcLocator)
virtual ~StatsServerAlg ()
virtual StatusCode initialize ()
virtual StatusCode execute ()
virtual StatusCode finalize ()
virtual StatusCode sysExecute ()
void put (IDataProviderSvc *svc, DataObject *object, const std::string &address, const bool useRootInTES=true) const
void put (DataObject *object, const std::string &address, const bool useRootInTES=true) const
Gaudi::Utils::GetData< TYPE
>::return_type 
get (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Gaudi::Utils::GetData< TYPE
>::return_type 
get (const std::string &location, const bool useRootInTES=true) const
TYPE * getDet (IDataProviderSvc *svc, const std::string &location) const
TYPE * getDet (const std::string &location) const
bool exist (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
bool exist (const std::string &location, const bool useRootInTES=true) const
bool existDet (IDataProviderSvc *svc, const std::string &location) const
bool existDet (const std::string &location) const
TYPE * getOrCreate (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
TYPE * getOrCreate (const std::string &location, const bool useRootInTES=true) const
bool registerContext () const
INTupleSvcevtColSvc () const
IAlgContextSvccontextSvc () const
TOOL * tool (const std::string &type, const std::string &name, const IInterface *parent=0, bool create=true) const
TOOL * tool (const std::string &type, const IInterface *parent=0, bool create=true) const
SERVICE * svc (const std::string &name, const bool create=true) const
IUpdateManagerSvcupdMgrSvc () const
IDataProviderSvcfastContainersSvc () const
StatusCode Error (const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
StatusCode Warning (const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
StatusCode Print (const std::string &msg, const StatusCode st=StatusCode::SUCCESS, const MSG::Level lev=MSG::INFO) const
StatusCode Assert (const bool ok, const std::string &message="", const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Assert (const bool ok, const char *message, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Exception (const std::string &msg, const GaudiException &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Exception (const std::string &msg, const std::exception &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Exception (const std::string &msg="no message", const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
MsgStreammsgStream (const MSG::Level level) const
MsgStreamalways () const
MsgStreamfatal () const
MsgStreamerr () const
MsgStreamerror () const
MsgStreamwarning () const
MsgStreaminfo () const
MsgStreamdebug () const
MsgStreamverbose () const
MsgStreammsg () const
const Statisticscounters () const
StatEntitycounter (const std::string &tag) const
MSG::Level msgLevel () const
bool msgLevel (const MSG::Level level) const
void resetMsgStream () const
bool typePrint () const
bool propsPrint () const
bool statPrint () const
bool errorsPrint () const
long printStat (const MSG::Level level=MSG::ALWAYS) const
long printErrors (const MSG::Level level=MSG::ALWAYS) const
long printProps (const MSG::Level level=MSG::ALWAYS) const
void registerCondition (const std::string &condition, StatusCode(CallerClass::*mf)()=NULL)
void registerCondition (const std::string &condition, CondType *&condPtrDest, StatusCode(CallerClass::*mf)()=NULL)
void registerCondition (char *condition, StatusCode(CallerClass::*mf)()=NULL)
void registerCondition (TargetClass *condition, StatusCode(CallerClass::*mf)()=NULL)
StatusCode runUpdate ()
TransientFastContainer< T > * getFastContainer (const std::string &location, typename TransientFastContainer< T >::size_type initial=0)
StatusCode release (const IInterface *interface) const
unsigned long release ()
const std::string & context () const
const std::string & rootInTES () const
double globalTimeOffset () const
virtual StatusCode sysStart ()
virtual StatusCode sysInitialize ()
virtual StatusCode sysReinitialize ()
virtual StatusCode sysRestart ()
virtual StatusCode sysStop ()
virtual StatusCode sysFinalize ()
virtual StatusCode sysBeginRun ()
virtual StatusCode sysEndRun ()
virtual const std::string & name () const
virtual const std::string & version () const
virtual StatusCode configure ()
virtual StatusCode terminate ()
virtual StatusCode start ()
virtual StatusCode stop ()
virtual StatusCode reinitialize ()
virtual StatusCode restart ()
virtual bool isExecuted () const
virtual void setExecuted (bool state)
virtual void resetExecuted ()
virtual StatusCode beginRun ()
virtual StatusCode endRun ()
virtual Gaudi::StateMachine::State FSMState () const
virtual Gaudi::StateMachine::State targetFSMState () const
virtual bool isEnabled () const
virtual bool filterPassed () const
virtual void setFilterPassed (bool state)
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
void setOutputLevel (int level)
IAuditorSvcauditorSvc () const
IChronoStatSvcchronoSvc () const
IChronoStatSvcchronoStatService () const
IDataProviderSvcdetSvc () const
IDataProviderSvcdetDataService () const
IConversionSvcdetCnvSvc () const
IConversionSvcdetDataCnvService () const
IDataProviderSvceventSvc () const
IDataProviderSvcevtSvc () const
IDataProviderSvceventDataService () const
IConversionSvceventCnvSvc () const
IConversionSvceventDataCnvService () const
IHistogramSvchistoSvc () const
IHistogramSvchistogramDataService () const
IMessageSvcmsgSvc () const
IMessageSvcmessageService () const
INTupleSvcntupleSvc () const
INTupleSvcntupleService () const
IRndmGenSvcrandSvc () const
IToolSvctoolSvc () const
IExceptionSvcexceptionSvc () const
ISvcLocatorserviceLocator () const
ISvcLocatorsvcLoc () const
StatusCode createSubAlgorithm (const std::string &type, const std::string &name, Algorithm *&pSubAlg)
std::vector< Algorithm * > * subAlgorithms () const
virtual StatusCode setProperty (const Property &p)
virtual StatusCode setProperty (const std::string &s)
virtual StatusCode setProperty (const std::string &n, const std::string &v)
StatusCode setProperty (const std::string &name, const TYPE &value)
virtual StatusCode getProperty (Property *p) const
virtual const PropertygetProperty (const std::string &name) const
virtual StatusCode getProperty (const std::string &n, std::string &v) const
virtual const std::vector<
Property * > & 
getProperties () const
StatusCode setProperties ()
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
IMonitorSvcmonitorSvc () const
void declareInfo (const std::string &name, const T &var, const std::string &desc) const
void declareInfo (const std::string &name, const std::string &format, const void *var, int size, const std::string &desc) const
unsigned long addRef ()
StatusCode queryInterface (const InterfaceID &riid, void **)

Static Public Member Functions

static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()

Public Attributes

 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR

Protected Types

typedef std::map< std::string,
StatEntity
Statistics
typedef std::map< std::string,
unsigned int > 
Counter
typedef std::vector< IAlgTool * > AlgTools
typedef std::pair< IInterface *,
std::string > 
ServiceEntry
typedef std::vector< ServiceEntryServices

Protected Member Functions

StatusCode releaseTool (const IAlgTool *tool) const
StatusCode releaseSvc (const IInterface *svc) const
bool isInitialized () const
bool isFinalized () const
int outputLevel () const
IntegerPropertyoutputLevelProperty ()
void initOutputLevel (Property &prop)

Static Protected Attributes

static const bool IgnoreRootInTES
static const bool UseRootInTES

Private Member Functions

StatusCode startServer ()
StatusCode stopServer ()
StatusCode processRequests ()

Private Attributes

int m_processInterval
int m_portNumber
IStatisticsSvcm_statsSvc
TServerSocket * m_server
TMonitor * m_monitor
TList * m_clients

Detailed Description

Definition at line 23 of file StatsServerAlg.h.


Constructor & Destructor Documentation

StatsServerAlg::StatsServerAlg ( const std::string &  name,
ISvcLocator pSvcLocator 
)

Definition at line 13 of file StatsServerAlg.cc.

00015   : GaudiAlgorithm(name,pSvcLocator),
00016     m_statsSvc(0),
00017     m_server(0),
00018     m_monitor(0),
00019     m_clients(0)
00020 {
00021   declareProperty("ProcessInterval",
00022                   m_processInterval=1,
00023                   "Interval for processing requests to server");
00024   declareProperty("PortNumber",
00025                   m_portNumber=9090,
00026                   "Port Number for server");
00027 }

StatsServerAlg::~StatsServerAlg (  )  [virtual]

Definition at line 29 of file StatsServerAlg.cc.

00030 {
00031 }


Member Function Documentation

StatusCode StatsServerAlg::initialize (  )  [virtual]

Reimplemented from GaudiAlgorithm.

Definition at line 33 of file StatsServerAlg.cc.

00034 {
00035   // Initialize the necessary services
00036   StatusCode sc = this->service("StatisticsSvc",m_statsSvc,true);
00037   if(sc.isFailure()){
00038     error() << "Failed to get StatisticsSvc" << endreq;
00039     return sc;
00040   }
00041 
00042   // Start the server
00043   sc = startServer();
00044   return sc;
00045 }

StatusCode StatsServerAlg::execute (  )  [virtual]

Reimplemented from GaudiAlgorithm.

Definition at line 47 of file StatsServerAlg.cc.

00048 {
00049   static int currentCycle = 0;
00050   currentCycle += 1;
00051   StatusCode sc = StatusCode::SUCCESS;
00052   // Process server requests every 'n' event cycles
00053   if( currentCycle % m_processInterval == 0 ){
00054     info() << "Processing requests to server" << endreq;
00055     sc = processRequests();
00056   }
00057   return StatusCode::SUCCESS;
00058 }

StatusCode StatsServerAlg::finalize (  )  [virtual]

Reimplemented from GaudiAlgorithm.

Definition at line 60 of file StatsServerAlg.cc.

00061 {
00062   if( m_statsSvc ) m_statsSvc->release();
00063   StatusCode sc = stopServer();
00064   return sc;
00065 }

StatusCode StatsServerAlg::startServer (  )  [private]

Definition at line 69 of file StatsServerAlg.cc.

00069                                       {
00070   // Start the Server
00071 
00072   m_server = new TServerSocket(m_portNumber, kTRUE);
00073   if (!m_server->IsValid()){
00074     error() << "Failed to start server on port " << m_portNumber << endreq;
00075     return StatusCode::FAILURE;
00076   }
00077   m_monitor = new TMonitor;
00078   m_monitor->Add( m_server );
00079   m_clients = new TList;
00080   
00081   return StatusCode::SUCCESS;
00082 }

StatusCode StatsServerAlg::stopServer (  )  [private]

Definition at line 84 of file StatsServerAlg.cc.

00084                                      {
00085   // Stop the Server
00086   m_clients->Delete();
00087   delete m_clients;
00088   delete m_server;
00089   delete m_monitor;
00090   return StatusCode::SUCCESS;
00091 }

StatusCode StatsServerAlg::processRequests (  )  [private]

Definition at line 93 of file StatsServerAlg.cc.

00093                                           {
00094   // Process any requests from clients
00095   int timeout = 20; // timeout if no requests after 20ms 
00096   TSocket* s = m_monitor->Select(timeout);
00097   if( !s ){
00098     error() << "Failure in client socket monitor." << endreq;
00099     return StatusCode::FAILURE;
00100   }
00101   if( s == (TSocket*)-1 ){
00102     // No pending requests before timeout
00103     return StatusCode::SUCCESS;
00104   }
00105 
00106   // Found a request
00107   if( s->IsA() == TServerSocket::Class() ){
00108     // New connection
00109     TSocket* sock = ((TServerSocket*)s)->Accept();
00110     m_monitor->Add(sock);
00111     m_clients->Add(sock);
00112     info() << "Accepted connection from client: " 
00113            << sock->GetInetAddress().GetHostName() << endreq;
00114     return StatusCode::SUCCESS;
00115   }
00116 
00117   // Request for statistics service
00118   char request[1024];
00119   if (s->Recv(request, sizeof(request)) <= 0) {
00120     // Closing connection
00121     m_monitor->Remove(s);
00122     m_clients->Remove(s);
00123     info() << "Closed connection from client: " 
00124            << s->GetInetAddress().GetHostName() << endreq;
00125     delete s;
00126     return StatusCode::SUCCESS;
00127   }
00128 
00129   info() << "Received request: " << request << endreq;
00130 
00131   // Respond to actual request (white-space separated list of paths)
00132   // Return a TMap of path/result pairs
00133   
00134   TMap itemMap;
00135   TList cleanupList;
00136   cleanupList.SetOwner();
00137   TObjString* nullObject = new TObjString("NULL");
00138   cleanupList.Add( nullObject );
00139 
00140   TString reqStr( request );
00141   TObjArray* paths = reqStr.Tokenize( " " );
00142   info() << "Number of requested paths: " << paths->GetEntriesFast() << endreq;
00143   for(int pathIdx=0; pathIdx<paths->GetEntriesFast(); pathIdx++){
00144 
00145     TObjString* path = new TObjString( *(dynamic_cast<TObjString*>(paths->At(pathIdx))));
00146     cleanupList.Add( path );
00147     std::string pathStr( path->GetName() );
00148     info() << "Retrieving path: \"" << pathStr << "\"" << endreq;
00149 
00150     // Check if path exists
00151     if(! m_statsSvc->exists( pathStr ) ){
00152       warning() << "Request for invalid path: " << pathStr << endreq;
00153       itemMap.Add( path, nullObject );
00154       continue;
00155     }
00156 
00157     // Check if path has an object
00158     TObject* object = m_statsSvc->get( pathStr );
00159     if( object ){
00160       info() << "Found object at path: " << pathStr << endreq;
00161       itemMap.Add( path, object );
00162       continue;
00163     }
00164 
00165     // Path is not an object, must be a directory
00166     std::vector<std::string> subFolds = m_statsSvc->getSubFolders( pathStr );
00167     TList* subFolders = new TList();
00168     subFolders->SetName("subFolders");
00169     subFolders->SetOwner();
00170     for(size_t idx=0; idx<subFolds.size(); idx++){
00171       subFolders->Add( new TObjString( subFolds[idx].c_str() ) );
00172     }
00173 
00174     std::vector<std::string> conts = m_statsSvc->getContents( pathStr );
00175     TList* contents = new TList();
00176     contents->SetName("contents");
00177     contents->SetOwner();
00178     for(size_t idx=0; idx<conts.size(); idx++){
00179       contents->Add( new TObjString( conts[idx].c_str() ) );
00180     }
00181 
00182     TMap* directory = new TMap();
00183     directory->SetName("directory");
00184     directory->SetOwner();
00185     directory->Add(new TObjString("subFolders"),subFolders);
00186     directory->Add(new TObjString("contents"),contents);
00187     itemMap.Add( path, directory );
00188     cleanupList.Add( directory );
00189   }
00190   delete paths;
00191 
00192   // Send requested items to client
00193   TMessage answer(kMESS_OBJECT);
00194   answer.WriteObject( &itemMap );
00195   s->Send(answer);
00196 
00197   cleanupList.Delete();
00198 
00199   return StatusCode::SUCCESS;
00200 }


Member Data Documentation

int StatsServerAlg::m_processInterval [private]

Definition at line 43 of file StatsServerAlg.h.

int StatsServerAlg::m_portNumber [private]

Definition at line 46 of file StatsServerAlg.h.

IStatisticsSvc* StatsServerAlg::m_statsSvc [private]

Definition at line 49 of file StatsServerAlg.h.

TServerSocket* StatsServerAlg::m_server [private]

Definition at line 52 of file StatsServerAlg.h.

TMonitor* StatsServerAlg::m_monitor [private]

Definition at line 55 of file StatsServerAlg.h.

TList* StatsServerAlg::m_clients [private]

Definition at line 58 of file StatsServerAlg.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:10:02 2011 for StatisticsSvc by doxygen 1.4.7