Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create output directories #170

Merged
merged 6 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions k4FWCore/components/PodioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
* limitations under the License.
*/
#include <cstdlib>
#include <filesystem>
#include <system_error>

#include "GaudiKernel/MsgStream.h"

#include "PodioOutput.h"
#include "k4FWCore/PodioDataSvc.h"
Expand All @@ -38,6 +42,20 @@ StatusCode PodioOutput::initialize() {
return StatusCode::FAILURE;
}

// check whether output directory needs to be created and eventually create it
auto outDirPath = std::filesystem::path(m_filename.value()).parent_path();
if (!outDirPath.empty() && !std::filesystem::is_directory(outDirPath)) {
std::error_code ec;
std::filesystem::create_directories(outDirPath, ec);
andresailer marked this conversation as resolved.
Show resolved Hide resolved
if (ec.value() != 0) {
error() << "Output directory \"" << outDirPath << "\" was not created!" << endmsg;
error() << "Error " << ec.value() << ": " << ec.message() << endmsg;

return StatusCode::FAILURE;
}
debug() << "Created output directory: " << outDirPath << endmsg;
}

m_framewriter = std::make_unique<podio::ROOTWriter>(m_filename);
m_switch = KeepDropSwitch(m_outputCommands);

Expand Down
1 change: 1 addition & 0 deletions test/k4FWCoreTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function(add_test_with_env testname)
endfunction()

add_test_with_env(CreateExampleEventData options/createExampleEventData.py)
add_test_with_env(CreateExampleEventDataInDirectory options/createExampleEventDataInDirectory.py)

add_test_with_env(CheckExampleEventData options/checkExampleEventData.py PROPERTIES DEPENDS CreateExampleEventData)
add_test_with_env(CheckExampleEventData_noCollections options/checkExampleEventData.py --collections= PROPERTIES DEPENDS CreateExampleEventData)
Expand Down
41 changes: 41 additions & 0 deletions test/k4FWCoreTest/options/createExampleEventDataInDirectory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Copyright (c) 2014-2024 Key4hep-Project.
#
# This file is part of Key4hep.
# See https://key4hep.github.io/key4hep-doc/ for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from Gaudi.Configuration import INFO
from Configurables import ApplicationMgr
from Configurables import k4FWCoreTest_CreateExampleEventData
from Configurables import k4DataSvc
from Configurables import PodioOutput

podioevent = k4DataSvc("EventDataSvc")

producer = k4FWCoreTest_CreateExampleEventData()

out = PodioOutput("out")
out.filename = "output/dir/output_k4test_exampledata.root"
out.outputCommands = ["keep *"]


ApplicationMgr(
TopAlg=[producer, out],
EvtSel="NONE",
EvtMax=100,
ExtSvc=[podioevent],
OutputLevel=INFO,
StopOnSignal=True,
)
Loading