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

[WIP] Merge the PodioDataSvc into k4DataSvc #163

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions k4FWCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ gaudi_install(PYTHON)


gaudi_add_library(k4FWCore
SOURCES src/PodioDataSvc.cpp
src/KeepDropSwitch.cpp
LINK Gaudi::GaudiKernel podio::podioRootIO ROOT::Core ROOT::RIO ROOT::Tree
)
SOURCES src/k4DataSvc.cpp
src/KeepDropSwitch.cpp
LINK Gaudi::GaudiKernel podio::podioRootIO ROOT::Core ROOT::RIO ROOT::Tree
)
target_include_directories(k4FWCore PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
Expand Down
6 changes: 3 additions & 3 deletions k4FWCore/components/PodioInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "PodioInput.h"
#include "Gaudi/Functional/Consumer.h"

#include "k4FWCore/PodioDataSvc.h"
#include "k4FWCore/k4DataSvc.h"

#include "edm4hep/CaloHitContributionCollection.h"
#include "edm4hep/CalorimeterHitCollection.h"
Expand Down Expand Up @@ -194,9 +194,9 @@ PodioInput::PodioInput(const std::string& name, ISvcLocator* svcLoc) : Consumer(
return;

// check whether we have the PodioEvtSvc active
m_podioDataSvc = dynamic_cast<PodioDataSvc*>(evtSvc().get());
m_podioDataSvc = dynamic_cast<k4DataSvc*>(evtSvc().get());
if (!m_podioDataSvc) {
error() << "Could not get PodioDataSvc" << endmsg;
error() << "Could not get k4DataSvc" << endmsg;
}
fillReaders();
}
Expand Down
4 changes: 2 additions & 2 deletions k4FWCore/components/PodioInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <string>
#include <vector>

class PodioDataSvc;
class k4DataSvc;

/** @class PodioInput
*
Expand All @@ -51,7 +51,7 @@ class PodioInput final : public Gaudi::Functional::Consumer<void(), BaseClass_t>
Gaudi::Property<std::vector<std::string>> m_collectionNames{
this, "collections", {}, "Collections that should be read (default all)"};
// Data service: needed to register objects and get collection IDs. Just an observing pointer.
PodioDataSvc* m_podioDataSvc;
k4DataSvc* m_podioDataSvc;
mutable std::map<std::string_view, std::function<void(std::string_view)>> m_readers;
};

Expand Down
4 changes: 2 additions & 2 deletions k4FWCore/components/PodioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "GaudiKernel/MsgStream.h"

#include "PodioOutput.h"
#include "k4FWCore/PodioDataSvc.h"
#include "k4FWCore/k4DataSvc.h"
#include "rootUtils.h"

DECLARE_COMPONENT(PodioOutput)
Expand All @@ -36,7 +36,7 @@ StatusCode PodioOutput::initialize() {
return StatusCode::FAILURE;

// check whether we have the PodioEvtSvc active
m_podioDataSvc = dynamic_cast<PodioDataSvc*>(evtSvc().get());
m_podioDataSvc = dynamic_cast<k4DataSvc*>(evtSvc().get());
if (nullptr == m_podioDataSvc) {
error() << "Could not get DataSvc!" << endmsg;
return StatusCode::FAILURE;
Expand Down
6 changes: 3 additions & 3 deletions k4FWCore/components/PodioOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace podio {
#include <vector>

// forward declarations
class PodioDataSvc;
class k4DataSvc;

class PodioOutput : public Gaudi::Algorithm {
public:
Expand All @@ -44,7 +44,7 @@ class PodioOutput : public Gaudi::Algorithm {

/// Initialization of PodioOutput. Acquires the data service, creates trees and root file.
StatusCode initialize();
/// Execute. For the first event creates branches for all collections known to PodioDataSvc and prepares them for
/// Execute. For the first event creates branches for all collections known to k4DataSvc and prepares them for
/// writing. For the following events it reconnects the branches with collections and prepares them for write.
StatusCode execute(const EventContext&) const;
/// Finalize. Writes the meta data tree; writes file and cleans up all ROOT-pointers.
Expand All @@ -62,7 +62,7 @@ class PodioOutput : public Gaudi::Algorithm {
"An optional file path to copy the outputfile to."};
/// Switch for keeping or dropping outputs
KeepDropSwitch m_switch;
PodioDataSvc* m_podioDataSvc;
k4DataSvc* m_podioDataSvc;
/// The actual ROOT frame writer
std::unique_ptr<podio::ROOTWriter> m_framewriter;
/// The stored collections
Expand Down
13 changes: 1 addition & 12 deletions k4FWCore/components/k4DataSvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "k4DataSvc.h"
#include "k4FWCore/k4DataSvc.h"

// Instantiation of a static factory class used by clients to create
// instances of this service
DECLARE_COMPONENT(k4DataSvc)

/// Standard Constructor
k4DataSvc::k4DataSvc(const std::string& name, ISvcLocator* svc) : PodioDataSvc(name, svc) {
declareProperty("inputs", m_filenames = {}, "Names of the files to read");
declareProperty("input", m_filename = "", "Name of the file to read");
declareProperty("FirstEventEntry", m_1stEvtEntry = 0, "First event to read");
}

/// Standard Destructor
k4DataSvc::~k4DataSvc() {}
33 changes: 0 additions & 33 deletions k4FWCore/components/k4DataSvc.h

This file was deleted.

4 changes: 2 additions & 2 deletions k4FWCore/include/k4FWCore/DataHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define K4FWCORE_DATAHANDLE_H

#include "k4FWCore/DataWrapper.h"
#include "k4FWCore/PodioDataSvc.h"
#include "k4FWCore/k4DataSvc.h"

#include "Gaudi/Algorithm.h"
#include "GaudiKernel/DataObjectHandle.h"
Expand Down Expand Up @@ -93,7 +93,7 @@ DataHandle<T>::DataHandle(const std::string& descriptor, Gaudi::DataHandle::Mode
if (a == Gaudi::DataHandle::Writer) {
m_eds.retrieve().ignore();
m_dataPtr = nullptr;
auto* podio_data_service = dynamic_cast<PodioDataSvc*>(m_eds.get());
auto* podio_data_service = dynamic_cast<k4DataSvc*>(m_eds.get());
if (nullptr != podio_data_service) {
if constexpr (std::is_integral_v<T> || std::is_floating_point_v<T>) {
m_dataPtr = new T();
Expand Down
18 changes: 9 additions & 9 deletions k4FWCore/include/k4FWCore/MetaDataHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// GAUDI
#include "Gaudi/Algorithm.h"

#include "k4FWCore/PodioDataSvc.h"
#include "k4FWCore/k4DataSvc.h"
#include "podio/GenericParameters.h"

#include "GaudiKernel/MsgStream.h"
Expand All @@ -41,12 +41,12 @@ template <typename T> class MetaDataHandle {

private:
std::string fullDescriptor() const;
void checkPodioDataSvc();
void checkk4DataSvc();

private:
ServiceHandle<IDataProviderSvc> m_eds;
std::string m_descriptor;
PodioDataSvc* m_podio_data_service{nullptr};
k4DataSvc* m_podio_data_service{nullptr};
const Gaudi::DataHandle* m_dataHandle{nullptr}; // holds the identifier in case we do collection metadata
Gaudi::DataHandle::Mode m_mode;
};
Expand All @@ -58,8 +58,8 @@ template <typename T>
MetaDataHandle<T>::MetaDataHandle(const std::string& descriptor, Gaudi::DataHandle::Mode a)
: m_eds("EventDataSvc", "DataHandle"), m_descriptor(descriptor), m_mode(a) {
m_eds.retrieve().ignore();
m_podio_data_service = dynamic_cast<PodioDataSvc*>(m_eds.get());
checkPodioDataSvc();
m_podio_data_service = dynamic_cast<k4DataSvc*>(m_eds.get());
checkk4DataSvc();
}

//---------------------------------------------------------------------------
Expand All @@ -68,8 +68,8 @@ MetaDataHandle<T>::MetaDataHandle(const Gaudi::DataHandle& handle, const std::st
Gaudi::DataHandle::Mode a)
: m_eds("EventDataSvc", "DataHandle"), m_descriptor(descriptor), m_dataHandle(&handle), m_mode(a) {
m_eds.retrieve().ignore();
m_podio_data_service = dynamic_cast<PodioDataSvc*>(m_eds.get());
checkPodioDataSvc();
m_podio_data_service = dynamic_cast<k4DataSvc*>(m_eds.get());
checkk4DataSvc();
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -109,14 +109,14 @@ template <typename T> std::string MetaDataHandle<T>::fullDescriptor() const {
}

//---------------------------------------------------------------------------
template <typename T> void MetaDataHandle<T>::checkPodioDataSvc() {
template <typename T> void MetaDataHandle<T>::checkk4DataSvc() {
// do not do this check during the genconf step
const std::string cmd = System::cmdLineArgs()[0];
if (cmd.find("genconf") != std::string::npos)
return;

if (nullptr == m_podio_data_service) {
std::cout << "ERROR: MetaDataHandles require the PodioDataSvc" << std::endl;
std::cout << "ERROR: MetaDataHandles require the k4DataSvc" << std::endl;
}
}

Expand Down
118 changes: 5 additions & 113 deletions k4FWCore/include/k4FWCore/PodioDataSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,119 +16,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FWCORE_PODIODATASVC_H
#define FWCORE_PODIODATASVC_H
#ifndef K4FWCORE_PODIODATASVC_H
#define K4FWCORE_PODIODATASVC_H

#include "GaudiKernel/DataSvc.h"
#include "GaudiKernel/IConversionSvc.h"
// PODIO
#include <utility>
#include "podio/CollectionBase.h"
#include "podio/CollectionIDTable.h"
#include "podio/Frame.h"
#include "podio/podioVersion.h"
#if PODIO_BUILD_VERSION >= PODIO_VERSION(0, 99, 0)
#include "podio/ROOTReader.h"
#else
#include "podio/ROOTFrameReader.h"
namespace podio {
using ROOTReader = podio::ROOTFrameReader;
}
#endif
// Forward declarations
#include "k4FWCore/DataWrapper.h"
class DataWrapperBase;
class PodioOutput;
template <typename T> class MetaDataHandle;

/** @class PodioEvtSvc EvtDataSvc.h
*
* An EvtDataSvc for PODIO classes
*
* @author B. Hegner
*/
class PodioDataSvc : public DataSvc {
template <typename T> friend class MetaDataHandle;
friend class PodioOutput;
friend class Lcio2EDM4hepTool;

public:
typedef std::vector<std::pair<std::string, podio::CollectionBase*>> CollRegistry;

StatusCode initialize() final;
StatusCode reinitialize() final;
StatusCode finalize() final;
StatusCode clearStore() final;
StatusCode i_setRoot(std::string root_path, IOpaqueAddress* pRootAddr) final;
StatusCode i_setRoot(std::string root_path, DataObject* pRootObj) final;

/// Standard Constructor
PodioDataSvc(const std::string& name, ISvcLocator* svc);

/// Standard Destructor
virtual ~PodioDataSvc();
#include "k4FWCore/k4DataSvc.h"

// Use DataSvc functionality except where we override
using DataSvc::registerObject;
/// Overriding standard behaviour of evt service
/// Register object with the data store.
virtual StatusCode registerObject(std::string_view parentPath, std::string_view fullPath,
DataObject* pObject) override final;
using PodioDataSvc [[deprecated("Use k4DataSvc instead")]] = k4DataSvc;

const std::string_view getCollectionType(const std::string& collName);

template <typename T> StatusCode readCollection(const std::string& collName) {
DataObject* objectPtr = nullptr;
if (DataSvc::findObject("/Event", "/" + collName, objectPtr)) {
debug() << "Collection " << collName << " already read, not reading it again" << endmsg;
return StatusCode::SUCCESS;
}
const T* collection(nullptr);
collection = static_cast<const T*>(m_eventframe.get(collName));
if (collection == nullptr) {
error() << "Collection " << collName << " does not exist." << endmsg;
}
auto wrapper = new DataWrapper<T>;
wrapper->setData(collection);
m_podio_datawrappers.push_back(wrapper);
return DataSvc::registerObject("/Event", "/" + collName, wrapper);
}

const podio::Frame& getEventFrame() const { return m_eventframe; }

/// Resets caches of reader and event store, increases event counter
void endOfRead();

/// TODO: Make this private again after conversions have been properly solved
podio::Frame& getMetaDataFrame() { return m_metadataframe; }

private:
/// PODIO reader for ROOT files
podio::ROOTReader m_reader;
/// PODIO Frame, used to initialise collections
podio::Frame m_eventframe;
/// PODIO Frame, used to store metadata
podio::Frame m_metadataframe;
/// Counter of the event number
int m_eventNum{0};
/// Number of events in the file / to process
int m_numAvailableEvents{-1};
int m_requestedEventMax{-1};
/// Whether reading from file at all
bool m_reading_from_file{false};

SmartIF<IConversionSvc> m_cnvSvc;

// Registry of data wrappers; needed for memory management
std::vector<DataWrapperBase*> m_podio_datawrappers;

protected:
/// ROOT file name the input is read from. Set by option filename
std::vector<std::string> m_filenames;
std::string m_filename;
/// Jump to nth events at the beginning. Set by option FirstEventEntry
/// This option is helpful when we want to debug an event in the middle of a file
unsigned m_1stEvtEntry{0};
bool m_bounds_check_needed{true};
};
#endif // CORE_PODIODATASVC_H
#endif
Loading
Loading