ATLAS Offline Software
IdDictField.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 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 
12 IdDictField::IdDictField (const std::string& name)
13  : m_name(name)
14 {
15 }
16 
17 
18 
19 bool IdDictField::verify() const {
20  return(true);
21 }
22 
23 IdDictLabel* IdDictField::find_label(const std::string& name) const {
24  for (size_t i = 0; i < m_labels.size(); ++i) {
26  if ((label != 0) && (label->name() == name)) return(label);
27  }
28 
29  return(0);
30 }
31 
32 void
34  m_labels.push_back(label);
35 }
36 
37 void
39  m_index = index;
40 }
41 
42 size_t
44  return m_labels.size();
45 }
46 
47 const std::string&
49  try{
50  return m_labels.at(index)->name();
51  } catch (std::out_of_range& e) {
52  throw std::out_of_range(std::format("IdDictField::get_label : Attempt to access index {} in vector of size {}",
53  index, m_labels.size()));
54  }
55 }
56 
58 IdDictField::get_label_value(const std::string& name) const {
60  if (std::ranges::find_if(name,[](const char c){ return !std::isdigit(c); }) != name.end()) {
61  for (const auto* label: m_labels) {
62  if (label == nullptr) continue;
63  if (label->valued()) value = label->value();
64  if (label->name() == name) {
65  return(value);
66  }
67  value++;
68  }
69  }
70  try{
71  value = std::stoi(name);
72  return value;
73  } catch (const std::invalid_argument& e) {
74  std::cerr << "Warning : label " << name << " not found: "<<e.what() << std::endl;
75  }
76 
77  return(0);
78 }
79 
81  for (size_t i = 0; i < m_labels.size(); ++i) {
83  delete label;
84  }
85  m_labels.clear();
86 }
IdDictLabel::value
int value() const
Definition: IdDictLabel.h:51
IdDictField::set_index
void set_index(size_t index)
Definition: IdDictField.cxx:38
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
IdDictField::m_index
size_t m_index
Definition: IdDictField.h:55
IdDictField::get_label
const std::string & get_label(size_t index) const
Definition: IdDictField.cxx:48
IdDictLabel.h
vtune_athena.format
format
Definition: vtune_athena.py:14
IdDictField::add_label
void add_label(IdDictLabel *label)
Definition: IdDictField.cxx:33
index
Definition: index.py:1
IdDictField::clear
void clear()
Definition: IdDictField.cxx:80
IdDictField::find_label
IdDictLabel * find_label(const std::string &name) const
Definition: IdDictField.cxx:23
athena.value
value
Definition: athena.py:124
IdDictLabel::valued
bool valued() const
Definition: IdDictLabel.h:58
m_name
std::string m_name
Definition: ColumnarPhysliteTest.cxx:63
IdDictField::index
size_t index() const
Definition: IdDictField.h:67
IdDictField::label
const IdDictLabel & label(size_t index) const
Definition: IdDictField.h:74
IdDictLabel
Definition: IdDictLabel.h:10
lumiFormat.i
int i
Definition: lumiFormat.py:85
IdDictField::get_label_number
size_t get_label_number() const
Definition: IdDictField.cxx:43
IdDictField::verify
bool verify() const
Definition: IdDictField.cxx:19
add-xsec-uncert-quadrature-N.label
label
Definition: add-xsec-uncert-quadrature-N.py:104
IdDictLabel::name
const std::string & name() const
Definition: IdDictLabel.h:44
IdDictField::name
const std::string & name() const
Definition: IdDictField.h:60
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:54
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
IdDictField.h
IdDictField::IdDictField
IdDictField(const std::string &name)
Definition: IdDictField.cxx:12
ExpandedIdentifier::element_type
int element_type
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:106
python.compressB64.c
def c
Definition: compressB64.py:93