diff --git a/Event/EventBookkeeperTools/CMakeLists.txt b/Event/EventBookkeeperTools/CMakeLists.txt index 06ad4153ce53ed701a7fea64af6c028798ad3e34..5222f72af67b9eeea8fe0aeabc1a3e68c8fa0d46 100644 --- a/Event/EventBookkeeperTools/CMakeLists.txt +++ b/Event/EventBookkeeperTools/CMakeLists.txt @@ -5,6 +5,15 @@ # Declare the package name: atlas_subdir( EventBookkeeperTools ) +if( XAOD_STANDALONE ) + set( xaod_access_deps Control/xAODRootAccess ) + set( xaod_access_lib xAODRootAccess ) +# ... for AthAnalysisBase (Athena calls this POOLRootAccess) +else() + set( xaod_access_deps PhysicsAnalysis/POOLRootAccess ) + set( xaod_access_lib POOLRootAccessLib ) +endif() + # Declare the package's dependencies: atlas_depends_on_subdirs( PUBLIC Control/AthToolSupport/AsgTools @@ -13,6 +22,7 @@ atlas_depends_on_subdirs( PUBLIC Event/xAOD/xAODCutFlow GaudiKernel PRIVATE + ${xaod_access_deps} Control/SGTools Control/StoreGate Event/EventBookkeeperMetaData @@ -27,19 +37,29 @@ atlas_add_component( EventBookkeeperTools src/*.cxx src/components/*.cxx INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} - LINK_LIBRARIES ${ROOT_LIBRARIES} AsgTools AthenaBaseComps AthenaKernel xAODCutFlow GaudiKernel SGTools StoreGateLib SGtests EventBookkeeperMetaData EventInfo xAODEventInfo ) + LINK_LIBRARIES ${ROOT_LIBRARIES} AsgTools AthenaBaseComps AthenaKernel xAODCutFlow + GaudiKernel SGTools StoreGateLib SGtests EventBookkeeperMetaData EventInfo xAODEventInfo ) + +atlas_add_executable( dump-cbk + util/dump-cbk.cxx + INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} + LINK_LIBRARIES ${ROOT_LIBRARIES} ${xaod_access_lib} AsgTools ) # Install files from the package: atlas_install_python_modules( python/*.py ) atlas_install_joboptions( share/*.py ) +atlas_install_runtime( scripts/dump-cbk ) # Tests +atlas_add_test( BookkeeperDumperTool + SCRIPT test/test_BookkeeperDumperTool.py + POST_EXEC_SCRIPT nopost.sh ) + atlas_add_test( CutflowSvcDummyAlg SCRIPT athena EventBookkeeperTools/TestCutFlowSvcDummyAlg.py - PROPERTIES TIMEOUT 300 ) -atlas_add_test( CutflowSvcDumpBookkeepers - SCRIPT athena EventBookkeeperTools/TestCutFlowSvcDumpBookkeepers.py - PROPERTIES TIMEOUT 300 ) + PROPERTIES TIMEOUT 300 + POST_EXEC_SCRIPT nopost.sh ) atlas_add_test( CutflowSvcOutput SCRIPT athena EventBookkeeperTools/TestCutFlowSvcOutput.py - PROPERTIES TIMEOUT 300 ) + PROPERTIES TIMEOUT 300 + POST_EXEC_SCRIPT nopost.sh ) diff --git a/Event/EventBookkeeperTools/python/EventBookkeeperToolsConfig.py b/Event/EventBookkeeperTools/python/EventBookkeeperToolsConfig.py new file mode 100644 index 0000000000000000000000000000000000000000..5af8fc42b4fdd40d77d75c9a0f44f08d3ff3eccd --- /dev/null +++ b/Event/EventBookkeeperTools/python/EventBookkeeperToolsConfig.py @@ -0,0 +1,10 @@ +"""Define functions for event bookkeeping configuration using ComponentAccumulator + +Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +""" +from AthenaServices.MetaDataSvcConfig import MetaDataSvcCfg + + +def BookkeeperDumperToolCfg(flags): + """BookkeeperDumperTool configuration""" + return MetaDataSvcCfg(flags, toolNames=['BookkeeperDumperTool']) diff --git a/Event/EventBookkeeperTools/python/__init__.py b/Event/EventBookkeeperTools/python/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Event/EventBookkeeperTools/share/TestCutFlowSvcDumpBookkeepers.py b/Event/EventBookkeeperTools/share/TestCutFlowSvcDumpBookkeepers.py deleted file mode 100644 index 4658977616439d9739e9fe298ee4e5cb83c643c3..0000000000000000000000000000000000000000 --- a/Event/EventBookkeeperTools/share/TestCutFlowSvcDumpBookkeepers.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -############################################################### -# -# Minimal athena options to execute the CutFlowSvc -# -## @file TestCutFlowSvcDumpBookkkeepers.py -## -## @brief Test basic CutFlowSvc functionality and dump existing cutbookkeepers -## -## @author Tadej Novak <tadej.novak@cern.ch> -# -#============================================================== - -# basic job configuration -import AthenaCommon.AtlasUnixStandardJob - -# setup the input -from AthenaCommon.AthenaCommonFlags import athenaCommonFlags -if 'inputFiles' in dir(): - athenaCommonFlags.FilesInput = inputFiles.split(',') - del inputFiles -else: - athenaCommonFlags.FilesInput = [ - '/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/CommonInputs/mc16_13TeV.410501.PowhegPythia8EvtGen_A14_ttbar_hdamp258p75_nonallhad.merge.AOD.e5458_s3126_r9364_r9315/AOD.11182705._000001.pool.root.1' - ] - -# get a handle to the default top-level algorithm sequence -from AthenaCommon.AlgSequence import AlgSequence -topSequence = AlgSequence() - -# get a handle to the ServiceManager and the Tool service -from AthenaCommon.AppMgr import ServiceMgr, ToolSvc - -# get a handle to the ApplicationManager -from AthenaCommon.AppMgr import theApp - -# load POOL support -import AthenaPoolCnvSvc.ReadAthenaPool - -# setup the CutFlowSvc and corresponding tools -from EventBookkeeperTools.CutFlowHelpers import CreateCutFlowSvc, CreateBookkeeperDumperTool -CreateCutFlowSvc() - -# setup the bookkeeper dumper tool -CreateBookkeeperDumperTool() - -# set debug logging -ServiceMgr.MessageSvc.defaultLimit = 9999999 -ServiceMgr.CutFlowSvc.OutputLevel = DEBUG -ToolSvc.CutBookkeepersTool.OutputLevel = VERBOSE -ToolSvc.PDFSumOfWeights.OutputLevel = DEBUG - -# run on 10 events -theApp.EvtMax = 1 diff --git a/Event/EventBookkeeperTools/src/BookkeeperDumperTool.cxx b/Event/EventBookkeeperTools/src/BookkeeperDumperTool.cxx index 275c08d087fe7e824200462cc37252069e614f9c..ae07d44a89e9c337febbe94062eaec7cb9643d42 100755 --- a/Event/EventBookkeeperTools/src/BookkeeperDumperTool.cxx +++ b/Event/EventBookkeeperTools/src/BookkeeperDumperTool.cxx @@ -22,6 +22,15 @@ BookkeeperDumperTool::BookkeeperDumperTool(const std::string &name) } +StatusCode BookkeeperDumperTool::initialize() +{ + if (m_standaloneMode.value()) { + ATH_CHECK(beginInputFile()); + } + + return StatusCode::SUCCESS; +} + StatusCode BookkeeperDumperTool::beginInputFile() { @@ -41,7 +50,7 @@ StatusCode BookkeeperDumperTool::beginInputFile() << " nc=" << cbk->nChildren()); } } else { - ATH_MSG_INFO("No complete CutBookkeepers found: " << inputMetaStore()->dump()); + ATH_MSG_INFO("No complete CutBookkeepers found"); } // Incomplete CutBookkeepers @@ -60,7 +69,7 @@ StatusCode BookkeeperDumperTool::beginInputFile() << " nc=" << cbk->nChildren()); } } else { - ATH_MSG_INFO("No incomplete CutBookkeepers found: " << inputMetaStore()->dump()); + ATH_MSG_INFO("No incomplete CutBookkeepers found"); } // Complete PDF CutBookkeepers @@ -79,7 +88,7 @@ StatusCode BookkeeperDumperTool::beginInputFile() << " nc=" << cbk->nChildren()); } } else { - ATH_MSG_INFO("No PDF CutBookkeepers found: " << inputMetaStore()->dump()); + ATH_MSG_INFO("No PDF CutBookkeepers found"); } // Incomplete PDF CutBookkeepers @@ -98,7 +107,7 @@ StatusCode BookkeeperDumperTool::beginInputFile() << " nc=" << cbk->nChildren()); } } else { - ATH_MSG_INFO("No incomplete PDF CutBookkeepers found: " << inputMetaStore()->dump()); + ATH_MSG_INFO("No incomplete PDF CutBookkeepers found"); } return StatusCode::SUCCESS; diff --git a/Event/EventBookkeeperTools/src/BookkeeperDumperTool.h b/Event/EventBookkeeperTools/src/BookkeeperDumperTool.h index 337dc446034137a1bdf12292b2c0f161e788f0e1..604d1fcc9d55d901bdc0bfdd4361f82db414070f 100755 --- a/Event/EventBookkeeperTools/src/BookkeeperDumperTool.h +++ b/Event/EventBookkeeperTools/src/BookkeeperDumperTool.h @@ -28,11 +28,15 @@ class BookkeeperDumperTool : public asg::AsgMetadataTool, public: BookkeeperDumperTool(const std::string &name = "BookkeeperDumperTool"); + virtual StatusCode initialize() final; + virtual StatusCode beginInputFile() final; virtual StatusCode beginInputFile(const SG::SourceID &) final { return StatusCode::SUCCESS; } virtual StatusCode endInputFile() final { return StatusCode::SUCCESS; } virtual StatusCode endInputFile(const SG::SourceID &) final { return StatusCode::SUCCESS; } virtual StatusCode metaDataStop() final { return StatusCode::SUCCESS; } + + Gaudi::Property<bool> m_standaloneMode{this, "StandaloneMode", false, "Dump on initialize when running standalone"}; }; #endif diff --git a/Event/EventBookkeeperTools/test/test_BookkeeperDumperTool.py b/Event/EventBookkeeperTools/test/test_BookkeeperDumperTool.py new file mode 100755 index 0000000000000000000000000000000000000000..a149da0f8ff7902831659302438a0499dd2e2017 --- /dev/null +++ b/Event/EventBookkeeperTools/test/test_BookkeeperDumperTool.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +"""Dump CutBookkeepers + +Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +""" +import sys +from argparse import ArgumentParser + +from AthenaCommon.Configurable import Configurable +from AthenaConfiguration.AllConfigFlags import ConfigFlags +from AthenaConfiguration.MainServicesConfig import MainServicesSerialCfg +from AthenaConfiguration.TestDefaults import defaultTestFiles +from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg + +from EventBookkeeperTools.EventBookkeeperToolsConfig import BookkeeperDumperToolCfg + +# Argument parsing +parser = ArgumentParser(prog='dump-cbk') +parser.add_argument('input', metavar='input', type=str, nargs='?', + help='Specify the input file') +args = parser.parse_args() + +# Setup configuration +Configurable.configurableRun3Behavior = True + +if args.input: + ConfigFlags.Input.Files = [args.input] +else: + ConfigFlags.Input.Files = defaultTestFiles.AOD +ConfigFlags.lock() + +# Setup tools +acc = MainServicesSerialCfg() +acc.merge(PoolReadCfg(ConfigFlags)) +acc.merge(BookkeeperDumperToolCfg(ConfigFlags)) + +# Execute and finish +sc = acc.run(maxEvents=1) + +# Success should be 0 +sys.exit(not sc.isSuccess()) diff --git a/Event/EventBookkeeperTools/util/dump-cbk.cxx b/Event/EventBookkeeperTools/util/dump-cbk.cxx new file mode 100644 index 0000000000000000000000000000000000000000..8999459b11e8c3c061dd4b9a230c1fb9736c1169 --- /dev/null +++ b/Event/EventBookkeeperTools/util/dump-cbk.cxx @@ -0,0 +1,78 @@ +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + +// Setup for reading ATLAS data +#ifdef XAOD_STANDALONE +#include <xAODRootAccess/Init.h> +#include <xAODRootAccess/TEvent.h> +#else +#include <POOLRootAccess/TEvent.h> +#endif +#include <xAODRootAccess/tools/TFileAccessTracer.h> + +// ASG +#include <AsgTools/MessageCheck.h> +#include <AsgTools/ToolHandle.h> +#include <AsgTools/AsgMetadataTool.h> +#include <AthAnalysisBaseComps/AthAnalysisHelper.h> + +ANA_MSG_HEADER(CutFlow) +ANA_MSG_SOURCE(CutFlow, "Dump") + +// ROOT dependencies +#include <TFile.h> + +// Main routine... here we go! +int main(int argc, char **argv) +{ + // Make sure things know we are not in StatusCode land + using namespace CutFlow; + ANA_CHECK_SET_TYPE (int); + + if (argc < 2) { + ANA_MSG_ERROR("Input file missing."); + return 1; + } + const char *inputFile = argv[1]; + + // Setup for reading -- if this fails, we have major problems +#ifdef XAOD_STANDALONE + if ( ! xAOD::Init().isSuccess() ) { + throw std::runtime_error("Cannot initialise xAOD access !"); + } + ANA_MSG_INFO("Using xAOD access"); +#else + IAppMgrUI *app = POOL::Init(); + ANA_MSG_INFO("Using POOL access"); +#endif + + xAOD::TFileAccessTracer::enableDataSubmission(false); + + ANA_MSG_INFO("Reading file:" << inputFile); + + // Input chain + std::unique_ptr<TFile> file(TFile::Open(inputFile, "READ")); + ANA_CHECK(file.get()); +#ifdef XAOD_STANDALONE + xAOD::TEvent event(xAOD::TEvent::kClassAccess); +#else + POOL::TEvent event(POOL::TEvent::kClassAccess); +#endif + ANA_CHECK(event.readFrom(file.get())); + + // Load metadata + event.getEntries(); + + // Retrieve the tool + ToolHandle<asg::AsgMetadataTool> tool("BookkeeperDumperTool/BookkeeperDumperTool"); + ANA_CHECK(AAH::setProperty(tool, "StandaloneMode", true)); + ANA_CHECK(tool.retrieve()); + + // Trigger finalization of all services and tools created by the Gaudi Application +#ifndef XAOD_STANDALONE + app->finalize(); +#endif + + return 0; +}