File indexing completed on 2025-12-14 10:19:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef FWCORE_PODIODATASVC_H
0020 #define FWCORE_PODIODATASVC_H
0021
0022 #include "GaudiKernel/DataSvc.h"
0023 #include "GaudiKernel/IConversionSvc.h"
0024
0025 #include "podio/CollectionBase.h"
0026 #include "podio/CollectionIDTable.h"
0027 #include "podio/Frame.h"
0028 #include "podio/ROOTReader.h"
0029 #include <utility>
0030
0031 #include "k4FWCore/DataWrapper.h"
0032 class DataWrapperBase;
0033 class PodioOutput;
0034 namespace k4FWCore {
0035 template <typename T>
0036 class MetaDataHandle;
0037 }
0038
0039
0040
0041
0042
0043
0044
0045 class PodioDataSvc : public DataSvc {
0046 template <typename T>
0047 friend class k4FWCore::MetaDataHandle;
0048 friend class PodioOutput;
0049 friend class Lcio2EDM4hepTool;
0050
0051 public:
0052 typedef std::vector<std::pair<std::string, podio::CollectionBase*>> CollRegistry;
0053
0054 StatusCode initialize() final;
0055 StatusCode reinitialize() final;
0056 StatusCode finalize() final;
0057 StatusCode clearStore() final;
0058 StatusCode i_setRoot(std::string root_path, IOpaqueAddress* pRootAddr) final;
0059 StatusCode i_setRoot(std::string root_path, DataObject* pRootObj) final;
0060
0061
0062 PodioDataSvc(const std::string& name, ISvcLocator* svc);
0063
0064
0065 using DataSvc::registerObject;
0066
0067
0068 StatusCode registerObject(std::string_view parentPath, std::string_view fullPath, DataObject* pObject) final;
0069
0070 const std::string_view getCollectionType(const std::string& collName);
0071
0072 template <typename T>
0073 StatusCode readCollection(const std::string& collName) {
0074 DataObject* objectPtr = nullptr;
0075 if (DataSvc::findObject("/Event", "/" + collName, objectPtr)) {
0076 debug() << "Collection " << collName << " already read, not reading it again" << endmsg;
0077 return StatusCode::SUCCESS;
0078 }
0079 const T* collection(nullptr);
0080 collection = static_cast<const T*>(m_eventframe.get(collName));
0081 if (collection == nullptr) {
0082 error() << "Collection " << collName << " does not exist." << endmsg;
0083 }
0084 auto wrapper = new DataWrapper<T>;
0085 wrapper->setData(collection);
0086 m_podio_datawrappers.push_back(wrapper);
0087 return DataSvc::registerObject("/Event", "/" + collName, wrapper);
0088 }
0089
0090 const podio::Frame& getEventFrame() const { return m_eventframe; }
0091
0092
0093 void endOfRead();
0094
0095
0096 podio::Frame& getMetaDataFrame() { return m_metadataframe; }
0097
0098 void setCollsToRead(const std::vector<std::string>& collsToRead) { m_collsToRead = collsToRead; }
0099
0100 private:
0101
0102 podio::ROOTReader m_reader;
0103
0104 podio::Frame m_eventframe;
0105
0106 podio::Frame m_metadataframe;
0107
0108 int m_eventNum{0};
0109
0110 int m_numAvailableEvents{-1};
0111 int m_requestedEventMax{-1};
0112
0113 bool m_reading_from_file{false};
0114
0115 SmartIF<IConversionSvc> m_cnvSvc;
0116
0117
0118 std::vector<DataWrapperBase*> m_podio_datawrappers;
0119
0120 std::vector<std::string> m_collsToRead{};
0121
0122 protected:
0123
0124 std::vector<std::string> m_filenames;
0125 std::string m_filename;
0126
0127
0128 unsigned m_1stEvtEntry{0};
0129 bool m_bounds_check_needed{true};
0130 };
0131 #endif