15#include "Gaudi/Interfaces/IOptionsSvc.h"
16#include "GaudiKernel/IMessageSvc.h"
17#include "GaudiKernel/ISvcLocator.h"
18#include "GaudiKernel/ITHistSvc.h"
19#include "GaudiKernel/MsgStream.h"
20#include "Gaudi/Property.h"
21#include "GaudiKernel/ServiceHandle.h"
59 std::map<IMonitorToolBase*,ToolBench*>::iterator it, itE;
69 typedef std::map<std::string,TObject*>
ObjMap_t;
148 std::map<IMonitorToolBase*,ToolBench*>::iterator it =
m_toolbenchmarks.find(t);
183std::string strToLower(
const std::string&
str );
196 ,
m_d(new
Imp(this, name))
231 std::string lcstr( strToLower(
str) );
233 if( lcstr ==
"user" )
235 else if( lcstr ==
"nooutput" )
237 else if( lcstr ==
"online" )
239 else if( lcstr ==
"tier0" )
241 else if( lcstr ==
"tier0raw" )
243 else if( lcstr ==
"tier0esd" )
245 else if( lcstr ==
"aod" )
247 else if( lcstr ==
"altprod" )
253 MsgStream log( ms,
"AthenaMonManager::envStringToEnum()" );
254 log << MSG::WARNING <<
"Unknown AthenaMonManager::Environment_t \""
255 <<
str <<
"\", returning \"user\"" <<
endmsg;
267 std::string lcstr( strToLower(
str) );
269 if( lcstr ==
"userdefined" )
271 else if( lcstr ==
"montecarlo" )
273 else if( lcstr ==
"collisions" )
275 else if( lcstr ==
"cosmics" )
277 else if( lcstr ==
"heavyioncollisions" )
283 MsgStream log( ms,
"AthenaMonManager::dataTypeStringToEnum()" );
284 log << MSG::WARNING <<
"Unknown AthenaMonManager::DataType_t \""
285 <<
str <<
"\", returning \"userDefined\"" <<
endmsg;
297 return Imp::s_environment;
301 return Imp::s_LBsLowStat;
304 return Imp::s_LBsMedStat;
307 return Imp::s_LBsHigStat;
314 return Imp::s_dataType;
320 return m_d->m_forkedProcess;
328 if (Imp::s_runLBOverridden) {
329 return Imp::s_lumiBlock;
331 return Gaudi::Hive::currentContext().eventID().lumi_block();
340 if (Imp::s_runLBOverridden) {
343 return Gaudi::Hive::currentContext().eventID().run_number();
362 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
"AthenaMonManager::initialize():" <<
endmsg;
370 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
" --> Initializing static data" <<
endmsg;
373 msg(MSG::DEBUG) <<
" * \"ManualDataTypeSetup\" = " <<
m_d->m_manualDataTypeSetupProp <<
endmsg;
377 if(
m_d->m_manualDataTypeSetupProp ) {
378 Imp::s_dataTypeStr =
m_d->m_dataTypeProp;
384 Imp::s_dataTypeStr =
m_d->m_dataTypeProp;
388 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
" * \"DataType\" = " << Imp::s_dataType <<
endmsg;
390 Imp::s_environmentStr =
m_d->m_environmentProp;
393 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
" * \"Environment\" = " << Imp::s_environment <<
endmsg;
395 Imp::s_LBsLowStat =
m_d->m_LBsLowStatProp;
396 Imp::s_LBsMedStat =
m_d->m_LBsMedStatProp;
397 Imp::s_LBsHigStat =
m_d->m_LBsHigStatProp;
399 msg(MSG::DEBUG) <<
" * \"LBsInLowStatInterval\" = " << Imp::s_LBsLowStat <<
endmsg;
400 msg(MSG::DEBUG) <<
" * \"LBsInMediumStatInterval\" = " << Imp::s_LBsMedStat <<
endmsg;
401 msg(MSG::DEBUG) <<
" * \"LBsInHighStatInterval\" = " << Imp::s_LBsHigStat <<
endmsg;
404 m_d->m_isPrimaryManager =
true;
407 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
" * \"ManualRunLBSetup\" = " <<
m_d->m_manualRunLBProp <<
endmsg;
409 if(
m_d->m_manualRunLBProp ) {
410 Imp::s_run =
m_d->m_runProp;
411 Imp::s_lumiBlock =
m_d->m_lumiBlockProp;
412 Imp::s_runLBOverridden =
true;
414 msg(MSG::DEBUG) <<
" --> using run = " << Imp::s_run <<
", lumiBlock = " << Imp::s_lumiBlock <<
endmsg;
417 msg(MSG::DEBUG) <<
" --> using run = " << Imp::s_run <<
", lumiBlock = " << Imp::s_lumiBlock <<
endmsg;
422 m_d->m_dataTypeProp = Imp::s_dataTypeStr;
423 m_d->m_environmentProp = Imp::s_environmentStr;
430 const std::string client = name() + std::string(
"Properties");
431 ATH_MSG_DEBUG(
" --> Adding properties under name \"" << client <<
"\"");
432 joSvc->set( client +
".FileKey",
m_d->m_fileKeyProp );
433 joSvc->set( client +
".DataType",
m_d->m_dataTypeProp );
434 joSvc->set( client +
".Environment",
m_d->m_environmentProp );
438 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
" --> Retrieved AthenaMonTools" <<
endmsg;
441 m_d->m_eventCounter =
m_d->m_everyNevents;
443 ToolHandleArray<IMonitorToolBase>::iterator monToolsEnd =
m_monTools.end();
444 for( ToolHandleArray<IMonitorToolBase>::iterator i =
m_monTools.begin(); i != monToolsEnd; ++i ) {
445 ToolHandle<IMonitorToolBase>& tool = *i;
452 if (
m_d->m_doResourceMon) {
454 tb->m_bench_alginit_retrieve = bench_tmp;
458 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
" --> Exiting successfully" <<
endmsg;
460 return StatusCode::SUCCESS;
468 const EventContext& ctx = Gaudi::Hive::currentContext();
470 m_d->m_forkedProcess=
false;
471 pid_t currPID=getpid();
473 if (
m_d->m_lastPID!=0 &&
m_d->m_lastPID!=currPID) {
474 m_d->m_forkedProcess=
true;
477 m_d->m_lastPID=currPID;
480 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
"AthenaMonManager::execute():" <<
endmsg;
484 ToolHandleArray<IMonitorToolBase>::iterator monToolsEnd =
m_monTools.end();
485 for( ToolHandleArray<IMonitorToolBase>::iterator i =
m_monTools.begin(); i != monToolsEnd; ++i ) {
486 ToolHandle<IMonitorToolBase>& tool = *i;
487 m_d->toolAudStart(tool);
489 if (
m_d->m_doResourceMon)
491 if( tool->preSelector() ) {
493 sc = tool->fillHists(ctx);
495 if( !
sc.isSuccess() ) {
496 if (
msgLvl(MSG::WARNING))
msg(MSG::WARNING) <<
"IMonitorToolBase::fillHists() unsuccessful" <<
endmsg;
501 if (
m_d->m_doResourceMon) {
504 tb->m_bench_algexec_fillHists += bench_tmp;
505 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
" --> m_doResourceMon is True" <<
endmsg;
509 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
" --> Done calling IMonitorToolBase::fillHists()" <<
endmsg;
511 if(
m_d->m_eventCounter > 0 ) {
512 m_d->m_eventCounter--;
514 else if(
m_d->m_eventCounter == 0 ) {
515 for( ToolHandleArray<IMonitorToolBase>::iterator i =
m_monTools.begin(); i != monToolsEnd; ++i ) {
516 ToolHandle<IMonitorToolBase>& tool = *i;
517 m_d->toolAudStart(tool);
520 if (
m_d->m_doResourceMon)
522 sc = tool->checkHists(
false);
523 if (
m_d->m_doResourceMon) {
526 tb->m_bench_algexec_checkHists += bench_tmp;
528 if( !
sc.isSuccess() ) {
529 if (
msgLvl(MSG::WARNING))
msg(MSG::WARNING) <<
"IMonitorToolBase::checkHists() unsuccessful" <<
endmsg;
533 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
" --> Done calling IMonitorToolBase::checkHists()" <<
endmsg;
535 m_d->m_eventCounter =
m_d->m_everyNevents;
537 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
" --> Exiting successfully" <<
endmsg;
539 return StatusCode::SUCCESS;
547 return StatusCode::SUCCESS;
555 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
"AthenaMonManager::finalize():" <<
endmsg;
559 ToolHandleArray<IMonitorToolBase>::iterator monToolsEnd =
m_monTools.end();
560 for( ToolHandleArray<IMonitorToolBase>::iterator i =
m_monTools.begin(); i != monToolsEnd; ++i ) {
561 ToolHandle<IMonitorToolBase>& tool = *i;
562 m_d->toolAudStart(tool);
564 sc = tool->runStat();
565 if( !
sc.isSuccess() ) {
566 if (
msgLvl(MSG::WARNING))
msg(MSG::WARNING) <<
"IMonitorToolBase::runStat() unsuccessful" <<
endmsg;
571 tb->m_bench_algfin_finalHists.startMeasurement();
572 sc = tool->finalHists();
574 tb->m_bench_algfin_finalHists.finishMeasurement();
575 if( !
sc.isSuccess() ) {
576 if (
msgLvl(MSG::WARNING))
msg(MSG::WARNING) <<
"IMonitorToolBase::finalHists() unsuccessful" <<
endmsg;
579 tb->m_bench_algfin_checkHists.startMeasurement();
580 sc = tool->checkHists(
true);
582 tb->m_bench_algfin_checkHists.finishMeasurement();
583 if( !
sc.isSuccess() ) {
584 if (
msgLvl(MSG::WARNING))
msg(MSG::WARNING) <<
"IMonitorToolBase::checkHists() unsuccessful" <<
endmsg;
591 msg(MSG::DEBUG) <<
" --> Done calling IMonitorToolBase::finalHists() and IMonitorToolBase::checkHists()" <<
endmsg;
592 msg(MSG::DEBUG) <<
" --> Exiting successfully" <<
endmsg;
594 return StatusCode::SUCCESS;
603 if (
msgLvl(MSG::DEBUG))
msg(MSG::DEBUG) <<
"AthenaMonManager::start():" <<
endmsg;
607 ToolHandleArray<IMonitorToolBase>::iterator monToolsEnd =
m_monTools.end();
608 for( ToolHandleArray<IMonitorToolBase>::iterator i =
m_monTools.begin(); i != monToolsEnd; ++i ) {
609 ToolHandle<IMonitorToolBase>& tool = *i;
610 m_d->toolAudStart(tool);
612 if (
m_d->m_doResourceMon)
614 sc = tool->bookHists();
615 if (
m_d->m_doResourceMon) {
618 tb->m_bench_algexec_bookHists += bench_tmp;
620 if( !
sc.isSuccess() ) {
621 if (
msgLvl(MSG::WARNING))
msg(MSG::WARNING) <<
"IMonitorToolBase::bookHists() unsuccessful" <<
endmsg;
626 msg(MSG::DEBUG) <<
" --> Done calling IMonitorToolBase::bookHists()" <<
endmsg;
627 msg(MSG::DEBUG) <<
" --> Exiting successfully" <<
endmsg;
630 return StatusCode::SUCCESS;
638 return m_d->m_fileKeyProp;
646 m_d->m_objMap.emplace( key,
h );
657 Imp::ObjMap_t::iterator i =
m_d->m_objMap.find( key );
658 if( i !=
m_d->m_objMap.end() ) {
659 TObject* o = i->second;
660 TH1*
h =
dynamic_cast<TH1*
>( o );
666 bool doRecursiveReferenceDelete = gROOT->MustClean();
667 gROOT->SetMustClean(
false);
668 TDirectory* dir =
h->GetDirectory();
669 TDirectory* g = gDirectory;
676 if( !
sc.isSuccess() ) {
677 if (
msgLvl(MSG::WARNING))
msg(MSG::WARNING) <<
"AthenaMonManager::WriteAndDeleteHist(): Failure to deReg( TObject* )" <<
endmsg;
680 gROOT->SetMustClean(doRecursiveReferenceDelete);
681 m_d->m_objMap.erase( key );
696std::string strToLower(
const std::string&
str )
698 std::string lstr(
str);
699 std::string::const_iterator from =
str.begin();
700 std::string::const_iterator strend =
str.end();
701 std::string::iterator to = lstr.begin();
702 while( from != strend ) {
#define ATH_CHECK
Evaluate an expression and check for errors.
void tolower(std::string &s)
Define macros for attributes used to control the static checker.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
bool msgLvl(const MSG::Level lvl) const
Header file for AthHistogramAlgorithm.
static const MSG::Level s_resourceMonThreshold
unsigned m_mgcopies_initval
AthenaMonManager * m_theManager
std::string m_fileKeyProp
std::map< std::string, TObject * > ObjMap_t
unsigned int m_LBsMedStatProp
Imp(AthenaMonManager *man, const std::string &name)
unsigned int m_LBsLowStatProp
std::string m_environmentProp
static std::atomic< bool > s_staticDataAreInit
unsigned m_nMonGroupCopies
std::string m_dataTypeProp
ToolBench * getToolBench(IMonitorToolBase *t)
unsigned int m_LBsHigStatProp
bool m_manualDataTypeSetupProp
static std::string s_dataTypeStr ATLAS_THREAD_SAFE
void toolAudStart(const T &tool)
SmartIF< ISGAudSvc > m_sgAudSvc
std::map< IMonitorToolBase *, ToolBench * > m_toolbenchmarks
unsigned int m_lumiBlockProp
static std::atomic< ISvcLocator * > s_svcLocator
virtual StatusCode start()
virtual StatusCode stop()
static unsigned int getLBsLowStat()
ToolHandleArray< IMonitorToolBase > m_monTools
DataType_t
An enumeration of the different types of data the monitoring application may be running over.
ServiceHandle< ITHistSvc > m_THistSvc
static unsigned int fillNumber()
static Environment_t envStringToEnum(const std::string &str)
Converts a string to an Environment_t of the same name.
static DataType_t dataTypeStringToEnum(const std::string &str)
Converts a string to a DataType_t of the same name.
Environment_t
An enumeration of the different types of running environment the monitoring application may be in.
virtual void writeAndDelete(const std::string &key)
If the TObject is owned by this manager, its Write() method is called and it is deleted.
virtual StatusCode finalize()
static unsigned int getLBsHigStat()
AthenaMonManager(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute()
virtual StatusCode initialize()
static unsigned int getLBsMedStat()
static unsigned int lumiBlockNumber()
virtual std::string fileKey() const
static Environment_t environment()
Returns the running environment of the monitoring application to help ManagedMonitorToolBase objects ...
virtual ~AthenaMonManager()
static unsigned int runNumber()
static DataType_t dataType()
Returns the data type that the monitoring application is running over to help ManagedMonitorToolBase ...
virtual void passOwnership(TObject *h, const std::string &key)
Pass ownership of a TObject to this manager so that it will be deleted appropriately.