Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:15:25

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2024, Nathan Brei, Dmitry Kalinkin
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); // load_file can except
0032       auto result_ptr = lut.get();
0033       m_cache.insert({filename, std::move(lut)});
0034       return result_ptr;
0035     } else {
0036       return pair->second.get();
0037     }
0038   }
0039 
0040 private:
0041   std::mutex m_mutex;
0042   std::map<std::string, std::unique_ptr<PIDLookupTable>> m_cache;
0043 
0044   ALGORITHMS_DEFINE_LOGGED_SERVICE(PIDLookupTableSvc);
0045 };
0046 
0047 } // namespace eicrecon