EICrecon
JANA based reconstruction for the EPIC detector
Loading...
Searching...
No Matches
PIDLookupTableSvc.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// Copyright (C) 2024, Nathan Brei, Dmitry Kalinkin
3
4#pragma once
5
6#include <algorithms/logger.h>
7#include "PIDLookupTable.h"
8#include <JANA/Services/JServiceLocator.h>
9#include <JANA/JLogger.h>
10#include <mutex>
11#include <filesystem>
12
13namespace eicrecon {
14
15class PIDLookupTableSvc : public algorithms::LoggedService<PIDLookupTableSvc> {
16public:
17 void init() {};
18
19 const PIDLookupTable* load(std::string filename, const PIDLookupTable::Binning& binning) {
20 std::lock_guard<std::mutex> lock(m_mutex);
21 auto pair = m_cache.find(filename);
22 if (pair == m_cache.end()) {
23 auto lut = std::make_unique<PIDLookupTable>();
24 info("Loading PID lookup table \"{}\"", filename);
25
26 if (!std::filesystem::exists(filename)) {
27 error("PID lookup table \"{}\" not found", filename);
28 return nullptr;
29 }
30
31 lut->load_file(filename, binning); // load_file can except
32 auto result_ptr = lut.get();
33 m_cache.insert({filename, std::move(lut)});
34 return result_ptr;
35 } else {
36 return pair->second.get();
37 }
38 }
39
40private:
41 std::mutex m_mutex;
42 std::map<std::string, std::unique_ptr<PIDLookupTable>> m_cache;
43
44 ALGORITHMS_DEFINE_LOGGED_SERVICE(PIDLookupTableSvc);
45};
46
47} // namespace eicrecon
Definition PIDLookupTableSvc.h:15
const PIDLookupTable * load(std::string filename, const PIDLookupTable::Binning &binning)
Definition PIDLookupTableSvc.h:19
void init()
Definition PIDLookupTableSvc.h:17
Definition PIDLookupTable.h:16
-client
Definition CalorimeterClusterRecoCoG.cc:37
Definition PIDLookupTable.h:24