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