ATLAS Offline Software
IdDictField.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #include "IdDict/IdDictField.h"
6 #include "IdDict/IdDictLabel.h"
7 #include <stdexcept>
8 #include <format>
9 #include <iostream>
10 
11 
13 }
14 
16  const std::string& /*tag*/) {
17 }
18 
20 }
21 
22 bool IdDictField::verify() const {
23  return(true);
24 }
25 
26 IdDictLabel* IdDictField::find_label(const std::string& name) const {
27  for (size_t i = 0; i < m_labels.size(); ++i) {
29  if ((label != 0) && (label->m_name == name)) return(label);
30  }
31 
32  return(0);
33 }
34 
35 void
37  m_labels.push_back(label);
38 }
39 
40 size_t
42  return m_labels.size();
43 }
44 
45 const std::string
47  std::string result;
48  try{
49  result = m_labels.at(index)->m_name;
50  } catch (std::out_of_range& e) {
51  throw std::out_of_range(std::format("IdDictField::get_label : Attempt to access index {} in vector of size {}",
52  index, m_labels.size()));
53  }
54  return result;
55 }
56 
58 IdDictField::get_label_value(const std::string& name) const {
60  try{
61  value = std::stoi(name);
62  return value;
63  } catch (std::invalid_argument& e) {
64  for (const auto* label:m_labels) {
65  if (label == nullptr) continue;
66  if (label->m_valued) value = label->m_value;
67  if (label->m_name == name) {
68  return(value);
69  }
70  value++;
71  }
72  }
73  std::cerr << "Warning : label " << name << " not found" << std::endl;
74  return(0);
75 }
76 
78  for (size_t i = 0; i < m_labels.size(); ++i) {
80  delete label;
81  }
82  m_labels.clear();
83 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
get_generator_info.result
result
Definition: get_generator_info.py:21
IdDictLabel.h
vtune_athena.format
format
Definition: vtune_athena.py:14
IdDictField::add_label
void add_label(IdDictLabel *label)
Definition: IdDictField.cxx:36
index
Definition: index.py:1
IdDictField::clear
void clear()
Definition: IdDictField.cxx:77
IdDictField::find_label
IdDictLabel * find_label(const std::string &name) const
Definition: IdDictField.cxx:26
IdDictField::generate_implementation
void generate_implementation(const IdDictMgr &idd, const std::string &tag="")
Definition: IdDictField.cxx:15
athena.value
value
Definition: athena.py:124
IdDictMgr
Definition: IdDictMgr.h:14
lumiFormat.i
int i
Definition: lumiFormat.py:85
IdDictField::get_label_number
size_t get_label_number() const
Definition: IdDictField.cxx:41
IdDictField::verify
bool verify() const
Definition: IdDictField.cxx:22
add-xsec-uncert-quadrature-N.label
label
Definition: add-xsec-uncert-quadrature-N.py:104
IdDictLabel
Definition: IdDictLabel.h:10
IdDictField::get_label_value
ExpandedIdentifier::element_type get_label_value(const std::string &name) const
Definition: IdDictField.cxx:58
IdDictField::m_labels
std::vector< IdDictLabel * > m_labels
Definition: IdDictField.h:29
IdDictField::get_label
const std::string get_label(size_t index) const
Definition: IdDictField.cxx:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
IdDictField.h
IdDictField::reset_implementation
void reset_implementation()
Definition: IdDictField.cxx:19
ExpandedIdentifier::element_type
int element_type
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:106
IdDictField::resolve_references
void resolve_references(const IdDictMgr &idd)
Definition: IdDictField.cxx:12