8#ifdef USE_BOOST_FILESYSTEM
9 #include <boost/filesystem.hpp>
16 sio::block(
"CollectionIDs", sio::version::encode_version(0, 3)) {
18 _names = table->names();
20 _types.reserve(_names.size());
21 _isSubsetColl.reserve(_names.size());
22 for (
const int id : _ids) {
24 if (!store->
get(
id, tmp)) {
26 <<
"PODIO-ERROR cannot construct CollectionIDTableBlock because a collection is missing from the store (id: "
27 <<
id <<
", name: " << table->name(
id) <<
")" << std::endl;
39 if (version >= sio::version::encode_version(0, 2)) {
40 device.data(_isSubsetColl);
49 device.data(_isSubsetColl);
63 if (version >= sio::version::encode_version(0, 2)) {
85 data->emplace(
id, std::move(params));
90 device.data((
int)
data->size());
91 for (
const auto& [
id, params] : *
data) {
98 const bool isSubsetColl)
const {
99 const auto it = _map.find(typeStr);
101 if (it != _map.end()) {
102 auto blk = std::shared_ptr<SIOBlock>(it->second->create(name));
103 blk->createBuffers(isSubsetColl);
111 const std::string& name)
const {
113 const auto it = _map.find(typeStr);
115 if (it != _map.end()) {
116 auto blk = std::shared_ptr<SIOBlock>(it->second->create(name));
124SIOBlockLibraryLoader::SIOBlockLibraryLoader() {
125 for (
const auto& [lib, dir] : getLibNames()) {
126 const auto status = loadLib(lib);
128 case LoadStatus::Success:
129 std::cerr <<
"Loaded SIOBlocks library \'" << lib <<
"\' (from " << dir <<
")" << std::endl;
131 case LoadStatus::AlreadyLoaded:
132 std::cerr <<
"SIOBlocks library \'" << lib <<
"\' already loaded. Not loading again from " << dir << std::endl;
134 case LoadStatus::Error:
135 std::cerr <<
"ERROR while loading SIOBlocks library \'" << lib <<
"\' (from " << dir <<
")" << std::endl;
141SIOBlockLibraryLoader::LoadStatus SIOBlockLibraryLoader::loadLib(
const std::string& libname) {
142 if (_loadedLibs.find(libname) != _loadedLibs.end()) {
143 return LoadStatus::AlreadyLoaded;
145 void* libhandle = dlopen(libname.c_str(), RTLD_LAZY | RTLD_GLOBAL);
147 _loadedLibs.insert({libname, libhandle});
148 return LoadStatus::Success;
151 return LoadStatus::Error;
154std::vector<std::tuple<std::string, std::string>> SIOBlockLibraryLoader::getLibNames() {
155#ifdef USE_BOOST_FILESYSTEM
156 namespace fs = boost::filesystem;
158 namespace fs = std::filesystem;
160 std::vector<std::tuple<std::string, std::string>> libs;
163 const auto ldLibPath = std::getenv(
"LD_LIBRARY_PATH");
167 std::istringstream stream(ldLibPath);
168 while (std::getline(stream, dir,
':')) {
169 if (not fs::exists(dir)) {
173 for (
auto& lib : fs::directory_iterator(dir)) {
174 const auto filename = lib.path().filename().string();
175 if (filename.find(
"SioBlocks") != std::string::npos) {
176 libs.emplace_back(std::move(filename), dir);
186 std::find_if(m_recordMap.begin(), m_recordMap.end(), [&name](
const auto& entry) { return entry.first == name; });
188 if (it == m_recordMap.end()) {
189 m_recordMap.push_back({name, {startPos}});
191 it->second.push_back(startPos);
196 const auto it = std::find_if(m_recordMap.cbegin(), m_recordMap.cend(),
197 [&name](
const auto& entry) { return entry.first == name; });
198 if (it != m_recordMap.cend()) {
199 return it->second.size();
205 const auto it = std::find_if(m_recordMap.cbegin(), m_recordMap.cend(),
206 [&name](
const auto& keyVal) { return keyVal.first == name; });
207 if (it != m_recordMap.end()) {
208 if (iEntry < it->second.size()) {
209 return it->second[iEntry];
217 std::vector<std::string_view> cats;
218 cats.reserve(m_recordMap.size());
219 for (
const auto& [cat, _] : m_recordMap) {
220 cats.emplace_back(cat);
232 std::vector<SIOFileTOCRecord::PositionType> positions;
233 device.data(positions);
235 record->m_recordMap.emplace_back(std::move(name), std::move(positions));
240 device.data((
int)
record->m_recordMap.size());
241 for (
const auto& [name, positions] :
record->m_recordMap) {
243 device.data(positions);
virtual std::string getValueTypeName() const =0
fully qualified type name of elements - with namespace
virtual bool isSubsetCollection() const =0
check if this collection is a subset collection
bool get(const std::string &name, const T *&collection)
access a collection by name. returns true if successful
CollectionIDTable * getCollectionIDTable() const
const StringMap & getStringMap() const
const IntMap & getIntMap() const
const FloatMap & getFloatMap() const
const DoubleMap & getDoubleMap() const
std::shared_ptr< SIOBlock > createBlock(const podio::CollectionBase *col, const std::string &name) const
SIOCollectionIDTableBlock()
void write(sio::write_device &device) override
void read(sio::read_device &device, sio::version_type version) override
PositionType getPosition(const std::string &name, unsigned iEntry=0) const
size_t getNRecords(const std::string &name) const
sio_helpers::position_type PositionType
std::vector< std::string_view > getRecordNames() const
void addRecord(const std::string &name, PositionType startPos)
void readGenericParameters(sio::read_device &device, GenericParameters ¶ms, sio::version_type version)
void readMapLike(sio::read_device &device, MapLikeT &map)
Read anything that iterates like an std::map.
void writeGenericParameters(sio::write_device &device, const GenericParameters ¶ms)
void writeMapLike(sio::write_device &device, const MapLikeT &map)
Write anything that iterates like an std::map.
void read(sio::read_device &device, sio::version_type version) override
void write(sio::write_device &device) override
SIOFileTOCRecord * record