From e6c4ce2f50eb80f82c9440a85363b132f915fe82 Mon Sep 17 00:00:00 2001 From: Yuriy Ilchenko <Yuriy.Ilchenko@cern.ch> Date: Tue, 5 Aug 2014 09:53:33 +0200 Subject: [PATCH] EnableLumi is set to false by default (AthenaMonitoring-02-01-09) --- .../AthenaMonitoring/AthenaMon.h | 43 + .../AthenaMonitoring/AthenaMonManager.h | 132 + .../AthenaMonitoring/DQAtlasReadyFilterTool.h | 35 + .../AthenaMonitoring/DQBadLBFilterTool.h | 41 + .../AthenaMonitoring/DQDummyFilterTool.h | 25 + .../DQFilledBunchFilterTool.h | 33 + .../AthenaMonitoring/FastPhysMonToolBase.h | 110 + .../AthenaMonitoring/IDQFilterTool.h | 30 + .../AthenaMonitoring/IMonitorToolBase.h | 46 + .../AthenaMonitoring/LogFileMsgStream.h | 85 + .../AthenaMonitoring/ManagedMonitorToolBase.h | 896 +++++++ .../AthenaMonitoring/ManagedMonitorToolTest.h | 76 + .../AthenaMonitoring/MonitorToolBase.h | 97 + Control/AthenaMonitoring/cmt/requirements | 41 + .../python/BadLBFilterTool.py | 112 + Control/AthenaMonitoring/python/DQMonFlags.py | 395 +++ .../share/AtlasReadyFilterTool_jobOptions.py | 25 + .../share/CondDB_jobOptions.py | 10 + .../share/DQMonFlagsConfig_jobOptions.py | 400 +++ .../share/DataQualityInit_jobOptions.py | 55 + .../share/DataQualitySteering_jobOptions.py | 270 ++ .../share/FilledBunchFilterTool_jobOptions.py | 25 + .../share/ManagedMonitorToolTest.py | 103 + .../share/TrigDecTool_jobOptions.py | 34 + .../share/aod2hist_topoptions.py | 35 + Control/AthenaMonitoring/src/AthMonBench.cxx | 35 + Control/AthenaMonitoring/src/AthMonBench.h | 125 + Control/AthenaMonitoring/src/AthenaMon.cxx | 198 ++ .../AthenaMonitoring/src/AthenaMonManager.cxx | 914 +++++++ .../src/DQAtlasReadyFilterTool.cxx | 69 + .../src/DQBadLBFilterTool.cxx | 110 + .../src/DQDummyFilterTool.cxx | 18 + .../src/DQFilledBunchFilterTool.cxx | 46 + .../src/FastPhysMonToolBase.cxx | 105 + .../src/LWHistAthMonWrapper.h | 45 + .../src/LWHistAthMonWrapper.icc | 53 + .../src/ManagedMonitorToolBase.cxx | 2270 +++++++++++++++++ .../src/ManagedMonitorToolTest.cxx | 333 +++ .../AthenaMonitoring/src/MonitorToolBase.cxx | 277 ++ .../components/AthenaMonitoring_entries.cxx | 27 + .../src/components/AthenaMonitoring_load.cxx | 4 + 41 files changed, 7783 insertions(+) create mode 100755 Control/AthenaMonitoring/AthenaMonitoring/AthenaMon.h create mode 100755 Control/AthenaMonitoring/AthenaMonitoring/AthenaMonManager.h create mode 100644 Control/AthenaMonitoring/AthenaMonitoring/DQAtlasReadyFilterTool.h create mode 100644 Control/AthenaMonitoring/AthenaMonitoring/DQBadLBFilterTool.h create mode 100644 Control/AthenaMonitoring/AthenaMonitoring/DQDummyFilterTool.h create mode 100644 Control/AthenaMonitoring/AthenaMonitoring/DQFilledBunchFilterTool.h create mode 100644 Control/AthenaMonitoring/AthenaMonitoring/FastPhysMonToolBase.h create mode 100644 Control/AthenaMonitoring/AthenaMonitoring/IDQFilterTool.h create mode 100755 Control/AthenaMonitoring/AthenaMonitoring/IMonitorToolBase.h create mode 100755 Control/AthenaMonitoring/AthenaMonitoring/LogFileMsgStream.h create mode 100755 Control/AthenaMonitoring/AthenaMonitoring/ManagedMonitorToolBase.h create mode 100755 Control/AthenaMonitoring/AthenaMonitoring/ManagedMonitorToolTest.h create mode 100755 Control/AthenaMonitoring/AthenaMonitoring/MonitorToolBase.h create mode 100755 Control/AthenaMonitoring/cmt/requirements create mode 100644 Control/AthenaMonitoring/python/BadLBFilterTool.py create mode 100644 Control/AthenaMonitoring/python/DQMonFlags.py create mode 100644 Control/AthenaMonitoring/share/AtlasReadyFilterTool_jobOptions.py create mode 100644 Control/AthenaMonitoring/share/CondDB_jobOptions.py create mode 100644 Control/AthenaMonitoring/share/DQMonFlagsConfig_jobOptions.py create mode 100644 Control/AthenaMonitoring/share/DataQualityInit_jobOptions.py create mode 100644 Control/AthenaMonitoring/share/DataQualitySteering_jobOptions.py create mode 100644 Control/AthenaMonitoring/share/FilledBunchFilterTool_jobOptions.py create mode 100755 Control/AthenaMonitoring/share/ManagedMonitorToolTest.py create mode 100644 Control/AthenaMonitoring/share/TrigDecTool_jobOptions.py create mode 100644 Control/AthenaMonitoring/share/aod2hist_topoptions.py create mode 100644 Control/AthenaMonitoring/src/AthMonBench.cxx create mode 100644 Control/AthenaMonitoring/src/AthMonBench.h create mode 100755 Control/AthenaMonitoring/src/AthenaMon.cxx create mode 100755 Control/AthenaMonitoring/src/AthenaMonManager.cxx create mode 100644 Control/AthenaMonitoring/src/DQAtlasReadyFilterTool.cxx create mode 100644 Control/AthenaMonitoring/src/DQBadLBFilterTool.cxx create mode 100644 Control/AthenaMonitoring/src/DQDummyFilterTool.cxx create mode 100644 Control/AthenaMonitoring/src/DQFilledBunchFilterTool.cxx create mode 100644 Control/AthenaMonitoring/src/FastPhysMonToolBase.cxx create mode 100644 Control/AthenaMonitoring/src/LWHistAthMonWrapper.h create mode 100644 Control/AthenaMonitoring/src/LWHistAthMonWrapper.icc create mode 100755 Control/AthenaMonitoring/src/ManagedMonitorToolBase.cxx create mode 100755 Control/AthenaMonitoring/src/ManagedMonitorToolTest.cxx create mode 100755 Control/AthenaMonitoring/src/MonitorToolBase.cxx create mode 100755 Control/AthenaMonitoring/src/components/AthenaMonitoring_entries.cxx create mode 100755 Control/AthenaMonitoring/src/components/AthenaMonitoring_load.cxx diff --git a/Control/AthenaMonitoring/AthenaMonitoring/AthenaMon.h b/Control/AthenaMonitoring/AthenaMonitoring/AthenaMon.h new file mode 100755 index 00000000000..aa2f999680a --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/AthenaMon.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHENAMON_H +#define ATHENAMON_H + +#include "GaudiKernel/Algorithm.h" + +#include "AthenaMonitoring/IMonitorToolBase.h" + +class AthenaMon:public Algorithm { + public: + + AthenaMon (const std::string& name, ISvcLocator* pSvcLocator); + + virtual ~AthenaMon(); + + virtual StatusCode initialize(); + virtual StatusCode execute(); + virtual StatusCode finalize(); + + virtual StatusCode beginRun(); + virtual StatusCode endRun(); + + protected: + + std::vector<IMonitorToolBase*> m_monTools; + + private: + + std::vector<std::string> m_monToolNames; + + std::vector<std::string> m_THistSvc_streamnameMapping; + + long m_everyNevents; + long m_eventCounter; + + bool m_bookHistsinInitialize; + +}; + +#endif diff --git a/Control/AthenaMonitoring/AthenaMonitoring/AthenaMonManager.h b/Control/AthenaMonitoring/AthenaMonitoring/AthenaMonManager.h new file mode 100755 index 00000000000..7231f976d6b --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/AthenaMonManager.h @@ -0,0 +1,132 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef AthenaMonManager_H +#define AthenaMonManager_H + +#include <map> +#include <string> + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "GaudiKernel/StatusCode.h" +#include "GaudiKernel/ToolHandle.h" + +class ISvcLocator; +class ITHistSvc; +class ManagedMonitorToolBase; +class TObject; +class IMonitorToolBase; +class LWHist; + +/** + * An Algorithm that manages a set of modules, + * each inheriting from ManagedMonitorToolBase, by setting common + * configuration variables and organizing the output data. It provides + * all the functionality and behaviour of AthenaMon. + * + * $Id: AthenaMonManager.h,v 1.21 2009-05-08 09:50:22 sschaetz Exp $ + * + * @author Michael Wilson, CERN, January 2007 + */ + +class AthenaMonManager : public AthAlgorithm { + + public: + + /** + * An enumeration of the different types of running environment the + * monitoring application may be in. The running environment may be + * used to select which histograms are produced, and where they are + * located in the output. For example, the output paths of the + * histograms are different for the "user", "online" and the various + * offline flags. The 'tier0Raw' and 'tier0ESD' are used to select + * sets of histograms for production either during the RAW --> ESD + * transform or during the ESD --> AOD transform (but not both!) + * Strings of the same names may be given as jobOptions. + */ + enum Environment_t { user = 0, noOutput, online, tier0, tier0Raw, tier0ESD, altprod, AOD }; + + /** + * An enumeration of the different types of data the + * monitoring application may be running over. This can be used to + * select which histograms to produce, e.g., to prevent the production + * of colliding-beam histograms when running on cosmic-ray data. + * Strings of the same names may be given as jobOptions. + */ + enum DataType_t { userDefined = 0, monteCarlo, collisions, cosmics, heavyIonCollisions }; + + AthenaMonManager( const std::string& name, ISvcLocator* pSvcLocator ); + + virtual ~AthenaMonManager(); + + /** + * Converts a string to an Environment_t of the same name. + * static method (shared by all AthenaMonManager instances during run-time) + */ + static Environment_t envStringToEnum( const std::string& str ); + + /** + * Converts a string to a DataType_t of the same name. + */ + static DataType_t dataTypeStringToEnum( const std::string& str ); + + /** + * Returns the running environment of the monitoring application + * to help ManagedMonitorToolBase objects determine which histograms to produce. + */ + static Environment_t environment(); + + /** + * Returns the data type that the monitoring application is running over + * to help ManagedMonitorToolBase objects determine which histograms to produce. + */ + static DataType_t dataType(); + + static unsigned int lumiBlockNumber(); + static unsigned int runNumber(); + static unsigned int fillNumber(); + + static unsigned int getLBsLowStat(); + static unsigned int getLBsMedStat(); + static unsigned int getLBsHigStat(); + + virtual StatusCode initialize(); + virtual StatusCode execute(); + virtual StatusCode finalize(); + + virtual StatusCode beginRun(); + virtual StatusCode endRun(); + + virtual std::string fileKey() const; + + /** + * Pass ownership of a TObject/LWHist to this manager so that it will be deleted appropriately. + */ + virtual void passOwnership( TObject* h, const std::string& key ); + virtual void passOwnership( LWHist* h, const std::string& key ); + + /** + * If the TObject is owned by this manager, its Write() method is called and it is deleted. + */ + virtual void writeAndDelete( const std::string& key ); + virtual LWHist *ownedLWHistOfKey(const std::string& key) const; + // If you know it is an LWHist use writeAndDeleteLWHist. The just deleted LWHist pointer will be returned (0 if nothing deleted) + virtual LWHist *writeAndDeleteLWHist( const std::string& key, const std::string& streamName, bool doDelete = true ); + + virtual void writeAndDeleteLWHist( LWHist*lwh ); + + protected: + ToolHandleArray<IMonitorToolBase> m_monTools; + + virtual void setEventInfo(); + + ITHistSvc* m_THistSvc; + + private: + // Use private implementation idiom for more flexible development. + class Imp; + Imp *d; +}; + +#endif diff --git a/Control/AthenaMonitoring/AthenaMonitoring/DQAtlasReadyFilterTool.h b/Control/AthenaMonitoring/AthenaMonitoring/DQAtlasReadyFilterTool.h new file mode 100644 index 00000000000..42f2384a72d --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/DQAtlasReadyFilterTool.h @@ -0,0 +1,35 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef DQATLASREADYFILTERTOOL_H +#define DQATLASREADYFILTERTOOL_H + +#include "AthenaMonitoring/IDQFilterTool.h" +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/StatusCode.h" + +// This filter tool rejects events where the ATLAS READY flag is not set +// @author Peter Onyisi <ponyisi@cern.ch> + +class DQAtlasReadyFilterTool : public AthAlgTool, virtual public IDQFilterTool { + public: + DQAtlasReadyFilterTool(const std::string&,const std::string&,const IInterface*); + + virtual ~DQAtlasReadyFilterTool (); + + virtual StatusCode initialize(); + + virtual bool accept() ; + + virtual StatusCode updateCache() ; + + StatusCode callback( IOVSVC_CALLBACK_ARGS ); + + private: + bool m_fallbackValue; + bool m_alwaysReturnTrue; + bool m_valueCache; +}; + +#endif //DQATLASREADYFILTERTOOL_H diff --git a/Control/AthenaMonitoring/AthenaMonitoring/DQBadLBFilterTool.h b/Control/AthenaMonitoring/AthenaMonitoring/DQBadLBFilterTool.h new file mode 100644 index 00000000000..fc3e05cc5ae --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/DQBadLBFilterTool.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef DQBadLBFILTERTOOL_H +#define DQBadLBFILTERTOOL_H + +#include "AthenaMonitoring/IDQFilterTool.h" +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/StatusCode.h" + +#include <string> +#include <vector> + +// This filter tool rejects events where the a bad LB block is flagged from a given defect +// @author Michele Petteni <mpetteni@sfu.ca> + +class DQBadLBFilterTool : public AthAlgTool, virtual public IDQFilterTool { + public: + DQBadLBFilterTool(const std::string&,const std::string&,const IInterface*); + + virtual ~DQBadLBFilterTool (); + + virtual StatusCode initialize(); + + virtual bool accept() ; + + virtual StatusCode updateCache() ; + + StatusCode callback( IOVSVC_CALLBACK_ARGS ); + + private: + bool m_fallbackValue; + bool m_ignoreRecoverable; + bool m_alwaysReturnTrue; + bool m_valueCache; + std::vector<int> m_listofdefects; + std::vector<std::string> m_listofdefects_str; +}; + +#endif //DQATLASREADYFILTERTOOL_H diff --git a/Control/AthenaMonitoring/AthenaMonitoring/DQDummyFilterTool.h b/Control/AthenaMonitoring/AthenaMonitoring/DQDummyFilterTool.h new file mode 100644 index 00000000000..fb47b39d130 --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/DQDummyFilterTool.h @@ -0,0 +1,25 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef DQDUMMYFILTERTOOL_H +#define DQDUMMYFILTERTOOL_H + +#include "AthenaMonitoring/IDQFilterTool.h" +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/StatusCode.h" + +// This filter tool rejects events where the ATLAS READY flag is not set +// @author Peter Onyisi <ponyisi@cern.ch> + +class DQDummyFilterTool : public AthAlgTool, virtual public IDQFilterTool { + public: + DQDummyFilterTool(const std::string&,const std::string&,const IInterface*); + + virtual ~DQDummyFilterTool (); + + virtual bool accept() ; + +}; + +#endif //DQDUMMYFILTERTOOL_H diff --git a/Control/AthenaMonitoring/AthenaMonitoring/DQFilledBunchFilterTool.h b/Control/AthenaMonitoring/AthenaMonitoring/DQFilledBunchFilterTool.h new file mode 100644 index 00000000000..7a9f2481aa6 --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/DQFilledBunchFilterTool.h @@ -0,0 +1,33 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef DQFILLEDBUNCHFILTERTOOL_H +#define DQFILLEDBUNCHFILTERTOOL_H + +#include "AthenaMonitoring/IDQFilterTool.h" +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/StatusCode.h" +#include "GaudiKernel/ToolHandle.h" +#include "TrigAnalysisInterfaces/IBunchCrossingTool.h" + +// This filter tool only accepts events which are filled (or only those not filled, if m_invert is set) +// @author Peter Onyisi <ponyisi@cern.ch> + +class DQFilledBunchFilterTool : public AthAlgTool, virtual public IDQFilterTool { + public: + DQFilledBunchFilterTool(const std::string&,const std::string&,const IInterface*); + + virtual ~DQFilledBunchFilterTool (); + + virtual StatusCode initialize(); + + virtual bool accept() ; + + private: + bool m_alwaysReturnTrue; + bool m_invert; + ToolHandle< Trig::IBunchCrossingTool > m_bunchtool; +}; + +#endif //DQFILLEDBUNCHFILTERTOOL_H diff --git a/Control/AthenaMonitoring/AthenaMonitoring/FastPhysMonToolBase.h b/Control/AthenaMonitoring/AthenaMonitoring/FastPhysMonToolBase.h new file mode 100644 index 00000000000..2c5b729590e --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/FastPhysMonToolBase.h @@ -0,0 +1,110 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//Dear emacs, this is -*-c++-*- +#ifndef FASTPHYSMONTOOLBASE_H +#define FASTPHYSMONTOOLBASE_H + +#include "AthenaMonitoring/ManagedMonitorToolBase.h" +#include "GaudiKernel/IIncidentListener.h" + +class TTree; + + +/** + * @class FastPhysMonToolBase + * @brief Base-class for MonTools used in the context of "Fast Physics Monitoring" + * @author Walter Lampl, March 2011 + * + * Derives from ManagedMonitorToolBase + * TTrees registed with the regFPMTree method of this class will have + * RunNumber, EventNumber and LumiBlockN as additonal variables + * + * If other commonalities among the Fast Physics Monitoring tools are identified, + * we could implement them here too. + */ + +class FastPhysMonToolBase: public ManagedMonitorToolBase, + public IIncidentListener { + + public: + /** + * @brief Regular AlgTool Constructor + */ + FastPhysMonToolBase( const std::string & type, const std::string & name, + const IInterface* parent ) ; + + + /** + * @brief Destructor + */ + virtual ~FastPhysMonToolBase(); + + /** + * @brief Regular initialize method + */ + virtual StatusCode initialize(); + + + /** + * @brief Method to register a Fast Physics Monitoring TTree + * @param tree Pointer to the tree to be registered + * @param systemName Appears as folder name in the ROOT file + * @param chain Forwarded to ManagedMonToolBase::regTree + * @param merge Forwarded to ManagedMonToolBase::regTree + * + * Forwards to regTree method of ManagedMonitorToolBase + */ + StatusCode regFPMTree(TTree* tree,const std::string& systemName,const std::string& chain="", const std::string& merge=""); + + + /** + * @brief Method to create and register a Fast Physics Monitoring TTree + * @return Pointer to the new tree + * @param treeName ROOT name of the new tree + * @param treeTitle Titel of the new tree + * @param systemName Appears as folder name in the ROOT file + * @param chain Forwarded to ManagedMonToolBase::regTree + * @param merge Forwarded to ManagedMonToolBase::regTree + * + * Forwards to regTree method of ManagedMonitorToolBase + */ + TTree* regFPMTree(const std::string& treeName, const std::string treeTitle, const std::string& systemName, + const std::string& chain="", const std::string& merge=""); + + + /** + * @brief book method called by the framework + * + * Calls the bookNtuple() method exactly once per job + * Can be overloaded by concrete tool if more specialization is needed + */ + virtual StatusCode bookHistograms( ); + + /** + * @brief bookNtuple method called by the framework + * + * Needs to be implemented by the concrete FastPhysMonTool! + */ + virtual StatusCode bookNtuple(); + + private: + + /** + * @brief Incident handle method + */ + void handle(const Incident&); + + //Basic Ntuple variables + uint32_t m_eventNumber; + uint32_t m_runNumber; + uint32_t m_LBNumber; + double m_mcEventWeight; + + bool m_booked; + +}; + + +#endif diff --git a/Control/AthenaMonitoring/AthenaMonitoring/IDQFilterTool.h b/Control/AthenaMonitoring/AthenaMonitoring/IDQFilterTool.h new file mode 100644 index 00000000000..1bb4dd2011a --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/IDQFilterTool.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef IDQFILTERTOOL_H +#define IDQFILTERTOOL_H + +#include "GaudiKernel/IAlgTool.h" + +// Interface class for tools to be used in DQ tools to filter input +// @author Peter Onyisi <ponyisi@cern.ch> + +/** Must declare this, with name of interface*/ +static const InterfaceID IID_IDQFilterTool("IDQFilterTool", 1, 0); + +class IDQFilterTool : virtual public IAlgTool { + public: + /**Declared here, and defined below*/ + static const InterfaceID& interfaceID(); + + /**Pure virtual*/ + virtual bool accept() = 0; +}; + +inline const InterfaceID& IDQFilterTool::interfaceID() +{ + return IID_IDQFilterTool; +} + +#endif //IDQFILTERTOOL_H diff --git a/Control/AthenaMonitoring/AthenaMonitoring/IMonitorToolBase.h b/Control/AthenaMonitoring/AthenaMonitoring/IMonitorToolBase.h new file mode 100755 index 00000000000..57e6c7d56fc --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/IMonitorToolBase.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef IMONITORTOOLBASE_H +#define IMONITORTOOLBASE_H + +#include "GaudiKernel/IAlgTool.h" +#include <vector> + + +// Declaration of the interface ID ( interface id, major version, minor version) +static const InterfaceID IID_IMonitorToolBase("IMonitorToolBase", 1 , 0); + + +// The interface implemented by concrete Monitoring tools. +// Concrete tools, derived from the MonitorToolBase base abstract +// class are controlled via this interface. +// +// @author Manuel Diaz <Manuel.Diaz.Gomez@cern.ch> + + +class IMonitorToolBase : virtual public IAlgTool + +{ + public: + + // Retrieve interface ID + static const InterfaceID& interfaceID() { return IID_IMonitorToolBase; } + + virtual StatusCode setupOutputStreams(std::vector<std::string> Mapping + = std::vector<std::string>() ) = 0; + + //Virtual destructor + virtual ~IMonitorToolBase() {} + + // book & fill (pure virtual) + virtual StatusCode bookHists() = 0; + virtual StatusCode fillHists() = 0; + virtual StatusCode finalHists() = 0; + virtual StatusCode runStat() = 0; + virtual StatusCode checkHists(bool fromFinalize) = 0; + virtual bool preSelector() = 0; + virtual StatusCode convertLWHists() = 0; +}; +#endif diff --git a/Control/AthenaMonitoring/AthenaMonitoring/LogFileMsgStream.h b/Control/AthenaMonitoring/AthenaMonitoring/LogFileMsgStream.h new file mode 100755 index 00000000000..ed0b95f2cfe --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/LogFileMsgStream.h @@ -0,0 +1,85 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef LOGFILEMSGSTREAM_H +#define LOGFILEMSGSTREAM_H + +// ******************************************************************** +// +// NAME: LogFileMsgStream.H +// +// DESCRIPTION: class for piping output to logfile and MessageSvc +// +// AUTHOR: Rolf Seuster 27.10.2005: 1st implementation +// +// ******************************************************************** + +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/Message.h" + +#include <fstream> +#include <string> + +class LogFileMsgStream : public MsgStream { + public: + // constructor + LogFileMsgStream(IMessageSvc* svc, + const std::string& source, + const std::string& filename, + bool startlogging ) : + MsgStream(svc, source), m_FormatString("") + { + if(startlogging) + m_logfile.open(filename.c_str(), + std::ofstream::out | std::ofstream::app); + }; + + // destructor + ~LogFileMsgStream() { + if(m_logfile.is_open()) + m_logfile.close(); + }; + + /// Accept MsgStream activation using MsgStreamer operator + // almost plain copy from MsgStream.h + LogFileMsgStream& operator<< (MSG::Level level) { + return (LogFileMsgStream&)MsgStream::report(level); + } + + /// General templated stream operator + // template <typename T> + // copied from MsgStream.h, doesn't work for all types (vectors) + // but that deficit doesn't harm + template <class T> + MsgStream& operator<< (const T& arg) { + if(isActive()) m_stream << arg; + return *this; + } + + // copied from MsgStream.cpp + // here we copy the output to a file as well + MsgStream& doOutput() { + Message msg(m_source,m_currLevel,m_stream.str()); + if(m_FormatString!="") + msg.setFormat(m_FormatString); + if(m_logfile.is_open()) + m_logfile << msg << "\n"; + return MsgStream::doOutput(); + } + + void setFormat(std::string str) { + m_FormatString=str; + } + + private: + // default constructor, unusable ! + LogFileMsgStream(); + + std::ofstream m_logfile; + + std::string m_FormatString; + +}; + +#endif diff --git a/Control/AthenaMonitoring/AthenaMonitoring/ManagedMonitorToolBase.h b/Control/AthenaMonitoring/AthenaMonitoring/ManagedMonitorToolBase.h new file mode 100755 index 00000000000..59ffbc61b69 --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/ManagedMonitorToolBase.h @@ -0,0 +1,896 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ManagedMonitorToolBase_H +#define ManagedMonitorToolBase_H + +#define ManagedMonitorToolBase_Uses_API_201401 + +#include <string> +#include <vector> +#include <map> +#include <set> + +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/ServiceHandle.h" +#include "GaudiKernel/ToolHandle.h" +#include "GaudiKernel/StatusCode.h" + +#include "AthenaMonitoring/AthenaMonManager.h" +#include "AthenaMonitoring/IMonitorToolBase.h" + +#include "GaudiKernel/ToolHandle.h" +#include "LumiBlockComps/ILuminosityTool.h" +#include "LumiBlockComps/ITrigLivefractionTool.h" + +class IInterface; +class ISvcLocator;//not needed +class TGraph; +class LWHist; +class TH1; +class TH2; +class TTree; +class ITHistSvc; +namespace Trig { + class ITrigDecisionTool; +} +class IDQFilterTool; + +#include <cctype> +#include <ctime> +#include <sstream> + +#include "TGraph.h" +#include "TH1.h" +#include "TH2.h" +#include "TTree.h" +//#include "../src/AthMonBench.h" + +#include "GaudiKernel/IHistogramSvc.h" +#include "GaudiKernel/IJobOptionsSvc.h" +#include "GaudiKernel/IMessageSvc.h" +#include "GaudiKernel/ISvcLocator.h" +#include "GaudiKernel/MsgStream.h" + +#include "AthenaMonitoring/IDQFilterTool.h" +#include "GaudiKernel/ITHistSvc.h" + +/** + * Provides functionality for users to implement + * and save histograms, ntuples, and summary data, while allowing a central + * manager to coordinate and configure many ManagedMonitorToolBase instances. + * + * $Id: ManagedMonitorToolBase.h,v 1.21 2009-05-08 09:52:58 sschaetz Exp $ + * + * @author Michael Wilson, CERN, January 2007 + */ + +class ManagedMonitorToolBase : public AthAlgTool, virtual public IMonitorToolBase +{ + public: + + + /** + * An enumeration describing how detailed a particular monitoring object is. + * + * summary: used to summarize the state of the system + * + * runstat: same as summary + * + * shift: used to flag potential problems + * + * expert: essential for diagnosing problems identified by shift-level objects + * + * debug: useful for standalone debugging, but not for routine monitoring; + * not essential for diagnosing problems during normal running + * + * transient: too detailed to ever be written; always summarized by the user + * by means of another object + */ + + // enum LevelOfDetail_t { summary = 0, runstat = 0, shift, expert, debug, transient }; + + + /** + * An enumeration describing the interval over which a particular monitoring object + * is filled (i.e., interval over which the method Fill(...) is called). + * This information may be stored with the monitoring object if an application is + * only able to partially fill the object (i.e., a job sees only part of a run or fill). + * This information may be ignored in some running Environments. + * The 'fill' interval corresponds to a fill of the LHC. The 'all' interval corresponds + * to all available data. The 'lumiBlock' and 'fill' intervals are only valid for + * the 'collisions' DataType_t. + */ + + + // Old version of Interval_t. + // Must be removed after testing is done, + + enum Interval_t { file = 0, eventsBlock, lumiBlock, + lowStat, medStat, higStat, + run, fill, all }; + + + //enum Interval_t { lowStat, lumiBlock, run}; + + /** + * An enumeration describing how the class handles the histogram. + * + * attrib_unmanaged: histograms with this attribute will not be rebooked automatically and must + * be managed by the user code. + * + * attrib_x_is_lb: indicates that the x-axis of the histogram is the luminosity block number and + * that the histogram should be rebooked as necessary if the current LB exceeds + * the range. + */ + enum MgmtAttr_t { ATTRIB_MANAGED = 0, ATTRIB_UNMANAGED = 1, ATTRIB_X_VS_LB = 2}; + + + /** + * A container of information describing a monitoring object. + */ + + class MonGroup { + public: + + inline MonGroup( ManagedMonitorToolBase* tool, const std::string& system, + Interval_t interval ) + : m_tool(tool), m_system(system), m_interval(interval), m_histo_mgmt(ATTRIB_MANAGED), m_chain(""), m_merge("") { } + + inline MonGroup( ManagedMonitorToolBase* tool, const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt ) + : m_tool(tool), m_system(system), m_interval(interval), m_histo_mgmt(histo_mgmt), m_chain(""), m_merge("") { } + + inline MonGroup( ManagedMonitorToolBase* tool, const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt, const std::string& chain ) + : m_tool(tool), m_system(system), m_interval(interval), m_histo_mgmt(histo_mgmt), m_chain(chain), m_merge("") { } + + inline MonGroup( ManagedMonitorToolBase* tool, const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt, const std::string& chain, + const std::string& merge ) + : m_tool(tool), m_system(system), m_interval(interval), m_histo_mgmt(histo_mgmt), m_chain(chain), m_merge(merge) { } + + + /** + * Registers a TH1 (including TH2, TH3, and TProfile) to be included in the output stream + * using logical parameters that describe the histogram. The optional 'dqmAlgorithm' + * parameter may be used to specify an algorithm to automatically check the + * histogram after it has been filled. + */ + StatusCode regHist( TH1* h ); + + + /** + * Returns a TH1 via the pointer passed as the first + * argument. The histogram name, without the leading path or stream name, must be + * given as the second argument. + */ + + StatusCode getHist( TH1*& h, const std::string& hName ); + + + /** + * Returns a TH2 via the pointer passed as the first + * argument. The histogram name, without the leading path or stream name, must be + * given as the second argument. + */ + + StatusCode getHist( TH2*& h, const std::string& hName ); + + + /** + * Registers a TGraph to be included in the output stream + * using logical parameters that describe the histogram. The optional 'dqmAlgorithm' + * parameter may be used to specify an algorithm to automatically check the + * histogram after it has been filled. + */ + + StatusCode regGraph( TGraph* g ); + + + /** + * Registers a TTree to be included in the output stream + * using logical parameters that describe the histogram. + */ + + StatusCode regTree( TTree* t ); + + /** + * Write and delete a histogram + */ + + StatusCode writeAndDelete( TH1* h); + + + /** + * De-registers a TH1 from the THistSvc, but does NOT delete the object. + */ + + StatusCode deregHist( TH1* h ); + + + /** + * De-registers a TGraph from the THistSvc, but does NOT delete the object (also works for LWHists). + */ + + StatusCode deregGraph( TGraph* g ); + + + /** + * De-registers a TObject from the THistSvc, but does NOT delete the object (also works for LWHists). + */ + + StatusCode deregObject( const std::string& objName ); + + + /** + * De-registers all TH1 objects from the THistSvc, but does NOT delete the objects. + */ + + StatusCode deregAll(); + + /** + * Support for lightweight histograms (NB: The various + * deReg methods also work, but of course will just + * prevent the LWHist's from being dereg'ed later). + */ + StatusCode regHist( LWHist* h ); + /* + template <class TLWHist> + StatusCode regHist( TLWHist*& h ) + { + if( m_tool != 0 ) { + std::string hName( h->GetName() ); + HistMapLW_t::value_type valToInsert( hName, h );//Fixme: Just keep a list of the hists + m_mapLW.insert( valToInsert ); + return m_tool->regHist( h, *this ); + } + + return StatusCode::FAILURE; + } + */ + + StatusCode getHist( LWHist*& h, const std::string& hName ); + StatusCode deregHist( LWHist* h ); + + + inline const std::string& system() const { return m_system; } + //inline LevelOfDetail_t level() const { return m_level; } + inline Interval_t interval() const { return m_interval; } + inline MgmtAttr_t histo_mgmt() const { return m_histo_mgmt; } + inline const std::string& chain() const { return m_chain; } + inline const std::string& merge() const { return m_merge; } + + /** + * A mapping of histogram name to histogram object. + */ + + typedef std::map<std::string,TH1*> HistMap_t; + typedef std::map<std::string,LWHist*> HistMapLW_t; + + + /** + * A map containing all histograms registered with this MonGroup. + * NB: Does not return LWHists (support for this could be added). + */ + + inline HistMap_t& map() { return m_map; } + inline HistMapLW_t& mapLW() { return m_mapLW; } + + //Copy and assignment constructors! To forbid eventually, but for now we monitor their usage: + MonGroup( const MonGroup & o ) + : m_tool(o.m_tool), + m_system(o.m_system), + //m_level(o.m_level), + m_interval(o.m_interval), + m_histo_mgmt(o.m_histo_mgmt), + m_chain(o.m_chain), + m_merge(o.m_merge), + m_map(o.m_map), + m_mapLW(o.m_mapLW) + { + badusage(); + } + + MonGroup & operator= ( const MonGroup & o ) + { + if (&o != this) { + m_tool = o.m_tool; + m_system = o.m_system; + //m_level = o.m_level; + m_interval = o.m_interval; + m_histo_mgmt = o.m_histo_mgmt; + m_chain = o.m_chain; + m_merge = o.m_merge; + m_map = o.m_map; + m_mapLW = o.m_mapLW; + } + badusage(); + return *this; + } + static unsigned ncopies(); + private: + inline MonGroup() { } + ManagedMonitorToolBase* m_tool; + std::string m_system; + //LevelOfDetail_t m_level; + Interval_t m_interval; + MgmtAttr_t m_histo_mgmt; + std::string m_chain; + std::string m_merge; + HistMap_t m_map; + HistMapLW_t m_mapLW; + static void badusage(); + }; + + + template <class T> + class MgmtParams { + public: + inline MgmtParams(T* templateHist, MonGroup group) + : m_templateHist(templateHist), m_group(group) { } + + T* m_templateHist; + MonGroup m_group; + + }; + + + /** + * A function-object base class allowing the specific implementation of getStreamName + * to be decided at runtime. + */ + + class StreamNameFcn { + public: + virtual ~StreamNameFcn(){}; + + /** + * A function that converts a MonGroup of logical parameters into a physical + * output stream name. + */ + + virtual std::string getStreamName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, bool usePreviousInterval=false ) = 0; + + /** + * A function that returns TDirectory path in a file that corresponds to a given MonGroup and object name. + */ + + virtual std::string getDirectoryName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, const bool usePreviousInterval ) = 0; + + /** + * A helper non-virtual function, parses id string. String format: id = /root/rem + * The method is needed to separate root stream from the directory in a file. + * E.g. typical streamName is /TestMon/run_211670/lb_360/spacepointVsEvent_managed + * - TestMon is the stream from configuration file + * (svcMgr.THistSvc.Output += ["TestMon DATAFILE='TestMon.root' OPT='RECREATE'"]) + * - run_211670/lb_360/ - directory path + * - spacepointVsEvent_managed - object name + * + * in this case, + * root = TestMon + * rem = run_211670/lb_360/spacepointVsEvent_managed + * + */ + static void parseString(const std::string& streamName, std::string& root, std::string& rem); + }; + + + /** + * Converts a LevelOfDetail_t to a string of the same name. + */ + + //static std::string levelOfDetailEnumToString( LevelOfDetail_t level, bool useOnlineConventions = false ); + + + /** + * Converts a string to the corresponding LevelOfDetail_t. + */ + + //static LevelOfDetail_t levelOfDetailStringToEnum( const std::string& str ); + + + /** + * Converts a Interval_t to a string of the same name. + */ + + static std::string intervalEnumToString( Interval_t interval ); + + + /** + * Converts a string to the corresponding Interval_t. + */ + + static Interval_t intervalStringToEnum( const std::string& str ); + + + ManagedMonitorToolBase( const std::string & type, const std::string & name, + const IInterface* parent ); + + virtual ~ManagedMonitorToolBase(); + + + /** + * Returns the function object that converts logical paramters into a physical stream name. + */ + + virtual StreamNameFcn* streamNameFunction(); + + + virtual StatusCode initialize(); + + /** + * Calls bookHists( true, true, true ) and initializes lumiBlock and run numbers. + */ + + virtual StatusCode bookHists(); + + /** + * Calls fillHists( bool, bool, bool ); if an eventBlock,lumiBlock, or run has turned over, + * calls procHists( bool, bool, bool ) and bookHists( bool, bool, bool ). + */ + + virtual StatusCode fillHists(); + + /** + * Calls procHists( true, true, true ). + */ + + virtual StatusCode finalHists(); + + + /** + * Deal with the LW histograms + */ + virtual StatusCode convertLWHists(); + + + /** + * An inheriting class should either override this function or bookHists(). + */ + + virtual StatusCode bookHistograms(); + + + /** + * An inheriting class should either override this function, bookHists() or bookHistograms(). + */ + + virtual StatusCode bookHistogramsRecurrent(); + + + /** + * An inheriting class should either override this function or fillHists(). + */ + + virtual StatusCode fillHistograms(); + + + /** + * An inheriting class should either override this function or finalHists(). + */ + + virtual StatusCode procHistograms( ); + + + /** + * Takes a pointer to a managing object to get information from it when needed. + */ + + virtual void setMonManager( AthenaMonManager* manager ); + + + /** + * Registers a TH1 (including TH2, TH3, and TProfile) to be included in the output stream + * using logical parameters that describe the histogram. + */ + virtual StatusCode regHist( TH1* h, const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt = ATTRIB_MANAGED, const std::string& chain = "", const std::string& merge = "" ); + + /** + * Registers a TH1 (including TH2, TH3, and TProfile) to be included in the output stream + * using logical parameters that describe the histogram. A histogram is passed + * via reference to a pointer. + */ + virtual StatusCode regHist( TH1* h, const MonGroup& group ); + + + /** + * Returns a TH1 via the pointer passed as the first + * argument. The histogram name, without the leading path or stream name, must be + * given as the second argument. + */ + + virtual StatusCode getHist( TH1*& h, const std::string& hName, const std::string& system, Interval_t interval ); + + /** + * Returns a TH1 via the pointer passed as the first + * argument. The histogram name, without the leading path or stream name, must be + * given as the second argument. + */ + + virtual StatusCode getHist( TH1*& h, const std::string& hName, const MonGroup& group ); + + + /** + * Returns a TH2 via the pointer passed as the first + * argument. The histogram name, without the leading path or stream name, must be + * given as the second argument. + */ + + virtual StatusCode getHist( TH2*& h, const std::string& hName, const std::string& system, + Interval_t interval ); + + /** + * Returns a TH2 via the pointer passed as the first + * argument. The histogram name, without the leading path or stream name, must be + * given as the second argument. + */ + + virtual StatusCode getHist( TH2*& h, const std::string& hName, const MonGroup& group ); + + + /** + * Registers a TGraph to be included in the output stream + * using logical parameters that describe the graph. + */ + + + virtual StatusCode regGraph( TGraph* g, const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt = ATTRIB_MANAGED, const std::string& chain = "", const std::string& merge = "" ); + + /** + * Registers a TGraph to be included in the output stream + * using logical parameters that describe the graph. + */ + + virtual StatusCode regGraph( TGraph* g, const MonGroup& group ); + + + /** + * Registers a TTree to be included in the output stream + * using logical parameters that describe it. + */ + + virtual StatusCode regTree( TTree* t, const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt = ATTRIB_MANAGED, const std::string& chain = "", const std::string& merge = "" ); + + /** + * Registers a TTree to be included in the output stream + * using logical parameters that describe it. + */ + + virtual StatusCode regTree( TTree* t, const MonGroup& group ); + + + /** + * Support for lightweight histograms: + */ + + virtual StatusCode regHist( LWHist* h, const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt = ATTRIB_MANAGED, const std::string& chain = "", const std::string& merge = "" ); + virtual StatusCode regHist( LWHist* h, const MonGroup& group ); + + /* + template <class TLWHist> + StatusCode regHist( TLWHist*& h,const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt, const std::string& chain, const std::string& merge ); + + template <class TLWHist> + StatusCode regHist( TLWHist*& h, const MonGroup& group ); + */ + + virtual StatusCode getHist( LWHist*& h, const std::string& hName, const std::string& system, Interval_t interval ); + virtual StatusCode getHist( LWHist*& h, const std::string& hName, const MonGroup& group ); + virtual StatusCode deregHist( LWHist* h ); + + /** + * Write out histogram and delete it + */ + + virtual StatusCode writeAndDelete( TH1* h, const MonGroup& group ); + + + /** + * De-registers a TH1 from the THistSvc, but does NOT delete the object. + */ + + virtual StatusCode deregHist( TH1* h ); + + + /** + * De-registers a TGraph from the THistSvc, but does NOT delete the object. + */ + + virtual StatusCode deregGraph( TGraph* g ); + + + /** + * De-registers a TObject from the THistSvc, but does NOT delete the object. + * (NB: LightWeight histograms are not even registered until readout). + */ + + virtual StatusCode deregObject( const std::string& objName, const std::string& system, Interval_t interval ); + + + /** + * De-registers a TObject from the THistSvc, but does NOT delete the object. + * (NB: LightWeight histograms are not even registered until readout). + */ + + virtual StatusCode deregObject( const std::string& objName, const MonGroup& group ); + + + /** + * This implementation does nothing---streams in this class + * should be managed by the AthenaMonManager. + * Consider using MonitorToolBase for user-managed streams. + */ + + virtual StatusCode setupOutputStreams( std::vector<std::string> Mapping + = std::vector<std::string>() ); + + + /** + * This implementation does nothing; equivalent functionality may be provided by + * procHists( true, true, true ). + */ + + virtual StatusCode runStat(); + + + /** + * This implementation does nothing; equivalent functionality may be provided by + * procHists(...) with appropriate arguments. + */ + + virtual StatusCode checkHists( bool calledFromFinalize ); + + virtual bool preSelector(); + + + /** + * Average mu, i.e. <mu> + * + */ + virtual float lbAverageInteractionsPerCrossing(); + + /** + * Instantaneous number of interactions, i.e. mu + * + */ + virtual float lbInteractionsPerCrossing(); + + /** + * Average luminosity (in ub-1 s-1 => 10^30 cm-2 s-1) + * + */ + virtual float lbAverageLuminosity(); + + /** + * Instantaneous luminosity + * + */ + virtual float lbLuminosityPerBCID(); + + /** + * Luminosity block time (in seconds) + * + */ + virtual double lbDuration(); + + /** + * Average luminosity livefraction + * + */ + virtual float lbAverageLivefraction(); + + /** + * Livefraction per bunch crossing ID + * + */ + virtual float livefractionPerBCID(); + + /** + * Average Integrated Luminosity Live Fraction + * + */ + virtual double lbLumiWeight(); + + + protected: + std::map< Interval_t, std::vector< MgmtParams<TH1> > > m_templateHistograms; + // Runs over the vector of managed histograms, register clonned histogram and saves it to a file. + StatusCode regManagedHistograms(std::vector< MgmtParams<TH1> >& m_templateHistograms); + + std::map< Interval_t, std::vector< MgmtParams<TGraph> > > m_templateGraphs; + // Runs over the vector of managed graphs, register clonned graph and saves it to a file. + StatusCode regManagedGraphs(std::vector< MgmtParams<TGraph> >& m_templateGraphs); + + std::map< Interval_t, std::vector< MgmtParams<TTree> > > m_templateTrees; + // Runs over the vector of managed trees, register clonned tree and saves it to a file. + StatusCode regManagedTrees(std::vector< MgmtParams<TTree> >& m_templateTrees); + + std::map< Interval_t, std::vector< MgmtParams<LWHist> > > m_templateLWHistograms; + // Runs over the vector of managed histograms and register them (just a helper method). + StatusCode regManagedLWHistograms(std::vector< MgmtParams<LWHist> >& m_templateLWHistograms, bool usePreviousInterval, bool doDelete=false); + + std::vector<std::string> m_vTrigChainNames, m_vTrigGroupNames; + StatusCode parseList(const std::string&, std::vector<std::string>&); + + StatusCode registerMetadata(const std::string& streamName, const std::string& hName, const MonGroup& group); + + /** + * Fixes THistSvc->deReg(obj) when obj is TGraph instance. + * Read more in source file about this bug. + */ + StatusCode THistSvc_deReg_fixTGraph(TFile* file, TGraph* theGraph, std::string& directoryName); + + inline unsigned int get_nEvents() const { + return m_nEvents; + } + + inline long get_procNEventsProp() const { + return m_procNEventsProp; + } + + class OutputMetadata { + public: + OutputMetadata( TTree* metadata ); + virtual ~OutputMetadata(); + + virtual void fill( const std::string& name, + //LevelOfDetail_t level, + Interval_t interval, + std::string trigger, + std::string merge ); + + protected: + void copyString( char* to, const std::string& from ); + const int charArrSize; + TTree* m_metadata; + char* m_nameData; + //char* m_levelData; + char* m_intervalData; + char* m_triggerData; + char* m_mergeData; + }; + + + class DefaultStream : public StreamNameFcn { + public: + DefaultStream( const std::string& fileKey ) + : m_fileKey(fileKey) { } + virtual ~DefaultStream() { } + virtual std::string getStreamName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, bool usePreviousInterval=false ); + virtual std::string getDirectoryName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, const bool usePreviousInterval ); + + private: + const std::string m_fileKey; + }; + + + class NoOutputStream : public StreamNameFcn { + public: + virtual std::string getStreamName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, bool usePreviousInterval=false ); + virtual std::string getDirectoryName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, const bool usePreviousInterval ); + }; + + + class OnlineStream : public StreamNameFcn { + public: + virtual std::string getStreamName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, bool usePreviousInterval=false ); + virtual std::string getDirectoryName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, const bool usePreviousInterval ); + }; + + + class OfflineStream : public StreamNameFcn { + public: + OfflineStream( const std::string& fileKey, AthenaMonManager::DataType_t /*dataType*/, + AthenaMonManager::Environment_t /*environment*/ ) + : m_fileKey(fileKey) { } + + virtual ~OfflineStream() { } + virtual std::string getStreamName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, bool usePreviousInterval=false ); + virtual std::string getDirectoryName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, const bool usePreviousInterval ); + + private: + OfflineStream() { } + const std::string m_fileKey; + //AthenaMonManager::DataType_t m_dataType; + //AthenaMonManager::Environment_t m_environment; + std::set<std::string> m_ebNames; + void getLBrange(int*,int*,int,int); + }; + + virtual bool trigChainsArePassed(std::vector<std::string>&); + + virtual StreamNameFcn* getNewStreamNameFcn() const; + + + /** + * Variable allowing clients to determine when to book new and process old histograms; + * values are updated by fillHists() based on counting lumiBlocks, + * and are correctly set when fillHistograms(), + * bookHistograms() and procHistograms() are called. + */ + + bool newLowStatInterval, newMedStatInterval, newHigStatInterval; + bool newLowStat, newLumiBlock, newRun; + bool newEventsBlock; + + bool endOfEventsBlock, endOfLowStat, endOfLumiBlock, endOfRun; + + typedef std::map<std::string,OutputMetadata*> MDMap_t; + MDMap_t m_metadataMap; + + std::set<LWHist*> m_lwhists; + AthenaMonManager* m_manager; + + std::string m_managerNameProp; + + std::string m_fileKey; + std::string m_dataTypeStr; + std::string m_environmentStr; + unsigned int m_detailLevel; + + AthenaMonManager::DataType_t m_dataType; + AthenaMonManager::Environment_t m_environment; + + StreamNameFcn* m_streamNameFcn; + + ServiceHandle<ITHistSvc> m_THistSvc; + ToolHandle<Trig::ITrigDecisionTool> m_trigDecTool; + ToolHandleArray<IDQFilterTool> m_DQFilterTools; + + long m_procNEventsProp; + std::string m_path; + long m_preScaleProp; + std::string m_triggerChainProp; + std::string m_triggerGroupProp; + + bool m_useTrigger; + + unsigned int m_lastLumiBlock; + unsigned int m_lastRun; + int m_lastLowStatInterval, m_lastMedStatInterval, m_lastHigStatInterval; + + unsigned int m_nEvents; + unsigned int m_nEventsIgnoreTrigger; + unsigned int m_nLumiBlocks; + bool m_haveClearedLastEventBlock; + + + private: + /** + * Private helper class. Used to restore gFile and gDirectory values + * after those being changed in a block of the code. + */ + class GlobalDirectoryRestore { + public: + GlobalDirectoryRestore(); + ~GlobalDirectoryRestore(); + private: + TDirectory* m_gd; + TFile* m_gf; + }; + + //bool findStream(const std::string& id, std::string& stream, std::string& rem) const; + //std::string dirname(std::string& dir) const; + + ToolHandle<ILuminosityTool> m_lumiTool; + ToolHandle<ITrigLivefractionTool> m_liveTool; + bool m_hasRetrievedLumiTool; + bool m_bookHistogramsInitial; + bool m_useLumi; + int m_cycleNum; + std::set<Interval_t> m_supportedIntervalsForRebooking; + + // Use private implementation idiom for more flexible development. + class Imp; + Imp * d; + +}; + +#endif diff --git a/Control/AthenaMonitoring/AthenaMonitoring/ManagedMonitorToolTest.h b/Control/AthenaMonitoring/AthenaMonitoring/ManagedMonitorToolTest.h new file mode 100755 index 00000000000..5c1c86fc8bf --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/ManagedMonitorToolTest.h @@ -0,0 +1,76 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ManagedMonitorToolTest_H +#define ManagedMonitorToolTest_H + +#include <vector> + +#include "AthenaMonitoring/ManagedMonitorToolBase.h" +#include "TRandom3.h" + +class TH1; +class TGraph; +class TTree; +class TH1D; +class TH1D_LW; +class TH1F_LW; +class TH2F; +class TH2F_LW; + +class ManagedMonitorToolTest : public ManagedMonitorToolBase +{ + public: + + ManagedMonitorToolTest( const std::string & type, const std::string & name, + const IInterface* parent ); + + virtual ~ManagedMonitorToolTest(); + + virtual StatusCode bookHistogramsRecurrent(); + virtual StatusCode bookHistograms(); + virtual StatusCode fillHistograms(); + virtual StatusCode procHistograms(); + + protected: + + static const long s_nEnsembles; + static const double s_ensembleGenMean; + static const double s_ensembleGenSigma; + + bool m_generatorIsInit; + unsigned long m_generatorSeedProp; + + std::vector<TH1*> m_ensembles; + TH1* m_ensembleMean; + TH1* m_ensembleRMS; + TH1* m_ensembleMeanPull; + TH1* m_ensembleMeanPullDist; + + TH1* m_managedHist0_lowStat; + TH1* m_managedHist1_lowStat; + TH1* m_managedHist2_lowStat; + TH1* m_managedHist_lumiBlock; + TH1* m_managedHist_eventsBlock; + TH1* m_managedHist_run; + + TGraph* m_graph; + TGraph* m_managedGraph; + TTree* m_ntuple; + TTree* m_managedNtuple; + std::vector<int> m_spacepoint; + std::vector<int> m_event; + int m_counter; + int m_variable1, m_variable2; + + TH1D_LW *m_hlw_1D; + TH1F_LW *m_hlw_1F; + TH2F_LW *m_hlw_2F; + + int m_offset; + TRandom3 m_gen; + +}; + +#endif diff --git a/Control/AthenaMonitoring/AthenaMonitoring/MonitorToolBase.h b/Control/AthenaMonitoring/AthenaMonitoring/MonitorToolBase.h new file mode 100755 index 00000000000..c489cb48ed3 --- /dev/null +++ b/Control/AthenaMonitoring/AthenaMonitoring/MonitorToolBase.h @@ -0,0 +1,97 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef MONITORTOOLBASE_H +#define MONITORTOOLBASE_H + +#include "GaudiKernel/AlgTool.h" +#include "GaudiKernel/IHistogramSvc.h" +#include "GaudiKernel/ITHistSvc.h" + +#include "IMonitorToolBase.h" + +#include <string> +#include <vector> +#include <map> + +class MonitorToolBase : public AlgTool, + virtual public IMonitorToolBase + +{ + + public: + typedef std::map<std::string,std::string> map_type; + + public: + + MonitorToolBase(const std::string & type, const std::string & name, + const IInterface* parent); + + // setup output streams + StatusCode setupOutputStreams(std::vector<std::string> Mapping + = std::vector<std::string>() ); + + //default destructor + virtual ~MonitorToolBase(); + + StatusCode initialize() + { m_counter=m_preScale; return StatusCode::SUCCESS; }; + + //default finalHists() method + virtual StatusCode finalHists(); + + //default checkHists() method, called periodically (argument false) + // or after finalHists (argument true) + virtual StatusCode checkHists(bool fromFinalize); + + //default runStat() method - empty + virtual StatusCode runStat(); + + virtual bool histsNotBooked(); + + virtual bool preSelector(); + + // Simple method for accessing histo service for booking + IHistogramSvc* ToolHistoSvc(); + + // Simple method for accessing root histo service for booking + ITHistSvc* ToolRootHistSvc(); + + // Functions for use in dynamic histogram booking + void SetBookStatus(bool status); + + virtual StatusCode convertLWHists() { return StatusCode::SUCCESS; } //Reimplement if using LWHists + + protected: + + std::string getStreamName(unsigned int number, bool useDefault=true); + + std::string getStreamName(std::string stream, bool useDefault=true); + + protected: + + IHistogramSvc* m_histsvc; + ITHistSvc* m_rootsvc; + bool m_isBooked; + std::string m_path; + + // default stream name + std::string m_THistSvc_streamname; + + // multiple StreamNames + std::vector<std::string> m_THistSvc_streamnameMapping; + std::map<std::string,std::string> m_map_THistSvc_streamnames; + bool setupStreamMap; + + std::string m_THistSvc_refStream; + + std::string m_LogFileName; + std::string m_FormatString; + + unsigned long m_preScale; + unsigned long m_counter; + +}; + +#endif diff --git a/Control/AthenaMonitoring/cmt/requirements b/Control/AthenaMonitoring/cmt/requirements new file mode 100755 index 00000000000..3718b43640e --- /dev/null +++ b/Control/AthenaMonitoring/cmt/requirements @@ -0,0 +1,41 @@ +package AthenaMonitoring + +author Manuel Diaz <Manuel.Diaz@cern.ch> +author Robert McPherson <Robert.McPherson@cern.ch> +author Michael Wilson <Michael.G.Wilson@cern.ch> +author Sebastian Schaetzel <Sebastian.Schaetzel@cern.ch> +author Peter Onyisi <ponyisi@cern.ch> + +use AtlasPolicy AtlasPolicy-* +use AthenaBaseComps AthenaBaseComps-* Control +use GaudiInterface GaudiInterface-* External +use AtlasROOT AtlasROOT-* External +use TrigAnalysisInterfaces TrigAnalysisInterfaces-* Trigger/TrigAnalysis +use LumiBlockComps LumiBlockComps-* LumiBlock + +private +apply_tag ROOTGraphicsLibs +use AthenaKernel AthenaKernel-* Control +use TrigDecisionInterface TrigDecisionInterface-* Trigger/TrigEvent +use EventInfo EventInfo-* Event +use AthenaPoolUtilities AthenaPoolUtilities-* Database/AthenaPOOL +use SGAudCore SGAudCore-* Control/SGMon +use AtlasCORAL AtlasCORAL-* External +use LWHists LWHists-* Tools + +#Get this lib in debug mode: +#macro cppdebugflags '$(cppdebugflags_s)' +#macro_remove componentshr_linkopts "-Wl,-s" +#macro_remove AtlasCxxPolicy_pp_cppflags "-DNDEBUG" +#For testing that we don't have any alignment problems: +#macro_append AtlasCxxPolicy_pp_cppflags "-Wpadded" +macro_append cppflags "-std=c++0x" +macro_append cpplinkflags "-std=c++0x" +end_private + +apply_pattern declare_joboptions files="*.py" +apply_pattern declare_python_modules files="*.py" + +apply_pattern dual_use_library files=*.cxx + +macro_append cppflags "" \ diff --git a/Control/AthenaMonitoring/python/BadLBFilterTool.py b/Control/AthenaMonitoring/python/BadLBFilterTool.py new file mode 100644 index 00000000000..244842f50df --- /dev/null +++ b/Control/AthenaMonitoring/python/BadLBFilterTool.py @@ -0,0 +1,112 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +from PyUtils.Decorators import memoize + +def _resolve_db_tag(origDbTag): + from AthenaCommon.GlobalFlags import globalflags + if origDbTag is not None: + dbtag = origDbTag + else: + dbtag = globalflags.ConditionsTag() + dbtag = dbtag if dbtag != '' else 'HEAD' + return dbtag + +# Set up the bad lb filter tool +# Cache instances that are already created +@memoize +def GetBadLBFilterTool(name, defects, alwaysReturnTrue=False, ignoreRecoverable=False, autoconfigure=True, origDbTag=None): + """ + Configure an instance of the bad LB filter tool. If called twice with the same options, will return the same instance. + Arguments: + - name: name of instance to create + - defects: the defects to use for LB rejection. Tool will return false if any of these defects is present. These may be virtual defects. NOTE: the value you pass must be a 'hashable' type. The best choice is to pass a tuple; you can create a tuple from any iterable object with tuple(obj). + - alwaysReturnTrue (optional; default=False): if True, the tool will never reject any LBs. + - ignoreRecoverable (optional; default=False): if True, the tool will ignore defects that are marked as recoverable + - autoconfigure (optional; default=True): automatically handle certain cases, e.g. Monte Carlo, where we want to always return True + - origDbTag (optional): if set, will override automatic configuration of database tag (only for testing) + """ + import operator + from AthenaMonitoring.DQMonFlags import DQMonFlags + from AthenaCommon.GlobalFlags import globalflags + from AthenaCommon.AppMgr import ToolSvc + from AthenaCommon.Logging import logging + log = logging.getLogger('BadLBFilterTool') + + # if online or MC, we don't want to do any filtering, or even access + # the DBs + if autoconfigure and (DQMonFlags.monManEnvironment == 'online' + or globalflags.DataSource.get_Value() == 'geant4' + ): + log.info('Disabling bad LB filter tool due to inappropriate environment; returning dummy') + from AthenaMonitoring.AthenaMonitoringConf import DQDummyFilterTool + monFilterTool = DQDummyFilterTool(name) + ToolSvc += monFilterTool + return monFilterTool + + from AthenaMonitoring.AthenaMonitoringConf import DQBadLBFilterTool + from DQDefects import DefectsDB + dbtag = _resolve_db_tag(origDbTag) + ddb = DefectsDB('COOLOFL_GLOBAL/COMP200', tag=dbtag) + + primary_defects = set() + for defect in defects: + if defect in ddb.defect_names: + primary_defects.add(defect) + elif defect in ddb.virtual_defect_names: + primary_defects |= ddb.virtual_defect_logics(defect).primary_defects + else: + raise ValueError('%s is not a known defect' % defect) + + log.info ("Tool name %s to be configured with intolerable defects %s" % (name, list(primary_defects))) + + primary_defect_ids = [ddb.defect_id_map[id] for id in primary_defects] + + monFilterTool = DQBadLBFilterTool(name) + monFilterTool.defectList = primary_defect_ids + monFilterTool.alwaysReturnTrue = alwaysReturnTrue + monFilterTool.ignoreRecoverable = ignoreRecoverable + + if globalflags.DataSource.get_Value() != 'geant4': + from IOVDbSvc.CondDB import conddb + if not conddb.folderRequested('/GLOBAL/DETSTATUS/DEFECTS'): + conddb.addFolder('GLOBAL_OFL', '/GLOBAL/DETSTATUS/DEFECTS') + + ToolSvc += monFilterTool + return monFilterTool + +def GetLArBadLBFilterTool(origDbTag=None): + """ + Configure a LAr defect-specific instance of the bad LB filter tool. If called twice with the same options, will return the same instance. + Arguments: + - origDbTag (optional): if set, will override automatic configuration of database tag (only for testing) + """ + import operator + from AthenaCommon.Logging import logging + log = logging.getLogger('BadLBFilterTool/LAr') + + # if online or MC, we don't want to do any filtering, or even access + # the DBs + from AthenaMonitoring.DQMonFlags import DQMonFlags + from AthenaCommon.GlobalFlags import globalflags + if (DQMonFlags.monManEnvironment == 'online' + or globalflags.DataSource.get_Value() == 'geant4' + ): + log.info('Disabling LAr bad LB filter tool due to inappropriate environment') + lar_defects = [] + else: + from DQDefects import DefectsDB + dbtag = _resolve_db_tag(origDbTag) + ddb = DefectsDB('COOLOFL_GLOBAL/COMP200', tag=dbtag) + defects = ddb.defect_names + defectliststr = [] + defectlist = [] + lar_defects = reduce(operator.or_, [set(ddb.virtual_defect_logics[z].clauses) for z in \ + ('EMBA', 'EMBC', 'EMECA', 'EMECC', 'HECA', 'HECC', 'FCALA', \ + 'FCALC')])-set(['LAR_UNCHECKED','LAR_GENERAL','DISABLED','NONGREEN']) + lar_defects = set(defect for defect in lar_defects + if ('LAR' in defect and + (('HVTRIP' in defect) or ('SEV' in defect) or + ('CORRUPT' in defect) or ('HVRAMPUP' in defect)))) + + return GetBadLBFilterTool('LArBadLBFilterTool', tuple(lar_defects), + origDbTag=origDbTag) diff --git a/Control/AthenaMonitoring/python/DQMonFlags.py b/Control/AthenaMonitoring/python/DQMonFlags.py new file mode 100644 index 00000000000..618f5dda9a2 --- /dev/null +++ b/Control/AthenaMonitoring/python/DQMonFlags.py @@ -0,0 +1,395 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +## +## @file DataQualityTools/python/DQMonFlags.py +## @purpose Python module to hold common flags to configure JobOptions +## + +""" DQMonFlags + Python module to hold flags for Data Quality monitoring + +""" + +__author__ = "S. Schaetzel" +__version__= "$Revision: 1.11 $" +__doc__ = "DQMonFlags" + +__all__ = [ "DQMonFlags" ] + +# kindly stolen from InDetKeys by A. Wildauer + +##----------------------------------------------------------------------------- +## Import + +from AthenaCommon.JobProperties import JobProperty, JobPropertyContainer +from AthenaCommon.JobProperties import jobproperties + +##----------------------------------------------------------------------------- +## 1st step: define JobProperty classes +list=[] +class doMonitoring(JobProperty): + """ Global switch for monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doMonitoring] + +class doGlobalMon(JobProperty): + """ Switch for global combined monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doGlobalMon] + +class doLVL1CaloMon(JobProperty): + """ Switch for L1 calo monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doLVL1CaloMon] + +class doCTPMon(JobProperty): + """ Switch for CTP monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doCTPMon] + +class doHLTMon(JobProperty): + """ Switch for HLT monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doHLTMon] + +class doPixelMon(JobProperty): + """ Switch for pixel monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doPixelMon] + +class doSCTMon(JobProperty): + """ Switch for SCT monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doSCTMon] + +class doTRTMon(JobProperty): + """ Switch for TRT monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doTRTMon] + +class doTRTElectronMon(JobProperty): + """ Switch for TRT electron monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doTRTElectronMon] + +class doInDetGlobalMon(JobProperty): + """ Switch for inner detector global monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doInDetGlobalMon] + +class doInDetAlignMon(JobProperty): + """ Switch for inner detector alignment monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doInDetAlignMon] + +class doInDetPerfMon(JobProperty): + """ Switch for inner detector performance monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doInDetPerfMon] + +class doTileMon(JobProperty): + """ Switch for tile calorimeter monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doTileMon] + +class doLArMon(JobProperty): + """ Switch for LAr calorimeter monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doLArMon] + +class doCaloMon(JobProperty): + """ Switch for combined calorimeter monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doCaloMon] + +class doEgammaMon(JobProperty): + """ Switch for e/gamma monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doEgammaMon] + +class doJetMon(JobProperty): + """ Switch for jet monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doJetMon] + +class doMissingEtMon(JobProperty): + """ Switch for missing E_T monitoring""" + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doMissingEtMon] + +class doTauMon(JobProperty): + """ Switch for tau monitoring""" + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doTauMon] + +class doJetTagMon(JobProperty): + """ Switch for jet-tag monitoring""" + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doJetTagMon] + +class doMuonRawMon(JobProperty): + """ Switch for muon spectrometer raw data monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doMuonRawMon] + +class doMuonTrackMon(JobProperty): + """ Switch for muon track monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=False +list+=[doMuonTrackMon] + +class doMuonAlignMon(JobProperty): + """ Switch for muon alignment monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doMuonAlignMon] + +class doMuonSegmentMon(JobProperty): + """ Switch for muon segment monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=False +list+=[doMuonSegmentMon] + +class doMuonPhysicsMon(JobProperty): + """ Switch for muon physics monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=False +list+=[doMuonPhysicsMon] + +class doMuonTrkPhysMon(JobProperty): + """ Switch for muon track physics monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doMuonTrkPhysMon] + +class doMuonCombinedMon(JobProperty): + """ Switch for muon combined monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doMuonCombinedMon] + +class doLucidMon(JobProperty): + """ Switch for LUCID monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doLucidMon] + +class doStreamAwareMon(JobProperty): + """ Switch for stream-aware monitoring """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[doStreamAwareMon] + +class monType(JobProperty): + """ type of monitoring (BS, ESD)""" + statusOn = True + allowedTypes = ['str'] + StoredValue = 'BS_ESD' +list+=[monType] + +class monManEnvironment(JobProperty): + """ MonManager environment """ + statusOn = True + allowedTypes = ['str'] + StoredValue = 'tier0ESD' +list+=[monManEnvironment] + +class monManFileKey(JobProperty): + """ MonManager file key """ + statusOn = True + allowedTypes = ['str'] + StoredValue = 'CombinedMonitoring' +list+=[monManFileKey] + +class monManDataType(JobProperty): + """ MonManager data type """ + statusOn=True + allowedTypes=['str'] + StoredValue='collisions' +list+=[monManDataType] + +class monManLBsInLowStatInterval(JobProperty): + """ number of LBs in low statistics interval """ + statusOn = True + allowedTypes = ['int'] + StoredValue = 20 +list+=[monManLBsInLowStatInterval] + +class monManLBsInMediumStatInterval(JobProperty): + """ number of LBs in medium statistics interval """ + statusOn = True + allowedTypes = ['int'] + StoredValue = 60 +list+=[monManLBsInMediumStatInterval] + +class monManLBsInHighStatInterval(JobProperty): + """ number of LBs in high statistics interval """ + statusOn = True + allowedTypes = ['int'] + StoredValue = 180 +list+=[monManLBsInHighStatInterval] + +class monManManualDataTypeSetup(JobProperty): + """ MonManager ManualDataTypeSetup """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[monManManualDataTypeSetup] + +class monManManualRunLBSetup(JobProperty): + """ MonManager ManualRunLBSetup """ + statusOn=True + allowedTypes=['bool'] + StoredValue=False +list+=[monManManualRunLBSetup] + +class monManRun(JobProperty): + """ MonManager Run """ + statusOn=True + allowedTypes=['int'] + StoredValue=1 +list+=[monManRun] + +class monManLumiBlock(JobProperty): + """ MonManager LumiBlock """ + statusOn=True + allowedTypes=['int'] + StoredValue=1 +list+=[monManLumiBlock] + +class useTrigger(JobProperty): + """ use trigger (trigger-aware monitoring) """ + statusOn=True + allowedTypes=['bool'] + StoredValue=True +list+=[useTrigger] + +class monManMaxPrescale(JobProperty): + """ MonManager maxPrescale """ + statusOn=True + allowedTypes=['int'] + StoredValue=1000000 +list+=[monManMaxPrescale] + +class triggerChainMap(JobProperty): + """ Trigger map of toolname -> chain """ + statusOn=True + allowedTypes=['dict'] + StoredValue={} +list+=[triggerChainMap] + +class monManStream(JobProperty): + """ MonManager data processing stream """ + statusOn = True + allowedTypes = ['str'] + StoredValue = 'express' +list+=[monManStream] + +class histogramFile(JobProperty): + """ output file with histograms """ + statusOn = True + allowedTypes = ['str'] + StoredValue = 'Monitor.root' +list+=[histogramFile] + +class nameTrigDecTool(JobProperty): + """ name of trigger decision tool """ + statusOn = True + allowedTypes = ['str'] + StoredValue = 'monTrigDecTool' +list+=[nameTrigDecTool] + +class monToolPostExec(JobProperty): + """ MonManager environment """ + statusOn = True + allowedTypes = ['str'] + StoredValue = None +list+=[monToolPostExec] + +class disableAtlasReadyFilter(JobProperty): + """ Disable DQAtlasReadyFilterTool (will always return true if this is set) """ + statusOn=True + allowedTypes=['bool'] + StoredValue=False +list+=[disableAtlasReadyFilter] + +class disableFilledBunchFilter(JobProperty): + """ Disable DQFilledBunchFilterTool (will always return true if this is set) """ + statusOn=True + allowedTypes=['bool'] + StoredValue=False +list+=[disableFilledBunchFilter] + +##----------------------------------------------------------------------------- +## 2nd step +## Definition of the DQMon flag container +class DQMonFlagsCont(JobPropertyContainer): + """Container for Data Quality Monitoring flags + """ + pass + +##----------------------------------------------------------------------------- +## 3rd step +## adding the container to the general top-level container +jobproperties.add_Container(DQMonFlagsCont) + +##----------------------------------------------------------------------------- +## 4th step +## adding properties to DQMonFlags container +for j in list: + jobproperties.DQMonFlagsCont.add_JobProperty(j) + +##----------------------------------------------------------------------------- +## 5th step +## short-cut +DQMonFlags = jobproperties.DQMonFlagsCont diff --git a/Control/AthenaMonitoring/share/AtlasReadyFilterTool_jobOptions.py b/Control/AthenaMonitoring/share/AtlasReadyFilterTool_jobOptions.py new file mode 100644 index 00000000000..c05eacabd4e --- /dev/null +++ b/Control/AthenaMonitoring/share/AtlasReadyFilterTool_jobOptions.py @@ -0,0 +1,25 @@ +# Set up the ATLAS Ready filter tool +from AthenaCommon.Logging import logging + +arft_local_logger = logging.getLogger('AtlasReadyFilterTool_jobOptions') + +if not 'DQMonFlags' in dir(): + arft_local_logger.debug("AtlasReadyFilterTool_jobOptions.py: DQMonFlags not yet imported - I import them now") + from AthenaMonitoring.DQMonFlags import DQMonFlags + +if not 'monAtlasReadyFilterTool' in dir(): + if globalflags.DataSource.get_Value() != 'geant4': + from IOVDbSvc.CondDB import conddb + conddb.addFolder('TDAQ', '/TDAQ/RunCtrl/DataTakingMode') + + from AthenaMonitoring.AthenaMonitoringConf import DQAtlasReadyFilterTool + monAtlasReadyFilterTool = DQAtlasReadyFilterTool() + if (DQMonFlags.monManEnvironment == 'online' + or globalflags.DataSource.get_Value() == 'geant4' + or 'collisions' not in DQMonFlags.monManDataType.get_Value() + or DQMonFlags.disableAtlasReadyFilter.get_Value()): + arft_local_logger.info("Disabling ATLAS Ready monitoring filter") + monAtlasReadyFilterTool.alwaysReturnTrue = True + ToolSvc += monAtlasReadyFilterTool + +del arft_local_logger diff --git a/Control/AthenaMonitoring/share/CondDB_jobOptions.py b/Control/AthenaMonitoring/share/CondDB_jobOptions.py new file mode 100644 index 00000000000..5713a327363 --- /dev/null +++ b/Control/AthenaMonitoring/share/CondDB_jobOptions.py @@ -0,0 +1,10 @@ + +## ************************************************************ +## $Id: CondDB_jobOptions.py,v 1.1 2008-09-23 13:29:11 mgwilson Exp $ +## ************************************************************ + +from IOVDbSvc.CondDB import conddb + +## Allow retrieval of the length of luminosity blocks +conddb.addFolder('TRIGGER','/TRIGGER/LUMI/LBLB') + diff --git a/Control/AthenaMonitoring/share/DQMonFlagsConfig_jobOptions.py b/Control/AthenaMonitoring/share/DQMonFlagsConfig_jobOptions.py new file mode 100644 index 00000000000..653f4081751 --- /dev/null +++ b/Control/AthenaMonitoring/share/DQMonFlagsConfig_jobOptions.py @@ -0,0 +1,400 @@ +######################################################################## +# Offline AthenaMonitoring configuration +# set DQMonFlags; defaults are in DataQualityTools/python/DQMonFlags.py +######################################################################## + +local_logger = logging.getLogger('DQMonFlagsConfig_jobOptions') + +if not 'DQMonFlags' in dir(): + local_logger.debug("DQMonFlags not yet imported - I import them now") + from AthenaMonitoring.DQMonFlags import DQMonFlags + +if not 'rec' in dir(): + from RecExConfig.RecFlags import rec + +if rec.doTrigger() == False: + DQMonFlags.useTrigger=False # steers trigger-awareness + DQMonFlags.doLVL1CaloMon=False + DQMonFlags.doCTPMon=False + DQMonFlags.doHLTMon=False + +# Set the data type based on beamType/HI flag +if globalflags.DataSource.get_Value() == 'geant4': + DQMonFlags.monManDataType = 'monteCarlo' +elif rec.doHeavyIon(): + DQMonFlags.monManDataType = 'heavyioncollisions' +elif jobproperties.Beam.beamType() == 'cosmics': + DQMonFlags.monManDataType = 'cosmics' +elif jobproperties.Beam.beamType() == 'collisions': + DQMonFlags.monManDataType = 'collisions' +elif jobproperties.Beam.beamType() == 'singlebeam': + ## There is no singlebeam in AthenaMonitoring + DQMonFlags.monManDataType = 'collisions' +else: + local_logger.warning("invalid jobproperties.Beam.beamType(): %s, using default (%s)", + jobproperties.Beam.beamType(), DQMonFlags.monManDataType) + + +# First, test to see if this is being run online +if athenaCommonFlags.isOnline: + DQMonFlags.monManEnvironment='online' + +# Running offline; set the monMan environment based on monType +elif DQMonFlags.monType=='BSonly': + DQMonFlags.monManEnvironment='tier0Raw' + if rec.readESD(): + DQMonFlags.doMonitoring=False + +elif DQMonFlags.monType=='ESDonly': + DQMonFlags.monManEnvironment='tier0ESD' + if rec.readRDO(): + DQMonFlags.doMonitoring=False + +elif (DQMonFlags.monType=='BS_ESD'): + if rec.readRDO(): + DQMonFlags.monManEnvironment='tier0Raw' + if rec.readESD(): + DQMonFlags.monManEnvironment='tier0ESD' + if rec.readAOD(): + DQMonFlags.monManEnvironment='AOD' + +elif DQMonFlags.monType=='BSall': + DQMonFlags.monManEnvironment='tier0' + if rec.readESD(): + DQMonFlags.doMonitoring=False +else: + local_logger.warning("invalid DQMonFlags.monType: %s, using default monManEnvironment", DQMonFlags.monType()) + +if not DQMonFlags.doMonitoring(): + local_logger.info("monitoring globally switched off") + DQMonFlags.doGlobalMon=False + DQMonFlags.doLVL1CaloMon=False + DQMonFlags.doCTPMon=False + DQMonFlags.doHLTMon=False + DQMonFlags.doPixelMon=False + DQMonFlags.doSCTMon=False + DQMonFlags.doTRTMon=False + DQMonFlags.doTRTElectronMon=False + DQMonFlags.doInDetGlobalMon=False + DQMonFlags.doInDetAlignMon=False + DQMonFlags.doInDetPerfMon=False + DQMonFlags.doLArMon=False + DQMonFlags.doCaloMon=False + DQMonFlags.doTileMon=False + DQMonFlags.doEgammaMon=False + DQMonFlags.doMissingEtMon=False + DQMonFlags.doJetMon=False + DQMonFlags.doTauMon=False + DQMonFlags.doJetTagMon=False + DQMonFlags.doMuonRawMon=False + DQMonFlags.doMuonSegmentMon=False + DQMonFlags.doMuonTrackMon=False + DQMonFlags.doMuonAlignMon=False + DQMonFlags.doMuonPhysicsMon=False + DQMonFlags.doMuonTrkPhysMon=False + DQMonFlags.doMuonCombinedMon=False + DQMonFlags.doLucidMon=False +else: + local_logger.info("monitoring environment set to %s", DQMonFlags.monManEnvironment()) + + # AOD monitoring + if DQMonFlags.monManEnvironment == 'AOD': + DQMonFlags.histogramFile='MonitorAOD.root' + DQMonFlags.doCaloMon=False + DQMonFlags.doLArMon=False + DQMonFlags.doTileMon=False +# DQMonFlags.doJetMon=False + # ?? + DQMonFlags.doCTPMon=False + DQMonFlags.doSCTMon=False + DQMonFlags.doTRTMon=False + DQMonFlags.doTRTElectronMon=False +# DQMonFlags.doInDetGlobalMon=False +# DQMonFlags.doInDetAlignMon=False + + DQMonFlags.doGlobalMon=False + DQMonFlags.doLVL1CaloMon=False + DQMonFlags.doHLTMon=False + DQMonFlags.doEgammaMon=False + DQMonFlags.doMuonRawMon=False + DQMonFlags.doLucidMon=False + + # ESD monitoring: switch off DQ monitoring packages which are not yet migrated: + elif DQMonFlags.monManEnvironment == 'tier0ESD': + DQMonFlags.histogramFile='MonitorESD.root' + DQMonFlags.doCTPMon=False + DQMonFlags.doSCTMon=False + DQMonFlags.doTRTMon=False + DQMonFlags.doTRTElectronMon=False + DQMonFlags.doInDetGlobalMon=False + DQMonFlags.doInDetAlignMon=False + # ESD monitoring: packages which use only ESD: disable when running over BS + elif DQMonFlags.monManEnvironment == 'tier0Raw': + DQMonFlags.doInDetPerfMon=False + DQMonFlags.doMissingEtMon=False + DQMonFlags.doTauMon=False + DQMonFlags.doMuonTrackMon=False + DQMonFlags.doMuonAlignMon=False + DQMonFlags.doMuonPhysicsMon=False + DQMonFlags.doMuonSegmentMon=False + DQMonFlags.doMuonTrkPhysMon=False + DQMonFlags.doMuonCombinedMon=False + DQMonFlags.doLucidMon=False + DQMonFlags.doJetTagMon=False + + # switch off monitoring if reco is off during BS reading + if rec.readRDO() and not 'DetFlags' in dir(): + from AthenaCommon.DetFlags import DetFlags + + if rec.readRDO(): + if not DetFlags.detdescr.ID_on(): + local_logger.info("ID reco is off, switching off ID monitoring") + DQMonFlags.doPixelMon=False + DQMonFlags.doSCTMon=False + DQMonFlags.doTRTMon=False + DQMonFlags.doTRTElectronMon=False + DQMonFlags.doInDetGlobalMon=False + DQMonFlags.doInDetAlignMon=False + DQMonFlags.doInDetPerfMon=False + + if not DetFlags.detdescr.LAr_on(): + local_logger.info("LAr reco is off, switching off LAr monitoring") + DQMonFlags.doLArMon=False + + if not DetFlags.detdescr.Tile_on(): + local_logger.info("Tile reco is off, switching off Tile monitoring") + DQMonFlags.doTileMon=False + + if (not DetFlags.detdescr.LAr_on()) and (not DetFlags.detdescr.Tile_on()) : + local_logger.info("LAr and Tile reco are off, switching off Calo monitoring") + DQMonFlags.doCaloMon=False + + if not DetFlags.detdescr.Muon_on(): + local_logger.info("Muon reco is off, switching off muon monitoring") + DQMonFlags.doMuonRawMon=False + DQMonFlags.doMuonSegmentMon=False + DQMonFlags.doMuonTrackMon=False + DQMonFlags.doMuonAlignMon=False + DQMonFlags.doMuonPhysicsMon=False + DQMonFlags.doMuonTrkPhysMon=False + DQMonFlags.doMuonCombinedMon=False + +# turn monitoring off if rec.do<System>=False +# add more protections against reco off and running over bytestream +# +# From David Rousseau (4 Nov 2009): https://savannah.cern.ch/bugs/?59075 +# rec.doCalo=False means: "do not do anything wrt to calo" +# CaloRecFlags.Enabled=False means: switch off just the calo reco +# (and similar flags for other systems) + +if rec.readRDO(): + from CaloRec.CaloRecFlags import jobproperties + from InDetRecExample.InDetJobProperties import InDetFlags + from MuonRecExample.MuonRecFlags import muonRecFlags + from MuonCombinedRecExample.MuonCombinedRecFlags import muonCombinedRecFlags + from egammaRec.egammaRecFlags import jobproperties + from JetRec.JetRecFlags import jobproperties + from tauRec.tauRecFlags import jobproperties + +if (not rec.doCalo()) or (rec.readRDO() and not jobproperties.CaloRecFlags.Enabled()): + DQMonFlags.doCaloMon=False + DQMonFlags.doTileMon=False + DQMonFlags.doLArMon=False + +if (not rec.doInDet()) or (rec.readRDO() and not jobproperties.InDetJobProperties.Enabled()): + DQMonFlags.doPixelMon=False + DQMonFlags.doSCTMon=False + DQMonFlags.doTRTMon=False + DQMonFlags.doTRTElectronMon=False + DQMonFlags.doInDetGlobalMon=False + DQMonFlags.doInDetAlignMon=False + DQMonFlags.doInDetPerfMon=False + +if (not rec.doMuon()) or (rec.readRDO() and not jobproperties.MuonRec.Enabled()): + DQMonFlags.doMuonRawMon=False + DQMonFlags.doMuonSegmentMon=False + DQMonFlags.doMuonTrackMon=False + DQMonFlags.doMuonAlignMon=False + DQMonFlags.doMuonPhysicsMon=False + DQMonFlags.doMuonTrkPhysMon=False + DQMonFlags.doMuonCombinedMon=False + +if (not rec.doMuonCombined()) or (rec.readRDO() and not jobproperties.MuonCombinedRec.Enabled()): + DQMonFlags.doMuonCombinedMon=False + +if (not rec.doEgamma()) or (rec.readRDO() and not jobproperties.egammaRecFlags.Enabled()): + DQMonFlags.doEgammaMon=False + +#if (not rec.doJetRec()) or (rec.readRDO() and not jobproperties.JetRecFlags.Enabled()): +if (rec.readRDO() and not jobproperties.JetRecFlags.Enabled()): + DQMonFlags.doJetMon=False + +#if (not rec.doTau()) or (rec.readRDO() and not jobproperties.TauRecFlags.Enabled()): +if (not rec.doTau()): + DQMonFlags.doTauMon=False + +# +# Stream Aware Monitoring +# Turn off tools on a stream basis to save cpu +# + +if DQMonFlags.doStreamAwareMon: + local_logger.info("Setting stream-aware monitoring for stream %s", rec.triggerStream()) + + from TrigHLTMonitoring.HLTMonFlags import HLTMonFlags + from LArMonTools.LArMonFlags import LArMonFlags + + # Some LAr monitoring is only done on a couple of streams for cpu sake + # So set them as false by default. Turn them on as needed + LArMonFlags.doLArRODMonTool=False # savannah bug report #83390 + LArMonFlags.doLArRawMonitorSignal=False + + # All monitoring turned on for express stream (except LArRawChannelMon) + # HIP runs will use the express settings for MinBias, MinBiasOverlay, HardProbes, bulk, and UPC + if (rec.triggerStream()=='express' or + (rec.doHIP() and rec.triggerStream() in ['MinBias', 'MinBiasOverlay', 'HardProbes', 'bulk', 'UPC'])): + LArMonFlags.doLArRawChannelMon=False + LArMonFlags.doLArRODMonTool=True # savannah bug report #83390 + + elif (rec.triggerStream()=='CosmicCalo'): + LArMonFlags.doLArRawMonitorSignal=True + HLTMonFlags.doBjet=False + DQMonFlags.doJetTagMon=False + elif (rec.triggerStream()=='JetTauEtmiss'): + DQMonFlags.doEgammaMon=False + DQMonFlags.doPixelMon=False + DQMonFlags.doSCTMon=False + DQMonFlags.doTRTMon=False + LArMonFlags.doLArRawChannelMon=False + elif (rec.triggerStream()=='Egamma'): + DQMonFlags.doJetMon=False + DQMonFlags.doMissingEtMon=False + DQMonFlags.doTauMon=False + HLTMonFlags.doBjet=False + HLTMonFlags.doTau=False + HLTMonFlags.doJet=False + HLTMonFlags.doMuon=False + DQMonFlags.doMuonRawMon=False + DQMonFlags.doMuonTrackMon=False + DQMonFlags.doMuonAlignMon=False + DQMonFlags.doMuonCombinedMon=False + DQMonFlags.doMuonSegmentMon=False + DQMonFlags.doMuonPhysicsMon=False + DQMonFlags.doMuonTrkPhysMon=False + DQMonFlags.doTileMon=False + DQMonFlags.doPixelMon=False + DQMonFlags.doSCTMon=False + DQMonFlags.doJetTagMon=False + LArMonFlags.doLArRawChannelMon=False + elif (rec.triggerStream()=='Muons'): + DQMonFlags.doEgammaMon=False + DQMonFlags.doJetMon=False + DQMonFlags.doMissingEtMon=False + DQMonFlags.doTauMon=False + HLTMonFlags.doBjet=False + HLTMonFlags.doEgamma=False + HLTMonFlags.doTau=False + HLTMonFlags.doJet=False + HLTMonFlags.doCalo=False + DQMonFlags.doTileMon=False + DQMonFlags.doPixelMon=False + DQMonFlags.doSCTMon=False + DQMonFlags.doTRTMon=False + DQMonFlags.doCaloMon=False + DQMonFlags.doJetTagMon=False + LArMonFlags.doLArRawChannelMon=False + LArMonFlags.doLArCollisionTimeMon=False + LArMonFlags.doLArAffectedRegions=False + #LArMonFlags.doLArFEBMon=False + LArMonFlags.doLArHVCorrectionMonTool=False + LArMonFlags.doLArCoverage=False + LArMonFlags.doLArDigitMon=False + LArMonFlags.doLArNoisyROMon=False + elif (rec.triggerStream()=='IDCosmic'): + DQMonFlags.doEgammaMon=False + DQMonFlags.doJetMon=False + DQMonFlags.doMissingEtMon=False + DQMonFlags.doTauMon=False + HLTMonFlags.doBjet=False + HLTMonFlags.doEgamma=False + HLTMonFlags.doTau=False + HLTMonFlags.doJet=False + HLTMonFlags.doCalo=False + HLTMonFlags.doMuon=False + DQMonFlags.doTileMon=False + DQMonFlags.doPixelMon=False + DQMonFlags.doSCTMon=False + DQMonFlags.doMuonRawMon=False + DQMonFlags.doMuonTrackMon=False + DQMonFlags.doMuonAlignMon=False + DQMonFlags.doMuonCombinedMon=False + DQMonFlags.doMuonSegmentMon=False + DQMonFlags.doMuonPhysicsMon=False + DQMonFlags.doMuonTrkPhysMon=False + DQMonFlags.doCaloMon=False + DQMonFlags.doJetTagMon=False + LArMonFlags.doLArRawChannelMon=False + LArMonFlags.doLArCollisionTimeMon=False + LArMonFlags.doLArAffectedRegions=False + #LArMonFlags.doLArFEBMon=False + LArMonFlags.doLArHVCorrectionMonTool=False + LArMonFlags.doLArCoverage=False + LArMonFlags.doLArDigitMon=False + LArMonFlags.doLArNoisyROMon=False + elif (rec.triggerStream()=='ZeroBias'): + DQMonFlags.doEgammaMon=False + DQMonFlags.doTauMon=False + HLTMonFlags.doBjet=False + HLTMonFlags.doEgamma=False + HLTMonFlags.doTau=False + HLTMonFlags.doJet=False + HLTMonFlags.doCalo=False + HLTMonFlags.doMuon=False + DQMonFlags.doPixelMon=False + DQMonFlags.doMuonRawMon=False + DQMonFlags.doMuonTrackMon=False + DQMonFlags.doMuonAlignMon=False + DQMonFlags.doMuonCombinedMon=False + DQMonFlags.doMuonSegmentMon=False + DQMonFlags.doMuonPhysicsMon=False + DQMonFlags.doMuonTrkPhysMon=False + DQMonFlags.doTRTMon=False + DQMonFlags.doJetTagMon=False + LArMonFlags.doLArRawChannelMon=False + LArMonFlags.doLArCollisionTimeMon=False + LArMonFlags.doLArAffectedRegions=False + #LArMonFlags.doLArFEBMon=False + LArMonFlags.doLArHVCorrectionMonTool=False + LArMonFlags.doLArCoverage=False + LArMonFlags.doLArDigitMon=False + LArMonFlags.doLArNoisyROMon=False + LArMonFlags.doLArRODMonTool=True # savannah bug report #83390 + + # Default stream-aware settings for unspecified streams + # Only run a select few set of tools + else: + DQMonFlags.doEgammaMon=False + DQMonFlags.doJetMon=False + DQMonFlags.doMissingEtMon=False + DQMonFlags.doTauMon=False + # HLT experts need monitoring in various unspecified streams + #DQMonFlags.doHLTMon=False + DQMonFlags.doMuonTrackMon=False + DQMonFlags.doMuonAlignMon=False + DQMonFlags.doMuonCombinedMon=False + DQMonFlags.doMuonSegmentMon=False + DQMonFlags.doMuonPhysicsMon=False + DQMonFlags.doMuonTrkPhysMon=False + DQMonFlags.doCaloMon=False + DQMonFlags.doJetTagMon=False + +else: + local_logger.info("Stream-Aware monitoring is turned OFF") + +# disabled until further notice 20140401 - PUEO +DQMonFlags.doMuonRawMon=False + +DQMonFlags.lock_JobProperties() +DQMonFlags.print_JobProperties() + +del local_logger diff --git a/Control/AthenaMonitoring/share/DataQualityInit_jobOptions.py b/Control/AthenaMonitoring/share/DataQualityInit_jobOptions.py new file mode 100644 index 00000000000..814979e131e --- /dev/null +++ b/Control/AthenaMonitoring/share/DataQualityInit_jobOptions.py @@ -0,0 +1,55 @@ +############################################################################### +# Offline AthenaMonitoring configuration included in RecExCommon before # +# reconstruction is set up # +# # +# $Id: DataQualityInit_jobOptions.py,v 1.3 2009-03-20 16:38:54 sschaetz Exp $ # +############################################################################### + +# DQMonFlags +try: + include("AthenaMonitoring/DQMonFlagsConfig_jobOptions.py") +except Exception: + treatException("Could not load AthenaMonitoring/DQMonFlagsConfig_jobOptions.py") + +if DQMonFlags.doMonitoring(): + if DQMonFlags.useTrigger(): + # trigger decision tool + try: + include("AthenaMonitoring/TrigDecTool_jobOptions.py") + except Exception: + treatException("Could not load AthenaMonitoring/TrigDecTool_jobOptions.py") + + # set up first monitoring manager to set static variables + from AthenaMonitoring.AthenaMonitoringConf import AthenaMonManager + monManGlobal = AthenaMonManager(name="AthenaMonManager", + FileKey = DQMonFlags.monManFileKey(), + ManualDataTypeSetup = DQMonFlags.monManManualDataTypeSetup(), + DataType = DQMonFlags.monManDataType(), + Environment = DQMonFlags.monManEnvironment(), + LBsInLowStatInterval = DQMonFlags.monManLBsInLowStatInterval(), + LBsInMediumStatInterval = DQMonFlags.monManLBsInMediumStatInterval(), + LBsInHighStatInterval = DQMonFlags.monManLBsInHighStatInterval(), + ManualRunLBSetup = DQMonFlags.monManManualRunLBSetup(), + Run = DQMonFlags.monManRun(), + LumiBlock = DQMonFlags.monManLumiBlock()) + topSequence += monManGlobal + + # set up histogram output file + if (DQMonFlags.histogramFile() != "") and (DQMonFlags.monManFileKey() != ""): + from AthenaCommon.AppMgr import ServiceMgr as svcMgr + if not hasattr(svcMgr, 'THistSvc'): + from GaudiSvc.GaudiSvcConf import THistSvc + svcMgr += THistSvc() + svcMgr.THistSvc.Output += [ DQMonFlags.monManFileKey() + " DATAFILE='" + DQMonFlags.histogramFile() + "' OPT='RECREATE'"] + +# inner detector monitoring +if not 'InDetFlags' in dir(): + from InDetRecExample.InDetJobProperties import InDetFlags + +InDetFlags.doMonitoringPixel=DQMonFlags.doPixelMon() +InDetFlags.doMonitoringSCT=DQMonFlags.doSCTMon() +InDetFlags.doMonitoringTRT=DQMonFlags.doTRTMon() +InDetFlags.doMonitoringGlobal=DQMonFlags.doInDetGlobalMon() +InDetFlags.doMonitoringPrimaryVertexingEnhanced=DQMonFlags.doInDetGlobalMon() +InDetFlags.doMonitoringAlignment=DQMonFlags.doInDetAlignMon() + diff --git a/Control/AthenaMonitoring/share/DataQualitySteering_jobOptions.py b/Control/AthenaMonitoring/share/DataQualitySteering_jobOptions.py new file mode 100644 index 00000000000..7c6279b57f7 --- /dev/null +++ b/Control/AthenaMonitoring/share/DataQualitySteering_jobOptions.py @@ -0,0 +1,270 @@ +# ******************************************************************************** +# Offline AthenaMonitoring configuration +# +# $Id: DataQualitySteering_jobOptions.py,v 1.15 2009-05-05 08:20:08 sschaetz Exp $ +# ******************************************************************************** + +# disable InDetPerformanceMonitoring, JetMonitoring until further notice +# - PUEO 20140401 +TRTELEMON=False +IDPERFMON=False + +local_logger = logging.getLogger('DataQualitySteering_jobOptions') + +if DQMonFlags.doMonitoring(): + if DQMonFlags.useTrigger(): + if not hasattr(ToolSvc, DQMonFlags.nameTrigDecTool()): + local_logger.debug("trigger decision tool not found, including it now") + include("AthenaMonitoring/TrigDecTool_jobOptions.py") + + + # don't set up lumi access if in MC + if globalflags.DataSource.get_Value() != 'geant4': + if not hasattr(ToolSvc,"LuminosityTool"): + if athenaCommonFlags.isOnline: + local_logger.debug("luminosity tool not found, importing online version") + from LumiBlockComps.LuminosityToolDefault import LuminosityToolOnline + ToolSvc+=LuminosityToolOnline() + else: + local_logger.debug("luminosity tool not found, importing offline version") + from LumiBlockComps.LuminosityToolDefault import LuminosityToolDefault + ToolSvc+=LuminosityToolDefault() + + if not hasattr(ToolSvc,"TrigLivefractionTool"): + local_logger.debug("live fraction tool not found, importing") + from LumiBlockComps.TrigLivefractionToolDefault import TrigLivefractionToolDefault + ToolSvc+=TrigLivefractionToolDefault() + + include("AthenaMonitoring/AtlasReadyFilterTool_jobOptions.py") + include("AthenaMonitoring/FilledBunchFilterTool_jobOptions.py") + + # Ugly hack to get list of tools in job at this point + # We will compare the list at the end of the script to get the monitoring + # tools + monToolSet_before = set(ToolSvc.getChildren()) + + #---------------------------# + # Inner detector monitoring # + #---------------------------# + if DQMonFlags.doPixelMon() or DQMonFlags.doSCTMon() or DQMonFlags.doTRTMon() or \ + DQMonFlags.doInDetGlobalMon() or DQMonFlags.doInDetAlignMon(): + try: + include("InDetRecExample/InDetMonitoring.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up inner detector monitoring") + + #----------------------------# + # Global combined monitoring # + #----------------------------# + if DQMonFlags.doGlobalMon(): + try: + include("DataQualityTools/DataQualityMon_jobOptions.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up global monitoring") + + #--------------------# + # Trigger monitoring # + #--------------------# + if DQMonFlags.doLVL1CaloMon(): + try: + include("TrigT1CaloMonitoring/TrigT1CaloMonitoring_forRecExCommission.py") + include("TrigT1Monitoring/TrigT1Monitoring_forRecExCommission.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up L1 Calo monitoring") + + if DQMonFlags.doCTPMon(): + try: + include("TrigT1CTMonitoring/TrigT1CTMonitoringJobOptions_forRecExCommission.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up central trigger monitoring") + + if DQMonFlags.doHLTMon(): + try: + include("TrigHLTMonitoring/HLTMonitoring_topOptions.py") + HLTMonMan = topSequence.HLTMonManager + HLTMonMan.FileKey = DQMonFlags.monManFileKey() + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up HLT monitoring") + + #--------------# + # TRT electron # + #--------------# + if DQMonFlags.doTRTElectronMon() and TRTELEMON: + try: + include("InDetPerformanceMonitoring/TRT_Monitoring_RecExCommonAddOn_jobOptions.py") + TRTElMonMan = topSequence.TRTElectronMonManager + TRTElMonMan.FileKey = DQMonFlags.monManFileKey() + TRTElMonMan.Environment = DQMonFlags.monManEnvironment() + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up TRT electron monitoring") + + #----------------# + # ID performance # + #----------------# + if DQMonFlags.doInDetPerfMon() and IDPERFMON: + try: + include("InDetPerformanceMonitoring/IDPerfMon_jobOptions.py") + IDPerfMonManager = topSequence.IDPerfMonManager + IDPerfMonManager.FileKey = DQMonFlags.monManFileKey() + IDPerfMonManager.Environment = DQMonFlags.monManEnvironment() + include("InDetDiMuonMonitoring/InDetDiMuMon_jobOptions.py") + InDetDiMuMonManager = topSequence.InDetDiMuMonManager + InDetDiMuMonManager.FileKey = DQMonFlags.monManFileKey() + InDetDiMuMonManager.Environment = DQMonFlags.monManEnvironment() + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up InDetPerformance/InDetDiMuon monitoring") + + #--------------------# + # TileCal monitoring # + #--------------------# + if DQMonFlags.doTileMon(): + try: + include("TileMonitoring/TileMon_jobOptions.py") + + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up Tile monitoring") + + #------------------# + # LAr monitoring # + #------------------# + if DQMonFlags.doLArMon(): + # FIXME: don't use global flags here + if 'doLArCollisionTimeMon' not in dir(): + doLArCollisionTimeMon=True + if doLArCollisionTimeMon: + include ("LArCellRec/LArCollisionTime_jobOptions.py") + try: + LArMon = AthenaMonManager(name="LArMonManager", + FileKey = DQMonFlags.monManFileKey(), + Environment = DQMonFlags.monManEnvironment(), + ManualDataTypeSetup = DQMonFlags.monManManualDataTypeSetup(), + DataType = DQMonFlags.monManDataType()) + topSequence += LArMon + include("LArMonTools/LArAllMonitoring_jobOptions.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up LAr monitoring") + + #-------------------------------------------------------------------------# + # Calo monitoring - cells and clusters independent of LAr or Tile origin # + #-------------------------------------------------------------------------# + if DQMonFlags.doCaloMon(): + try: + include("CaloMonitoring/CaloAllMonitoring_jobOptions.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up Calo monitoring") + + #-------------------# + # Egamma monitoring # + #-------------------# + if DQMonFlags.doEgammaMon(): + try: + include("egammaPerformance/egammaMonitoring_jobOptions.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up Egamma monitoring") + + #----------------# + # MET monitoring # + #----------------# + if DQMonFlags.doMissingEtMon(): + try: + include("MissingETMonitoring/MissingET_Monitoring.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up ETmiss monitoring") + + #----------------# + # Jet monitoring # + #----------------# + if DQMonFlags.doJetMon(): + try: + include("JetMonitoring/JetMonitoring_jobOptions.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up Jet monitoring") + + #----------------# + # Tau monitoring # + #----------------# + if DQMonFlags.doTauMon(): + try: + include("tauMonitoring/tauMonitoring_jobOptions.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up Tau monitoring") + + #--------------------# + # Jet tag monitoring # + #--------------------# + if DQMonFlags.doJetTagMon(): + try: + include("JetTagMonitoring/JetTagMonitoring_jobOptions.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up jet-tag monitoring") + + #-----------------------------# + # MuonSpectrometer monitoring # + #-----------------------------# + if (DQMonFlags.doMuonRawMon() or DQMonFlags.doMuonSegmentMon() + or DQMonFlags.doMuonTrackMon() or DQMonFlags.doMuonAlignMon() + or DQMonFlags.doMuonTrkPhysMon() or DQMonFlags.doMuonPhysicsMon()): + try: + include("MuonDQAMonitoring/MuonDetMonitoring.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up Muon detector monitoring") + + #--------------------------# + # Combined muon monitoring # + #--------------------------# + if DQMonFlags.doMuonCombinedMon(): + try: + monManMuonCombined = AthenaMonManager(name="MuonCombinedMonManager", + FileKey = DQMonFlags.monManFileKey(), + Environment = DQMonFlags.monManEnvironment(), + ManualDataTypeSetup = DQMonFlags.monManManualDataTypeSetup(), + DataType = DQMonFlags.monManDataType()) + topSequence += monManMuonCombined + include("MuonCombinedDQA/MuonCombinedMonitoring_jobOptions.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up Muon combined performance monitoring") + + #------------------# + # LUCID monitoring # + #------------------# + if DQMonFlags.doLucidMon(): + try: + include("LUCID_Monitoring/LUCIDMon_jobOptions.py") + except Exception: + treatException("DataQualitySteering_jobOptions.py: exception when setting up LUCID monitoring") + + + #------------------------# + # Trigger chain steering # + #------------------------# + trigMap = DQMonFlags.triggerChainMap.get_Value() + for toolName, trigChain in trigMap.iteritems(): + local_logger.debug("Applying trigger %s to %s", trigChain, toolName) + if hasattr(ToolSvc,toolName): + tool = getattr(ToolSvc,toolName) + tool.TriggerChain = trigChain + else: + local_logger.debug("%s is not found in ToolSvc. Cannot set trigger chain!", toolName) + + #--------------------------# + # Post-setup configuration # + #--------------------------# + monToolSet_after = set(ToolSvc.getChildren()) + for tool in monToolSet_after-monToolSet_before: + # if we have the FilterTools attribute, assume this is in fact a + # monitoring tool + # stop lumi access if we're in MC + if globalflags.DataSource.get_Value() == 'geant4': + if 'EnableLumi' in dir(tool): + tool.EnableLumi = False + if DQMonFlags.monToolPostExec(): + local_logger.debug('DQ Post-Setup Configuration') + postprocfunc = eval(DQMonFlags.monToolPostExec()) + if hasattr(tool, 'FilterTools'): + local_logger.debug('Applying postexec transform to ===> %s', tool) + postprocfunc(tool) + del postprocfunc + + del monToolSet_before, monToolSet_after + +del local_logger diff --git a/Control/AthenaMonitoring/share/FilledBunchFilterTool_jobOptions.py b/Control/AthenaMonitoring/share/FilledBunchFilterTool_jobOptions.py new file mode 100644 index 00000000000..c72e6941286 --- /dev/null +++ b/Control/AthenaMonitoring/share/FilledBunchFilterTool_jobOptions.py @@ -0,0 +1,25 @@ +# Set up the filled bunch filter tool +include.block('AthenaMonitoring/FilledBunchFilterTool_jobOptions.py') +from AthenaCommon.Logging import logging + +fbft_local_logger = logging.getLogger('FilledBunchFilterTool_jobOptions') + +if not 'DQMonFlags' in dir(): + fbft_local_logger.info("FilledBunchFilterTool_jobOptions.py: DQMonFlags not yet imported - I import them now") + from AthenaMonitoring.DQMonFlags import DQMonFlags + +if not 'monFilledBunchFilterTool' in dir(): + fbft_local_logger.info('Configuring monFilledBunchFilterTool') + from AthenaMonitoring.AthenaMonitoringConf import DQFilledBunchFilterTool + from TrigBunchCrossingTool.BunchCrossingTool import BunchCrossingTool + monFilledBunchFilterTool = DQFilledBunchFilterTool() + monFilledBunchFilterTool.bunchCrossingTool = BunchCrossingTool() + if (rec.triggerStream() == 'CosmicCalo' + or globalflags.DataSource.get_Value() == 'geant4' + or 'collisions' not in DQMonFlags.monManDataType.get_Value() + or DQMonFlags.disableFilledBunchFilter.get_Value()): + fbft_local_logger.info('Filled bunch filter being configured to always return true') + monFilledBunchFilterTool.alwaysReturnTrue = True + ToolSvc += monFilledBunchFilterTool + +del fbft_local_logger diff --git a/Control/AthenaMonitoring/share/ManagedMonitorToolTest.py b/Control/AthenaMonitoring/share/ManagedMonitorToolTest.py new file mode 100755 index 00000000000..98d9af1d2e1 --- /dev/null +++ b/Control/AthenaMonitoring/share/ManagedMonitorToolTest.py @@ -0,0 +1,103 @@ +from AthenaCommon.GlobalFlags import globalflags +globalflags.DetGeo = 'atlas' +globalflags.DataSource = 'data' +globalflags.InputFormat = 'pool' + +from AthenaCommon.AthenaCommonFlags import athenaCommonFlags as af +af.FilesInput = [ +"/afs/cern.ch/user/y/yuraic/testarea/test_lumi/data/data12_8TeV.00211670.express_express.merge.ESD.r4065_p1278_tid01070414_00/ESD.01070414._000034.pool.root.1" +#"root://eosatlas//eos/atlas/atlasdatadisk/data12_8TeV/ESD/r4065/data12_8TeV.00204955.express_express.recon.ESD.r4065_tid01034439_00/ESD.01034439._000461.pool.root.1" +] + +af.EvtMax=150 # number of event to process + +from RecExConfig.RecFlags import rec +rec.AutoConfiguration = ['everything'] +rec.readRDO = False +rec.readESD = True +rec.readAOD = True +rec.doCBNT = False +rec.doWriteESD = False +rec.doWriteAOD = False +rec.doWriteTAG = False +rec.doDPD = False +rec.doAOD = True +#rec.doDPD = True +rec.doFileMetaData = True + +# Output log setting +OutputLevel = INFO + +# main jobOption - must always be included +include ("RecExCommon/RecExCommon_topOptions.py") + +# Must do tool configuration here for DB access to be autoconfigured from RecExCommon +from LumiBlockComps.LuminosityToolDefault import LuminosityToolDefault +lumiTool = LuminosityToolDefault() +lumiTool.OutputLevel = DEBUG +ToolSvc += lumiTool + +from LumiBlockComps.TrigLivefractionToolDefault import TrigLivefractionToolDefault +liveTool = TrigLivefractionToolDefault() +liveTool.OutputLevel = DEBUG +ToolSvc += liveTool + +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() + +## add an AthenaMonManager algorithm to the list of algorithms to be ran +from AthenaMonitoring.AthenaMonitoringConf import AthenaMonManager +topSequence += AthenaMonManager( "AthMonTestMan" ) + +from AthenaCommon.AppMgr import ServiceMgr as svcMgr +svcMgr.MessageSvc.OutputLevel = INFO +#svcMgr.MessageSvc.OutputLevel = WARNING +#svcMgr.MessageSvc.OutputLevel = DEBUG + +# ************************ +# Monitoring configuration +# ************************ + +## Setup the output file(s): +from GaudiSvc.GaudiSvcConf import THistSvc +svcMgr += THistSvc() + +## The string "TestMon" in the argument below is the 'FileKey' +## used by Athena to access the output file internally +svcMgr.THistSvc.Output += ["TestMon DATAFILE='TestMon.root' OPT='RECREATE'"] +svcMgr.THistSvc.PrintAll = True +svcMgr.THistSvc.OutputLevel = 1 + +## AthenaMonManager is the Algorithm that manages many classes inheriting +## from ManagedMonitorToolBase +monMan = topSequence.AthMonTestMan + +## FileKey must match that given to THistSvc +monMan.FileKey = "TestMon" + +## Set global monitoring parameters: see the AthenaMonManager class +## in the Control/AthenaMonitoring package +monMan.ManualDataTypeSetup = True +monMan.DataType = "monteCarlo" +monMan.Environment = "altprod" +monMan.ManualRunLBSetup = False +#monMan.Run = 1 +#monMan.LumiBlock = 1 + +from AthenaMonitoring.AthenaMonitoringConf import ManagedMonitorToolTest +TestTool = ManagedMonitorToolTest ( +name = "TestTool", +PreScale = 0, +GeneratorSeed = 65539, +EnableLumi = False, +ProcessNEvents = 40 +## The next line is for cases when the AlgTool cannot be attached directly to AthenaMonManager +# ManagerName = "AthMonTestMan" +) +TestTool.OutputLevel = INFO + +ToolSvc += TestTool +monMan.AthenaMonTools += [ TestTool ] + + + diff --git a/Control/AthenaMonitoring/share/TrigDecTool_jobOptions.py b/Control/AthenaMonitoring/share/TrigDecTool_jobOptions.py new file mode 100644 index 00000000000..aeb89bc4341 --- /dev/null +++ b/Control/AthenaMonitoring/share/TrigDecTool_jobOptions.py @@ -0,0 +1,34 @@ +tdt_local_logger = logging.getLogger('TrigDecTool_jobOptions') + +# Set up the trigger decision tool (for trigger-aware monitoring) +if not 'DQMonFlags' in dir(): + tdt_local_logger.debug("DQMonFlags not yet imported - I import them now") + from AthenaMonitoring.DQMonFlags import DQMonFlags + +if DQMonFlags.useTrigger(): + if not 'rec' in dir(): + from RecExConfig.RecFlags import rec + + if rec.readESD() and (DQMonFlags.monManEnvironment=='tier0ESD'): + # for ESD->AOD use trigger config stored as in-file meta-data, + if not 'TriggerFlags' in dir(): + from TriggerJobOpts.TriggerFlags import TriggerFlags + TriggerFlags.configurationSourceList = ['ds'] + + # set up trigger config service + if not 'TriggerConfigGetter' in dir(): + from TriggerJobOpts.TriggerConfigGetter import TriggerConfigGetter + cfg = TriggerConfigGetter() + + if not hasattr(ToolSvc, DQMonFlags.nameTrigDecTool()): + from TrigDecisionTool.TrigDecisionToolConf import Trig__TrigDecisionTool + monTrigDecTool = Trig__TrigDecisionTool(name=DQMonFlags.nameTrigDecTool(), + OutputLevel=ERROR, + PublicChainGroups = {"EFTau": "EF_[0-9]?tau.*", + "EFPhoton": "EF_[0-9]?g*", + "EFJets":"EF_J.*", + } + ) + ToolSvc += monTrigDecTool + +del tdt_local_logger diff --git a/Control/AthenaMonitoring/share/aod2hist_topoptions.py b/Control/AthenaMonitoring/share/aod2hist_topoptions.py new file mode 100644 index 00000000000..d14062d5623 --- /dev/null +++ b/Control/AthenaMonitoring/share/aod2hist_topoptions.py @@ -0,0 +1,35 @@ +from AthenaCommon.AthenaCommonFlags import athenaCommonFlags as af +af.FilesInput = [ +# "/afs/cern.ch/user/j/jboyd/gencomm/ForEric/data11_7TeV.00186156.express_express.recon.AOD.f391._lb0535._SFO-ALL._0001.1" +# "/afs/cern.ch/atlas/maxidisk/d36/lumiJuly2010/data10_7TeV.00152166.physics_MinBias.merge.AOD.r1239_p134_tid129143_00/AOD.129143._000120.pool.root.1" +# "root://eosatlas.cern.ch//eos/atlas/atlasdatadisk/data12_8TeV/AOD/r4065/data12_8TeV.00204955.express_express.recon.AOD.r4065_tid01034439_00/AOD.01034439._000460.pool.root.1" + "AOD.01034439._000460.pool.root.1" +] + +af.EvtMax=-1 # number of event to process +#af.EvtMax=100 # number of event to process + +#====================================================================================== + +from RecExConfig.RecFlags import rec +rec.AutoConfiguration = ['everything'] +rec.readRDO = False +rec.readESD = False +rec.readAOD = True +rec.doCBNT = False +rec.doWriteESD = False +rec.doWriteAOD = False +rec.doWriteTAG = False +rec.doDPD = False +#rec.doFileMetaData = False +rec.doHist = False +rec.doMonitoring = True + +# Output log setting +OutputLevel = INFO + +# main jobOption - must always be included +include ("RecExCommon/RecExCommon_topOptions.py") + + + diff --git a/Control/AthenaMonitoring/src/AthMonBench.cxx b/Control/AthenaMonitoring/src/AthMonBench.cxx new file mode 100644 index 00000000000..716585e8e69 --- /dev/null +++ b/Control/AthenaMonitoring/src/AthMonBench.cxx @@ -0,0 +1,35 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AthMonBench.h" +#include <cstring> +#include <stdio.h> + +AthMonBench::TMem AthMonBench::currentVMem_ExcludingLWPools() +{ + long result = -1; + FILE* file = fopen("/proc/self/status", "r"); + if (!file) + return result; + char line[128]; + while (fgets(line, 128, file) != NULL){ + if (strncmp(line, "VmSize:", 7) == 0) { + std::stringstream s(&(line[7])); + s >> result; + result *= 1024;//NB: ~1K uncertainty + result -= LWHistStats::getTotalPoolMemAllocated(); + break; + } + } + fclose(file); + return result; +} + +std::ostream& operator << ( std::ostream& os, const AthMonBench& br) { + if (br.valid()) + os << "deltaMemLW: "<<br.deltaMemLW_mb()<<" mb, "<<"deltaMemOther: "<<br.deltaMemOther_mb()<<" mb, deltaCPU: "<<br.deltaCPU_ms()<<" ms"; + else + os <<" [no data]"; + return os; +} diff --git a/Control/AthenaMonitoring/src/AthMonBench.h b/Control/AthenaMonitoring/src/AthMonBench.h new file mode 100644 index 00000000000..307a12a2c36 --- /dev/null +++ b/Control/AthenaMonitoring/src/AthMonBench.h @@ -0,0 +1,125 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +//////////////////////////////////////////////////////////////// +// // +// Header file for class AthMonBench // +// // +// Description: Helper class for taking LWhists-aware // +// per-mon-tool benchmarks of CPU and mem. // +// // +// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) // +// Initial version: June 2009 // +// // +//////////////////////////////////////////////////////////////// + +#ifndef ATHMONBENCH_H +#define ATHMONBENCH_H + +#include <ctime> +#include <sstream> +#include <ostream> +#include "LWHists/LWHistStats.h" +#include "GaudiKernel/IMessageSvc.h" + +class AthMonBench { +public: + + static const MSG::Level s_resourceMonThreshold = MSG::DEBUG; + + AthMonBench(); + ~AthMonBench(){} + + //Modify: + void reset(); + bool isReset() const; + void setUnitCount();//To avoid normalising when accessing results (for "Total" kind of reports) + + //Taking data: + void startMeasurement(); + void finishMeasurement(); + + //For adding/subtracting individual measurements: + void operator-=(const AthMonBench& o); + void operator+=(const AthMonBench& o); + + //Access results: + double deltaMemLW_mb() const; + double deltaMemOther_mb() const; + double deltaCPU_ms() const; + bool valid() const; + +private: + typedef long long TMem;//bytes + TMem m_deltaMemLW; + TMem m_deltaMemOther; + clock_t m_deltaCPU; + int m_count; + static TMem currentVMem_ExcludingLWPools(); +}; + +std::ostream& operator << ( std::ostream& os, const AthMonBench& br); + +///////////// +// Inlines // +///////////// +inline AthMonBench::AthMonBench() { reset(); } + +inline void AthMonBench::reset() +{ + m_deltaMemLW = 0; + m_deltaMemOther = 0; + m_deltaCPU = 0; + m_count = 0; +} + +inline bool AthMonBench::isReset() const { + return !(m_deltaMemLW||m_deltaMemOther||m_deltaCPU||m_count); +} + +//For creating single measurements +inline void AthMonBench::startMeasurement() { + if (!isReset()) + m_count = -99999; + m_deltaMemLW = LWHistStats::getTotalPoolMemUsed(); + m_deltaMemOther = currentVMem_ExcludingLWPools(); + m_deltaCPU = clock(); +} + +inline void AthMonBench::finishMeasurement() { + m_deltaMemLW = LWHistStats::getTotalPoolMemUsed() - m_deltaMemLW; + m_deltaMemOther = currentVMem_ExcludingLWPools() - m_deltaMemOther; + m_deltaCPU = clock() - m_deltaCPU; + ++m_count; + if (m_count!=1) { + //Something is wrong: + reset(); + m_count = -99999; + } +} + +//For adding/subtracting individual measurements: +inline void AthMonBench::operator-=(const AthMonBench& o) { + m_deltaMemLW -= o.m_deltaMemLW; + m_deltaMemOther -= o.m_deltaMemOther; + m_deltaCPU -= o.m_deltaCPU; + m_count -= o.m_count; +} + +inline void AthMonBench::operator+=(const AthMonBench& o) { + m_deltaMemLW += o.m_deltaMemLW; + m_deltaMemOther += o.m_deltaMemOther; + m_deltaCPU += o.m_deltaCPU; + m_count += o.m_count; +} + +//To get results: +inline double AthMonBench::deltaMemLW_mb() const { return valid()?m_deltaMemLW/(1024.0*1024.0*m_count): -99.99; } +inline double AthMonBench::deltaMemOther_mb() const { return valid()?m_deltaMemOther/(1024.0*1024.0*m_count): -99.99; } +inline double AthMonBench::deltaCPU_ms() const { return valid()?m_deltaCPU*1.0e3/double(m_count*CLOCKS_PER_SEC) : -99.99; } +inline bool AthMonBench::valid() const { return m_count>0; } +inline void AthMonBench::setUnitCount() { if (valid()) m_count=1; } + +#endif diff --git a/Control/AthenaMonitoring/src/AthenaMon.cxx b/Control/AthenaMonitoring/src/AthenaMon.cxx new file mode 100755 index 00000000000..430162991cd --- /dev/null +++ b/Control/AthenaMonitoring/src/AthenaMon.cxx @@ -0,0 +1,198 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ******************************************************************** +// +// NAME: AthenaMon.cxx +// +// AUTHOR: Rob McPherson & Manuel Diaz +// Manuel Diaz 01.04.2004 Changed interface access from +// IAlgTool to IMonitorToolBase +// +// ******************************************************************** + +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/IToolSvc.h" +#include "GaudiKernel/StatusCode.h" +#include "GaudiKernel/ListItem.h" + +#include "AthenaMonitoring/AthenaMon.h" + +class ISvcLocator; +// class AlgFactory; + +/*---------------------------------------------------------------*/ +AthenaMon::AthenaMon(const std::string& name, ISvcLocator* pSvcLocator) : + Algorithm(name, pSvcLocator) +{ + MsgStream log(msgSvc(), "AthenaMon"); + + declareProperty("AthenaMonTools",m_monToolNames); + declareProperty("CheckEveryNoEvents",m_everyNevents=-1); + declareProperty("BookHistsinInitialize",m_bookHistsinInitialize=true); + m_THistSvc_streamnameMapping.clear(); + declareProperty("THistSvc_OutPutStreamMapping",m_THistSvc_streamnameMapping); +} + +/*---------------------------------------------------------------*/ +AthenaMon::~AthenaMon() +{ +} + +/*---------------------------------------------------------------*/ +StatusCode AthenaMon::initialize() +/*---------------------------------------------------------------*/ +{ + MsgStream log(msgSvc(), name()); + log << MSG::INFO << "initialize AthenaMon algorithm" << endreq; + + std::vector<std::string>::iterator it = m_monToolNames.begin(); + IToolSvc* p_toolSvc; + StatusCode sc = service("ToolSvc",p_toolSvc); + + if (sc.isFailure()) { + log << MSG::FATAL << " Tool Service not found " << endreq; + return StatusCode::FAILURE; + } + + for (; it < m_monToolNames.end(); it++) { + + std::string toolname(*it); + IMonitorToolBase* p_tool; + + ListItem mytool(toolname); + + sc = p_toolSvc->retrieveTool(mytool.type(), mytool.name(), p_tool); + if(sc.isFailure()) { + log << MSG::FATAL << "Unable to create " << toolname + << " AlgTool" << endreq; + return StatusCode::FAILURE; + } else { + + log << MSG::INFO + << "Tool Name = " << toolname + << endreq; + + sc = p_tool->setupOutputStreams(m_THistSvc_streamnameMapping); + if(sc.isFailure()) { + log << MSG::WARNING << "Unable to setup the OutPutStreams in " + << toolname << endreq; + } + + // shall I book histograms now ? + if(m_bookHistsinInitialize) + { + // Try to book the histograms now. If the tool uses + // dynamic booking, it should define bookHists as empty. + sc = p_tool->bookHists(); + if(sc.isFailure()) { + log << MSG::WARNING << "Unable to book in " << toolname << endreq; + } + } + m_monTools.push_back(p_tool); + } + } + m_eventCounter=m_everyNevents; + return StatusCode::SUCCESS; +} + +/*---------------------------------------------------------------*/ +StatusCode AthenaMon::execute() +{ + MsgStream log(msgSvc(), name()); + + log << MSG::DEBUG << "executing AthenaMon algorithm" << endreq; + + //Invoke all declared alg monitoring tools to fill their histograms + std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin(); + + for (; it < m_monTools.end(); it++) { + if((*it)->preSelector()) + if((*it)->fillHists().isFailure()) { + log << MSG::WARNING << "Error Filling Histograms" << endreq; + // return StatusCode::FAILURE; + } + } + if(m_eventCounter==0) { + //Invoke periodically all declared alg monitoring tools to check their histograms + it = m_monTools.begin(); + + for (; it < m_monTools.end(); it++) { + log << MSG::INFO << "calling checkHists of tool " << endreq; + StatusCode sc = (*it)->checkHists(false); + if(sc.isFailure()) { + log << MSG::WARNING << "Can\'t call checkHists of tool." << endreq; + // return StatusCode::FAILURE; + } + } + m_eventCounter=m_everyNevents; + } + if(m_eventCounter>0) m_eventCounter--; + return StatusCode::SUCCESS; +} + +/*---------------------------------------------------------------*/ +StatusCode AthenaMon::finalize() +{ + MsgStream log(msgSvc(), name()); + + log << MSG::INFO << "finalizing AthenaMon algorithm" << endreq; + + //Invoke all declared alg monitoring tools to finalize their histograms + std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin(); + + for (; it < m_monTools.end(); it++) { + log << MSG::INFO << "finalizing tool " << endreq; + StatusCode sc = (*it)->finalHists(); + if(sc.isFailure()) { + log << MSG::WARNING << "Can\'t finalize a tool." << endreq; + // return StatusCode::FAILURE; + } + } + //Invoke all declared alg monitoring tools to check their histograms + it = m_monTools.begin(); + + for (; it < m_monTools.end(); it++) { + log << MSG::INFO << "calling checkHists of tool " << endreq; + StatusCode sc = (*it)->checkHists(true); + if(sc.isFailure()) { + log << MSG::WARNING << "Can\'t call checkHists of tool." << endreq; + // return StatusCode::FAILURE; + } + } + + return StatusCode::SUCCESS; +} + +/*---------------------------------------------------------------*/ +StatusCode AthenaMon::beginRun() +{ + MsgStream log(msgSvc(), name()); + log << MSG::INFO << "beginRun()" << endreq; + + // histograms already booked + if(m_bookHistsinInitialize) + return StatusCode::SUCCESS; + + std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin(); + for (; it < m_monTools.end(); it++) + if((*it)->bookHists().isFailure()) + log << MSG::WARNING << "Error Filling Histograms" << endreq; + + return StatusCode::SUCCESS; +} + +/*---------------------------------------------------------------*/ +StatusCode AthenaMon::endRun() +{ + MsgStream log(msgSvc(), name()); + log << MSG::INFO << "endRun()" << endreq; + + std::vector<IMonitorToolBase*>::iterator it = m_monTools.begin(); + for (; it < m_monTools.end(); it++) + if((*it)->runStat().isFailure()) + log << MSG::WARNING << "Error calling runStat" << endreq; + + return StatusCode::SUCCESS; +} diff --git a/Control/AthenaMonitoring/src/AthenaMonManager.cxx b/Control/AthenaMonitoring/src/AthenaMonManager.cxx new file mode 100755 index 00000000000..000bf199166 --- /dev/null +++ b/Control/AthenaMonitoring/src/AthenaMonManager.cxx @@ -0,0 +1,914 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: AthenaMonManager.cxx,v 1.36 2009-05-08 09:50:05 sschaetz Exp $ +// ********************************************************************** + +#include "AthenaMonitoring/AthenaMonManager.h" + +#include <cctype> + +#include "TDirectory.h" +#include "TH1.h" +#include "TObject.h" +#include "TROOT.h" +#include "LWHists/LWHist.h" +#include "LWHists/LWHistControls.h" +#include "LWHists/LWHistStats.h" +#include "LWHistAthMonWrapper.h" +#include "AthMonBench.h" + +#include "GaudiKernel/IMessageSvc.h" +#include "GaudiKernel/IJobOptionsSvc.h" +#include "GaudiKernel/ISvcLocator.h" +#include "GaudiKernel/ITHistSvc.h" +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/Property.h" +#include "GaudiKernel/ServiceHandle.h" + +#include "AthenaMonitoring/IMonitorToolBase.h" +#include "AthenaMonitoring/ManagedMonitorToolBase.h" +#include "AthenaPoolUtilities/AthenaAttributeList.h" +#include "EventInfo/EventID.h" +#include "EventInfo/EventInfo.h" + +#include "SGAudCore/ISGAudSvc.h" + +#include <limits.h> +#include <vector> + +class AthenaMonManager::Imp { + public: + Imp(AthenaMonManager*man,const std::string& name) : m_theManager(man), + m_sgAudSvc(0), + m_isPrimaryManager(false), + m_everyNevents(-1), + m_eventCounter(-1), + m_fileKeyProp(name), + m_manualDataTypeSetupProp(false), + m_dataTypeProp("userDefined"), + m_environmentProp("user"), + m_LBsLowStatProp(10), + m_LBsMedStatProp(30), + m_LBsHigStatProp(90), + m_manualRunLBProp(false), + m_runProp(0), + m_lumiBlockProp(0), + m_nMonGroupCopies(0), + m_nActiveLWHists(0), + m_doResourceMon(false) {} + ~Imp() + { + std::map<IMonitorToolBase*,ToolBench*>::iterator it, itE; + + for (it=m_toolbenchmarks.begin(),itE=m_toolbenchmarks.end();it!=itE;++it) { + delete it->second; + } + + m_toolbenchmarks.clear(); + } + + //These were protected before we moved to a private implementation: + typedef std::map<std::string,TObject*> ObjMap_t; + ObjMap_t m_objMap; + + typedef std::map<std::string,LWHist*> ObjMapLW_t; + ObjMapLW_t m_objMapLW; + + AthenaMonManager * m_theManager; + ISGAudSvc * m_sgAudSvc; + + bool m_isPrimaryManager; + + long m_everyNevents; + long m_eventCounter; + + std::string m_fileKeyProp; + + bool m_manualDataTypeSetupProp; + std::string m_dataTypeProp; + std::string m_environmentProp; + unsigned int m_LBsLowStatProp, m_LBsMedStatProp, m_LBsHigStatProp; + + bool m_manualRunLBProp; + + unsigned int m_runProp; + unsigned int m_lumiBlockProp; + + unsigned m_nMonGroupCopies; + long m_nActiveLWHists; + + //NB: The LW hist leak checker is now also looking for + //inappropriate usage of MonGroup copy constructors (temporary + //until we outlaw copy/assignment of MonGroups): + class LWHistLeakChecker { + Imp * m_d; + long m_initVal; + unsigned m_mgcopies_initval; + public: + LWHistLeakChecker(Imp*d) : m_d(d), m_initVal(LWHistStats::nActiveLWHists()), + m_mgcopies_initval(ManagedMonitorToolBase::MonGroup::ncopies()) {} + ~LWHistLeakChecker() + { m_d->m_nActiveLWHists += LWHistStats::nActiveLWHists()-m_initVal; + m_d->m_nMonGroupCopies += ManagedMonitorToolBase::MonGroup::ncopies()-m_mgcopies_initval; } + }; + + template<class T> void toolAudStart(const T&tool) { if (m_sgAudSvc) m_sgAudSvc->setFakeCurrentAlg(m_theManager->name()+"_MT_"+tool->name()); } + void toolAudEnd() { if (m_sgAudSvc) m_sgAudSvc->clearFakeCurrentAlg(); } + + bool m_doResourceMon; + class ToolBench{ + public: + ToolBench(IMonitorToolBase * t) : m_theTool(t) {} + const IMonitorToolBase * m_theTool; + AthMonBench m_bench_alginit_retrieve; + AthMonBench m_bench_algexec_fillHists;//NB: includes call to preselector + AthMonBench m_bench_algexec_checkHists; + AthMonBench m_bench_algexec_bookHists; + //NB: So far we don't check the call to runStat() + AthMonBench m_bench_algfin_finalHists; + AthMonBench m_bench_algfin_checkHists; + AthMonBench m_bench_algfin_convertLWHists; + void report(AthenaMonManager*a) { + MSG::Level l(AthMonBench::s_resourceMonThreshold); + a->msg(l)<<"Init ResourceSummary ["<<m_theTool->name()<<"] --> load/create/initialize : "<<m_bench_alginit_retrieve<<endreq; + m_bench_algexec_checkHists.setUnitCount(); + m_bench_algexec_bookHists.setUnitCount(); + a->msg(l)<<"Exec ResourceSummary ["<<m_theTool->name()<<"] --> book : "<<m_bench_algexec_bookHists<<endreq; + a->msg(l)<<"Exec ResourceSummary ["<<m_theTool->name()<<"] --> check : "<<m_bench_algexec_checkHists<<endreq; + a->msg(l)<<"Exec ResourceSummary ["<<m_theTool->name()<<"] --> fill : "<<m_bench_algexec_fillHists<<endreq; + a->msg(l)<<"Fin ResourceSummary ["<<m_theTool->name()<<"] --> finalHists : "<<m_bench_algfin_finalHists<<endreq; + a->msg(l)<<"Fin ResourceSummary ["<<m_theTool->name()<<"] --> checkHists(fromFinalize==true) : "<<m_bench_algfin_checkHists<<endreq; + a->msg(l)<<"Fin ResourceSummary ["<<m_theTool->name()<<"] --> final LWHist conversion+writeout : "<<m_bench_algfin_convertLWHists<<endreq; + } + + }; + std::map<IMonitorToolBase*,ToolBench*> m_toolbenchmarks; + ToolBench* getToolBench(IMonitorToolBase* t) { + std::map<IMonitorToolBase*,ToolBench*>::iterator it = m_toolbenchmarks.find(t); + if (it==m_toolbenchmarks.end()) { + ToolBench*tb =new ToolBench(t); + m_toolbenchmarks[t] = tb; + return tb; + } + return it->second; + } + + // The data below should be truly global for a job, and inheriting classes should + // not have the option of modifying them. + // The data are set from the corresponding m_* properties of the first AthenaMonManager + // in the Athena algorithm chain (this manager sets s_staticDataAreInit to true). + + static ISvcLocator* s_svcLocator; + + static bool s_staticDataAreInit; + + static std::string s_dataTypeStr; + static std::string s_environmentStr; + static DataType_t s_dataType; + static Environment_t s_environment; + + static unsigned int s_lumiBlock; + static unsigned int s_run; + static unsigned int s_fill; + static unsigned int s_LBsLowStat; + static unsigned int s_LBsMedStat; + static unsigned int s_LBsHigStat; +}; + +ISvcLocator* AthenaMonManager::Imp::s_svcLocator(0); + +bool AthenaMonManager::Imp::s_staticDataAreInit(false); + +std::string AthenaMonManager::Imp::s_dataTypeStr("userDefined"); +std::string AthenaMonManager::Imp::s_environmentStr("user"); +AthenaMonManager::DataType_t AthenaMonManager::Imp::s_dataType(userDefined); +AthenaMonManager::Environment_t AthenaMonManager::Imp::s_environment(user); + +unsigned int AthenaMonManager::Imp::s_lumiBlock(0); +unsigned int AthenaMonManager::Imp::s_run(0); +unsigned int AthenaMonManager::Imp::s_fill(0); +unsigned int AthenaMonManager::Imp::s_LBsLowStat(0); +unsigned int AthenaMonManager::Imp::s_LBsMedStat(0); +unsigned int AthenaMonManager::Imp::s_LBsHigStat(0); +namespace { + + std::string strToLower( const std::string& str ); + +} // unnamed namespace + +// ********************************************************************* +// Public Methods +// ********************************************************************* + +AthenaMonManager:: + AthenaMonManager( const std::string& name, ISvcLocator* pSvcLocator ) + : AthAlgorithm( name, pSvcLocator ), m_THistSvc(0), d(new Imp(this, name)) +{ + declareProperty( "AthenaMonTools", m_monTools ); + declareProperty( "CheckEveryNoEvents", d->m_everyNevents ); + declareProperty( "FileKey", d->m_fileKeyProp ); + declareProperty( "ManualDataTypeSetup", d->m_manualDataTypeSetupProp ); + declareProperty( "DataType", d->m_dataTypeProp ); + declareProperty( "Environment", d->m_environmentProp ); + declareProperty( "LBsInLowStatInterval", d->m_LBsLowStatProp ); + declareProperty( "LBsInMediumStatInterval", d->m_LBsMedStatProp ); + declareProperty( "LBsInHighStatInterval", d->m_LBsHigStatProp ); + declareProperty( "ManualRunLBSetup", d->m_manualRunLBProp ); + declareProperty( "Run", d->m_runProp ); + declareProperty( "LumiBlock", d->m_lumiBlockProp ); + + if( Imp::s_svcLocator==0 ) + Imp::s_svcLocator = pSvcLocator; +} + + +AthenaMonManager:: +~AthenaMonManager() +{ + if (d->m_nActiveLWHists) + msg(MSG::WARNING) << d->m_nActiveLWHists<< " LW histograms were created but never deleted" << endreq; + /* + if (d->m_nMonGroupCopies) + msg(MSG::WARNING) << "Usage of MonGroup copy constructor or assignment operator detected in associated tools " + << d->m_nMonGroupCopies<<" time(s). This usually happens when tools pass MonGroup's around by" + <<" value. This behaviour will be forbidden at the compilation stage soon, so please fix your packages!" << endreq; + */ + delete d; + + // If it is known that ManagedMonitorToolBase objects are deleted _after_ this object, + // then one should call setMonManager(0) on each of them. +} + + +AthenaMonManager::Environment_t +AthenaMonManager:: +envStringToEnum( const std::string& str ) +{ + std::string lcstr( strToLower(str) ); + + if( lcstr == "user" ) + return user; + else if( lcstr == "nooutput" ) + return noOutput; + else if( lcstr == "online" ) + return online; + else if( lcstr == "tier0" ) + return tier0; + else if( lcstr == "tier0raw" ) + return tier0Raw; + else if( lcstr == "tier0esd" ) + return tier0ESD; + else if( lcstr == "aod" ) + return AOD; + else if( lcstr == "altprod" ) + return altprod; + + if( Imp::s_svcLocator!=0 ) { + IMessageSvc* ms(0); + StatusCode sc = Imp::s_svcLocator->service( "MessageSvc", ms, true ); + if( sc.isSuccess() ) { + MsgStream log( ms, "AthenaMonManager::envStringToEnum()" ); + log << MSG::WARNING << "Unknown AthenaMonManager::Environment_t \"" + << str << "\", returning \"user\"" << endreq; + } + } + + return user; +} + + +AthenaMonManager::DataType_t +AthenaMonManager:: +dataTypeStringToEnum( const std::string& str ) +{ + std::string lcstr( strToLower(str) ); + + if( lcstr == "userdefined" ) + return userDefined; + else if( lcstr == "montecarlo" ) + return monteCarlo; + else if( lcstr == "collisions" ) + return collisions; + else if( lcstr == "cosmics" ) + return cosmics; + else if( lcstr == "heavyioncollisions" ) + return heavyIonCollisions; + + if( Imp::s_svcLocator!=0 ) { + IMessageSvc* ms(0); + StatusCode sc = Imp::s_svcLocator->service( "MessageSvc", ms, true ); + if( sc.isSuccess() ) { + MsgStream log( ms, "AthenaMonManager::dataTypeStringToEnum()" ); + log << MSG::WARNING << "Unknown AthenaMonManager::DataType_t \"" + << str << "\", returning \"userDefined\"" << endreq; + } + } + + return userDefined; +} + + +AthenaMonManager::Environment_t +AthenaMonManager:: +environment() +{ + return Imp::s_environment; +} + +unsigned int AthenaMonManager::getLBsLowStat() { return Imp::s_LBsLowStat; } +unsigned int AthenaMonManager::getLBsMedStat() { return Imp::s_LBsMedStat; } +unsigned int AthenaMonManager::getLBsHigStat() { return Imp::s_LBsHigStat; } + +AthenaMonManager::DataType_t +AthenaMonManager:: +dataType() +{ + return Imp::s_dataType; +} + + +unsigned int +AthenaMonManager:: +lumiBlockNumber() +{ + return Imp::s_lumiBlock; +} + + +unsigned int +AthenaMonManager:: +runNumber() +{ + return Imp::s_run; +} + + +unsigned int +AthenaMonManager:: +fillNumber() +{ + return Imp::s_fill; +} + + +StatusCode +AthenaMonManager:: +initialize() +{ + Imp::LWHistLeakChecker lc(d); + + //typedef std::vector<IMonitorToolBase*> MonList_t; + //typedef MonList_t::iterator MonIter_t; + + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "AthenaMonManager::initialize():" << endreq; + + if (Imp::s_svcLocator->service("SGAudSvc", d->m_sgAudSvc, false/*do not create*/).isFailure()) + d->m_sgAudSvc=0; + + + d->m_doResourceMon = msgLvl(AthMonBench::s_resourceMonThreshold); + + StatusCode sc; + sc.setChecked(); + + sc = service( "THistSvc", m_THistSvc, true ); + if( !sc.isSuccess() ) { + msg(MSG::ERROR) << "!! Unable to locate the THistSvc service !!" << endreq; + return sc; + } + + if( !Imp::s_staticDataAreInit ) { + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " --> Initializing static data" << endreq; + + if (msgLvl(MSG::DEBUG)) { + msg(MSG::DEBUG) << " * \"ManualDataTypeSetup\" = " << d->m_manualDataTypeSetupProp << endreq; + } + + if( d->m_manualDataTypeSetupProp ) { + Imp::s_dataTypeStr = d->m_dataTypeProp; + Imp::s_dataType = dataTypeStringToEnum( d->m_dataTypeProp ); + } + else { + Imp::s_dataTypeStr = d->m_dataTypeProp; + Imp::s_dataType = dataTypeStringToEnum( d->m_dataTypeProp ); + } + + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " * \"DataType\" = " << Imp::s_dataType << endreq; + + Imp::s_environmentStr = d->m_environmentProp; + Imp::s_environment = envStringToEnum( d->m_environmentProp ); + + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " * \"Environment\" = " << Imp::s_environment << endreq; + + Imp::s_LBsLowStat = d->m_LBsLowStatProp; + Imp::s_LBsMedStat = d->m_LBsMedStatProp; + Imp::s_LBsHigStat = d->m_LBsHigStatProp; + if (msgLvl(MSG::DEBUG)) { + msg(MSG::DEBUG) << " * \"LBsInLowStatInterval\" = " << Imp::s_LBsLowStat << endreq; + msg(MSG::DEBUG) << " * \"LBsInMediumStatInterval\" = " << Imp::s_LBsMedStat << endreq; + msg(MSG::DEBUG) << " * \"LBsInHighStatInterval\" = " << Imp::s_LBsHigStat << endreq; + } + + d->m_isPrimaryManager = true; + Imp::s_staticDataAreInit = true; + + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " * \"ManualRunLBSetup\" = " << d->m_manualRunLBProp << endreq; + + if( d->m_manualRunLBProp ) { + Imp::s_run = d->m_runProp; + Imp::s_lumiBlock = d->m_lumiBlockProp; + if (msgLvl(MSG::DEBUG)) + msg(MSG::DEBUG) << " --> using run = " << Imp::s_run << ", lumiBlock = " << Imp::s_lumiBlock << endreq; + } else { + if (msgLvl(MSG::DEBUG)) + msg(MSG::DEBUG) << " --> using run = " << Imp::s_run << ", lumiBlock = " << Imp::s_lumiBlock << endreq; + } + } + + // Ensure consistency among all managers + d->m_dataTypeProp = Imp::s_dataTypeStr; + d->m_environmentProp = Imp::s_environmentStr; + + // Provide a virtual Algorithm with a subset of the properties + IJobOptionsSvc* joSvc = 0; + sc = service( "JobOptionsSvc", joSvc ); + if( !sc.isSuccess() ) { + msg(MSG::ERROR) << "!! Unable to locate the JobOptionsSvc service !!" << endreq; + return sc; + } + ATH_MSG_DEBUG(" --> Found service \"JobOptionsSvc\""); + + std::string client = name() + std::string("Properties"); + ATH_MSG_DEBUG(" --> Adding properties under name \"" << client << "\""); + StatusCode sc1 = joSvc->addPropertyToCatalogue( client, StringProperty("FileKey",d->m_fileKeyProp) ); + StatusCode sc2 = joSvc->addPropertyToCatalogue( client, StringProperty("DataType",d->m_dataTypeProp) ); + StatusCode sc3 = joSvc->addPropertyToCatalogue( client, StringProperty("Environment",d->m_environmentProp) ); + joSvc->release(); + if( !(sc1.isSuccess() && sc2.isSuccess() && sc3.isSuccess()) ) { + msg(MSG::ERROR) << "!! Unable to add properties to JobOptionsSvc service !!" << endreq; + return StatusCode::FAILURE; + } + ATH_MSG_DEBUG(" --> Added Properties"); + + //Determine (globally for now), whether or not LW histograms use a + //ROOT backend (necessary for online monitoring, and perhaps for + //debugging): + bool root_backend_for_lwhists = (environment()==AthenaMonManager::online); + if( root_backend_for_lwhists != LWHistControls::hasROOTBackend() ) + LWHistControls::setROOTBackend(root_backend_for_lwhists); + +// if( m_monTools.size() > 0 ) { +// sc = m_monTools.retrieve(); +// if( !sc.isSuccess() ) { +// msg(MSG::ERROR) << "!! Unable to retrieve monitoring tool " << m_monTools << endreq; +// return sc; +// } +// if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " --> Retrieved AthenaMonTools" << endreq; +// } + + d->m_eventCounter = d->m_everyNevents; + + ToolHandleArray<IMonitorToolBase>::iterator monToolsEnd = m_monTools.end(); + for( ToolHandleArray<IMonitorToolBase>::iterator i = m_monTools.begin(); i != monToolsEnd; ++i ) { + ToolHandle<IMonitorToolBase>& tool = *i; + d->toolAudStart(tool); + AthMonBench bench_tmp; + if (d->m_doResourceMon) + bench_tmp.startMeasurement(); + StatusCode sc_toolret = tool.retrieve(); + if (d->m_doResourceMon) + bench_tmp.finishMeasurement(); + d->toolAudEnd(); + if( sc_toolret.isFailure() ) { + msg(MSG::ERROR) << "Failed to retrieve monitoring tool " << tool << endreq; + return StatusCode::FAILURE; + } + else { + msg(MSG::INFO) << "Retrieved tool " << tool << endreq; + } + IMonitorToolBase* mon = tool.operator->(); + ManagedMonitorToolBase* managed = dynamic_cast<ManagedMonitorToolBase*>( mon ); + if( managed != 0 ) { + managed->setMonManager( this ); + } + if (d->m_doResourceMon) { + Imp::ToolBench* tb = d->getToolBench(mon); + tb->m_bench_alginit_retrieve = bench_tmp; + } + + } + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " --> Exiting successfully" << endreq; + + return StatusCode::SUCCESS; +} + + +StatusCode +AthenaMonManager:: +execute() +{ + Imp::LWHistLeakChecker lc(d); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "AthenaMonManager::execute():" << endreq; + + StatusCode sc; + sc.setChecked(); + + if( !d->m_manualRunLBProp ) { + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " --> Calling setEventInfo()" << endreq; + setEventInfo(); + } + + ToolHandleArray<IMonitorToolBase>::iterator monToolsEnd = m_monTools.end(); + for( ToolHandleArray<IMonitorToolBase>::iterator i = m_monTools.begin(); i != monToolsEnd; ++i ) { + ToolHandle<IMonitorToolBase>& tool = *i; + d->toolAudStart(tool); + AthMonBench bench_tmp; + if (d->m_doResourceMon) + bench_tmp.startMeasurement(); + if( tool->preSelector() ) { + //if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " --> The tool is preSelector" << endreq; + + // Uncomment to test luminosity tools + // I don't know where exactly it must be placed exactly + // Yuriy - start + /* + IMonitorToolBase* mon = tool.operator->(); + ManagedMonitorToolBase* managed = dynamic_cast<ManagedMonitorToolBase*>( mon ); + + float avgmu = managed->lbAverageInteractionsPerCrossing(); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Test, Average mu: " << avgmu << endreq; + + float instmu = managed->lbInteractionsPerCrossing(); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Test, Instantaneous mu: " << instmu << endreq; + + float avglumi = managed->lbAverageLuminosity(); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Test, Average lumi: " << avglumi << endreq; + + float instlumi = managed->lbLuminosityPerBCID(); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Test, Instantaneous lumi: " << instlumi << endreq; + + double duration = managed->lbDuration(); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Test, Lumiblock duration: " << duration << endreq; + + double live = managed->livefractionPerBCID(); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Test, lumiinst livefraction: " << live << endreq; + + float lumilive = managed->lbAverageLivefraction(); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Test, lumiavg livefraction: " << lumilive << endreq; + + double lumiweight = managed->lbLumiWeight(); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Test, Lumiblock weight: " << lumiweight << endreq; + */ + // Yuriy - end + + sc = tool->fillHists(); + + if( !sc.isSuccess() ) { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "IMonitorToolBase::fillHists() unsuccessful" << endreq; + } + } + + + if (d->m_doResourceMon) { + bench_tmp.finishMeasurement(); + Imp::ToolBench* tb = d->getToolBench(tool.operator->()); + tb->m_bench_algexec_fillHists += bench_tmp;//fixme: count events and subdivide + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " --> m_doResourceMon is True" << endreq; + } + d->toolAudEnd(); + } + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " --> Done calling IMonitorToolBase::fillHists()" << endreq; + + if( d->m_eventCounter > 0 ) { + d->m_eventCounter--; + } + else if( d->m_eventCounter == 0 ) { + for( ToolHandleArray<IMonitorToolBase>::iterator i = m_monTools.begin(); i != monToolsEnd; ++i ) { + ToolHandle<IMonitorToolBase>& tool = *i; + d->toolAudStart(tool); + AthMonBench bench_tmp; + + if (d->m_doResourceMon) + bench_tmp.startMeasurement(); + sc = tool->checkHists(false); + if (d->m_doResourceMon) { + bench_tmp.finishMeasurement(); + Imp::ToolBench* tb = d->getToolBench(tool.operator->()); + tb->m_bench_algexec_checkHists += bench_tmp;//fixme: count events and subdivide + } + if( !sc.isSuccess() ) { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "IMonitorToolBase::checkHists() unsuccessful" << endreq; + } + d->toolAudEnd(); + } + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " --> Done calling IMonitorToolBase::checkHists()" << endreq; + + d->m_eventCounter = d->m_everyNevents; + } + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " --> Exiting successfully" << endreq; + + return StatusCode::SUCCESS; +} + + +StatusCode +AthenaMonManager:: +finalize() +{ + Imp::LWHistLeakChecker lc(d); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "AthenaMonManager::finalize():" << endreq; + + StatusCode sc; + sc.setChecked(); + + ToolHandleArray<IMonitorToolBase>::iterator monToolsEnd = m_monTools.end(); + for( ToolHandleArray<IMonitorToolBase>::iterator i = m_monTools.begin(); i != monToolsEnd; ++i ) { + ToolHandle<IMonitorToolBase>& tool = *i; + d->toolAudStart(tool); + Imp::ToolBench* tb = d->m_doResourceMon ? d->getToolBench(tool.operator->()) : 0; + if (tb) + tb->m_bench_algfin_finalHists.startMeasurement(); + sc = tool->finalHists(); + if (tb) + tb->m_bench_algfin_finalHists.finishMeasurement(); + if( !sc.isSuccess() ) { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "IMonitorToolBase::finalHists() unsuccessful" << endreq; + } + if (tb) + tb->m_bench_algfin_checkHists.startMeasurement(); + sc = tool->checkHists(true); + if (tb) + tb->m_bench_algfin_checkHists.finishMeasurement(); + if( !sc.isSuccess() ) { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "IMonitorToolBase::checkHists() unsuccessful" << endreq; + } + if (tb) + tb->m_bench_algfin_convertLWHists.startMeasurement(); + sc = tool->convertLWHists(); + if (tb) + tb->m_bench_algfin_convertLWHists.finishMeasurement(); + if( !sc.isSuccess() ) { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "IMonitorToolBase::convertLWHists() unsuccessful" << endreq; + } + if (tb) + tb->report(this); + d->toolAudEnd(); + } + if (msgLvl(MSG::DEBUG)) { + msg(MSG::DEBUG) << " --> Done calling IMonitorToolBase::finalHists() and IMonitorToolBase::checkHists()" << endreq; + msg(MSG::DEBUG) << " --> Exiting successfully" << endreq; + } + return StatusCode::SUCCESS; +} + + +StatusCode +AthenaMonManager:: +beginRun() +{ + Imp::LWHistLeakChecker lc(d); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "AthenaMonManager::beginRun():" << endreq; + + StatusCode sc; + sc.setChecked(); + + ToolHandleArray<IMonitorToolBase>::iterator monToolsEnd = m_monTools.end(); + for( ToolHandleArray<IMonitorToolBase>::iterator i = m_monTools.begin(); i != monToolsEnd; ++i ) { + ToolHandle<IMonitorToolBase>& tool = *i; + d->toolAudStart(tool); + AthMonBench bench_tmp; + if (d->m_doResourceMon) + bench_tmp.startMeasurement(); + sc = tool->bookHists(); + if (d->m_doResourceMon) { + bench_tmp.finishMeasurement(); + Imp::ToolBench* tb = d->getToolBench(tool.operator->()); + tb->m_bench_algexec_bookHists += bench_tmp; + } + if( !sc.isSuccess() ) { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "IMonitorToolBase::bookHists() unsuccessful" << endreq; + } + d->toolAudEnd(); + } + if (msgLvl(MSG::DEBUG)) { + msg(MSG::DEBUG) << " --> Done calling IMonitorToolBase::bookHists()" << endreq; + msg(MSG::DEBUG) << " --> Exiting successfully" << endreq; + } + + return StatusCode::SUCCESS; +} + + +StatusCode +AthenaMonManager:: +endRun() +{ + Imp::LWHistLeakChecker lc(d); + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "AthenaMonManager::endRun():" << endreq; + + StatusCode sc; + sc.setChecked(); + + ToolHandleArray<IMonitorToolBase>::iterator monToolsEnd = m_monTools.end(); + for( ToolHandleArray<IMonitorToolBase>::iterator i = m_monTools.begin(); i != monToolsEnd; ++i ) { + ToolHandle<IMonitorToolBase>& tool = *i; + d->toolAudStart(tool); + sc = tool->runStat(); + if( !sc.isSuccess() ) { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "IMonitorToolBase::runStat() unsuccessful" << endreq; + } + d->toolAudEnd(); + } + if (msgLvl(MSG::DEBUG)) { + msg(MSG::DEBUG) << " --> Done calling IMonitorToolBase::runStat()" << endreq; + msg(MSG::DEBUG) << " --> Exiting successfully" << endreq; + } + return StatusCode::SUCCESS; +} + + +std::string +AthenaMonManager:: +fileKey() const +{ + return d->m_fileKeyProp; +} + + +void +AthenaMonManager:: +passOwnership( TObject* h, const std::string& key ) +{ + Imp::ObjMap_t::value_type valToInsert( key, h ); + d->m_objMap.insert( valToInsert ); +} + + +void +AthenaMonManager:: +passOwnership( LWHist* h, const std::string& key ) +{ + Imp::ObjMapLW_t::value_type valToInsert( key, h ); + d->m_objMapLW.insert( valToInsert ); +} + + + +LWHist * +AthenaMonManager:: +ownedLWHistOfKey(const std::string& key) const +{ + Imp::ObjMapLW_t::iterator iLW = d->m_objMapLW.find( key ); + return iLW == d->m_objMapLW.end() ? 0 : iLW->second; +} + + +void +AthenaMonManager:: +writeAndDeleteLWHist( LWHist*lwh ) +{ + writeAndDeleteLWHist(LWHistAthMonWrapper::key(lwh),LWHistAthMonWrapper::streamName(lwh)); +} + + +LWHist * +AthenaMonManager:: +writeAndDeleteLWHist( const std::string& key, const std::string& streamName, bool doDelete ) +{ +// std::cout<<"writeAndDeleteLWHist... maybe"<<std::endl; + //If is owned LWHist we write it in a root file and deletes it + returns it's (now deallocated) address. + + Imp::ObjMapLW_t::iterator iLW = d->m_objMapLW.find( key ); + if( iLW != d->m_objMapLW.end() ) { + //Fixme: add private helper method actualWriteAndDelete(TH1*), to use by both... + LWHist * lwhist =iLW->second; + TH1 * h = lwhist->getROOTHistBase(); + if( h != 0 ) { + //Get correct dir by doing a quick reg/dereg: + bool ok(false); + if (lwhist->usingROOTBackend()) { + //Already registered + ok = true; + } else { + //Delayed registration: + if (m_THistSvc->regHist( streamName, h ).isSuccess()) + // if (m_THistSvc->deReg( h ).isSuccess()) + ok = true; + } + + if (ok) { + bool doRecursiveReferenceDelete = gROOT->MustClean(); + gROOT->SetMustClean(false); + TDirectory* dir = h->GetDirectory(); + TDirectory* g = gDirectory; + if(dir) + dir->cd(); + h->Write(); + g->cd(); + + StatusCode sc = m_THistSvc->deReg( h ); + if( !sc.isSuccess() ) { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "AthenaMonManager::WriteAndDeleteHist(): Failure to deReg( TObject* )" << endreq; + } + + d->m_objMapLW.erase( iLW ); + lwhist->setOwnsROOTHisto(true);//Since we deregistered + if (doDelete) { + LWHistAthMonWrapper::deleteLWHist(lwhist); + lwhist=0; + } + gROOT->SetMustClean(doRecursiveReferenceDelete);//Should be after the deleteLWHist call + } + return lwhist; + } + } + return 0; +} + + + +void +AthenaMonManager:: +writeAndDelete( const std::string& key ) +{ + // If is owned TObject, we deregister from THistSvc, write it in a + // root file, and delete it. + + Imp::ObjMap_t::iterator i = d->m_objMap.find( key ); + if( i != d->m_objMap.end() ) { + TObject* o = i->second; + TH1* h = dynamic_cast<TH1*>( o ); + if( h != 0 ) { + // By default, ROOT does its own bookkeeping of references to + // histograms, and this leads to a significant amount of time + // spent in the TObject d'tor when there are >= O(1000) TDirectories. + // So, turn this bookkeeping off when deleting these histograms. + bool doRecursiveReferenceDelete = gROOT->MustClean(); + gROOT->SetMustClean(false); + TDirectory* dir = h->GetDirectory(); + TDirectory* g = gDirectory; + if( dir ) + dir->cd(); + h->Write(); + g->cd(); + + StatusCode sc = m_THistSvc->deReg( h ); + if( !sc.isSuccess() ) { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "AthenaMonManager::WriteAndDeleteHist(): Failure to deReg( TObject* )" << endreq; + } + delete o; + gROOT->SetMustClean(doRecursiveReferenceDelete); + d->m_objMap.erase( key ); + } + } +} + +// ********************************************************************* +// Protected Methods +// ********************************************************************* + +void +AthenaMonManager:: +setEventInfo() +{ + if( d->m_isPrimaryManager ) { + const DataHandle<EventInfo> evt; + const DataHandle<EventInfo> evtEnd; + StatusCode sc = evtStore()->retrieve( evt, evtEnd ); + + if( !sc.isSuccess() ) { + msg(MSG::ERROR) << "!! Unable to retrieve Event from StoreGate !!" << endreq; + return; + } + + Imp::s_run = evt->event_ID()->run_number(); + Imp::s_lumiBlock = evt->event_ID()->lumi_block(); + + if (msgLvl(MSG::DEBUG)) + msg(MSG::DEBUG) << " --> setEventInfo: run = " << Imp::s_run << ", lumiBlock = " << Imp::s_lumiBlock << endreq; + + } +} + + +// ********************************************************************* +// Private Methods +// ********************************************************************* +namespace { + + std::string strToLower( const std::string& str ) + { + std::string lstr(str); + std::string::const_iterator from = str.begin(); + std::string::const_iterator strend = str.end(); + std::string::iterator to = lstr.begin(); + while( from != strend ) { + *to++ = tolower(*from++); + } + return lstr; + } + +} // unnamed namespace diff --git a/Control/AthenaMonitoring/src/DQAtlasReadyFilterTool.cxx b/Control/AthenaMonitoring/src/DQAtlasReadyFilterTool.cxx new file mode 100644 index 00000000000..818d512a3bf --- /dev/null +++ b/Control/AthenaMonitoring/src/DQAtlasReadyFilterTool.cxx @@ -0,0 +1,69 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AthenaMonitoring/DQAtlasReadyFilterTool.h" +#include "AthenaPoolUtilities/AthenaAttributeList.h" + +DQAtlasReadyFilterTool::DQAtlasReadyFilterTool(const std::string& type,const std::string& name,const IInterface* parent) +: AthAlgTool( type, name, parent ) +, m_fallbackValue(true) +, m_alwaysReturnTrue(false) +, m_valueCache(true) +{ + declareInterface<IDQFilterTool>(this); + declareProperty("fallbackValue", m_fallbackValue); + declareProperty("alwaysReturnTrue", m_alwaysReturnTrue); +} + +DQAtlasReadyFilterTool::~DQAtlasReadyFilterTool () {} + +StatusCode DQAtlasReadyFilterTool::initialize() +{ + ATH_MSG_VERBOSE("ATLAS Ready initialize"); + // don't register callback if we always return true anyway + if (m_alwaysReturnTrue) return StatusCode::SUCCESS; + + const DataHandle<AthenaAttributeList> attrList; + StatusCode sc = detStore()->regFcn(&DQAtlasReadyFilterTool::callback, + this, attrList, + "/TDAQ/RunCtrl/DataTakingMode"); + if (sc.isFailure()) { + ATH_MSG_ERROR("Unable to register ATLAS Ready filter tool callback"); + return StatusCode::FAILURE; + } + if (sc.isFailure()) { + ATH_MSG_ERROR("Unable to set up ready value cache"); + return StatusCode::FAILURE; + } + return StatusCode::SUCCESS; +} + +StatusCode DQAtlasReadyFilterTool::updateCache() { + const AthenaAttributeList* attrList(0); + StatusCode sc = detStore()->retrieve(attrList, "/TDAQ/RunCtrl/DataTakingMode"); + if (sc.isFailure()) { + ATH_MSG_WARNING("Unable to retrieve DataTakingMode information; falling back to" << m_fallbackValue); + m_valueCache = m_fallbackValue; + return StatusCode::SUCCESS; + } + if (attrList != 0) { + ATH_MSG_VERBOSE("ReadyForPhysics is: " << (*attrList)["ReadyForPhysics"].data<uint32_t>()); + m_valueCache = ((*attrList)["ReadyForPhysics"].data<uint32_t>() != 0); + } + return StatusCode::SUCCESS; +} + +bool DQAtlasReadyFilterTool::accept() { + if (m_alwaysReturnTrue) { + return true; + } else { + ATH_MSG_DEBUG("ATLAS Ready accept called, value " << m_valueCache); + return m_valueCache; + } +} + +StatusCode DQAtlasReadyFilterTool::callback( IOVSVC_CALLBACK_ARGS) { + ATH_MSG_VERBOSE("ATLAS Ready callback called"); + return updateCache(); +} diff --git a/Control/AthenaMonitoring/src/DQBadLBFilterTool.cxx b/Control/AthenaMonitoring/src/DQBadLBFilterTool.cxx new file mode 100644 index 00000000000..2a79c672694 --- /dev/null +++ b/Control/AthenaMonitoring/src/DQBadLBFilterTool.cxx @@ -0,0 +1,110 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AthenaMonitoring/DQBadLBFilterTool.h" +#include "AthenaPoolUtilities/AthenaAttributeList.h" +#include "AthenaPoolUtilities/CondAttrListCollection.h" +#include "CoralBase/AttributeListException.h" + +DQBadLBFilterTool::DQBadLBFilterTool(const std::string& type,const std::string& name,const IInterface* parent) +: AthAlgTool( type, name, parent ) +, m_fallbackValue(true) +, m_ignoreRecoverable(true) +, m_alwaysReturnTrue(false) +, m_valueCache(true) +//, m_listofdefects(0) +//, m_listofdefects_str(0) +{ + + declareInterface<IDQFilterTool>(this); + declareProperty("fallbackValue", m_fallbackValue); + declareProperty("ignoreRecoverable", m_ignoreRecoverable); + declareProperty("alwaysReturnTrue", m_alwaysReturnTrue); + declareProperty("defectListStr", m_listofdefects_str); + declareProperty("defectList", m_listofdefects); + +} + +DQBadLBFilterTool::~DQBadLBFilterTool () {} + +StatusCode DQBadLBFilterTool::initialize() +{ + + ATH_MSG_DEBUG("size of defects list in Bad DB " << m_listofdefects_str.size()<< " : " << m_listofdefects.size()); + ATH_MSG_DEBUG("test other params fall and def " << m_fallbackValue << " : " << m_alwaysReturnTrue ); + + ATH_MSG_VERBOSE("ATLAS Ready initialize"); + // don't register callback if we always return true anyway + if (m_alwaysReturnTrue) return StatusCode::SUCCESS; + + const DataHandle<CondAttrListCollection> attrList; +// const DataHandle<AthenaAttributeList> attrList; + StatusCode sc = detStore()->regFcn(&DQBadLBFilterTool::callback, + this, attrList, + "/GLOBAL/DETSTATUS/DEFECTS"); + if (sc.isFailure()) { + ATH_MSG_ERROR("Unable to register Bad LB filter tool callback"); + return StatusCode::FAILURE; + } + if (sc.isFailure()) { + ATH_MSG_ERROR("Unable to set up ready value cache"); + return StatusCode::FAILURE; + } + return StatusCode::SUCCESS; +} + +StatusCode DQBadLBFilterTool::updateCache() { + + const CondAttrListCollection* attrListCol(0); + StatusCode sc = detStore()->retrieve(attrListCol, "/GLOBAL/DETSTATUS/DEFECTS"); + if (sc.isFailure()) { + ATH_MSG_WARNING("Unable to retrieve defect information; falling back to" << m_fallbackValue); + m_valueCache = m_fallbackValue; + return StatusCode::SUCCESS; + } + + m_valueCache = m_fallbackValue; + if (attrListCol != 0) { + + ATH_MSG_DEBUG("Col range " << " iov min " << attrListCol->minRange().start().event() << " iov max " << attrListCol->minRange().stop().event()); + + std::vector<int>::const_iterator defect_iter = m_listofdefects.begin(); + + for ( ; defect_iter != m_listofdefects.end();++defect_iter){ + + if (attrListCol->chanAttrListPair(*defect_iter) != attrListCol->end()){ + + const CondAttrListCollection::AttributeList* attrList = + &(attrListCol->attributeList( (*defect_iter) )); + + ATH_MSG_DEBUG("FOUND CHANNEL " << (*defect_iter) << " is: " << (*attrList)["present"].data<bool>()); + ATH_MSG_DEBUG("current channel : " << (*defect_iter) << " Name : " << attrListCol->chanName(*defect_iter) << " : iovrange " << attrListCol->iovRange(*defect_iter).start().event() << " : " << attrListCol->iovRange(*defect_iter).stop().event()); + ATH_MSG_DEBUG( "Check address " << attrList << " : " << *attrList); + if ((*attrList)["present"].data<bool>() != 0){ + if ((*attrList)["recoverable"].data<bool>() == 1 && m_ignoreRecoverable){ + continue; + } + m_valueCache = 0; + return StatusCode::SUCCESS; + } + } + } + + } + return StatusCode::SUCCESS; +} + +bool DQBadLBFilterTool::accept() { + if (m_alwaysReturnTrue) { + return true; + } else { + ATH_MSG_VERBOSE("Bad LB accept called, value " << m_valueCache); + return m_valueCache; + } +} + +StatusCode DQBadLBFilterTool::callback( IOVSVC_CALLBACK_ARGS ) { + ATH_MSG_VERBOSE("Bad LB callback called"); + return updateCache(); +} diff --git a/Control/AthenaMonitoring/src/DQDummyFilterTool.cxx b/Control/AthenaMonitoring/src/DQDummyFilterTool.cxx new file mode 100644 index 00000000000..cc256f41257 --- /dev/null +++ b/Control/AthenaMonitoring/src/DQDummyFilterTool.cxx @@ -0,0 +1,18 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AthenaMonitoring/DQDummyFilterTool.h" + +DQDummyFilterTool::DQDummyFilterTool(const std::string& type,const std::string& name,const IInterface* parent) +: AthAlgTool( type, name, parent ) +{ + declareInterface<IDQFilterTool>(this); +} + +DQDummyFilterTool::~DQDummyFilterTool () {} + +bool DQDummyFilterTool::accept() { + return true; +} + diff --git a/Control/AthenaMonitoring/src/DQFilledBunchFilterTool.cxx b/Control/AthenaMonitoring/src/DQFilledBunchFilterTool.cxx new file mode 100644 index 00000000000..99d216b03c3 --- /dev/null +++ b/Control/AthenaMonitoring/src/DQFilledBunchFilterTool.cxx @@ -0,0 +1,46 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AthenaMonitoring/DQFilledBunchFilterTool.h" +#include "AthenaKernel/errorcheck.h" +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" + +DQFilledBunchFilterTool::DQFilledBunchFilterTool(const std::string& type,const std::string& name,const IInterface* parent) +: AthAlgTool( type, name, parent ) +, m_alwaysReturnTrue(false) +, m_invert(false) +, m_bunchtool("Trig::TrigConfBunchCrossingTool/BunchCrossingTool") +{ + declareInterface<IDQFilterTool>(this); + declareProperty("alwaysReturnTrue", m_alwaysReturnTrue); + declareProperty("invert", m_invert); + declareProperty("bunchCrossingTool", m_bunchtool); +} + +DQFilledBunchFilterTool::~DQFilledBunchFilterTool () {} + +StatusCode DQFilledBunchFilterTool::initialize() +{ + ATH_MSG_VERBOSE("ATLAS Ready initialize"); + // don't register callback if we always return true anyway + if (m_alwaysReturnTrue) return StatusCode::SUCCESS; + + CHECK( m_bunchtool.retrieve() ); + return StatusCode::SUCCESS; +} + +bool DQFilledBunchFilterTool::accept() { + if (m_alwaysReturnTrue) { + return true; + } else { + const EventInfo* eventInfo(0); + CHECK( evtStore()->retrieve( eventInfo ) ); + + EventID::number_type bcid = eventInfo->event_ID()->bunch_crossing_id(); + bool value = m_bunchtool->isFilled(bcid) ^ m_invert; + ATH_MSG_VERBOSE("Filled bunch DQ tool accept called, value " << value); + return value; + } +} diff --git a/Control/AthenaMonitoring/src/FastPhysMonToolBase.cxx b/Control/AthenaMonitoring/src/FastPhysMonToolBase.cxx new file mode 100644 index 00000000000..fdd3b160811 --- /dev/null +++ b/Control/AthenaMonitoring/src/FastPhysMonToolBase.cxx @@ -0,0 +1,105 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AthenaMonitoring/FastPhysMonToolBase.h" +#include "GaudiKernel/IIncidentSvc.h" +#include "GaudiKernel/ServiceHandle.h" +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" +#include "EventInfo/EventType.h" +#include "TTree.h" + +FastPhysMonToolBase::FastPhysMonToolBase( const std::string & type, const std::string & name, + const IInterface* parent ): + ManagedMonitorToolBase(type,name,parent), + m_eventNumber(0),m_runNumber(0),m_LBNumber(0),m_mcEventWeight(0.),m_booked(false) +{} + +FastPhysMonToolBase::~FastPhysMonToolBase() {} + +StatusCode FastPhysMonToolBase::initialize() { + + ATH_MSG_DEBUG("Intializing FastPhysMonToolBase " << this->name()); + //Register Incident-handler + ServiceHandle<IIncidentSvc> incSvc("IncidentSvc",this->name()); + if (incSvc.retrieve().isFailure()) { + msg(MSG::ERROR) << "Can't retrieve IIncidentSvc" << endreq; + return StatusCode::FAILURE; + } + + incSvc->addListener(this,"BeginEvent"); + + + return ManagedMonitorToolBase::initialize(); +} + + + +void FastPhysMonToolBase::handle(const Incident&) { + + ATH_MSG_DEBUG("In incident handler..."); + const EventInfo* eventInfo; + if (evtStore()->retrieve(eventInfo).isFailure()) { + msg(MSG::ERROR) << "Can't retrieve EventInfo object" << endreq; + return; + } + + m_eventNumber=eventInfo->event_ID()->event_number(); + m_runNumber=eventInfo->event_ID()->run_number(); + m_LBNumber=eventInfo->event_ID()->lumi_block(); + m_mcEventWeight=eventInfo->event_type()->mc_event_weight(); + + return; +} + + +TTree* FastPhysMonToolBase::regFPMTree(const std::string& treeName, const std::string treeTitle, const std::string& systemName, + const std::string& chain, const std::string& merge) { + + TTree* tree=new TTree(treeName.c_str(),treeTitle.c_str()); + StatusCode sc=this->regFPMTree(tree,systemName,chain,merge); + if (sc.isFailure()) { + delete tree; + tree=NULL; + } + return tree; +} + +StatusCode FastPhysMonToolBase::regFPMTree(TTree* tree,const std::string& systemName,const std::string& chain, const std::string& merge) { + + ATH_MSG_DEBUG("Registering FPM Tree with name " << tree->GetName() << " with system name " << systemName); + + if (ManagedMonitorToolBase::regTree(tree,systemName,all, ManagedMonitorToolBase::ATTRIB_UNMANAGED, chain, merge).isFailure()) { + msg(MSG::ERROR) << "Failed to register Tree with name " << tree->GetName() << " with system name " << systemName << endreq; + return StatusCode::FAILURE; + } + + tree->Branch("EventNumber",&m_eventNumber); + tree->Branch("RunNumber",&m_runNumber); + tree->Branch("LumiBlockN",&m_LBNumber); + tree->Branch("MCEventWeight",&m_mcEventWeight); + + return StatusCode::SUCCESS; +} + +StatusCode FastPhysMonToolBase::bookHistograms() { + if (m_booked) return StatusCode::SUCCESS; + + + StatusCode sc=this->bookNtuple(); + if (sc.isFailure()) { + msg(MSG::ERROR) << "bookNtuple method failed!" << endreq; + return StatusCode::FAILURE; + } + + m_booked=true; + return StatusCode::SUCCESS; +} + + + +StatusCode FastPhysMonToolBase::bookNtuple() { + msg(MSG::ERROR) << "No bookNtuple() method implemented for this FastPhysMonTool!" << endreq; + return StatusCode::FAILURE; +} diff --git a/Control/AthenaMonitoring/src/LWHistAthMonWrapper.h b/Control/AthenaMonitoring/src/LWHistAthMonWrapper.h new file mode 100644 index 00000000000..29bf13f2485 --- /dev/null +++ b/Control/AthenaMonitoring/src/LWHistAthMonWrapper.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +//////////////////////////////////////////////////////////////// +// // +// Header file for class LWHistAthMonWrapper // +// // +// Description: Utility methods to associate a few custom // +// fields (key and streamName) with LWHists. // +// This makes book-keeping simpler, and saves // +// needless string copies and map lookups. // +// // +// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) // +// Initial version: March 2009 // +// // +//////////////////////////////////////////////////////////////// + +#ifndef LWHISTWRAPPER_H +#define LWHISTWRAPPER_H + +#include "LWHists/LWHist.h" +#include "LWHists/LWHistControls.h" + +class LWHistAthMonWrapper { +public: + + static void setStreamName(LWHist*, const std::string& streamName); + static void setKey(LWHist*, const std::string& key); + static const std::string& streamName(LWHist*); + static const std::string& key(LWHist*); + static void deleteLWHist(LWHist*);//always use this to delete LWHists in this package + static void removeCustomData(LWHist*); + +private: + struct LWHistAthenaMonCustomData; + LWHistAthMonWrapper(){} + ~LWHistAthMonWrapper(){} +}; + +#include "LWHistAthMonWrapper.icc" + +#endif + diff --git a/Control/AthenaMonitoring/src/LWHistAthMonWrapper.icc b/Control/AthenaMonitoring/src/LWHistAthMonWrapper.icc new file mode 100644 index 00000000000..99e6bce65af --- /dev/null +++ b/Control/AthenaMonitoring/src/LWHistAthMonWrapper.icc @@ -0,0 +1,53 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + + +struct LWHistAthMonWrapper::LWHistAthenaMonCustomData +{ + std::string streamName; + std::string key; +}; + +inline void LWHistAthMonWrapper::setStreamName(LWHist*h, const std::string& streamName) +{ + + if (!h->getCustomData()) + h->setCustomData(new LWHistAthenaMonCustomData); + reinterpret_cast<LWHistAthenaMonCustomData*>(h->getCustomData())->streamName = streamName; +} + +inline void LWHistAthMonWrapper::setKey(LWHist*h, const std::string& key) +{ + if (!h->getCustomData()) + h->setCustomData(new LWHistAthenaMonCustomData); + reinterpret_cast<LWHistAthenaMonCustomData*>(h->getCustomData())->key = key; +} + +inline const std::string& LWHistAthMonWrapper::streamName(LWHist*h) +{ + assert(h->getCustomData()); + return reinterpret_cast<LWHistAthenaMonCustomData*>(h->getCustomData())->streamName; + +} + +inline const std::string& LWHistAthMonWrapper::key(LWHist*h) +{ + assert(h->getCustomData()); + return reinterpret_cast<LWHistAthenaMonCustomData*>(h->getCustomData())->key; +} + +inline void LWHistAthMonWrapper::removeCustomData(LWHist*h) +{ + char *c = reinterpret_cast<char*>(h->getCustomData()); + if (c) + delete reinterpret_cast<LWHistAthenaMonCustomData*>(c); + h->setCustomData(0); +} + +inline void LWHistAthMonWrapper::deleteLWHist(LWHist*h) +{ + removeCustomData(h); + LWHist::safeDelete(h); +} diff --git a/Control/AthenaMonitoring/src/ManagedMonitorToolBase.cxx b/Control/AthenaMonitoring/src/ManagedMonitorToolBase.cxx new file mode 100755 index 00000000000..b5aebaeca7c --- /dev/null +++ b/Control/AthenaMonitoring/src/ManagedMonitorToolBase.cxx @@ -0,0 +1,2270 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ManagedMonitorToolBase_CXX +#define ManagedMonitorToolBase_CXX +// ************************************************************************* +// $Id: ManagedMonitorToolBase.cxx,v 1.36 2009-05-07 15:32:46 sschaetz Exp $ +// ************************************************************************* + +#include "AthenaMonitoring/ManagedMonitorToolBase.h" + +#include <cctype> +#include <ctime> +#include <sstream> + +#include "TGraph.h" +#include "TH1.h" +#include "TH2.h" +#include "TTree.h" +#include "TROOT.h" +#include "TFile.h" +#include "LWHists/LWHist.h" +#include "LWHistAthMonWrapper.h" +#include "AthMonBench.h" + +#include "GaudiKernel/IHistogramSvc.h" +#include "GaudiKernel/IJobOptionsSvc.h" +#include "GaudiKernel/IMessageSvc.h" +#include "GaudiKernel/ISvcLocator.h" +#include "GaudiKernel/MsgStream.h" + +#include "TrigDecisionInterface/ITrigDecisionTool.h" +#include "AthenaMonitoring/IDQFilterTool.h" +#include "GaudiKernel/ITHistSvc.h" + +//____________________________________________________________________ +class ManagedMonitorToolBase::Imp { +public: + static ISvcLocator* s_svcLocator; + Imp(ManagedMonitorToolBase*tc) : m_theclass(tc), + m_warnAboutMissingInitialize(true), + m_doResourceMon(false), + m_benchNFillAfterbook(0) {} + ~Imp() {} + + //Data members: + ManagedMonitorToolBase * m_theclass; + //To warn against clients that reimplemented initialize without calling ManagedMonitorToolBase::initialze(): + bool m_warnAboutMissingInitialize; + + //Internal methods and data members for detailed LWHists-aware CPU/mem monitoring: + bool m_doResourceMon; + AthMonBench m_bench_tmp; + AthMonBench m_bench_book; + AthMonBench m_bench_fillfirst; + AthMonBench m_bench_fillall; + AthMonBench m_bench_filllast; + AthMonBench m_bench_proc; + AthMonBench m_bench_total; + unsigned m_benchNFillAfterbook; + void benchPreBookHistograms(); + void benchPostBookHistograms(); + void benchPreFillHistograms(); + void benchPostFillHistograms(); + void benchPreProcHistograms(); + void benchPostProcHistograms(); + void benchFinalReport(); + void benchReset(); +}; + +////////////////////////////////////////////////////////////////////////////////////////////////// +///////////////////// Internal methods for detailed CPU/mem monitoring /////////////////// +////////////////////////////////////////////////////////////////////////////////////////////////// + +//____________________________________________________________________ +void ManagedMonitorToolBase::Imp::benchPreBookHistograms() +{ + if (!m_doResourceMon) + return; + benchReset(); + m_bench_book.startMeasurement(); +} + +//____________________________________________________________________ +void ManagedMonitorToolBase::Imp::benchPostBookHistograms() +{ + if (!m_doResourceMon) + return; + m_bench_book.finishMeasurement(); + m_bench_total += m_bench_book; + m_benchNFillAfterbook = 0; +} + +//____________________________________________________________________ +void ManagedMonitorToolBase::Imp::benchPreFillHistograms() +{ + if (!m_doResourceMon) + return; + m_bench_tmp.reset(); + m_bench_tmp.startMeasurement(); +} + +//____________________________________________________________________ +void ManagedMonitorToolBase::Imp::benchPostFillHistograms() +{ + if (!m_doResourceMon) + return; + m_bench_tmp.finishMeasurement(); + m_bench_total += m_bench_tmp; + ++m_benchNFillAfterbook; + if (m_benchNFillAfterbook==1) { + m_bench_fillfirst = m_bench_tmp; + } else { + m_bench_fillall += m_bench_tmp; + m_bench_filllast = m_bench_tmp; + } +} + +//____________________________________________________________________ +void ManagedMonitorToolBase::Imp::benchPreProcHistograms() +{ + if (!m_doResourceMon) + return; + m_bench_proc.startMeasurement(); +} + +//____________________________________________________________________ +void ManagedMonitorToolBase::Imp::benchPostProcHistograms() +{ + if (!m_doResourceMon) + return; + m_bench_proc.finishMeasurement(); + m_bench_total += m_bench_proc; + m_bench_fillall -= m_bench_filllast; + m_benchNFillAfterbook = 0; + benchFinalReport(); + benchReset(); +} + +//____________________________________________________________________ +void ManagedMonitorToolBase::Imp::benchReset() +{ + if (!m_doResourceMon) + return; + m_benchNFillAfterbook = 0; + m_bench_tmp.reset(); + m_bench_book.reset(); + m_bench_fillfirst.reset(); + m_bench_fillall.reset(); + m_bench_filllast.reset(); + m_bench_proc.reset(); + m_bench_total.reset(); + +} + +//____________________________________________________________________ +void ManagedMonitorToolBase::Imp::benchFinalReport() +{ + if (!m_doResourceMon) + return; + m_theclass->msg(AthMonBench::s_resourceMonThreshold) << "ResourceSummary --> Result of dedicated mon-tool resource monitoring:"<<endreq; + m_theclass->msg(AthMonBench::s_resourceMonThreshold) << "ResourceSummary --> Book : "<<m_bench_book << endreq; + m_theclass->msg(AthMonBench::s_resourceMonThreshold) << "ResourceSummary --> First Fill : "<<m_bench_fillfirst << endreq; + m_theclass->msg(AthMonBench::s_resourceMonThreshold) << "ResourceSummary --> Last Fill : "<<m_bench_filllast << endreq; + m_theclass->msg(AthMonBench::s_resourceMonThreshold) << "ResourceSummary --> Other Fills : "<<m_bench_fillall << endreq; + m_theclass->msg(AthMonBench::s_resourceMonThreshold) << "ResourceSummary --> Proc : "<<m_bench_proc << endreq; + m_bench_total.setUnitCount();//to avoid dividing by number of measurements + m_theclass->msg(AthMonBench::s_resourceMonThreshold) << "ResourceSummary --> Grand Total : "<<m_bench_total << endreq; + //NB: Needs total also! +} + + + +////////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////////////// + +ISvcLocator* ManagedMonitorToolBase::Imp::s_svcLocator(0); + +namespace { + + std::string strToLower( const std::string& str ); + std::string strToUpper( const std::string& str ); + +} // unnamed namespace + +static unsigned s_mmtb_mongroup_ncopies=0; +unsigned ManagedMonitorToolBase::MonGroup::ncopies() { return s_mmtb_mongroup_ncopies; } +void ManagedMonitorToolBase::MonGroup::badusage() { ++s_mmtb_mongroup_ncopies; } + +// ********************************************************************* +// Public Methods +// ********************************************************************* +StatusCode +ManagedMonitorToolBase::MonGroup:: +regHist( TH1* h ) +{ + if( m_tool != 0 ) { + std::string hName( h->GetName() ); + HistMap_t::value_type valToInsert( hName, h ); + m_map.insert( valToInsert ); + return m_tool->regHist( h, *this ); + } + + return StatusCode::FAILURE; +} + +StatusCode +ManagedMonitorToolBase::MonGroup:: +getHist( TH1*& h, const std::string& hName ) +{ + if( m_tool != 0 ) { + return m_tool->getHist( h, hName, *this ); + } + + return StatusCode::FAILURE; +} + + + +StatusCode +ManagedMonitorToolBase::MonGroup:: +regHist( LWHist* h ) +{ + if( m_tool != 0 ) { + std::string hName( h->GetName() ); + HistMapLW_t::value_type valToInsert( hName, h );//Fixme: Just keep a list of the hists + m_mapLW.insert( valToInsert ); + return m_tool->regHist( h, *this ); + } + + return StatusCode::FAILURE; +} + + + +StatusCode ManagedMonitorToolBase::MonGroup::getHist( LWHist*& h, const std::string& hName ) +{ + if( m_tool ) + return m_tool->getHist( h, hName, *this ); + + return StatusCode::FAILURE; +} + + +StatusCode +ManagedMonitorToolBase::MonGroup:: +getHist( TH2*& h, const std::string& hName ) +{ + if( m_tool != 0 ) { + return m_tool->getHist( h, hName, *this ); + } + + return StatusCode::FAILURE; +} + + +StatusCode +ManagedMonitorToolBase::MonGroup:: +regGraph( TGraph* g ) +{ + if( m_tool != 0 ) { + return m_tool->regGraph( g, *this ); + } + + return StatusCode::FAILURE; +} + + +StatusCode +ManagedMonitorToolBase::MonGroup:: +regTree( TTree* t ) +{ + if( m_tool != 0 ) { + return m_tool->regTree( t, *this ); + } + + return StatusCode::FAILURE; +} + + +StatusCode +ManagedMonitorToolBase::MonGroup:: +writeAndDelete( TH1* h ) +{ + if( m_tool != 0 ) { + std::string hName( h->GetName() ); + m_map.erase( hName ); + return m_tool->writeAndDelete( h, *this ); + } + + return StatusCode::FAILURE; +} + + +StatusCode +ManagedMonitorToolBase::MonGroup:: +deregHist( TH1* h ) +{ + if( m_tool != 0 ) { + std::string hName( h->GetName() ); + m_map.erase( hName ); + return m_tool->deregHist( h ); + } + + return StatusCode::FAILURE; +} + + +StatusCode ManagedMonitorToolBase::MonGroup::deregHist( LWHist* h ) +{ + if( m_tool != 0 ) { + std::string hName( h->GetName() ); + m_mapLW.erase( hName ); + return m_tool->deregHist( h ); + } + + return StatusCode::FAILURE; +} + + +StatusCode +ManagedMonitorToolBase::MonGroup:: +deregGraph( TGraph* g ) +{ + if( m_tool != 0 ) { + return m_tool->deregGraph( g ); + } + + return StatusCode::FAILURE; +} + + +StatusCode +ManagedMonitorToolBase::MonGroup:: +deregObject( const std::string& objName ) +{ + if( m_tool != 0 ) { + return m_tool->deregObject( objName, *this ); + } + + return StatusCode::FAILURE; +} + + +StatusCode +ManagedMonitorToolBase::MonGroup:: +deregAll() +{ + if( m_tool != 0 ) { + bool isSuccess(true); + StatusCode sc; + sc.setChecked(); + + typedef HistMap_t::const_iterator MapIter_t; + MapIter_t mapEnd = m_map.end(); + for( MapIter_t i = m_map.begin(); i != mapEnd; ++i ) { + sc = m_tool->deregHist( i->second ); + if( !sc.isSuccess() ) + isSuccess = false; + } + + typedef HistMapLW_t::const_iterator MapIterLW_t; + MapIterLW_t mapEndLW = m_mapLW.end(); + for( MapIterLW_t i = m_mapLW.begin(); i != mapEndLW; ++i ) { + sc = m_tool->deregHist( i->second ); + if( !sc.isSuccess() ) + isSuccess = false; + } + + m_map.clear(); + m_mapLW.clear(); + + if( isSuccess ) + return StatusCode::SUCCESS; + } + + return StatusCode::FAILURE; +} + + +ManagedMonitorToolBase:: +ManagedMonitorToolBase( const std::string & type, const std::string & name, + const IInterface* parent ) + : AthAlgTool( type, name, parent ) + , m_manager(0) + , m_managerNameProp("AthenaMonManager") + , m_fileKey("") + , m_dataTypeStr("userDefined") + , m_environmentStr("noOutput") + , m_detailLevel(1) + , m_dataType(AthenaMonManager::userDefined) + , m_environment(AthenaMonManager::user) + , m_streamNameFcn(0) + , m_THistSvc("THistSvc",name) + , m_trigDecTool("") + , m_DQFilterTools() + , m_procNEventsProp(0) + , m_path("") + , m_preScaleProp(0) + , m_triggerChainProp("") + , m_triggerGroupProp("") + , m_useTrigger(false) + , m_lastLumiBlock(0) + , m_lastRun(0) + , m_lastLowStatInterval(-1) + , m_lastMedStatInterval(-1) + , m_lastHigStatInterval(-1) + , m_nEvents(1) + , m_nEventsIgnoreTrigger(1) + , m_nLumiBlocks(1) + , m_haveClearedLastEventBlock(true) + , m_lumiTool("LuminosityTool") + , m_liveTool("TrigLivefractionTool") + , m_hasRetrievedLumiTool(false) + , m_bookHistogramsInitial(false) + , m_useLumi(false) + , m_cycleNum(0) + , d(new Imp(this)) +{ +// ManagedMonitorToolBase_resetHistStatistics(this); + declareInterface<IMonitorToolBase>(this); + declareProperty( "ProcessNEvents", m_procNEventsProp ); + declareProperty( "histoPathBase", m_path ); + declareProperty( "PreScale", m_preScaleProp ); + declareProperty( "TriggerChain", m_triggerChainProp ); + declareProperty( "TriggerGroup", m_triggerGroupProp ); + + // If a class would like to associate itself to a manager but cannot actually + // be referenced by it, the manager name can be set explicitly. Otherwise, + // it is set automatically. + declareProperty( "ManagerName", m_managerNameProp ); + + // The TrigDecisionTool, clients normally should not have to set this + declareProperty( "TrigDecisionTool", m_trigDecTool ); + + // The filter tools, to be specified in jobOptions + declareProperty( "FilterTools", m_DQFilterTools ); + + // Enable luminosity tool? + declareProperty( "EnableLumi", m_useLumi ); + + // How detailed should the monitoring be? + declareProperty( "DetailLevel", m_detailLevel ); + + // Properties that are overridden in initialize()---settings via jobOptions are ignored! + declareProperty( "FileKey", m_fileKey ); + declareProperty( "DataType", m_dataTypeStr ); + declareProperty( "Environment", m_environmentStr ); + + if( Imp::s_svcLocator==0 ) + Imp::s_svcLocator = svcLoc(); + + for (auto interval: { eventsBlock, lumiBlock, lowStat, run, all }) { + m_templateHistograms[interval] = std::vector< MgmtParams<TH1> >(); + m_templateGraphs[interval] = std::vector< MgmtParams<TGraph> >(); + m_templateTrees[interval] = std::vector< MgmtParams<TTree> >(); + m_templateLWHistograms[interval] = std::vector< MgmtParams<LWHist> >(); + m_supportedIntervalsForRebooking.insert(interval); + } +} + + +ManagedMonitorToolBase:: +~ManagedMonitorToolBase() +{ +// ManagedMonitorToolBase_printHistStatistics(this); + delete m_streamNameFcn; + + std::map<std::string,OutputMetadata*>::iterator mdend = m_metadataMap.end(); + for( std::map<std::string,OutputMetadata*>::iterator i = m_metadataMap.begin(); + i != mdend; ++i ) { + delete (i->second); + } + delete d; +} + + +ManagedMonitorToolBase::StreamNameFcn* +ManagedMonitorToolBase:: +streamNameFunction() +{ + if( m_streamNameFcn == 0 ) { + msg(MSG::ERROR) << "!! streamNameFunction() has not been initialized !!" << endreq; + msg(MSG::ERROR) << " --> neither ManagedMonitorToolBase::initialize() nor" << endreq; + msg(MSG::ERROR) << " --> ManagedMonitorToolBase::setMonManager() has been called." << endreq; + msg(MSG::ERROR) << " --> Correct configuration cannot be guaranteed from this point." << endreq; + m_streamNameFcn = getNewStreamNameFcn(); + } + return m_streamNameFcn; +} + + +/* +std::string +ManagedMonitorToolBase:: +levelOfDetailEnumToString( LevelOfDetail_t level, bool useOnlineConventions ) +{ + std::string str("summary"); + + switch( level ) { + case transient: + str = "transient"; + break; + case debug: + str = "debug"; + break; + case expert: + str = "expert"; + break; + case shift: + str = "shift"; + break; + case summary: + default: + if(useOnlineConventions) + str = "runstat"; + else + str = "summary"; + } + + if(useOnlineConventions) + str = strToUpper( str ); + + return str; +} +*/ + +/* +ManagedMonitorToolBase::LevelOfDetail_t +ManagedMonitorToolBase:: +levelOfDetailStringToEnum( const std::string& str ) +{ + std::string lcstr( strToLower(str) ); + + if( lcstr == "summary" || lcstr == "runstat" ) + return summary; + else if( lcstr == "shift" ) + return shift; + else if( lcstr == "expert" ) + return expert; + else if( lcstr == "debug" ) + return debug; + else if( lcstr == "transient" ) + return transient; + + // This is a static method (shared by all instances), so no "this" pointer + // is available (needed for msg). Have to use message service directly. + if( Imp::s_svcLocator!=0 ) { + IMessageSvc* ms(0); + StatusCode sc = Imp::s_svcLocator->service( "MessageSvc", ms, true ); + if( sc.isSuccess() ) { + MsgStream log( ms, "ManagedMonitorToolBase::levelOfDetailStringToEnum()" ); + log << MSG::WARNING << "Unknown ManagedMonitorToolBase::LevelOfDetail_t \"" + << str << "\", returning \"transient\"" << endreq; + } + } + + return transient; +} +*/ + + +std::string +ManagedMonitorToolBase:: +intervalEnumToString( Interval_t interval ) +{ + std::string str("file"); + + switch( interval ) { + case all: + str = "all"; + break; + case fill: + str = "fill"; + break; + case run: + str = "run"; + break; + case lowStat: + str = "lowStat"; + break; + case medStat: + str = "medStat"; + break; + case higStat: + str = "higStat"; + break; + case lumiBlock: + str = "lumiBlock"; + break; + case eventsBlock: + str = "eventsBlock"; + break; + case file: + str = "file"; + break; + default: + str = "unknown"; + } + + return str; +} + + +ManagedMonitorToolBase::Interval_t +ManagedMonitorToolBase:: +intervalStringToEnum( const std::string& str ) +{ + std::string lcstr( strToLower(str) ); + + if( lcstr == "all" ) + return all; + else if( lcstr == "fill" ) + return fill; + else if( lcstr == "run" ) + return run; + else if( lcstr == "lowStat" ) + return lowStat; + else if( lcstr == "medStat" ) + return medStat; + else if( lcstr == "higStat" ) + return higStat; + else if( lcstr == "lumiBlock" ) + return lumiBlock; + else if( lcstr == "eventsBlock" ) + return eventsBlock; + else if( lcstr == "file" ) + return file; + + if( Imp::s_svcLocator!=0 ) { + IMessageSvc* ms(0); + StatusCode sc = Imp::s_svcLocator->service( "MessageSvc", ms, true ); + if( sc.isSuccess() ) { + MsgStream log( ms, "ManagedMonitorToolBase::intervalStringToEnum()" ); + log << MSG::WARNING << "Unknown ManagedMonitorToolBase::Interval_t \"" + << str << "\", returning \"file\"" << endreq; + } + } + + return file; +} + + +StatusCode +ManagedMonitorToolBase:: +initialize() +{ + d->m_warnAboutMissingInitialize = false; + + StatusCode sc = AthAlgTool::initialize(); + if( !sc.isSuccess() ) + return StatusCode::FAILURE; + + ATH_MSG_DEBUG("ManagedMonitorToolBase::initialize():"); + + d->m_doResourceMon = msgLvl(AthMonBench::s_resourceMonThreshold); + + sc = m_THistSvc.retrieve(); + if( !sc.isSuccess() ) { + msg(MSG::ERROR) << "!! Unable to locate the THistSvc service !!" << endreq; + return sc; + } + ATH_MSG_DEBUG(" --> Found service \"THistSvc\""); + + if( !m_trigDecTool.empty() ) { + sc = m_trigDecTool.retrieve(); + if( !sc.isSuccess() ) { + msg(MSG::ERROR) << "!! Unable to retrieve the TrigDecisionTool !!" << endreq; + return sc; + } + ATH_MSG_DEBUG(" --> Found AlgTool \"TrigDecisionTool\""); + + if(m_triggerChainProp!="") { + ATH_MSG_DEBUG(" --> Found nonempty trigger chain list"); + sc=parseList(m_triggerChainProp, m_vTrigChainNames); + if(!sc.isSuccess()) { + msg(MSG::WARNING) << "Error parsing the trigger chain list, using empty list" << endreq; + m_vTrigChainNames.clear(); + } + } + else { + ATH_MSG_DEBUG(" --> trigger chain list empty"); + } + if(m_triggerGroupProp!="") { + ATH_MSG_DEBUG(" --> Found nonempty trigger group list"); + sc=parseList(m_triggerGroupProp, m_vTrigGroupNames); + if(!sc.isSuccess()) { + msg(MSG::WARNING) << "Error parsing the trigger group names list, using empty list" << endreq; + m_vTrigGroupNames.clear(); + } + } + else { + ATH_MSG_DEBUG(" --> trigger group list empty"); + } + } + else { + ATH_MSG_DEBUG(" --> no trigger decision tool specified"); + } + + sc = m_DQFilterTools.retrieve(); + if( !sc.isSuccess() ) { + ATH_MSG_ERROR("!! Unable to retrieve the Filter Tools !!"); + return sc; + } + + ServiceHandle<IJobOptionsSvc> joSvc( "JobOptionsSvc", name() ); + sc = joSvc.retrieve(); + if( !sc.isSuccess() ) { + msg(MSG::ERROR) << "!! Unable to locate the JobOptionsSvc service !!" << endreq; + return StatusCode::FAILURE; + } + ATH_MSG_DEBUG(" --> Found service \"JobOptionsSvc\""); + + std::string client( m_managerNameProp + "Properties" ); + ATH_MSG_DEBUG(" --> Asking for properties " << client); + sc = joSvc->setMyProperties( client, this ); + if( !sc.isSuccess() ) { + msg(MSG::ERROR) << "!! Unable to set properties in JobOptionsSvc !!" << endreq; + } + ATH_MSG_DEBUG(" --> Set Properties in \"JobOptionsSvc\""); + + ATH_MSG_DEBUG(" * Properties set from " << client << " to the values:\n" + << " FileKey: " << m_fileKey << "\n" + << " DataType: " << m_dataTypeStr << "\n" + << " Environment: " << m_environmentStr); + + m_dataType = AthenaMonManager::dataTypeStringToEnum( m_dataTypeStr ); + m_environment = AthenaMonManager::envStringToEnum( m_environmentStr ); + + if (m_useLumi) { + if (m_dataType == AthenaMonManager::monteCarlo) { + ATH_MSG_WARNING("Lumi use in monitoring enabled but tool configured for MC; disabling lumi tool use"); + } else { + // Get the luminosity tool + //CHECK(m_lumiTool.retrieve()); + StatusCode sc_lumiTool = m_lumiTool.retrieve(); + + // Get the livefration tool + //CHECK(m_liveTool.retrieve()); + StatusCode sc_liveTool = m_liveTool.retrieve(); + + // Set m_hasRetrievedLumiTool to true when both tools are retrieved successfully + if ( sc_lumiTool.isSuccess() && sc_liveTool.isSuccess() ) + m_hasRetrievedLumiTool = true; + } + } else { + ATH_MSG_DEBUG("!! Luminosity tool is disabled !!"); + } + + + delete m_streamNameFcn; + m_streamNameFcn = getNewStreamNameFcn(); + + ATH_MSG_DEBUG(" --> Exiting successfully"); + + return StatusCode::SUCCESS; +} + + +StatusCode +ManagedMonitorToolBase:: +bookHists() +{ + // The Run/LumiBlock numbers are not set when beginRun() is called. Therefore, + // book histograms on the first call to fillHists(), which is called from execute(). + return StatusCode::SUCCESS; +} + + +StatusCode +ManagedMonitorToolBase:: +fillHists() +{ + + if (d->m_warnAboutMissingInitialize) { + d->m_warnAboutMissingInitialize = false; + msg(MSG::WARNING) << "ManagedMonitorToolBase::initialize() never called from reimplementation!" << endreq; + } + + + bool isNewEventsBlock = ( m_procNEventsProp > 0 && ((m_nEvents % m_procNEventsProp) == 1) && m_haveClearedLastEventBlock ); + if (isNewEventsBlock) m_haveClearedLastEventBlock = false; + + newLowStat = false; + newLumiBlock = false; + newRun = false; + + newLowStatInterval = false; + newMedStatInterval = false; + newHigStatInterval = false; + + m_useTrigger = ( (m_triggerChainProp != "" || m_triggerGroupProp != "") && (!m_trigDecTool.empty()) ); + + if( m_manager != 0 ) { + newLumiBlock = ( m_lastLumiBlock != m_manager->lumiBlockNumber() ); + newRun = ( m_lastRun != m_manager->runNumber() ); + + if(newRun) { + newLumiBlock = true; + isNewEventsBlock = true; + } + + newEventsBlock = isNewEventsBlock; + + if( newLumiBlock ) { + // check if a new LB interval has started + // lowest lumiBlockNumber() is 1 + // m_lastLowStatInterval is -1 initially + int currentLB = m_manager->lumiBlockNumber(); + int LBsLowStat = m_manager->getLBsLowStat(); + int LBsMedStat = m_manager->getLBsMedStat(); + int LBsHigStat = m_manager->getLBsHigStat(); + + if( LBsLowStat*LBsMedStat*LBsHigStat == 0) { + msg(MSG::WARNING) << "zero LBs requested for interval" << endreq; + } + else { + if( ((currentLB-1)/LBsLowStat) != m_lastLowStatInterval ) newLowStatInterval = true; + if( ((currentLB-1)/LBsMedStat) != m_lastMedStatInterval ) newMedStatInterval = true; + if( ((currentLB-1)/LBsHigStat) != m_lastHigStatInterval ) newHigStatInterval = true; + } + } + + // Allow inheriting classes the option of using the lastLumiBloc/lastRun values + // before updating them + } + + + StatusCode sc0( StatusCode::SUCCESS ); + sc0.setChecked(); + StatusCode sc1( StatusCode::SUCCESS ); + sc1.setChecked(); + StatusCode sc2( StatusCode::SUCCESS ); + sc2.setChecked(); + StatusCode sc3( StatusCode::SUCCESS ); + sc3.setChecked(); + + // Set end of LowStat, LumiBlock and Run variables + // These are needed to be used in procHistograms(). + endOfEventsBlock = newEventsBlock; + endOfLowStat = newLowStatInterval; + endOfLumiBlock = newLumiBlock; + endOfRun = newRun; + + // just duplicates newLowStatInterval + newLowStat = newLowStatInterval; + + if( newEventsBlock || newLumiBlock || newRun ) { + + // Process histograms from the previous lumiBlock/run + if( m_nEvents != 1 ) { + d->benchPreProcHistograms(); + sc0 = procHistograms(); + d->benchPostProcHistograms(); + sc0.setChecked(); + } + // Re-book new histograms + d->benchPreBookHistograms(); + + if (!m_bookHistogramsInitial) { + sc1 = bookHistograms(); + m_bookHistogramsInitial = true; + } else { + std::vector<Interval_t> intervals_to_process; + if (newEventsBlock) intervals_to_process.push_back(eventsBlock); + if (newLumiBlock) intervals_to_process.push_back(lumiBlock); + if (newLowStatInterval) intervals_to_process.push_back(lowStat); + if (newRun) intervals_to_process.push_back(run); + for (const auto interval: intervals_to_process) { + sc1 = regManagedHistograms(m_templateHistograms[interval]); + sc1 = regManagedGraphs(m_templateGraphs[interval]); + sc1 = regManagedTrees(m_templateTrees[interval]); + sc1 = regManagedLWHistograms(m_templateLWHistograms[interval], true); + } + } + + sc3 = bookHistogramsRecurrent( ); + + d->benchPostBookHistograms(); + sc1.setChecked(); + sc3.setChecked(); + } + + // check filters + bool filterresult(true); + if (! m_DQFilterTools.empty()) { + ToolHandleArray<IDQFilterTool>::const_iterator ifilter(m_DQFilterTools.begin()), filterend(m_DQFilterTools.end()); + for (; filterresult && (ifilter != filterend); + ++ifilter) { + filterresult = (filterresult && (*ifilter)->accept()); + } + } + + + // ...and fill as normal + if(filterresult && + (!m_useTrigger + || (m_vTrigChainNames.size()>0 && trigChainsArePassed(m_vTrigChainNames)) + || (m_vTrigGroupNames.size()>0 && trigChainsArePassed(m_vTrigGroupNames))) ) { + d->benchPreFillHistograms(); + StatusCode sc3 = fillHistograms(); + m_haveClearedLastEventBlock = true; + d->benchPostFillHistograms(); + sc3.setChecked(); + ++m_nEvents; + } + + ++m_nEventsIgnoreTrigger; + if( newLumiBlock && (m_nEventsIgnoreTrigger != 1) ) { + ++m_nLumiBlocks; + } + if( m_manager != 0 ) { + m_lastRun = m_manager->runNumber(); + if( newLumiBlock ) { + m_lastLumiBlock = m_manager->lumiBlockNumber(); + + int LBsLowStat = m_manager->getLBsLowStat(); + int LBsMedStat = m_manager->getLBsMedStat(); + int LBsHigStat = m_manager->getLBsHigStat(); + if( LBsLowStat*LBsMedStat*LBsHigStat > 0) { + if( newLowStatInterval ) m_lastLowStatInterval = (m_lastLumiBlock-1)/LBsLowStat; + if( newMedStatInterval ) m_lastMedStatInterval = (m_lastLumiBlock-1)/LBsMedStat; + if( newHigStatInterval ) m_lastHigStatInterval = (m_lastLumiBlock-1)/LBsHigStat; + } + } + } + + return StatusCode::SUCCESS; +} + +StatusCode +ManagedMonitorToolBase:: +registerMetadata(const std::string& streamName, const std::string& hName, + const MonGroup& group) { + if( m_environment != AthenaMonManager::online ) { + TTree* metadata(0); + std::string mdStreamName( streamName ); + size_t found=mdStreamName.rfind("/"); + + if ( found != std::string::npos ) + mdStreamName.replace( found, mdStreamName.length(), "/metadata" ); + + MDMap_t::iterator i = m_metadataMap.find( mdStreamName ); + if( i == m_metadataMap.end() ) { + metadata = new TTree( "metadata", "Monitoring Metadata" ); + if (! metadata) return StatusCode::FAILURE; + StatusCode scmd = m_THistSvc->regTree( mdStreamName, metadata ); + if (scmd == StatusCode::FAILURE) return StatusCode::FAILURE; + MDMap_t::value_type valToInsert( mdStreamName, new OutputMetadata(metadata) ); + i = m_metadataMap.insert( valToInsert ).first; + } + + i->second->fill( hName, group.interval(), group.chain(), group.merge() ); + } + return StatusCode::SUCCESS; +} + +StatusCode +ManagedMonitorToolBase:: +regManagedHistograms(std::vector< MgmtParams<TH1> >& m_templateHistograms) +{ + // The method registers histograms with the THistSvc and saves them to file. + + // The funky business with registering and deregistering the histogram is needed + // to get the correct directory when saving histograms. THistSvc deals with ROOT + // to set up proper TDirectory, so we rely on it. + // E.g. + // m_THistSvc->regHist( streamName, h ): sets the correct TDirectory with streamName + // m_THistSvc->deReg( h ) - deregister from THistSvc otherwise THistSvc will try to save it + // at the end of execution + // use passownership of the histogram and save it to file + // m_manager->passOwnership( h, genericName ); + // m_manager->writeAndDelete( genericName ); + bool allIsOk = true; + + for( std::vector< MgmtParams<TH1> >::iterator it = m_templateHistograms.begin(); it != m_templateHistograms.end(); ++it ) { + MonGroup group = (*it).m_group; + + // Get a handle to the histogram + TH1* theHist = (*it).m_templateHist; + + // Clone the histogram + TH1* h = static_cast<TH1*>(theHist->Clone()); + theHist->Reset(); + + // Get name + std::string hName = h->GetName(); + + // Get the streamName for the previous interval + std::string streamName = streamNameFunction()->getStreamName( this, group, hName, true ); + + // Register the histogram with the THistSvc + StatusCode sc1 = m_THistSvc->deReg( theHist ); + if (sc1 == StatusCode::FAILURE) allIsOk = false; + + // Register clonned histogram under previous interval streamName + StatusCode sc2 = m_THistSvc->regHist( streamName, h ); + if (sc2 == StatusCode::FAILURE) allIsOk = false; + + if( m_manager != 0 ) { + std::string genericName = NoOutputStream().getStreamName( this, group, hName ); + m_manager->passOwnership( h, genericName ); + m_manager->writeAndDelete( genericName ); + } + + // Get streamName for the current interval + streamName = streamNameFunction()->getStreamName( this, group, hName, false ); + // Register metadata information with the current interval streamname + StatusCode smd = registerMetadata(streamName, hName, group); + if (smd != StatusCode::SUCCESS) allIsOk = false; + + // Re-register the original histogram with the current interval streamName + StatusCode sc3 = m_THistSvc->regHist( streamName, theHist ); + if (sc3 == StatusCode::FAILURE) allIsOk = false; + + } + + if (!allIsOk) return StatusCode::FAILURE; + + return StatusCode::SUCCESS; +} + +StatusCode +ManagedMonitorToolBase:: +THistSvc_deReg_fixTGraph( TFile* file, TGraph* theGraph, std::string& directoryName) +{ + // THistSvc employs TDirectory Append method when registering TGraph. + // When deReg is used to de-register TGraph object, THistSvc only removes the object + // from its internal management but forgets to delete from TDirectory. + // The current method fixes this problem by removing the TGraph object manually + // after THistSvc->deReg(TGraph* obj) is called. + + // Saves and restor gFile and gDirectory + GlobalDirectoryRestore restore; + + // This check is true when TGraph object is removed successfully + bool graphRemoved = false; + + // If no file, use gROOT instead + if (file != 0) { + file->cd("/"); + } else { + ATH_MSG_DEBUG("THistSvc_deReg_fixTGraph: could not recover the output file. Using gROOT as TDirectory!"); + gROOT->cd(); + } + + TDirectory* dir = file->GetDirectory(directoryName.c_str()); + if (dir != 0) { + dir->cd(); + TObject* obj = dir->Remove(theGraph); + if (obj != 0) + graphRemoved = true; + } + + if (!graphRemoved) { + return StatusCode::FAILURE; + } + + return StatusCode::SUCCESS; +} + +StatusCode +ManagedMonitorToolBase:: +regManagedGraphs(std::vector< MgmtParams<TGraph> >& m_templateGraphs) +{ + // See the description for the regManagedHistograms method + bool allIsOk = true; + + for( std::vector< MgmtParams<TGraph> >::iterator it = m_templateGraphs.begin(); it != m_templateGraphs.end(); ++it ) { + MonGroup group = (*it).m_group; + + // Get a handle to the graph + TGraph* theGraph = (*it).m_templateHist; + + // Clone the graph + TGraph* g = static_cast<TGraph*>(theGraph->Clone()); + theGraph->Set(0); // equivalent to Reset() for TH1 + + // Get name + std::string gName = g->GetName(); + + // Get the streamName for the previous interval + std::string streamName = streamNameFunction()->getStreamName( this, group, gName, true ); + + // De-register the original graph with the THistSvc + StatusCode sc1 = m_THistSvc->deReg( theGraph ); + if (sc1 == StatusCode::FAILURE) + allIsOk = false; + + // *** begin *** + // Fix THistSvc->deReg for TGraphs + bool doneCleaning = false; + std::string directoryName = streamNameFunction()->getDirectoryName( this, group, gName, true ); + TSeqCollection *filelist=gROOT->GetListOfFiles(); + for (int i=0; i<filelist->GetEntries(); i++) { + ATH_MSG_DEBUG( "List of files: " << filelist->At(i)->GetName()); + TFile* file = static_cast<TFile*>(filelist->At(i)); + StatusCode sc2 = THistSvc_deReg_fixTGraph(file, theGraph, directoryName); + if (sc2 == StatusCode::SUCCESS) + doneCleaning = true; + } + + // Check if TGraph fix has been applied successfully + if (!doneCleaning) { + ATH_MSG_ERROR("THistSvc_deReg_fixTGraph: failed to apply TGraph fix for the THist Svc!"); + allIsOk = false; + } + // *** end *** + + // Register clonned histogram under previous interval streamName + StatusCode sc3 = m_THistSvc->regGraph( streamName, g ); + if (sc3 == StatusCode::FAILURE) + allIsOk = false; + + // Get streamName for the current interval + streamName = streamNameFunction()->getStreamName( this, group, gName, false ); + // Register metadata information with the current interval streamname + StatusCode smd = registerMetadata(streamName, gName, group); + if (smd != StatusCode::SUCCESS) + allIsOk = false; + + // Re-register the original graph with the current interval streamName + StatusCode sc4 = m_THistSvc->regGraph( streamName, theGraph ); + if (sc4 == StatusCode::FAILURE) + allIsOk = false; + + } + + if (!allIsOk) return StatusCode::FAILURE; + + return StatusCode::SUCCESS; +} + +StatusCode +ManagedMonitorToolBase:: +regManagedTrees(std::vector< MgmtParams<TTree> >& m_templateTrees) +{ + // See the description for the regManagedHistograms method + bool allIsOk = true; + + for( std::vector< MgmtParams<TTree> >::iterator it = m_templateTrees.begin(); it != m_templateTrees.end(); ++it ) { + MonGroup group = (*it).m_group; + + // Get a handle to the original tree + TTree* theTree = (*it).m_templateHist; + + // Clone the tree + TTree* t = static_cast<TTree*>(theTree->Clone()); + theTree->Reset(); + + // Dumping the tree + std::string name = t->GetName(); + + // Get the streamName for the previous interval + std::string streamName = streamNameFunction()->getStreamName( this, group, name, true ); + + // De-register original tree with the THistSvc + StatusCode sc1 = m_THistSvc->deReg( theTree ); + if (sc1 == StatusCode::FAILURE) allIsOk = false; + + // Register clonned tree under previous interval streamName + StatusCode sc2 = m_THistSvc->regTree( streamName, t ); + if (sc2 == StatusCode::FAILURE) allIsOk = false; + + if( m_manager != 0 ) { + std::string genericName = NoOutputStream().getStreamName( this, group, name ); + m_manager->passOwnership( t, genericName ); + m_manager->writeAndDelete( genericName ); + } + + // Get streamName for the current interval + streamName = streamNameFunction()->getStreamName( this, group, name, false ); + // Register metadata information with the current interval streamname + StatusCode smd = registerMetadata(streamName, name, group); + if (smd != StatusCode::SUCCESS) allIsOk = false; + + // Re-register the original graph with the current interval streamName + StatusCode sc3 = m_THistSvc->regTree( streamName, theTree ); + if (sc3 == StatusCode::FAILURE) allIsOk = false; + + } + + if (!allIsOk) return StatusCode::FAILURE; + + return StatusCode::SUCCESS; +} + +StatusCode +ManagedMonitorToolBase:: +regManagedLWHistograms(std::vector<MgmtParams<LWHist> >& m_templateLWHistograms, bool usePreviousInterval, bool doDelete) +{ + bool allIsOk = true; + StatusCode sc1; + sc1.setChecked(); + + for( std::vector< MgmtParams<LWHist> >::iterator it = m_templateLWHistograms.begin(); it != m_templateLWHistograms.end(); ++it ) { + MonGroup group = (*it).m_group; + + // Get handle to the histogram + LWHist* h = (*it).m_templateHist; + + std::string hName = h->GetName(); + + std::string streamName = streamNameFunction()->getStreamName( this, group, hName, usePreviousInterval ); + LWHistAthMonWrapper::setStreamName(h,streamName); + + StatusCode smd = registerMetadata(streamName, hName, group); + if (smd != StatusCode::SUCCESS) allIsOk = false; + + //Only register with THistSvc if root backend, otherwise AthMonManager + //will do it for us + if (h->usingROOTBackend()) { + h->setOwnsROOTHisto(false);//Since might end up with thist svc + return m_THistSvc->regHist( streamName, h->getROOTHistBase() ); + } + + if( m_manager ) { + std::string genericName = NoOutputStream().getStreamName( this, group, hName ); + LWHistAthMonWrapper::setKey(h,genericName); + m_manager->passOwnership( h, genericName ); + ATH_MSG_DEBUG("!! LWHist: hName == " << hName); + ATH_MSG_DEBUG("!! LWHist: genericName == " << genericName); + ATH_MSG_DEBUG("!! LWHist: streamName == " << LWHistAthMonWrapper::streamName(h)); + m_manager->writeAndDeleteLWHist( genericName, LWHistAthMonWrapper::streamName(h), doDelete ); + if (! doDelete) h->Reset(); + // m_lwhists.erase(it); + } + } + + if (!allIsOk) return StatusCode::FAILURE; + + return StatusCode::SUCCESS; +} + +StatusCode +ManagedMonitorToolBase:: +finalHists() +{ + + // This assumes that the end of a file will naturally end a run, which is not always true. + // A merging application run afterwards should be able to put parts of a run together. + if( m_nEvents != 1 ) { + d->benchPreProcHistograms(); + + // Set end flags for the LowStat, LumiBlock and Run variables. + // This is needed to be used in the procHistograms method below. + endOfEventsBlock = true; + endOfLowStat = true; + endOfLumiBlock = true; + endOfRun = true; + + StatusCode sc = procHistograms(); + + StatusCode sc1( StatusCode::SUCCESS ); + sc1.setChecked(); + + for (const auto interval: m_supportedIntervalsForRebooking) { + //sc1 = regManagedHistograms(m_templateHistograms[interval], false); + //sc1 = regManagedGraphs(m_templateGraphs[interval], false); + //sc1 = regManagedTrees(m_templateTrees[interval], false); + sc1 = regManagedLWHistograms(m_templateLWHistograms[interval], false, true); + sc1.setChecked(); + } + + d->benchPostProcHistograms(); + return sc; + } + return StatusCode::SUCCESS; +} + + +StatusCode +ManagedMonitorToolBase:: +convertLWHists() +{ + // note that managed histograms will be converted by regMonitoredLWHistograms + // hence they are not in m_lwhists + if (m_manager) { + std::set<LWHist*>::iterator it(m_lwhists.begin()),itE(m_lwhists.end()); + for (;it!=itE;++it) + m_manager->writeAndDeleteLWHist( *it ); + m_lwhists.clear(); + } + return StatusCode::SUCCESS; + +} + + +StatusCode +ManagedMonitorToolBase:: +bookHistogramsRecurrent( ) +{ + if( newEventsBlock ) { } + if( newLumiBlock ) { } + if( newRun ) { } + + return StatusCode::SUCCESS; +} + + +StatusCode +ManagedMonitorToolBase:: +bookHistograms( ) +{ + + return StatusCode::SUCCESS; +} + +StatusCode +ManagedMonitorToolBase:: +fillHistograms() +{ + return StatusCode::SUCCESS; +} + + +StatusCode +ManagedMonitorToolBase:: +procHistograms( ) +{ + if( endOfEventsBlock ) { } + if( endOfLowStat ) { } + if( endOfLumiBlock ) { } + if( endOfRun) { } + + return StatusCode::SUCCESS; +} + + +void +ManagedMonitorToolBase:: +setMonManager( AthenaMonManager* manager ) +{ + ATH_MSG_DEBUG( "ManagedMonitorToolBase::setMonManager():"); + m_manager = manager; + if( m_manager != 0 ) { + ATH_MSG_DEBUG( " --> Setting manager"); + m_managerNameProp = m_manager->name(); + m_fileKey = m_manager->fileKey(); + m_dataType = m_manager->dataType(); + m_environment = m_manager->environment(); + delete m_streamNameFcn; + m_streamNameFcn = getNewStreamNameFcn(); + } + ATH_MSG_DEBUG( " --> Exiting successfully"); +} + +StatusCode +ManagedMonitorToolBase:: +regHist( TH1* h, const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt, const std::string& chain, const std::string& merge ) +{ + MonGroup group( this, system, interval, histo_mgmt, chain, merge ); + return regHist( h, group ); +} + +StatusCode +ManagedMonitorToolBase:: +regHist( TH1* h, const MonGroup& group ) +{ +// ManagedMonitorToolBase_addHistStatistics(this,h); + + if (!h) + return StatusCode::FAILURE; + + // This part of the code deals with MANAGED type + if ( (group.histo_mgmt() & ATTRIB_UNMANAGED) == 0 ) { + /* + Create an unmanaged group based on the original MonGroup instance passed + It is needed because managed histogram is presented as a number of unmanaged + histograms (one per each interval) + */ + MonGroup group_unmanaged( this, group.system(), group.interval(), ATTRIB_UNMANAGED, group.chain(), group.merge()); + + if (m_supportedIntervalsForRebooking.count(group.interval())) { + m_templateHistograms[group.interval()].push_back( MgmtParams<TH1>(h, group_unmanaged) ); + } else { + ATH_MSG_ERROR("Attempt to book managed histogram " << h->GetName() << " with invalid interval type " << intervalEnumToString(group.interval())); + return StatusCode::FAILURE; + } + + std::string hName = h->GetName(); + std::string streamName = streamNameFunction()->getStreamName( this, group_unmanaged, hName, false ); + StatusCode smd = registerMetadata(streamName, hName, group); + smd.setChecked(); + return m_THistSvc->regHist( streamName, h ); + } + + + // This part of the code deals with UNMANAGED type + std::string hName = h->GetName(); + + if( m_manager != 0 ) { + std::string genericName = NoOutputStream().getStreamName( this, group, hName ); + m_manager->writeAndDelete( genericName ); + m_manager->passOwnership( h, genericName ); + } + + std::string streamName = streamNameFunction()->getStreamName( this, group, hName, false ); + + StatusCode smd = registerMetadata(streamName, hName, group); + if (smd != StatusCode::SUCCESS) return StatusCode::FAILURE; + + return m_THistSvc->regHist( streamName, h ); +} + +StatusCode ManagedMonitorToolBase::regHist( LWHist* h,const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt, const std::string& chain, const std::string& merge ) +{ + MonGroup group( this, system, interval, histo_mgmt, chain, merge ); + return regHist( h, group ); +} + +StatusCode ManagedMonitorToolBase::regHist( LWHist* h, const MonGroup& group ) +{ + if (!h) + return StatusCode::FAILURE; + + if ( (group.histo_mgmt() & ATTRIB_UNMANAGED) == 0 ) { + // Create an unmanaged group based on the original MonGroup instance passed + // This is needed because managed histogram is presented as a number of unmanaged + // histograms (one per each interval) + MonGroup group_unmanaged( this, group.system(), group.interval(), ATTRIB_UNMANAGED, group.chain(), group.merge()); + + if (m_supportedIntervalsForRebooking.count(group.interval())) { + m_templateLWHistograms[group.interval()].push_back( MgmtParams<LWHist>(h, group_unmanaged) ); + } else { + ATH_MSG_ERROR("Attempt to book managed histogram " << h->GetName() << " with invalid interval type " << intervalEnumToString(group.interval())); + return StatusCode::FAILURE; + } + return StatusCode::SUCCESS; + } + + //FIXME: Code copied more or less verbatim from above. Collect most code (espc. for streamname) in common helpers!! + std::string hName = h->GetName(); + + if( m_manager ) { + std::string genericName = NoOutputStream().getStreamName( this, group, hName ); + LWHistAthMonWrapper::setKey(h,genericName); + LWHist* prevLWHist = m_manager->ownedLWHistOfKey(genericName); + if (prevLWHist) { + std::set<LWHist*>::iterator it = m_lwhists.find(prevLWHist); + if (it!=m_lwhists.end()) { + m_manager->writeAndDeleteLWHist( genericName, LWHistAthMonWrapper::streamName(prevLWHist) ); + m_lwhists.erase(it); + } + } + m_manager->passOwnership( h, genericName ); + } + + std::string streamName = streamNameFunction()->getStreamName( this, group, hName ); + LWHistAthMonWrapper::setStreamName(h,streamName); + + StatusCode smd = registerMetadata(streamName, hName, group); + if (smd != StatusCode::SUCCESS) return StatusCode::FAILURE; + + //Delay registration with THistSvc (unless root backend): + // m_lwhistMap.insert(std::pair<LWHist*,std::string>(h,streamName)); + m_lwhists.insert(h); + if (h->usingROOTBackend()) { + h->setOwnsROOTHisto(false);//Since might end up with thist svc + return m_THistSvc->regHist( streamName, h->getROOTHistBase() ); + } + + return StatusCode::SUCCESS; + +} + +StatusCode +ManagedMonitorToolBase:: +getHist( TH1*& h, const std::string& hName, const std::string& system, + Interval_t interval ) +{ + MonGroup group( this, system, interval ); + return getHist( h, hName, group ); +} + + +StatusCode +ManagedMonitorToolBase:: +getHist( TH1*& h, const std::string& hName, const MonGroup& group ) +{ + std::string streamName = streamNameFunction()->getStreamName( this, group, hName ); + return m_THistSvc->getHist( streamName, h ); +} + + +StatusCode ManagedMonitorToolBase::getHist( LWHist*& h, const std::string& hName, const std::string& system, + Interval_t interval ) +{ + MonGroup group( this, system, interval ); + return getHist( h, hName, group ); +} + + +StatusCode ManagedMonitorToolBase::getHist( LWHist*& h, const std::string& hName, const MonGroup& group ) +{ + h = 0; + std::string streamName = streamNameFunction()->getStreamName( this, group, hName ); + std::set<LWHist*>::iterator it(m_lwhists.begin()),itE(m_lwhists.end()); + for (;it!=itE;++it) { + if (LWHistAthMonWrapper::streamName(*it)==streamName) { + h = *it; + return StatusCode::SUCCESS; + } + } + return StatusCode::FAILURE; +} + + +StatusCode +ManagedMonitorToolBase:: +getHist( TH2*& h, const std::string& hName, const std::string& system, + Interval_t interval ) +{ + MonGroup group( this, system, interval ); + return getHist( h, hName, group ); +} + + +StatusCode +ManagedMonitorToolBase:: +getHist( TH2*& h, const std::string& hName, const MonGroup& group ) +{ + std::string streamName = streamNameFunction()->getStreamName( this, group, hName ); + return m_THistSvc->getHist( streamName, h ); +} + + +StatusCode +ManagedMonitorToolBase:: +regGraph( TGraph* g, const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt, const std::string& chain, const std::string& merge ) +{ + MonGroup group( this, system, interval, histo_mgmt, chain, merge ); + return regGraph( g, group ); +} + + +StatusCode +ManagedMonitorToolBase:: +regGraph( TGraph* g, const MonGroup& group ) +{ + if (!g) + return StatusCode::FAILURE; + + // This part of the code deals with MANAGED type + if ( (group.histo_mgmt() & ATTRIB_UNMANAGED) == 0 ) { + // Create an unmanaged group based on the original MonGroup instance passed + // This is needed because managed graph is presented as a number of unmanaged + // graphs (one per each interval) + MonGroup group_unmanaged( this, group.system(), group.interval(), ATTRIB_UNMANAGED, group.chain(), group.merge()); + + if (m_supportedIntervalsForRebooking.count(group.interval())) { + m_templateGraphs[group.interval()].push_back( MgmtParams<TGraph>(g, group_unmanaged) ); + } else { + ATH_MSG_ERROR("Attempt to book managed graph " << g->GetName() << " with invalid interval type " << intervalEnumToString(group.interval())); + return StatusCode::FAILURE; + } + + std::string name = g->GetName(); + std::string streamName = streamNameFunction()->getStreamName( this, group_unmanaged, name, false ); + StatusCode smd = registerMetadata(streamName, name, group); + smd.setChecked(); + return m_THistSvc->regGraph( streamName, g ); + //return m_THistSvc->regGraph( streamName ); + } + + // This part of the code deals with UNMANAGED type + std::string gName = g->GetName(); + + if( m_manager != 0 ) { + std::string genericName = NoOutputStream().getStreamName( this, group, gName ); + m_manager->writeAndDelete( genericName ); + m_manager->passOwnership( g, genericName ); + } + + std::string streamName = streamNameFunction()->getStreamName( this, group, gName, false ); + + StatusCode smd = registerMetadata(streamName, gName, group); + if (smd != StatusCode::SUCCESS) return StatusCode::FAILURE; + + return m_THistSvc->regGraph( streamName, g ); +} + + +StatusCode +ManagedMonitorToolBase:: +regTree( TTree* t, const std::string& system, + Interval_t interval, MgmtAttr_t histo_mgmt, const std::string& chain, const std::string& merge ) +{ + MonGroup group( this, system, interval, histo_mgmt, chain, merge ); + return regTree( t, group ); +} + + +StatusCode +ManagedMonitorToolBase:: +regTree( TTree* t, const MonGroup& group ) +{ + + // This part of the code deals with MANAGED type + if ( (group.histo_mgmt() & ATTRIB_UNMANAGED) == 0 ) { + // Create an unmanaged group based on the original MonGroup instance passed + // This is needed because managed tree is presented as a number of unmanaged + // trees (one per each interval) + MonGroup group_unmanaged( this, group.system(), group.interval(), ATTRIB_UNMANAGED, group.chain(), group.merge()); + + if (m_supportedIntervalsForRebooking.count(group.interval())) { + m_templateTrees[group.interval()].push_back( MgmtParams<TTree>(t, group_unmanaged) ); + } else { + ATH_MSG_ERROR("Attempt to book managed tree " << t->GetName() << " with invalid interval type " << intervalEnumToString(group.interval())); + return StatusCode::FAILURE; + } + + std::string name = t->GetName(); + std::string genericName = NoOutputStream().getStreamName( this, group_unmanaged, name ); + std::string streamName = streamNameFunction()->getStreamName( this, group_unmanaged, name, false ); + StatusCode smd = registerMetadata(streamName, name, group); + smd.setChecked(); + return m_THistSvc->regTree( streamName, t ); + } + + + // This part of the code deals with UNMANAGED type + std::string tName = t->GetName(); + + if( m_manager != 0 ) { + std::string genericName = NoOutputStream().getStreamName( this, group, tName ); + m_manager->writeAndDelete( genericName ); + m_manager->passOwnership( t, genericName ); + } + + std::string streamName = streamNameFunction()->getStreamName( this, group, tName, false ); + + StatusCode smd = registerMetadata(streamName, tName, group); + if (smd != StatusCode::SUCCESS) return StatusCode::FAILURE; + + return m_THistSvc->regTree( streamName, t ); +} + + +StatusCode +ManagedMonitorToolBase:: +writeAndDelete( TH1* h, const MonGroup& group ) { + if (!h) + return StatusCode::FAILURE; + + std::string hName = h->GetName(); + + if( m_manager != 0 ) { + std::string genericName = NoOutputStream().getStreamName( this, group, hName ); + m_manager->writeAndDelete( genericName ); + } + return StatusCode::SUCCESS; +} + + +StatusCode +ManagedMonitorToolBase:: +deregHist( TH1* h ) +{ + return m_THistSvc->deReg( h ); +} + + +StatusCode ManagedMonitorToolBase::deregHist( LWHist* h ) +{ + std::set<LWHist*>::iterator it = m_lwhists.find(h); + if (it==m_lwhists.end()) + return StatusCode::FAILURE; + LWHistAthMonWrapper:: removeCustomData(h); + m_lwhists.erase(it); + if (h->usingROOTBackend()) { + h->setOwnsROOTHisto(true); + return m_THistSvc->deReg( h->getROOTHistBase() ); + } + + return StatusCode::SUCCESS; +} + + +StatusCode +ManagedMonitorToolBase:: +deregGraph( TGraph* g ) +{ + return m_THistSvc->deReg( g ); +} + + +StatusCode +ManagedMonitorToolBase:: +deregObject( const std::string& objName, const std::string& system, + Interval_t interval ) +{ + MonGroup group( this, system, interval ); + return deregObject( objName, group ); +} + + +StatusCode +ManagedMonitorToolBase:: +deregObject( const std::string& objName, const MonGroup& group ) +{ + std::string streamName = streamNameFunction()->getStreamName( this, group, objName ); + std::set<LWHist*>::iterator it(m_lwhists.begin()),itE(m_lwhists.end()); + for (;it!=itE;++it) { + LWHist * hlw = *it; + if (LWHistAthMonWrapper::key(hlw)==objName) { + m_lwhists.erase(it); + if (hlw->usingROOTBackend()) { + hlw->setOwnsROOTHisto(true); + return m_THistSvc->deReg( hlw->getROOTHistBase() ); + } + return StatusCode::SUCCESS; + } + } + return m_THistSvc->deReg( streamName ); +} + + +StatusCode +ManagedMonitorToolBase:: +setupOutputStreams( std::vector<std::string> ) +{ + // All instances should write to the stream(s) defined by the + // AthenaMonManager. + + return StatusCode::SUCCESS; +} + + +StatusCode +ManagedMonitorToolBase:: +runStat() +{ + return StatusCode::SUCCESS; +} + + +StatusCode +ManagedMonitorToolBase:: +checkHists( bool ) +{ + // Histograms will be checked using the data-quality monitoring framework (DQMF) + + return StatusCode::SUCCESS; +} + + +bool +ManagedMonitorToolBase:: +preSelector() +{ + if( m_preScaleProp > 1 ) { + return ( (m_nEvents % m_preScaleProp) == 1 ); + } + return true; +} + + +// Average mu, i.e. <mu> +float +ManagedMonitorToolBase:: +lbAverageInteractionsPerCrossing() +{ + if ( m_hasRetrievedLumiTool ) { + return m_lumiTool->lbAverageInteractionsPerCrossing(); + } else { + ATH_MSG_FATAL("! Luminosity tool has been disabled ! lbAverageInteractionsPerCrossing() can't work properly! "); + } + return -0.0; +} + +// Instantaneous number of interactions, i.e. mu +float +ManagedMonitorToolBase:: +lbInteractionsPerCrossing() +{ + if ( m_hasRetrievedLumiTool ) { + float instmu = 0.; + + if (m_lumiTool->muToLumi() > 0.) + instmu = m_lumiTool->lbLuminosityPerBCID()/m_lumiTool->muToLumi(); + + return instmu; + } else { + ATH_MSG_FATAL("! Luminosity tool has been disabled ! lbInteractionsPerCrossing() can't work properly! "); + } + return -0.0; +} + +// Average luminosity (in ub-1 s-1 => 10^30 cm-2 s-1) +float +ManagedMonitorToolBase:: +lbAverageLuminosity() +{ + if ( m_hasRetrievedLumiTool ) { + return m_lumiTool->lbAverageLuminosity(); + } else { + ATH_MSG_FATAL("! Luminosity tool has been disabled ! lbAverageLuminosity() can't work properly! "); + } + return -0.0; +} + +// Instantaneous luminosity +float +ManagedMonitorToolBase:: +lbLuminosityPerBCID() +{ + if ( m_hasRetrievedLumiTool ) { + return m_lumiTool->lbLuminosityPerBCID(); + } else { + ATH_MSG_FATAL("! Luminosity tool has been disabled ! lbLuminosityPerBCID() can't work properly! "); + } + return -0.0; +} + + +// Average luminosity livefraction +float +ManagedMonitorToolBase:: +lbAverageLivefraction() +{ + if (m_environment == AthenaMonManager::online) + return 1.0; + + if ( m_hasRetrievedLumiTool ) { + return m_liveTool->lbAverageLivefraction(); + } else { + ATH_MSG_FATAL("! Luminosity tool has been disabled ! lbAverageLivefraction() can't work properly! "); + } + return -0.0; +} + +// Live Fraction per Bunch Crossing ID +float +ManagedMonitorToolBase:: +livefractionPerBCID() +{ + if (m_environment == AthenaMonManager::online) + return 1.0; + + if ( m_hasRetrievedLumiTool ) { + return m_liveTool->livefractionPerBCID(); + } else { + ATH_MSG_FATAL("! Luminosity tool has been disabled ! livefractionPerBCID() can't work properly! "); + } + return -0.0; +} + +// Average Integrated Luminosity Live Fraction +double +ManagedMonitorToolBase:: +lbLumiWeight() +{ + if ( m_hasRetrievedLumiTool ) { + return (lbAverageLuminosity()*lbDuration())*lbAverageLivefraction(); + } else{ + ATH_MSG_FATAL("! Luminosity tool has been disabled ! lbLumiWeight() can't work properly! "); + } + return -0.0; +} + + +// Luminosity block time (in seconds) +double +ManagedMonitorToolBase:: +lbDuration() +{ + if ( m_hasRetrievedLumiTool ) { + return m_lumiTool->lbDuration(); + } else { + ATH_MSG_FATAL("! Luminosity tool has been disabled ! lbDuration() can't work properly! "); + } + return -0.0; +} + + +// ********************************************************************* +// Protected Methods +// ********************************************************************* + +ManagedMonitorToolBase::OutputMetadata:: + OutputMetadata( TTree* metadata ) + : charArrSize(100) + , m_metadata(metadata) + , m_nameData(0) + //, m_levelData(0) + , m_intervalData(0) + , m_triggerData(0) + , m_mergeData(0) +{ + m_nameData = new char[charArrSize]; + //m_levelData = new char[charArrSize]; + m_intervalData = new char[charArrSize]; + m_triggerData = new char[charArrSize]; + m_mergeData = new char[charArrSize]; + m_metadata->Branch( "Name", m_nameData, "Name/C" ); + //m_metadata->Branch( "LevelOfDetail", m_levelData, "LevelOfDetail/C" ); + m_metadata->Branch( "Interval", m_intervalData, "Interval/C" ); + m_metadata->Branch( "TriggerChain", m_triggerData, "TriggerChain/C" ); + m_metadata->Branch( "MergeMethod", m_mergeData, "MergeMethod/C" ); +} + + +ManagedMonitorToolBase::OutputMetadata:: +~OutputMetadata() +{ + delete [] m_mergeData; + delete [] m_triggerData; + delete [] m_intervalData; + //delete [] m_levelData; + delete [] m_nameData; +} + + +void +ManagedMonitorToolBase::OutputMetadata:: +fill( const std::string& name, + //LevelOfDetail_t level, + Interval_t interval, + std::string trigger, + std::string merge ) +{ + // ROOT does not properly write empty strings to output files in all cases. I haven't reported + // this to the ROOT developers yet because I don't have time to develope a simple test case + // for them (independent of Atlas software). + // --M.G.Wilson, 7 July 2008 + if( trigger == "" ) + trigger = "<none>"; + if( merge == "" ) + merge = "<default>"; + + copyString( m_nameData, name ); + //copyString( m_levelData, ManagedMonitorToolBase::levelOfDetailEnumToString( level ) ); + copyString( m_intervalData, ManagedMonitorToolBase::intervalEnumToString( interval ) ); + copyString( m_triggerData, trigger ); + copyString( m_mergeData, merge ); + m_metadata->Fill(); +} + + +void +ManagedMonitorToolBase::OutputMetadata:: +copyString( char* to, const std::string& from ) +{ + int i = 0; + const char* f = from.c_str(); + while( (++i < charArrSize) && ((*to++ = *f++) != 0) ) {}; + if( i == charArrSize ) { + *to = 0; + } +} + + +std::string +ManagedMonitorToolBase::DefaultStream:: +getStreamName( const ManagedMonitorToolBase*, const MonGroup& group, const std::string& objName, bool ) +{ + std::ostringstream streamName; + + streamName << "/" << m_fileKey << "/"; + + streamName << group.system() << "/" << objName; + return streamName.str(); +} + +std::string +ManagedMonitorToolBase::DefaultStream:: +getDirectoryName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, const bool usePreviousInterval ) +{ + std::string streamName = getStreamName(tool, group, objName, usePreviousInterval); + std::string root, rem; + parseString(streamName, root, rem); + // Remove object name at the end + // to obtain directory path + rem.erase(rem.rfind("/"), rem.length()); + return rem; +} + + +std::string +ManagedMonitorToolBase::NoOutputStream:: +getStreamName( const ManagedMonitorToolBase*, const MonGroup& group, const std::string& objName, bool ) +{ + std::ostringstream streamName; + streamName << group.system() << "/" << objName; + return streamName.str(); +} + + +std::string +ManagedMonitorToolBase::NoOutputStream:: +getDirectoryName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, const bool usePreviousInterval ) +{ + return getStreamName(tool, group, objName, usePreviousInterval); +} + +std::string +ManagedMonitorToolBase::OnlineStream:: +getStreamName( const ManagedMonitorToolBase*, const MonGroup& group, const std::string& objName, bool ) +{ + std::ostringstream streamName; + //if( group.level() != ManagedMonitorToolBase::transient ) { + // streamName << "/" << ManagedMonitorToolBase::levelOfDetailEnumToString( group.level(), true ) << "/"; + //} + streamName << "/"; // slash is required for online environment; + // otherwise the output histograms are placed in 'temp' subdirectory + + streamName << group.system() << "/" << objName; + return streamName.str(); +} + +std::string +ManagedMonitorToolBase::OnlineStream:: +getDirectoryName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, const bool usePreviousInterval ) +{ + return getStreamName(tool, group, objName, usePreviousInterval); +} + +void +ManagedMonitorToolBase::OfflineStream:: +getLBrange(int *start, int *end, int LB, int length) { + if(start && end) { + *start = ((LB-1)/length) * length + 1; + *end = *start + length - 1; + } +} + +std::string +ManagedMonitorToolBase::OfflineStream:: +getStreamName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, bool usePreviousInterval ) +{ + std::ostringstream streamName; + + //bool isTemp = ( group.level() == ManagedMonitorToolBase::transient ); + bool isTemp = false; + + bool useRunFolders = group.interval() != all; + + bool useLBFolders = ( useRunFolders ) + && ( group.interval() == ManagedMonitorToolBase::lumiBlock ); + + bool useLowStatInterval = ( useRunFolders ) + && ( group.interval() == ManagedMonitorToolBase::lowStat ); + + bool useMedStatInterval = ( useRunFolders ) + && ( group.interval() == ManagedMonitorToolBase::medStat ); + + bool useHigStatInterval = ( useRunFolders ) + && ( group.interval() == ManagedMonitorToolBase::higStat ); + + bool useEBFolders = ( group.interval() == ManagedMonitorToolBase::eventsBlock ); + + if( !isTemp ) { + streamName << "/" << m_fileKey << "/"; + } + + if( useRunFolders ) { + if (usePreviousInterval && (group.interval() == ManagedMonitorToolBase::run) ) + streamName << "run_" << AthenaMonManager::runNumber() - 1 << "/"; + else + streamName << "run_" << AthenaMonManager::runNumber() << "/"; + } + + int currentLB = AthenaMonManager::lumiBlockNumber(); + if( useLBFolders ) { + if (usePreviousInterval && (group.interval() == ManagedMonitorToolBase::lumiBlock) ) + streamName << "lb_" << currentLB - 1 << "/"; + else + streamName << "lb_" << currentLB << "/"; + } + else if( useLowStatInterval ) { + int start, end; + if (usePreviousInterval && (group.interval() == ManagedMonitorToolBase::lowStat) ) + getLBrange(&start, &end, currentLB - 1, AthenaMonManager::getLBsLowStat()); + else + getLBrange(&start, &end, currentLB, AthenaMonManager::getLBsLowStat()); + streamName << "lowStat_LB" << start << "-" << end << "/"; + } + else if( useMedStatInterval ) { + int start, end; + getLBrange(&start, &end, currentLB, AthenaMonManager::getLBsMedStat()); + streamName << "medStat_LB" << start << "-" << end << "/"; + } + else if( useHigStatInterval ) { + int start, end; + getLBrange(&start, &end, currentLB, AthenaMonManager::getLBsHigStat()); + streamName << "higStat_LB" << start << "-" << end << "/"; + } + else if( useEBFolders ) { + // The number of events in an EventsBlock can vary for each ManagedMonitorToolBase object, + // so there is no global way to determine when an EventsBlock has rolled over. + + // determine an eventsBlock number + long eventsBlockNumber = 1; // assign some dafault value + long procNEventsProp = tool->get_procNEventsProp(); + unsigned int nEvents = tool->get_nEvents(); + if (procNEventsProp > 0) { + eventsBlockNumber = (long) nEvents / procNEventsProp; + if ((nEvents % procNEventsProp) != 0) + eventsBlockNumber++; + } + + // lower eventsBlock number by 1 if usePreviousInterval is true; + if (usePreviousInterval) { + eventsBlockNumber--; + } + + streamName << "eb_" << eventsBlockNumber << "/"; + } + + streamName << group.system() << "/" << objName; + + return streamName.str(); +} + +std::string +ManagedMonitorToolBase::OfflineStream:: +getDirectoryName( const ManagedMonitorToolBase* tool, const MonGroup& group, const std::string& objName, const bool usePreviousInterval ) +{ + std::string streamName = getStreamName(tool, group, objName, usePreviousInterval); + std::string root, rem; + parseString(streamName, root, rem); + // Remove object name at the end + // to obtain directory path + rem.erase(rem.rfind("/"), rem.length()); + return rem; +} + +bool +ManagedMonitorToolBase:: +trigChainsArePassed(std::vector<std::string>& vTrigNames) +{ + ATH_MSG_DEBUG( "ManagedMonitorToolBase::trigChainsArePassed:"); + + for(unsigned int i=0; i<vTrigNames.size(); i++) { + if( m_trigDecTool->isPassed(vTrigNames[i]) ) { + ATH_MSG_DEBUG( " + \"" << vTrigNames[i] << "\" passed, returning \'true\'"); + return true; + } + else { + ATH_MSG_DEBUG( " - \"" << vTrigNames[i] << "\" did not pass"); + } + } + + return false; +} + +StatusCode +ManagedMonitorToolBase:: +parseList(const std::string& line, std::vector<std::string>& result) { + std::string item; + std::stringstream ss(line); + + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "ManagedMonitorToolBase::parseList:"; + + while ( std::getline(ss, item, ',') ) { + std::stringstream iss(item); // remove + iss >> item; // whitespace + if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " " << item; + result.push_back(item); + } + + msg(MSG::DEBUG) << endreq; + return StatusCode::SUCCESS; +} + + +ManagedMonitorToolBase::StreamNameFcn* +ManagedMonitorToolBase:: +getNewStreamNameFcn() const +{ + StreamNameFcn* fcn(0); + + switch( m_environment ) { + case AthenaMonManager::noOutput: + fcn = new NoOutputStream(); + break; + case AthenaMonManager::online: + fcn = new OnlineStream(); + break; + case AthenaMonManager::user: + fcn = new DefaultStream( m_fileKey ); + break; + case AthenaMonManager::tier0: + case AthenaMonManager::tier0Raw: + case AthenaMonManager::tier0ESD: + case AthenaMonManager::AOD: + case AthenaMonManager::altprod: + default: + fcn = new OfflineStream( m_fileKey, m_dataType, m_environment ); + } + + return fcn; +} + +void +ManagedMonitorToolBase::StreamNameFcn:: +parseString(const std::string& streamName, std::string& root, std::string& rem) { + std::string::size_type pos = streamName.find("/"); + + if (pos == std::string::npos) { + root = ""; + rem = streamName; + return; + } + + if (pos == 0) { + parseString(streamName.substr(1,streamName.length()),root,rem); + } else { + root = streamName.substr(0,pos); + rem = streamName.substr(pos+1,streamName.length()); + } + +} + +// ********************************************************************* +// Private Methods +// ********************************************************************* + +// GlobalDirectoryRestore ctor +ManagedMonitorToolBase:: +GlobalDirectoryRestore:: +GlobalDirectoryRestore() { + m_gd = gDirectory; + m_gf = gFile; +} + +// GlobalDirectoryRestore dtor +ManagedMonitorToolBase:: +GlobalDirectoryRestore:: +~GlobalDirectoryRestore() { + gDirectory = m_gd; + gFile = m_gf; +} + +namespace { + + std::string strToLower( const std::string& str ) + { + std::string lstr(str); + std::string::const_iterator from = str.begin(); + std::string::const_iterator strend = str.end(); + std::string::iterator to = lstr.begin(); + while( from != strend ) { + *to++ = tolower(*from++); + } + return lstr; + } + + + std::string strToUpper( const std::string& str ) + { + std::string ustr(str); + std::string::const_iterator from = str.begin(); + std::string::const_iterator strend = str.end(); + std::string::iterator to = ustr.begin(); + while( from != strend ) { + *to++ = toupper(*from++); + } + return ustr; + } + +} // unnamed namespace + +#endif diff --git a/Control/AthenaMonitoring/src/ManagedMonitorToolTest.cxx b/Control/AthenaMonitoring/src/ManagedMonitorToolTest.cxx new file mode 100755 index 00000000000..f4e095d8eae --- /dev/null +++ b/Control/AthenaMonitoring/src/ManagedMonitorToolTest.cxx @@ -0,0 +1,333 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ********************************************************************** +// $Id: ManagedMonitorToolTest.cxx,v 1.9 2009-05-04 12:48:51 sschaetz Exp $ +// ********************************************************************** + +#include <sstream> + +#include "GaudiKernel/IJobOptionsSvc.h" +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/StatusCode.h" + +#include "AthenaMonitoring/AthenaMonManager.h" +#include "AthenaMonitoring/ManagedMonitorToolTest.h" + +#include "TH1.h" +#include "TH2.h" +#include "TGraph.h" +#include "TTree.h" +#include "LWHists/TH1D_LW.h" +#include "LWHists/TH1F_LW.h" +#include "LWHists/TH2F_LW.h" + +const long ManagedMonitorToolTest::s_nEnsembles = 100; +const double ManagedMonitorToolTest::s_ensembleGenMean = 1.0; +const double ManagedMonitorToolTest::s_ensembleGenSigma = 2.0; + + +// ********************************************************************* +// Public Methods +// ********************************************************************* + +ManagedMonitorToolTest:: +ManagedMonitorToolTest( const std::string & type, const std::string & name, + const IInterface* parent ) + : ManagedMonitorToolBase( type, name, parent ) + , m_generatorIsInit(false) + , m_generatorSeedProp(65539) + , m_ensembleMean(0) + , m_ensembleRMS(0) + , m_ensembleMeanPull(0) + , m_ensembleMeanPullDist(0) + , m_managedHist0_lowStat(0) + , m_managedHist1_lowStat(0) + , m_managedHist2_lowStat(0) + , m_managedHist_lumiBlock(0) + , m_managedHist_eventsBlock(0) + , m_managedHist_run(0) + , m_graph(0) + , m_managedGraph(0) + , m_ntuple(0) + , m_managedNtuple(0) + , m_counter(0) + , m_variable1(0) + , m_variable2(0) + , m_hlw_1D(0) + , m_hlw_1F(0) + , m_hlw_2F(0) + , m_offset(0) + , m_gen(65539) +{ + declareProperty( "GeneratorSeed", m_generatorSeedProp ); +} + + +ManagedMonitorToolTest:: +~ManagedMonitorToolTest() +{ +} + +// Description: Used for rebooking unmanaged histograms +StatusCode +ManagedMonitorToolTest:: +bookHistogramsRecurrent( ) +{ + + if( m_environment == AthenaMonManager::online ) { + // book histograms that are only made in the online environment... + } + + if( m_dataType == AthenaMonManager::cosmics ) { + // book histograms that are only relevant for cosmics data... + } + + if( !m_generatorIsInit ) { + m_gen.SetSeed( m_generatorSeedProp ); + m_generatorIsInit = true; + } + + + MonGroup gaussian_ensemble( this, "Stats/Gaussian", lumiBlock, ATTRIB_UNMANAGED ); + MonGroup gaussian_summary( this, "Stats/Gaussian", lumiBlock, ATTRIB_UNMANAGED ); + + if( newLowStatInterval ) { } + + if( newLumiBlock ) { + m_ensembles.clear(); + + for( int i = 0; i < s_nEnsembles; ++i ) { + std::ostringstream hName; + std::ostringstream hTitle; + + hName << "gaus_" << i; + hTitle << "A Gaussian Distribution (" << i << ", " + << s_ensembleGenMean << ", " << s_ensembleGenSigma << ")"; + TH1* h = new TH1F( hName.str().c_str(), hTitle.str().c_str(), + 50, s_ensembleGenMean-5.0*s_ensembleGenSigma, + s_ensembleGenMean+5.0*s_ensembleGenSigma ); + gaussian_ensemble.regHist( h ).ignore(); + m_ensembles.push_back( h ); + } + + + m_ensembleMean = new TH1F( "nthMean", "Means of the Ensembles", + s_nEnsembles, 0.0, s_nEnsembles ); + gaussian_summary.regHist( m_ensembleMean ).ignore(); + + + m_ensembleRMS = new TH1F( "nthRMS", "RMSs of the Ensembles", + s_nEnsembles, 0.0, s_nEnsembles ); + gaussian_summary.regHist( m_ensembleRMS ).ignore(); + + + m_ensembleMeanPull = new TH1F( "nthMeanPull", "Pulls of the Means of the Ensembles", + s_nEnsembles, 0.0, s_nEnsembles ); + gaussian_summary.regHist( m_ensembleMeanPull ).ignore(); + + + m_ensembleMeanPullDist = new TH1F( "meanPull", "Pull Distribution of Means", + 50, -5.0, 5.0 ); + gaussian_summary.regHist( m_ensembleMeanPullDist ).ignore(); + + } + + if( newRun ) { + + // Example for TGraph + MonGroup space_point( this, "SpacePoint", run, ATTRIB_UNMANAGED ); + m_graph = new TGraph(); + m_graph->SetNameTitle("spacepointVsEvent","Space-point vs Event"); + space_point.regGraph( m_graph ).ignore(); + + // Example for ntuple + MonGroup group_ntuple( this, "Ntuple", run, ATTRIB_UNMANAGED ); + m_ntuple = new TTree("ntupleName","ntupleTitle"); + m_ntuple->Branch("var1",&m_variable1,"var1/I"); + m_ntuple->Branch("var2",&m_variable2,"var2/I"); + group_ntuple.regTree( m_ntuple ).ignore(); + } + + return StatusCode::SUCCESS; +} + +// Description: Used for re-booking managed histograms +StatusCode +ManagedMonitorToolTest:: +bookHistograms( ) +{ + + if( m_environment == AthenaMonManager::online ) { + // book histograms that are only made in the online environment... + } + + if( m_dataType == AthenaMonManager::cosmics ) { + // book histograms that are only relevant for cosmics data... + } + + if( !m_generatorIsInit ) { + m_gen.SetSeed( m_generatorSeedProp ); + m_generatorIsInit = true; + } + + // Example for histograms + // Create managed histograms () + m_managedHist0_lowStat = new TH1F( "managedHist0_lowStat", "Managed Histogram, regHist Example 0; interval: lowStat", 5, 0.0, 5.0 ); + m_managedHist1_lowStat = new TH1F ( "managedHist1_lowStat", "Managed Histogram, regHist Example 1; interval: lowStat", 5, 0.0, 5.0 ); + m_managedHist2_lowStat = new TH1F ( "managedHist2_lowStat", "Managed Histogram, regHist Example 2; interval: lowStat", 5, 0.0, 5.0 ); + + m_managedHist_lumiBlock = new TH1F( "managedHist_lumiBlock", "Managed Histogram; interval: lumiBlock", 5, 0.0, 5.0 ); + m_managedHist_eventsBlock = new TH1F( "managedHist_eventsBlock", "Managed Histogram; interval: lumiBlock", 5, 0.0, 5.0 ); + m_managedHist_run = new TH1F( "managedHist0_run", "Managed Histogram; interval: run", 5, 0.0, 5.0 ); + + // Create MonGroup object for managing managed histograns from same group + MonGroup managed_booking_lowStat( this, "Managed/Histograms", lowStat ); // to be re-booked every lowStat interval + + // Case 1. Use the tool regHist method and pass MonGroup instance. + regHist( m_managedHist0_lowStat, managed_booking_lowStat ).ignore(); + + // Case 2. Use the tool regHist method and pass parameters manually. + regHist( m_managedHist1_lowStat, "Managed/Histograms", lowStat ).ignore(); + + // Case 3. Use regHist method of the MonGroup instance. + managed_booking_lowStat.regHist(m_managedHist2_lowStat).ignore(); + + + // Some more histogram examples + MonGroup managed_booking_lumiBlock( this, "Managed/Histograms", lumiBlock); // to re-booked every luminosity block + regHist( m_managedHist_lumiBlock, managed_booking_lumiBlock ).ignore(); + + MonGroup managed_eventsBlock(this, "Managed/Histograms", eventsBlock); // to re-booked every eventsBlock + regHist( m_managedHist_eventsBlock, managed_eventsBlock ).ignore(); + + MonGroup managed_booking_run( this, "Managed/Histograms", run); // to be re-booked every run + regHist( m_managedHist_run, managed_booking_run ).ignore(); + + // LW Histograms + // Register managed LW histogram. Case 1: use the tool regHist method and pass parameters manually. + m_hlw_1D = TH1D_LW::create("hLW_1D", "Simple 1D LW histograms", 100, 0, 100); + regHist( m_hlw_1D, "Managed/LW", lowStat ).ignore(); // to be re-booked ever lowStat interval + + // Register managed LW histogram (case 2). Use the tool regHist method and pass parameters manually. + m_hlw_1F = TH1F_LW::create("hLW_1F", "Simple 1F LW histograms", 100, 0, 100); + regHist( m_hlw_1F, "Managed/Histograms", eventsBlock ).ignore(); + + // Register managed LW histogram. Case 3: use regHist method of the MonGroup instance. + MonGroup LWcontent_lumiBlock( this, "Managed/LW", lumiBlock ); // to be re-booked every luminosity block + m_hlw_2F = TH2F_LW::create("hLW_2F","content comparison LW", 100, 0, 100, 50, 75, 125); + LWcontent_lumiBlock.regHist( m_hlw_2F ).ignore(); + + // Example for the managed TGraph + MonGroup managed_space_point( this, "Managed/SpacePoint", lumiBlock ); + m_managedGraph = new TGraph(); + m_managedGraph->SetNameTitle("spacepointVsEvent_managed","Space-point vs Event (Managed)"); + managed_space_point.regGraph( m_managedGraph ).ignore(); + + // Example for the managed ntuple + MonGroup managed_group_ntuple( this, "Managed/managed_Ntuple", lumiBlock ); + m_managedNtuple = new TTree("managedNtupleName","managedNtupleTitle"); + m_managedNtuple->Branch("var1",&m_variable1,"var1/I"); + m_managedNtuple->Branch("var2",&m_variable2,"var2/I"); + managed_group_ntuple.regTree( m_managedNtuple ).ignore(); + + return StatusCode::SUCCESS; +} + + +StatusCode +ManagedMonitorToolTest:: +fillHistograms() +{ + + std::vector<TH1*>::const_iterator ensembleEnd = m_ensembles.end(); + for( std::vector<TH1*>::const_iterator i = m_ensembles.begin(); i != ensembleEnd; ++i ) { + TH1* h = *i; + h->Fill( m_gen.Gaus( s_ensembleGenMean, s_ensembleGenSigma ) ); + } + + // TGraph + m_counter++; + m_event.push_back(m_counter); + m_spacepoint.push_back(m_counter%10); + + // TGraph (managed-rebooking) + // Use GetN() method. Otherwise need to handle manually in procHistograms + m_managedGraph->SetPoint(m_managedGraph->GetN(), m_counter, m_counter); + + // Ntuple + m_variable1 = m_counter; + m_variable2 = m_counter*2; + m_ntuple->Fill(); + + // Ntuple (managed-rebooking) + m_managedNtuple->SetBranchAddress("var1",&m_variable1); + m_managedNtuple->SetBranchAddress("var2",&m_variable2); + m_managedNtuple->Fill(); + + // Fill managed-rebooking histograms + m_managedHist0_lowStat->Fill(0); + m_managedHist1_lowStat->Fill(1); + m_managedHist2_lowStat->Fill(2); + + // newEventsBlock is a static variable. + // It is true when eventsBlock changed. + if (newEventsBlock) + m_offset += 1; + + // Fill out different histograms bins + m_managedHist_eventsBlock->Fill(m_offset); + + m_managedHist_lumiBlock->Fill(0); + m_managedHist_run->Fill(0); + + // Fill managed LW histogram + float x = m_gen.Gaus( 50., 15. ); + float y = m_gen.Gaus( 100., 10. ); + m_hlw_1D->Fill( x ); + m_hlw_1F->Fill( m_offset ); + m_hlw_2F->Fill( x, y ); + + return StatusCode::SUCCESS; +} + + +StatusCode +ManagedMonitorToolTest:: +procHistograms( ) +{ + + if( endOfLowStat || endOfLumiBlock ) { + for( int i = 0; i < s_nEnsembles; ++i ) { + TH1* h = m_ensembles[i]; + + double mean = h->GetMean(); + double mean_err = h->GetMeanError(); + double rms = h->GetRMS(); + double rms_err = h->GetRMSError(); + + m_ensembleMean->SetBinContent( i+1, mean ); + m_ensembleMean->SetBinError( i+1, mean_err ); + + m_ensembleRMS->SetBinContent( i+1, rms ); + m_ensembleRMS->SetBinError( i+1, rms_err ); + + double meanPull = mean_err > 0 ? (mean-s_ensembleGenMean)/mean_err : 0; + m_ensembleMeanPull->SetBinContent( i+1, meanPull ); + m_ensembleMeanPull->SetBinError( i+1, 1.0 ); + + m_ensembleMeanPullDist->Fill( meanPull ); + } + } + + + if( endOfRun ) { + // fill vectors to TGraph + for(unsigned int i=0; i<m_event.size(); i++) + m_graph->SetPoint(i, m_event[i], m_spacepoint[i]); + } + + return StatusCode::SUCCESS; +} + diff --git a/Control/AthenaMonitoring/src/MonitorToolBase.cxx b/Control/AthenaMonitoring/src/MonitorToolBase.cxx new file mode 100755 index 00000000000..5d0b666aa21 --- /dev/null +++ b/Control/AthenaMonitoring/src/MonitorToolBase.cxx @@ -0,0 +1,277 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// ******************************************************************** +// +// NAME: MonitorToolBase.cxx +// +// DESCRIPTION: Base abstract class for creating monitoring histogramming tools +// +// AUTHOR: Manuel Diaz & Peter Loch +// Rolf Seuster 28.10.2005: added support for logging output of +// checkHists() into logfile +// Rolf Seuster 24.10.2005: added support for THistSvc +// Rob McPherson 20.03.2004: added finalHists() +// Rob McPherson 29.03.2004: removed execute() default. +// reworked book flag routines +// Manuel Diaz 01.04.2004 slight change in class definition(inherit from IMonitorToolBase) +// +// ******************************************************************** + +#include "GaudiKernel/MsgStream.h" +#include "AthenaMonitoring/LogFileMsgStream.h" +#include "AthenaMonitoring/MonitorToolBase.h" + +/*---------------------------------------------------------*/ +MonitorToolBase::MonitorToolBase(const std::string & type, + const std::string & name, + const IInterface* parent) + : AlgTool(type, name, parent) + , m_histsvc(0) + , m_rootsvc(0) + , m_isBooked(false) + , m_path("/stat") + , setupStreamMap(false) + , m_LogFileName("my.default") + , m_FormatString("") + , m_preScale(1) + , m_counter(1) +/*---------------------------------------------------------*/ +{ + declareProperty("histoPathBase",m_path); + declareProperty("THistSvc_OutStream",m_THistSvc_streamname="/MonitorOutPut"); + declareProperty("THistSvc_RefStream",m_THistSvc_refStream="none"); + + m_THistSvc_streamnameMapping.clear(); + m_map_THistSvc_streamnames.clear(); + declareProperty("THistSvc_OutPutStreamMapping",m_THistSvc_streamnameMapping); + + // use a rather stupid default name, the real default + // later will be "CheckHist_"+RunNumber+".log" + // but now, we don't know the RunNumber yet! + // for now, overwritten by jobOptions + declareProperty("logfileName", m_LogFileName); + declareProperty("Format", m_FormatString); + declareProperty("PreScale", m_preScale); +} + +/*---------------------------------------------------------*/ +MonitorToolBase::~MonitorToolBase() +/*---------------------------------------------------------*/ +{ + MsgStream log(msgSvc(), name()); + log << MSG::INFO << "destructor has been called" << endreq; +} + +/*---------------------------------------------------------*/ +std::string +MonitorToolBase::getStreamName(unsigned int number, bool useDefault /* =true */ ) +/*---------------------------------------------------------*/ +{ + std::string str="empty"; // no trailing slash, histogram will be temporary + + if( ! setupStreamMap) + if( ! this->setupOutputStreams().isSuccess()) + { + MsgStream log(msgSvc(), name ()); + log << MSG::ERROR + << "Could not setup Outputstreams !" << endreq; + } + + // valid entry in vector ? + if( number < m_THistSvc_streamnameMapping.size() ) + return m_THistSvc_streamnameMapping[number]; + + // shall we use the default instead ? + if( useDefault ) + return m_THistSvc_streamname; + + // return "empty" string to make histogram temporary + return str; +} + +/*---------------------------------------------------------*/ +std::string +MonitorToolBase::getStreamName(std::string stream, bool useDefault /* = true */ ) +/*---------------------------------------------------------*/ +{ + std::string str="empty"; // no trailing slash, histogram will be temporary + + if( ! setupStreamMap) + if( ! this->setupOutputStreams().isSuccess() ) + { + MsgStream log(msgSvc(), name ()); + log << MSG::ERROR + << "Could not setup Outputstreams !" << endreq; + } + + // valid entry in map ? + map_type::iterator itr = m_map_THistSvc_streamnames.find(stream); + if( itr != m_map_THistSvc_streamnames.end() ) + return itr->second; + + // shall we use the default instead ? + if( useDefault ) + return m_THistSvc_streamname; + + // return "empty" string to make histogram temporary + return str; +} + +/*---------------------------------------------------------*/ +StatusCode +MonitorToolBase::setupOutputStreams(std::vector<std::string> Mapping + /* = std::vector<std::string>() */ ) +/*---------------------------------------------------------*/ +{ + MsgStream log(msgSvc(), name ()); + + // following statement is useless in the initialize, + // if the concrete tool implements its own iniitalize + m_counter=m_preScale; + + // did we get some stream mapping from AthenaMon in Mapping ? + if( Mapping.size() > 0 ) + // yes, insert it into m_THistSvc_streamnameMapping + m_THistSvc_streamnameMapping.insert(m_THistSvc_streamnameMapping.begin(), + Mapping.begin(),Mapping.end()); + + std::vector<std::string>::iterator itr = m_THistSvc_streamnameMapping.begin(); + while( itr != m_THistSvc_streamnameMapping.end() ) + { + std::string::size_type location = itr->find("/", 0); + if( location == std::string::npos ) + { + log << MSG::ERROR + << "No '/' found in StreamName " << *itr + << " ! Will not use this stream !" << endreq; + itr = m_THistSvc_streamnameMapping.erase(itr); + continue; + } + + // check, if already in map and issue warning that it's being replaced + std::map<std::string,std::string>::iterator iter = + m_map_THistSvc_streamnames.find(itr->substr(0,location)); + if( iter != m_map_THistSvc_streamnames.end() ) + { + log << MSG::WARNING + << "Will overwrite mapping of mnemonic/stream \"" + << iter->first << iter->second << "\" with \"" + << itr->substr(0,location) + << itr->substr(location) << "\" !!" + << endreq; + iter->second=itr->substr(location); + }else{ + m_map_THistSvc_streamnames[itr->substr(0,location)]=itr->substr(location); + } + itr->erase(0,location); + itr++; + } + + if(m_map_THistSvc_streamnames.size()>0) + { + log << MSG::INFO + << "Using following mapping of mnemonics to streams (in alphabetical order):" + << endreq; + for( map_type::const_iterator iter = m_map_THistSvc_streamnames.begin(); + iter != m_map_THistSvc_streamnames.end(); iter++ ) + log << MSG::INFO + << std::setw(20) + << iter->first << " writes to " + << std::setw(20) + << iter->second + << endreq; + } + // don't call again + setupStreamMap=true; + + return StatusCode::SUCCESS; +} + +/*---------------------------------------------------------*/ +bool MonitorToolBase::preSelector() +/*---------------------------------------------------------*/ +{ + if(m_counter==1) + { + m_counter=m_preScale; + return true; + } + else + if(m_counter>1) + m_counter--; + return false; +} + +/*---------------------------------------------------------*/ +void MonitorToolBase::SetBookStatus(bool status) +/*---------------------------------------------------------*/ +{ + m_isBooked = status; +} + +/*---------------------------------------------------------*/ +bool MonitorToolBase::histsNotBooked() +/*---------------------------------------------------------*/ +{ + return (not m_isBooked); +} + +/*---------------------------------------------------------*/ +StatusCode MonitorToolBase::finalHists() // Default finalHists(): do nothing. +/*---------------------------------------------------------*/ +{ + MsgStream log(msgSvc(), name()); + log << MSG::INFO << "default finalHists() called." << endreq; + return StatusCode::SUCCESS; +} + +/*---------------------------------------------------------*/ +StatusCode MonitorToolBase::runStat() // Default runStat(): do nothing. +/*---------------------------------------------------------*/ +{ + return StatusCode::SUCCESS; +} + +/*---------------------------------------------------------*/ +StatusCode MonitorToolBase::checkHists(bool fromFinalize) // Default checkHists(): do nothing. +/*---------------------------------------------------------*/ +{ + LogFileMsgStream log(msgSvc(), name(), m_LogFileName, fromFinalize); + if(m_FormatString!="") + log.setFormat(m_FormatString); + + if(fromFinalize) + log << MSG::INFO << "default checkHists() called from finalize()." << endreq; + else + log << MSG::INFO << "default checkHists() called periodically." << endreq; + return StatusCode::SUCCESS; +} +/*---------------------------------------------------------*/ +IHistogramSvc* MonitorToolBase::ToolHistoSvc() +/*---------------------------------------------------------*/ +{ + MsgStream log(msgSvc(), name()); + + StatusCode sc = service("HistogramDataSvc",m_histsvc, true); + if( sc.isFailure() ) { + log << MSG::WARNING << ">>> Unable to locate the Histogram service" << endreq; + } + + return m_histsvc; +} +/*---------------------------------------------------------*/ +ITHistSvc* MonitorToolBase::ToolRootHistSvc() +/*---------------------------------------------------------*/ +{ + MsgStream log(msgSvc(), name()); + + StatusCode sc = service("THistSvc",m_rootsvc, true); + if( sc.isFailure() ) { + log << MSG::WARNING << ">>> Unable to locate the Histogram service" << endreq; + } + + return m_rootsvc; +} +/*---------------------------------------------------------*/ diff --git a/Control/AthenaMonitoring/src/components/AthenaMonitoring_entries.cxx b/Control/AthenaMonitoring/src/components/AthenaMonitoring_entries.cxx new file mode 100755 index 00000000000..346bd4c9666 --- /dev/null +++ b/Control/AthenaMonitoring/src/components/AthenaMonitoring_entries.cxx @@ -0,0 +1,27 @@ +#include "AthenaMonitoring/AthenaMon.h" +#include "AthenaMonitoring/AthenaMonManager.h" +#include "AthenaMonitoring/ManagedMonitorToolTest.h" +#include "AthenaMonitoring/DQAtlasReadyFilterTool.h" +#include "AthenaMonitoring/DQFilledBunchFilterTool.h" +#include "AthenaMonitoring/DQDummyFilterTool.h" +#include "AthenaMonitoring/DQBadLBFilterTool.h" + +#include "GaudiKernel/DeclareFactoryEntries.h" + +DECLARE_ALGORITHM_FACTORY(AthenaMon) +DECLARE_ALGORITHM_FACTORY(AthenaMonManager) +DECLARE_TOOL_FACTORY(ManagedMonitorToolTest) +DECLARE_TOOL_FACTORY(DQAtlasReadyFilterTool) +DECLARE_TOOL_FACTORY(DQFilledBunchFilterTool) +DECLARE_TOOL_FACTORY(DQDummyFilterTool) +DECLARE_TOOL_FACTORY(DQBadLBFilterTool) + +DECLARE_FACTORY_ENTRIES(AthenaMonitoring) { + DECLARE_ALGORITHM(AthenaMon) + DECLARE_ALGORITHM(AthenaMonManager) + DECLARE_ALGTOOL(ManagedMonitorToolTest) + DECLARE_ALGTOOL(DQAtlasReadyFilterTool) + DECLARE_ALGTOOL(DQFilledBunchFilterTool) + DECLARE_ALGTOOL(DQDummyFilterTool) + DECLARE_ALGTOOL(DQBadLBFilterTool) +} diff --git a/Control/AthenaMonitoring/src/components/AthenaMonitoring_load.cxx b/Control/AthenaMonitoring/src/components/AthenaMonitoring_load.cxx new file mode 100755 index 00000000000..2d14ca78631 --- /dev/null +++ b/Control/AthenaMonitoring/src/components/AthenaMonitoring_load.cxx @@ -0,0 +1,4 @@ +#include "GaudiKernel/LoadFactoryEntries.h" + +LOAD_FACTORY_ENTRIES(AthenaMonitoring) + -- GitLab