-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move k4DataSvc to core library - Make PodioDataSvc an alias for now
- Loading branch information
Showing
8 changed files
with
171 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* 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. | ||
*/ | ||
#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/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 k4DataSvc | ||
* | ||
* An EvtDataSvc for PODIO classes | ||
* | ||
* @author B. Hegner | ||
*/ | ||
class k4DataSvc : 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 | ||
k4DataSvc(const std::string& name, ISvcLocator* svc); | ||
|
||
/// Standard Destructor | ||
virtual ~k4DataSvc(); | ||
|
||
// 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; | ||
|
||
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 |
Oops, something went wrong.