File indexing completed on 2025-01-18 09:55:45
0001
0002
0003
0004 #pragma once
0005
0006 #include <algorithms/logger.h>
0007 #include "PIDLookupTable.h"
0008 #include <JANA/Services/JServiceLocator.h>
0009 #include <JANA/JLogger.h>
0010 #include <mutex>
0011 #include <filesystem>
0012
0013 namespace eicrecon {
0014
0015 class PIDLookupTableSvc : public algorithms::LoggedService<PIDLookupTableSvc> {
0016 public:
0017 void init() {};
0018
0019 const PIDLookupTable* load(std::string filename, const PIDLookupTable::Binning &binning) {
0020 std::lock_guard<std::mutex> lock(m_mutex);
0021 auto pair = m_cache.find(filename);
0022 if (pair == m_cache.end()) {
0023 auto lut = std::make_unique<PIDLookupTable>();
0024 info("Loading PID lookup table \"{}\"", filename);
0025
0026 if (!std::filesystem::exists(filename)) {
0027 error("PID lookup table \"{}\" not found", filename);
0028 return nullptr;
0029 }
0030
0031 lut->load_file(filename, binning);
0032 auto result_ptr = lut.get();
0033 m_cache.insert({filename, std::move(lut)});
0034 return result_ptr;
0035 }
0036 else {
0037 return pair->second.get();
0038 }
0039 }
0040
0041 private:
0042 std::mutex m_mutex;
0043 std::map<std::string, std::unique_ptr<PIDLookupTable>> m_cache;
0044
0045 ALGORITHMS_DEFINE_LOGGED_SERVICE(PIDLookupTableSvc);
0046 };
0047
0048 }