ATLAS Offline Software
Loading...
Searching...
No Matches
CSVTablesBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5#ifndef OFFLINE_DECODER
6#include "ersL1Calo/Exceptions.h"
7#else
9#endif
10#include <fstream>
11#include <iostream>
12#include <cstdlib>
13#include <vector>
14/* \class CSVTables
15 * Simple class that when called generates a CSVWrapper
16 * for all 5 tables within data with access methods only when
17 * an individual table is called
18 */
19
20CSVTablesBase::CSVTablesBase(const std::string & subsystem) : m_subsystem(subsystem){
21 //Loop to set all table 'open' flags to false
22 for(auto& openbools: m_table_opens){
23 openbools = false;
24 }
25}
26std::shared_ptr<CSVWrapper> CSVTablesBase::GetTable(int table_num) {
27 //Check if table not open, the construct table
28 std::string suffixName = m_subsystem + "Map"
29 + std::to_string(table_num)
30 + ".csv";
31 if( not (m_table_opens.at(table_num-1) )){
32#ifdef OFFLINE_DECODER
33 auto mappingfilename = PathResolver::find_file("L1CaloFEXByteStream/2022-07-22/" + suffixName,"CALIBPATH");
34 auto file = std::ifstream(mappingfilename, std::ifstream::in);
35 if (!mappingfilename.empty() && file.good()) {
36 m_tables.at(table_num-1) = std::make_shared<CSVWrapper> (file);
37 m_table_opens.at(table_num-1) = true;
38 return m_tables.at(table_num-1);
39 } else {
40 throw std::runtime_error(std::string("Cannot find file ") + suffixName);
41 }
42#else
43 const char* l1caloRootEnv = std::getenv("L1CALO_ROOT");
44 if (!l1caloRootEnv) {
45 throw l1calo::EnvUndefined(ERS_HERE,"L1CALO_ROOT");
46 }
47 // To be able to use updated mappings while building the release
48 // check for files in the source area then the installed area.
49 std::string l1caloRoot(l1caloRootEnv);
50 auto baseDir = l1caloRoot.substr(0,l1caloRoot.find_last_of("/"));
51 std::vector<std::string> mapDirs = {
52 baseDir + "/channelMappings/data/",
53 baseDir + "/installed/share/data/channelMappings/",
54 };
55 for (auto& basePath: mapDirs) {
56 auto mappingfilename = basePath + suffixName;
57 auto file = std::ifstream(mappingfilename, std::ifstream::in);
58 if (file.good()) {
59 m_tables.at(table_num-1) = std::make_shared<CSVWrapper> (file);
60 m_table_opens.at(table_num-1) = true;
61 return m_tables.at(table_num-1);
62 }
63 }
64 std::string suffixPath = suffixName + " (under " + baseDir + ")";
65 throw l1calo::FileError(ERS_HERE,"open",suffixPath);
66#endif
67 }
68 return m_tables.at(table_num-1);
69}
std::array< std::shared_ptr< CSVWrapper >, 6 > m_tables
std::string m_subsystem
std::shared_ptr< CSVWrapper > GetTable(int table_num)
std::array< bool, 6 > m_table_opens
CSVTablesBase(const std::string &subsystem)
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
TFile * file