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