Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Feb 16, 2024
1 parent 004e073 commit e621800
Show file tree
Hide file tree
Showing 30 changed files with 175 additions and 205 deletions.
2 changes: 1 addition & 1 deletion k4FWCore/components/IIOSvc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2023 Key4hep-Project.
* Copyright (c) 2014-2024 Key4hep-Project.
*
* This file is part of Key4hep.
* See https://key4hep.github.io/key4hep-doc/ for further info.
Expand Down
34 changes: 13 additions & 21 deletions k4FWCore/components/IOSvc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2023 Key4hep-Project.
* Copyright (c) 2014-2024 Key4hep-Project.
*
* This file is part of Key4hep.
* See https://key4hep.github.io/key4hep-doc/ for further info.
Expand Down Expand Up @@ -59,26 +59,25 @@ StatusCode IOSvc::initialize() {
StatusCode IOSvc::finalize() { return Service::finalize(); }

std::tuple<std::vector<std::shared_ptr<podio::CollectionBase>>, std::vector<std::string>, podio::Frame> IOSvc::next() {

podio::Frame frame;
{
std::scoped_lock<std::mutex> lock(m_changeBufferLock);
info() << "m_nextEntry = " << m_nextEntry << " m_entries = " << m_entries << endmsg;
if (m_nextEntry < m_entries) {
frame = podio::Frame(std::move(m_reader->readEntry(podio::Category::Event, m_nextEntry)));
}
else {
return std::make_tuple(std::vector<std::shared_ptr<podio::CollectionBase>>(), std::vector<std::string>(), std::move(frame));
} else {
return std::make_tuple(std::vector<std::shared_ptr<podio::CollectionBase>>(), std::vector<std::string>(),
std::move(frame));
}
m_nextEntry++;
if (m_collectionNames.empty()) {
m_collectionNames = frame.getAvailableCollections();
m_collectionNames = frame.getAvailableCollections();
}
}

if (m_nextEntry >= m_entries) {
// if (true) {
auto ep = serviceLocator()->as<IEventProcessor>();
// if (true) {
auto ep = serviceLocator()->as<IEventProcessor>();
StatusCode sc = ep->stopRun();
if (sc.isFailure()) {
error() << "Error when stopping run" << endmsg;
Expand All @@ -100,8 +99,7 @@ std::tuple<std::vector<std::shared_ptr<podio::CollectionBase>>, std::vector<std:
// After every event if there is still a frame in the TES
// that means it hasn't been written so the collections inside the Frame
// should be removed so that they are deleted when the Frame is deleted
void IOSvc::handle( const Incident& incident ) {

void IOSvc::handle(const Incident& incident) {
StatusCode code;
if (m_hiveWhiteBoard) {
if (!incident.context().valid()) {
Expand All @@ -115,7 +113,7 @@ void IOSvc::handle( const Incident& incident ) {
throw GaudiException("Error when setting store", name(), StatusCode::FAILURE);
}
}
DataObject *p;
DataObject* p;
code = m_dataSvc->retrieveObject("/Event/_Frame", p);
if (code.isFailure()) {
info() << "No frame found" << endmsg;
Expand All @@ -124,7 +122,7 @@ void IOSvc::handle( const Incident& incident ) {

auto frame = dynamic_cast<AnyDataWrapper<podio::Frame>*>(p);
for (const auto& coll : frame->getData().getAvailableCollections()) {
DataObject *collPtr;
DataObject* collPtr;
code = m_dataSvc->retrieveObject("/Event/" + coll, collPtr);
if (code.isSuccess()) {
info() << "Removing collection: " << coll << endmsg;
Expand All @@ -136,16 +134,10 @@ void IOSvc::handle( const Incident& incident ) {
}
}

void IOSvc::setReadingCollectionNames(const std::vector<std::string>& names) {
m_collectionNames = names;
}
void IOSvc::setReadingCollectionNames(const std::vector<std::string>& names) { m_collectionNames = names; }

void IOSvc::setReadingFileNames(const std::vector<std::string>& names) {
m_readingFileNames = names;
}
void IOSvc::setReadingFileNames(const std::vector<std::string>& names) { m_readingFileNames = names; }

bool IOSvc::writeCollection(const std::string& collName) {
return m_switch.isOn(collName);
}
bool IOSvc::writeCollection(const std::string& collName) { return m_switch.isOn(collName); }

DECLARE_COMPONENT(IOSvc)
23 changes: 12 additions & 11 deletions k4FWCore/components/IOSvc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2023 Key4hep-Project.
* Copyright (c) 2014-2024 Key4hep-Project.
*
* This file is part of Key4hep.
* See https://key4hep.github.io/key4hep-doc/ for further info.
Expand All @@ -20,11 +20,11 @@
#define FWCORE_IOSVC_H

#include "Gaudi/Property.h"
#include "GaudiKernel/Service.h"
#include "GaudiKernel/IIncidentListener.h"
#include "GaudiKernel/IIncidentSvc.h"
#include "GaudiKernel/IDataProviderSvc.h"
#include "GaudiKernel/IHiveWhiteBoard.h"
#include "GaudiKernel/IIncidentListener.h"
#include "GaudiKernel/IIncidentSvc.h"
#include "GaudiKernel/Service.h"

#include "podio/ROOTReader.h"
#include "podio/ROOTWriter.h"
Expand All @@ -41,6 +41,7 @@

class IOSvc : public extends<Service, IIOSvc, IIncidentListener> {
using extends::extends;

public:
// Gaudi doesn't run the destructor of the Services so we have to
// manually ask for the writer to be deleted so it will call finish()
Expand All @@ -49,7 +50,8 @@ class IOSvc : public extends<Service, IIOSvc, IIncidentListener> {
StatusCode initialize() override;
StatusCode finalize() override;

std::tuple<std::vector<std::shared_ptr<podio::CollectionBase>>, std::vector<std::string>, podio::Frame> next() override;
std::tuple<std::vector<std::shared_ptr<podio::CollectionBase>>, std::vector<std::string>, podio::Frame> next()
override;

std::shared_ptr<std::vector<std::string>> getCollectionNames() const override {
return std::make_shared<std::vector<std::string>>(m_collectionNames);
Expand All @@ -59,15 +61,14 @@ class IOSvc : public extends<Service, IIOSvc, IIncidentListener> {
void setReadingFileNames(const std::vector<std::string>& names);

protected:

Gaudi::Property<unsigned int> m_bufferNbEvents{
this, "BufferNbEvents", 20000,
"approximate size of the buffer used to prefetch rawbanks in terms of number of events. Default is 20000"};
Gaudi::Property<unsigned int> m_nbSkippedEvents{this, "NSkip", 0, "First event to process"};

Gaudi::Property<std::vector<std::string>> m_collectionNames{this, "CollectionNames", {}, "List of files to read"};
Gaudi::Property<std::vector<std::string>> m_readingFileNames{this, "input", {}, "List of files to read"};
Gaudi::Property<std::string> m_writingFileName{this, "output", {}, "List of files to read"};
Gaudi::Property<std::string> m_writingFileName{this, "output", {}, "List of files to read"};
Gaudi::Property<std::vector<std::string>> m_outputCommands{
this, "outputCommands", {"keep *"}, "A set of commands to declare which collections to keep or drop."};
Gaudi::Property<std::string> m_inputType{this, "ioType", "ROOT", "Type of input file (ROOT, RNTuple)"};
Expand Down Expand Up @@ -98,13 +99,13 @@ class IOSvc : public extends<Service, IIOSvc, IIncidentListener> {
}

SmartIF<IDataProviderSvc> m_dataSvc;
SmartIF<IIncidentSvc> m_incidentSvc;
SmartIF<IHiveWhiteBoard> m_hiveWhiteBoard;
void handle(const Incident& incident) override;
SmartIF<IIncidentSvc> m_incidentSvc;
SmartIF<IHiveWhiteBoard> m_hiveWhiteBoard;
void handle(const Incident& incident) override;

int m_entries{0};
int m_nextEntry{0};

bool writeCollection(const std::string& collName) override;
};

Expand Down
115 changes: 52 additions & 63 deletions k4FWCore/components/Reader.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2023 Key4hep-Project.
* Copyright (c) 2014-2024 Key4hep-Project.
*
* This file is part of Key4hep.
* See https://key4hep.github.io/key4hep-doc/ for further info.
Expand All @@ -18,11 +18,10 @@
*/
#include "Gaudi/Functional/details.h"
#include "Gaudi/Functional/utilities.h"
#include "GaudiKernel/FunctionalFilterDecision.h"
#include "GaudiKernel/StatusCode.h"
#include "GaudiKernel/AnyDataWrapper.h"
#include "GaudiKernel/FunctionalFilterDecision.h"
#include "GaudiKernel/IDataProviderSvc.h"

#include "GaudiKernel/StatusCode.h"

#include "podio/CollectionBase.h"
#include "podio/Frame.h"
Expand All @@ -32,75 +31,65 @@

#include <memory>

template <typename Container>
using vector_of_ = std::vector<Container>;
template <typename Container>
using vector_of_optional_ = std::vector<std::optional<Container>>;

template <typename Container> using vector_of_ = std::vector<Container>;
template <typename Container> using vector_of_optional_ = std::vector<std::optional<Container>>;

class CollectionPusher : public Gaudi::Functional::details::BaseClass_t<Gaudi::Functional::Traits::useDefaults> {
using Traits_ = Gaudi::Functional::Traits::useDefaults;
using Out = std::shared_ptr<podio::CollectionBase>;
using base_class = Gaudi::Functional::details::BaseClass_t<Traits_>;
static_assert(std::is_base_of_v<Algorithm, base_class>, "BaseClass must inherit from Algorithm");

public:
CollectionPusher(std::string name, ISvcLocator* locator) :
base_class(std::move(name), locator)
{}

// derived classes can NOT implement execute
StatusCode execute(const EventContext&) const override final {
try {
auto out = (*this)();

auto outColls = std::get<0>(out);
auto outputLocations = std::get<1>(out);

// if (out.size() != m_outputs.size()) {
// throw GaudiException("Error during transform: expected " + std::to_string(m_outputs.size()) +
// " containers, got " + std::to_string(out.size()) + " instead",
// this->name(), StatusCode::FAILURE);
// }
for (unsigned i = 0; i != outColls.size(); ++i) {
auto objectp = std::make_unique<AnyDataWrapper<Out>>( std::move( outColls[i] ) );
if ( auto sc = m_dataSvc->registerObject( outputLocations[i], objectp.get() ); sc.isFailure() ) {
}
// The store has the ownership so we shouldn't delete the object
auto ptr = objectp.release();
using Traits_ = Gaudi::Functional::Traits::useDefaults;
using Out = std::shared_ptr<podio::CollectionBase>;
using base_class = Gaudi::Functional::details::BaseClass_t<Traits_>;
static_assert(std::is_base_of_v<Algorithm, base_class>, "BaseClass must inherit from Algorithm");

public:
CollectionPusher(std::string name, ISvcLocator* locator) : base_class(std::move(name), locator) {}

// derived classes can NOT implement execute
StatusCode execute(const EventContext&) const override final {
try {
auto out = (*this)();

auto outColls = std::get<0>(out);
auto outputLocations = std::get<1>(out);

// if (out.size() != m_outputs.size()) {
// throw GaudiException("Error during transform: expected " + std::to_string(m_outputs.size()) +
// " containers, got " + std::to_string(out.size()) + " instead",
// this->name(), StatusCode::FAILURE);
// }
for (unsigned i = 0; i != outColls.size(); ++i) {
auto objectp = std::make_unique<AnyDataWrapper<Out>>(std::move(outColls[i]));
if (auto sc = m_dataSvc->registerObject(outputLocations[i], objectp.get()); sc.isFailure()) {
}
return Gaudi::Functional::FilterDecision::PASSED;
} catch (GaudiException& e) {
(e.code() ? this->warning() : this->error()) << e.tag() << " : " << e.message() << endmsg;
return e.code();
// The store has the ownership so we shouldn't delete the object
auto ptr = objectp.release();
}
return Gaudi::Functional::FilterDecision::PASSED;
} catch (GaudiException& e) {
(e.code() ? this->warning() : this->error()) << e.tag() << " : " << e.message() << endmsg;
return e.code();
}
}

virtual std::tuple<vector_of_<Out>, std::vector<std::string>> operator()() const = 0;

private:
// if In is a pointer, it signals optional (as opposed to mandatory) input
// template <typename T>
// using InputHandle_t = InputHandle_t<Traits_, std::remove_pointer_t<T>>;
// Gaudi::Property<std::vector<DataObjID>> m_inputLocations; // TODO/FIXME: remove this duplication...
// TODO/FIXME: replace vector of DataObjID property + call-back with a
// vector<handle> property ... as soon as declareProperty can deal with that.
ServiceHandle<IDataProviderSvc> m_dataSvc{this, "EventDataSvc", "EventDataSvc"};
virtual std::tuple<vector_of_<Out>, std::vector<std::string>> operator()() const = 0;

};
private:
// if In is a pointer, it signals optional (as opposed to mandatory) input
// template <typename T>
// using InputHandle_t = InputHandle_t<Traits_, std::remove_pointer_t<T>>;
// Gaudi::Property<std::vector<DataObjID>> m_inputLocations; // TODO/FIXME: remove this duplication...
// TODO/FIXME: replace vector of DataObjID property + call-back with a
// vector<handle> property ... as soon as declareProperty can deal with that.
ServiceHandle<IDataProviderSvc> m_dataSvc{this, "EventDataSvc", "EventDataSvc"};
};

class Reader final : public CollectionPusher {
public:
Reader(const std::string& name, ISvcLocator* svcLoc) :
CollectionPusher(name, svcLoc) {
}
Reader(const std::string& name, ISvcLocator* svcLoc) : CollectionPusher(name, svcLoc) {}

// Gaudi doesn't run the destructor of the Services so we have to
// manually ask for the reader to be deleted so it will call finish()
// See https://gitlab.cern.ch/gaudi/Gaudi/-/issues/169
~Reader() {
iosvc->deleteReader();
}
~Reader() { iosvc->deleteReader(); }

ServiceHandle<IIOSvc> iosvc{this, "IOSvc", "IOSvc"};

Expand All @@ -123,18 +112,18 @@ class Reader final : public CollectionPusher {
// The IOSvc takes care of reading and passing the data
// By convention the Frame is pushed to the store
// so that it's deleted at the right time
std::tuple<std::vector<std::shared_ptr<podio::CollectionBase>>, std::vector<std::string>> operator()() const override {
std::tuple<std::vector<std::shared_ptr<podio::CollectionBase>>, std::vector<std::string>> operator()()
const override {
auto val = iosvc->next();

auto eds = eventSvc().as<IDataProviderSvc>();
auto eds = eventSvc().as<IDataProviderSvc>();
auto frame = std::move(std::get<2>(val));

auto tmp = new AnyDataWrapper<podio::Frame>(std::move(frame));
auto tmp = new AnyDataWrapper<podio::Frame>(std::move(frame));
auto code = eds->registerObject("/Event" + k4FWCore::frameLocation, tmp);

return std::make_tuple(std::get<0>(val), std::get<1>(val));
}

};

DECLARE_COMPONENT(Reader)
5 changes: 2 additions & 3 deletions k4FWCore/components/Writer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* * Copyright (c) 2014-2023 Key4hep-Project.
/* * Copyright (c) 2014-2024 Key4hep-Project.
*
* This file is part of Key4hep.
* See https://key4hep.github.io/key4hep-doc/ for further info.
Expand Down Expand Up @@ -71,7 +71,6 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
}

StatusCode finalize() override {

podio::Frame config_metadata_frame;

//// prepare job options metadata ///////////////////////
Expand All @@ -92,7 +91,7 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
// and have to be traversed like this. Note that Gaudi!577 will improve this.
for (const auto* name : {"NTupleSvc"}) {
std::stringstream config_stream;
auto svc = service<IProperty>(name);
auto svc = service<IProperty>(name);
if (!svc.isValid())
continue;
for (const auto* property : svc->getProperties()) {
Expand Down
6 changes: 3 additions & 3 deletions k4FWCore/include/k4FWCore/BaseClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
#ifndef K4FWCORE_FUNCTIONALUTILS_H
#define K4FWCORE_FUNCTIONALUTILS_H



#include "GaudiAlg/GaudiAlgorithm.h"
#include "GaudiKernel/DataObjectHandle.h"
#include "k4FWCore/DataWrapper.h"

// Base class used for the Traits template argument of the
// Gaudi::Functional algorithms
struct [[deprecated("Functional algorithms using the BaseClass.h header are deprecated and will be removed in the future")]] BaseClass_t {
struct [[deprecated(
"Functional algorithms using the BaseClass.h header are deprecated and will be removed in the "
"future")]] BaseClass_t {
template <typename T> using InputHandle = DataObjectReadHandle<DataWrapper<T>>;
template <typename T> using OutputHandle = DataObjectWriteHandle<DataWrapper<T>>;

Expand Down
3 changes: 1 addition & 2 deletions k4FWCore/include/k4FWCore/Consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ namespace k4FWCore {
Gaudi::Functional::details::RepeatValues_<KeyValues, sizeof...(In)> const& inputs)
: Consumer(std::move(name), locator, inputs, std::index_sequence_for<In...>{}) {}

template <size_t Index, typename... Handles>
void readMapInputs(const std::tuple<Handles...>& handles) const {
template <size_t Index, typename... Handles> void readMapInputs(const std::tuple<Handles...>& handles) const {
if constexpr (Index < sizeof...(Handles)) {
if constexpr (is_map_like<std::tuple_element_t<Index, std::tuple<In...>>>::value) {
using EDM4hepType =
Expand Down
Loading

0 comments on commit e621800

Please sign in to comment.