Skip to content
Snippets Groups Projects
Commit c27c9469 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Always write output files

See merge request gaudi/Gaudi!1432
parents 4a371dfa adc807ee
No related branches found
No related tags found
No related merge requests found
/***********************************************************************************\
* (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
* (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
* *
* This software is distributed under the terms of the Apache version 2 licence, *
* copied verbatim in the file "LICENSE". *
......@@ -42,6 +42,13 @@ namespace {
}
} // namespace
StatusCode OutputStream::start() {
return Algorithm::start().andThen( [this]() {
// Open the output file now to ensure it is always written even if empty
return m_pConversionSvc->connectOutput( m_outputName, m_outputType );
} );
}
// initialize data writer
StatusCode OutputStream::initialize() {
......@@ -126,6 +133,7 @@ StatusCode OutputStream::initialize() {
m_acceptNames.useUpdateHandler();
m_requireNames.useUpdateHandler();
m_vetoNames.useUpdateHandler();
return StatusCode::SUCCESS;
}
......
/***********************************************************************************\
* (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
* (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
* *
* This software is distributed under the terms of the Apache version 2 licence, *
* copied verbatim in the file "LICENSE". *
......@@ -139,6 +139,8 @@ protected:
virtual bool hasInput() const;
public:
/// Start OutputStream
StatusCode start() override;
/// Initialize OutputStream
StatusCode initialize() override;
/// Terminate OutputStream
......
#####################################################################################
# (c) Copyright 2023 CERN for the benefit of the LHCb and ATLAS collaborations #
# #
# This software is distributed under the terms of the Apache version 2 licence, #
# copied verbatim in the file "LICENSE". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
#####################################################################################
import os
from GaudiTests import run_gaudi
OUTPUT_FILE_NAME = "empty-output-file.dst"
def config():
"""
Configure a job writing to an empty file.
"""
from Configurables import GaudiPersistency
from GaudiConfig2 import Configurables as C
GaudiPersistency()
out = C.OutputStream(
ItemList=["/Event#999"],
Output=f"DATAFILE='PFN:{OUTPUT_FILE_NAME}' SVC='Gaudi::RootCnvSvc' OPT='RECREATE'",
)
app = C.ApplicationMgr(EvtMax=0, OutStream=[out.__opt_value__()])
return [app, out]
def test(tmp_path):
"""
Check that an output file is created even if no event is written to it.
"""
os.chdir(tmp_path)
if os.path.exists(OUTPUT_FILE_NAME):
os.remove(OUTPUT_FILE_NAME)
run_gaudi(f"{__file__}:config", check=True)
assert os.path.exists(
OUTPUT_FILE_NAME
), f"expected output file {OUTPUT_FILE_NAME} not found"
os.remove(OUTPUT_FILE_NAME)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment