Commit a355e62c authored by Werner Wiedenmann's avatar Werner Wiedenmann Committed by Graeme Stewart
Browse files

update for changed IROBDataProviderSvc interface (TrigDataAccessMonitoring-00-02-00)

parent 993a3568
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRIGDATAACCESSMONITORING_MONROBDATAPROVIDERSVC_H
#define TRIGDATAACCESSMONITORING_MONROBDATAPROVIDERSVC_H
/** ===============================================================
* MonROBDataProviderSvc.h
* ===============================================================
* Description: MonROBDataProviderSvc class for enabling the online
* ROB monitoring infrastructure with the offline
* ROBDataProviderSvc
*
* Created: Sep. 1 2009
* By: Werner Wiedenmann
*/
#include "GaudiKernel/Service.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/StatusCode.h"
#include "GaudiKernel/IIncidentListener.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/ServiceHandle.h"
#include "GaudiKernel/HistoProperty.h"
#include "ByteStreamCnvSvcBase/ROBDataProviderSvc.h"
#include "ByteStreamData/RawEvent.h"
#include "TrigDataAccessMonitoring/ROBDataMonitor.h"
#include "eformat/Status.h"
#include <vector>
#include <map>
// Forward declarations
class StoreGateSvc;
class IAlgContextSvc;
class TH1F; /// for monitoring purposes
class TH2F; /// for monitoring purposes
class MonROBDataProviderSvc : public ROBDataProviderSvc,
virtual public IIncidentListener
{
public:
typedef OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment ROBF ;
MonROBDataProviderSvc(const std::string& name, ISvcLocator* svcloc);
virtual ~MonROBDataProviderSvc(void);
virtual StatusCode initialize();
virtual StatusCode finalize();
virtual StatusCode queryInterface( const InterfaceID& riid, void** ppvInterface );
/// --- Implementation of IROBDataProviderSvc interface ---
/// Add ROBFragments to cache for given ROB ids, ROB fragments may be retrieved with DataCollector
virtual void addROBData(const std::vector<uint32_t>& robIds,
const std::string callerName="UNKNOWN");
/// Add a given LVL1/LVL2 ROBFragment to cache
virtual void setNextEvent(const std::vector<ROBF>& result);
/// Add all ROBFragments of a RawEvent to cache
virtual void setNextEvent(const RawEvent* re);
/// Retrieve ROBFragments for given ROB ids from cache
virtual void getROBData(const std::vector<uint32_t>& robIds,
std::vector<const ROBF*>& robFragments,
const std::string callerName="UNKNOWN");
/// Retrieve the whole event.
virtual const RawEvent* getEvent() ;
/// --- Implementation of IIncidentListener interface ---
// handler for BeginRun actions
void handle(const Incident& incident);
protected:
/**
* @brief Accessor method for the MsgStream.
* @return handle to the MsgStream.
*/
inline MsgStream& logStream() const { return *m_msg; }
/**
* @brief Accessor method for the message level variable.
* @return value of the message level for this algorithm.
*/
inline MSG::Level logLevel() const { return (m_msg != 0) ? m_msg->level() : MSG::NIL; }
private:
typedef ServiceHandle<StoreGateSvc> StoreGateSvc_t;
/// Reference to StoreGateSvc;
StoreGateSvc_t m_storeGateSvc;
/// Pointer to AlgContextSvc
IAlgContextSvc* m_algContextSvc;
/** @brief Pointer to MsgStream.*/
MsgStream* m_msg;
// monitoring
std::map<eformat::GenericStatus, std::string> m_map_GenericStatus;
std::vector<std::string> m_vec_SpecificStatus;
std::vector<uint32_t> m_robAlreadyAccessed;
BooleanProperty m_doMonitoring;
BooleanProperty m_doDetailedROBMonitoring;
StringProperty m_ROBDataMonitorCollection_SG_Name;
Histo1DProperty m_histProp_requestedROBsPerCall;
Histo1DProperty m_histProp_receivedROBsPerCall;
Histo1DProperty m_histProp_timeROBretrieval;
TH1F* m_hist_requestedROBsPerCall;
TH1F* m_hist_receivedROBsPerCall;
TH1F* m_hist_timeROBretrieval;
TH2F* m_hist_genericStatusForROB;
TH2F* m_hist_specificStatusForROB;
};
#endif
//Dear emacs, this is -*- c++ -*-
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ROBDATAMONITOR_H
#define ROBDATAMONITOR_H
#include "eformat/SourceIdentifier.h"
#include <sys/time.h>
#include <map>
#include <iostream>
#include <iomanip>
#include "DataModel/DataVector.h"
#include "CLIDSvc/CLASS_DEF.h"
namespace robmonitor {
/**
* A structure with data about ROB properties
*/
enum ROBHistory {
UNCLASSIFIED = 0, // ROB was requested but never arrived at processor. History unknown.
RETRIEVED = 1, // ROB was retrieved from ROS by DataCollector
CACHED = 2, // ROB was found already in the internal cache of the ROBDataProviderSvc
IGNORED = 4, // ROB was on the "ignore" list and therefore not retrieved
DISABLED = 8, // ROB was disabled in OKS and therefore not retrieved
NUM_ROBHIST_CODES = 5 // number of different history codes
};
/**
* A structure with data about ROB properties
*/
class ROBDataStruct {
public:
/** @brief default constructor */
ROBDataStruct();
/** @brief constructor
@param ROB Source ID
*/
ROBDataStruct(const uint32_t);
// data variables
uint32_t rob_id; // rob source id
uint32_t rob_size; // size of rob in words
robmonitor::ROBHistory rob_history; // History of ROB retrieval
std::vector<uint32_t> rob_status_words; // all status words in the ROB header
// Accessor functions
/** @brief ROB is unclassified */
bool isUnclassified();
/** @brief ROB was found in cache */
bool isCached();
/** @brief ROB was retrieved over network */
bool isRetrieved();
/** @brief ROB was ignored */
bool isIgnored();
/** @brief ROB was disabled in OKS */
bool isDisabled();
/** @brief ROB has no status words set */
bool isStatusOk();
// Extraction operators
friend std::ostream& operator<<(std::ostream& os, const robmonitor::ROBDataStruct& rhs);
};
/**
* The structure which is used to monitor the ROB data request in L2
* It is created for every addROBData call
*/
class ROBDataMonitorStruct {
public:
/** @brief default constructor */
ROBDataMonitorStruct();
/** @brief constructor
@param L1 ID
@param requestor name
*/
ROBDataMonitorStruct(const uint32_t, const std::string);
/** @brief constructor
@param L1 ID
@param vector of ROB Ids
@param requestor name
*/
ROBDataMonitorStruct(const uint32_t, const std::vector<uint32_t>&, const std::string);
// data variables
uint32_t lvl1ID; //current L1 ID from L1 ROBs
std::string requestor_name; //name of requesting algorithm
std::map<const uint32_t,robmonitor::ROBDataStruct> requested_ROBs; //map of ROBs requested
struct timeval start_time_of_ROB_request; //start time of ROB request
struct timeval end_time_of_ROB_request; //stop time of ROB request
// Accessor functions to ROB history summaries
/** @brief number of ROBs in structure */
unsigned allROBs();
/** @brief number of unclassified ROBs in structure */
unsigned unclassifiedROBs();
/** @brief number of cached ROBs in structure */
unsigned cachedROBs();
/** @brief number of retrieved ROBs in structure */
unsigned retrievedROBs();
/** @brief number of ignored ROBs in structure */
unsigned ignoredROBs();
/** @brief number of disabled ROBs in structure */
unsigned disabledROBs();
/** @brief number of ROBs with no status words set in structure */
unsigned statusOkROBs();
/** @brief elapsed time for ROB request in [ms] */
float elapsedTime();
// Extraction operators
friend std::ostream& operator<<(std::ostream& os, robmonitor::ROBDataMonitorStruct& rhs);
};
// Extraction operator for ROBDataStruct
inline std::ostream& operator<<(std::ostream& os, const robmonitor::ROBDataStruct& rhs) {
os << "[SourceID,Size(words),History,(Status words)]=["
<< std::hex << std::setfill( '0' ) << "0x" << std::setw(6) << rhs.rob_id
<< std::dec << std::setfill(' ')
<< "," << std::setw(8) << rhs.rob_size;
os << "," << std::setw(12);
if (rhs.rob_history == robmonitor::UNCLASSIFIED) {
os << "UNCLASSIFIED";
} else if (rhs.rob_history == robmonitor::RETRIEVED) {
os << "RETRIEVED";
} else if (rhs.rob_history == robmonitor::CACHED) {
os << "CACHED";
} else if (rhs.rob_history == robmonitor::IGNORED) {
os << "IGNORED";
} else if (rhs.rob_history == robmonitor::DISABLED) {
os << "DISABLED";
} else {
os << "invalid code";
}
os << ",(";
for (uint32_t i(0); i < rhs.rob_status_words.size(); ++i) {
if (i > 0) os << ",";
os << std::hex << std::setfill( '0' ) << "0x" << std::setw(8) << rhs.rob_status_words[i];
}
os << ")]";
return os;
}
// Extraction operator for ROBDataMonitorStruct
inline std::ostream& operator<<(std::ostream& os, robmonitor::ROBDataMonitorStruct& rhs) {
std::string prefix(" ");
std::string prefix2("-> ");
os << "ROB Request for L1 ID = " << std::dec << rhs.lvl1ID << " (decimal), L1 ID = 0x"
<< std::hex << rhs.lvl1ID << " (hex)" << std::dec;
os << "\n" << prefix << "Requestor name = " << rhs.requestor_name;
std::string s_time(ctime(&(rhs.start_time_of_ROB_request.tv_sec)));
os << "\n" << prefix << "Start time of ROB request = "
<< s_time.substr(0,s_time.size()-1)
<< " + " << static_cast<float>(rhs.start_time_of_ROB_request.tv_usec)/1000 << " [ms]";
std::string e_time(ctime(&(rhs.end_time_of_ROB_request.tv_sec)));
os << "\n" << prefix << "Stop time of ROB request = "
<< e_time.substr(0,e_time.size()-1)
<< " + " << static_cast<float>(rhs.end_time_of_ROB_request.tv_usec)/1000 << " [ms]";
os << "\n" << prefix << "Elapsed time for ROB request [ms] = " << rhs.elapsedTime();
os << "\n" << prefix << "Requested ROBs:";
os << "\n" << prefix << prefix2 << "All " << rhs.allROBs() ;
os << "\n" << prefix << prefix2 << "Unclassified " << rhs.unclassifiedROBs() ;
os << "\n" << prefix << prefix2 << "Cached " << rhs.cachedROBs() ;
os << "\n" << prefix << prefix2 << "Retrieved " << rhs.retrievedROBs() ;
os << "\n" << prefix << prefix2 << "Ignored " << rhs.ignoredROBs() ;
os << "\n" << prefix << prefix2 << "Disabled " << rhs.disabledROBs() ;
os << "\n" << prefix << prefix2 << "Status OK " << rhs.statusOkROBs() ;
for (std::map<const uint32_t,robmonitor::ROBDataStruct>::iterator it=rhs.requested_ROBs.begin();
it != rhs.requested_ROBs.end(); ++it) {
os << "\n" << prefix << prefix2 << (*it).second;
}
return os;
}
} // end namespace robmonitor
typedef DataVector<robmonitor::ROBDataMonitorStruct> ROBDataMonitorCollection;
CLASS_DEF( ROBDataMonitorCollection , 1303465505 , 1 )
#endif /* ROBDATAMONITOR_H */
package TrigDataAccessMonitoring
author Werner Wiedenmann <Werner.Wiedenmann@cern.ch>
use AtlasPolicy AtlasPolicy-*
use DataModel DataModel-* Control
use CLIDSvc CLIDSvc-* Control
use DataCollection DataCollection-* External
use GaudiInterface GaudiInterface-* External
use ByteStreamCnvSvcBase ByteStreamCnvSvcBase-* Event
use ByteStreamData ByteStreamData-* Event
private
use AtlasROOT AtlasROOT-* External
use StoreGate StoreGate-* Control
end_private
apply_pattern dual_use_library files="*.cxx"
apply_pattern declare_joboptions files="*.py"
private
use TestTools TestTools-* AtlasTest
apply_pattern UnitTest_run unit_test=Methods extrapatterns=".*"
ROBDataMonitorStruct req =
ROB Request for L1 ID = 12345 (decimal), L1 ID = 0x3039 (hex)
Requestor name = MyAlgorithm
Start time of ROB request = Mon Mar 16 10:39:57 2009 + 377.134 [ms]
Stop time of ROB request = Mon Mar 16 10:39:57 2009 + 377.135 [ms]
Elapsed time for ROB request [ms] = 0.001
Requested ROBs:
-> All 10
-> Unclassified 1
-> Cached 4
-> Retrieved 2
-> Ignored 2
-> Disabled 1
-> Status OK 7
-> [SourceID,Size(words),History,(Status words)]=[0x730001, 0, DISABLED,()]
-> [SourceID,Size(words),History,(Status words)]=[0x740001, 0, IGNORED,()]
-> [SourceID,Size(words),History,(Status words)]=[0x740002, 0, IGNORED,()]
-> [SourceID,Size(words),History,(Status words)]=[0x750001, 0, RETRIEVED,(0x00000004)]
-> [SourceID,Size(words),History,(Status words)]=[0x750002, 0, RETRIEVED,(0x00000004)]
-> [SourceID,Size(words),History,(Status words)]=[0x760000, 25000, CACHED,(0x00000000)]
-> [SourceID,Size(words),History,(Status words)]=[0x760001, 125000, CACHED,(0x00000008,0x00000002,0x00000004)]
-> [SourceID,Size(words),History,(Status words)]=[0x760002, 25000, CACHED,(0x00000000)]
-> [SourceID,Size(words),History,(Status words)]=[0x760003, 25000, CACHED,(0x00000000)]
-> [SourceID,Size(words),History,(Status words)]=[0x770000, 10000,UNCLASSIFIED,()]
#**************************************************************
#
# MonROBDataProviderSvc job options fragment
#
#==============================================================
from AthenaCommon.AppMgr import theApp
from AthenaCommon.AppMgr import ServiceMgr as svcMgr
from AthenaCommon import CfgMgr
# remove old ROBDataProviderSvc definition
if hasattr(svcMgr, 'ROBDataProviderSvc'):
if theApp.__dict__[ 'CreateSvc' ].count( svcMgr.ROBDataProviderSvc.getFullName() ):
theApp.__dict__[ 'CreateSvc' ].remove( svcMgr.ROBDataProviderSvc.getFullName() )
del svcMgr.allConfigurables['ROBDataProviderSvc']
del svcMgr.ROBDataProviderSvc
if dir().count('ROBDataProviderSvc'):
del ROBDataProviderSvc
# configure the offline monitoring ROBDataProviderSvc
svcMgr += CfgMgr.MonROBDataProviderSvc("ROBDataProviderSvc")
theApp.CreateSvc += [ svcMgr.ROBDataProviderSvc.getFullName() ]
ROBDataProviderSvc = svcMgr.ROBDataProviderSvc
# switch on algorithm auditing in case it is not yet done
theApp.AuditAlgorithms = True
#
#==============================================================
#
# End of MonROBDataProviderSvc job options fragment
#
#**************************************************************
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include <functional>
#include <algorithm>
#include "TrigDataAccessMonitoring/ROBDataMonitor.h"
using namespace robmonitor;
//
//--- ROBDataStruct
// -------------
ROBDataStruct::ROBDataStruct()
: rob_id(0),
rob_size(0),
rob_history(robmonitor::UNCLASSIFIED),
rob_status_words()
{}
ROBDataStruct::ROBDataStruct(const uint32_t srcId)
: rob_id(srcId),
rob_size(0),
rob_history(robmonitor::UNCLASSIFIED),
rob_status_words()
{}
bool ROBDataStruct::isUnclassified() {
return ((rob_history == robmonitor::UNCLASSIFIED) ? true : false);
}
bool ROBDataStruct::isCached() {
return ((rob_history == robmonitor::CACHED) ? true : false);
}
bool ROBDataStruct::isRetrieved() {
return ((rob_history == robmonitor::RETRIEVED) ? true : false);
}
bool ROBDataStruct::isIgnored() {
return ((rob_history == robmonitor::IGNORED) ? true : false);
}
bool ROBDataStruct::isDisabled() {
return ((rob_history == robmonitor::DISABLED) ? true : false);
}
bool ROBDataStruct::isStatusOk() {
if (rob_status_words.size() == 0) return true;
if ((rob_status_words.size() > 0) && (rob_status_words[0] == 0)) return true;
return false;
}
//
//--- ROBDataMonitorStruct
// --------------------
ROBDataMonitorStruct::ROBDataMonitorStruct()
:lvl1ID(0),
requestor_name("UNKNOWN"),
requested_ROBs(),
start_time_of_ROB_request(),
end_time_of_ROB_request()
{}
ROBDataMonitorStruct::ROBDataMonitorStruct(const uint32_t l1_id, const std::string req_nam="UNKNOWN")
:lvl1ID(l1_id),
requestor_name(req_nam),
requested_ROBs(),
start_time_of_ROB_request(),
end_time_of_ROB_request()
{}
ROBDataMonitorStruct::ROBDataMonitorStruct(const uint32_t l1_id,
const std::vector<uint32_t>& req_robs,
const std::string req_nam="UNKNOWN")
:lvl1ID(l1_id),
requestor_name(req_nam),
start_time_of_ROB_request(),
end_time_of_ROB_request()
{
for ( std::vector<uint32_t>::const_iterator it=req_robs.begin(); it != req_robs.end(); it++) {
requested_ROBs[ (*it) ] = robmonitor::ROBDataStruct( (*it) ) ;
}
}
unsigned ROBDataMonitorStruct::allROBs() {
return requested_ROBs.size();
}
unsigned ROBDataMonitorStruct::unclassifiedROBs() {
ptrdiff_t ret=0;
for ( std::map<const uint32_t,robmonitor::ROBDataStruct>::iterator it = requested_ROBs.begin();
it != requested_ROBs.end(); it++ ) {
if ((*it).second.isUnclassified()) ++ret;
}
return ret;
}
unsigned ROBDataMonitorStruct::cachedROBs() {
ptrdiff_t ret=0;
for ( std::map<const uint32_t,robmonitor::ROBDataStruct>::iterator it = requested_ROBs.begin();
it != requested_ROBs.end(); it++ ) {
if ((*it).second.isCached()) ++ret;
}
return ret;
}
unsigned ROBDataMonitorStruct::retrievedROBs() {
ptrdiff_t ret=0;
for ( std::map<const uint32_t,robmonitor::ROBDataStruct>::iterator it = requested_ROBs.begin();
it != requested_ROBs.end(); it++ ) {
if ((*it).second.isRetrieved()) ++ret;
}
return ret;
}
unsigned ROBDataMonitorStruct::ignoredROBs() {
ptrdiff_t ret=0;
for ( std::map<const uint32_t,robmonitor::ROBDataStruct>::iterator it = requested_ROBs.begin();
it != requested_ROBs.end(); it++ ) {
if ((*it).second.isIgnored()) ++ret;
}
return ret;
}
unsigned ROBDataMonitorStruct::disabledROBs() {
ptrdiff_t ret=0;
for ( std::map<const uint32_t,robmonitor::ROBDataStruct>::iterator it = requested_ROBs.begin();
it != requested_ROBs.end(); it++ ) {
if ((*it).second.isDisabled()) ++ret;
}
return ret;
}
unsigned ROBDataMonitorStruct::statusOkROBs() {
ptrdiff_t ret=0;
for ( std::map<const uint32_t,robmonitor::ROBDataStruct>::iterator it = requested_ROBs.begin();
it != requested_ROBs.end(); it++ ) {
if ((*it).second.isStatusOk()) ++ret;
}
return ret;
}
float ROBDataMonitorStruct::elapsedTime() {
int secs = 0 ;
if (end_time_of_ROB_request.tv_sec >= start_time_of_ROB_request.tv_sec)
secs = end_time_of_ROB_request.tv_sec - start_time_of_ROB_request.tv_sec;
int usecs = end_time_of_ROB_request.tv_usec - start_time_of_ROB_request.tv_usec;
return static_cast<float>(secs)*1000 + static_cast<float>(usecs)/1000;
}
#include "GaudiKernel/DeclareFactoryEntries.h"
#include "TrigDataAccessMonitoring/MonROBDataProviderSvc.h"
DECLARE_SERVICE_FACTORY( MonROBDataProviderSvc )
DECLARE_FACTORY_ENTRIES( TrigDataAccessMonitoring ) {
DECLARE_SERVICE( MonROBDataProviderSvc );
}