ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
Prompt::VarHolder Class Reference

#include <VarHolder.h>

Collaboration diagram for Prompt::VarHolder:

Public Member Functions

 VarHolder ()
 
virtual ~VarHolder ()
 
bool replaceVar (unsigned key, double value)
 
bool addVar (unsigned key, double value)
 Adds a variable to the VarHolder. More...
 
bool delVar (unsigned key)
 
double getVar (const unsigned key) const
 
bool getVar (const unsigned key, double &value) const
 
bool getVar (const unsigned key, float &value) const
 
bool hasKey (unsigned key) const
 
bool hasVar (unsigned key) const
 
int registerAllVars ()
 
bool registerVar (Prompt::Def::Var var, const std::string &name)
 
Prompt::Def::Var registerDynamicVar (const std::string &name)
 
std::string convert2Str (const Prompt::Def::Var var) const
 
Prompt::Def::Var convert2Var (const std::string &var)
 
Prompt::Def::Var convert2Var (const uint32_t key)
 
void getAllVarEnums ()
 
std::string asStr (const uint32_t key, const double val)
 
std::string asStr (const Prompt::Def::Var var)
 
std::vector< Prompt::Def::VarreadVars (const std::string &config)
 
std::vector< Prompt::Def::VarreadVectorVars (const std::vector< std::string > &keys)
 
virtual void clearVars ()
 

Static Public Member Functions

static std::string getObjectType ()
 

Private Attributes

VarMap m_gPromptVars
 
VarEntryVec m_fVars
 
std::vector< Prompt::Def::Varm_varEnums
 

Detailed Description

Definition at line 111 of file VarHolder.h.

Constructor & Destructor Documentation

◆ VarHolder()

Prompt::VarHolder::VarHolder ( )

Definition at line 16 of file VarHolder.cxx.

16  {
18 }

◆ ~VarHolder()

virtual Prompt::VarHolder::~VarHolder ( )
inlinevirtual

Definition at line 115 of file VarHolder.h.

Member Function Documentation

◆ addVar()

bool Prompt::VarHolder::addVar ( unsigned  key,
double  value 
)
inline

Adds a variable to the VarHolder.

This function adds a variable to the VarHolder using the specified key and value.

Parameters
keyThe key of the variable.
valueThe value of the variable.
Returns
True if the variable was successfully added, false otherwise.

Definition at line 210 of file VarHolder.h.

214  {
215  VarEntryVec::iterator vit = m_fVars.begin();
216  while(vit != m_fVars.end()) {
217  if(vit->getKey() == key) {
218  vit = m_fVars.erase(vit);
219  }
220  else {
221  ++vit;

◆ asStr() [1/2]

std::string Prompt::VarHolder::asStr ( const Prompt::Def::Var  var)

Definition at line 172 of file VarHolder.cxx.

173 {
174  return convert2Str(var);
175 }

◆ asStr() [2/2]

std::string Prompt::VarHolder::asStr ( const uint32_t  key,
const double  val 
)

Definition at line 178 of file VarHolder.cxx.

179 {
180  std::stringstream s;
181 
183 
184  if(var != Prompt::Def::NONE) {
185  s << asStr(var) << ": " << val;
186  }
187  else {
188  s << var << ": " << val;
189  }
190 
191  return s.str();
192 }

◆ clearVars()

void Prompt::VarHolder::clearVars ( )
inlinevirtual

Definition at line 285 of file VarHolder.h.

◆ convert2Str()

std::string Prompt::VarHolder::convert2Str ( const Prompt::Def::Var  var) const

Definition at line 77 of file VarHolder.cxx.

78 {
79  const VarMap::const_iterator vit = m_gPromptVars.find(var);
80 
81  if(vit == m_gPromptVars.end()) {
82  asg::msgUserCode::ANA_MSG_WARNING("Def::convert2Str - WARNING - unknown variable: " << var);
83  return "UNKNOWN";
84  }
85 
86  return vit->second;
87 }

◆ convert2Var() [1/2]

Prompt::Def::Var Prompt::VarHolder::convert2Var ( const std::string &  var)

Definition at line 90 of file VarHolder.cxx.

91 {
92  for (const VarMap::value_type &v: m_gPromptVars) {
93  if(var == v.second) {
94  return v.first;
95  }
96  }
97 
98  asg::msgUserCode::ANA_MSG_WARNING("Def::convert2Var - WARNING - unknown variable: " << var);
99 
100  return Prompt::Def::NONE;
101 }

◆ convert2Var() [2/2]

Prompt::Def::Var Prompt::VarHolder::convert2Var ( const uint32_t  key)

Definition at line 104 of file VarHolder.cxx.

105 {
106  getAllVarEnums();
107 
108  //
109  // Find matching enum by value
110  //
112  if(static_cast<uint32_t>(var) == key) {
113  return var;
114  }
115  }
116 
117  asg::msgUserCode::ANA_MSG_WARNING("Def::convert2Var - WARNING - unknown key: " << key);
118 
119  return Prompt::Def::NONE;
120 }

◆ delVar()

bool Prompt::VarHolder::delVar ( unsigned  key)
inline

Definition at line 223 of file VarHolder.h.

229  {
230  return std::find(m_fVars.begin(), m_fVars.end(), key) != m_fVars.end();
231  }
232  inline bool VarHolder::hasVar(unsigned key) const
233  {
234  return std::find(m_fVars.begin(), m_fVars.end(), key) != m_fVars.end();
235  }
236 

◆ getAllVarEnums()

void Prompt::VarHolder::getAllVarEnums ( )

Definition at line 67 of file VarHolder.cxx.

68 {
69  if(m_varEnums.empty()) {
70  for(const Prompt::VarMap::value_type &v: m_gPromptVars) {
71  m_varEnums.push_back(v.first);
72  }
73  }
74 }

◆ getObjectType()

static std::string Prompt::VarHolder::getObjectType ( )
inlinestatic

Definition at line 117 of file VarHolder.h.

◆ getVar() [1/3]

double Prompt::VarHolder::getVar ( const unsigned  key) const
inline

Definition at line 275 of file VarHolder.h.

276  {
277  m_fVars.clear();
278  }
279 }
280 
281 #endif // PROMPT_VARHOLDER_H

◆ getVar() [2/3]

bool Prompt::VarHolder::getVar ( const unsigned  key,
double &  value 
) const
inline

Definition at line 261 of file VarHolder.h.

266  {
267  //
268  // Find and return, if exists, value stored at key
269  //
270  double val = -1.0e9;
271  getVar(key, val);
272  return val;
273  }

◆ getVar() [3/3]

bool Prompt::VarHolder::getVar ( const unsigned  key,
float &  value 
) const
inline

Definition at line 247 of file VarHolder.h.

252  {
253  //
254  // Read variable
255  //
256  const VarEntryVec::const_iterator ivar = std::find(m_fVars.begin(), m_fVars.end(), key);
257  if(ivar != m_fVars.end()) {
258  value = ivar->getData();
259  return true;

◆ hasKey()

bool Prompt::VarHolder::hasKey ( unsigned  key) const
inline

Definition at line 238 of file VarHolder.h.

238  {
239  //
240  // Read variable
241  //

◆ hasVar()

bool Prompt::VarHolder::hasVar ( unsigned  key) const
inline

Definition at line 242 of file VarHolder.h.

243  {
244  value = ivar->getData();
245  return true;

◆ readVars()

std::vector< Prompt::Def::Var > Prompt::VarHolder::readVars ( const std::string &  config)

Definition at line 123 of file VarHolder.cxx.

126 {
127  //
128  // Read vector of variable names and convert to Var enums
129  //
130  std::vector<std::string> keys;
131  Def::StringTok(keys, config, ", ");
132 
133  std::vector<Prompt::Def::Var> vars;
134 
135  for(const std::string &key: keys) {
137  if(var != Prompt::Def::NONE) {
138  vars.push_back(var);
139  }
140  else {
141  asg::msgUserCode::ANA_MSG_WARNING("Prompt::Def::readVars - unknown variable name: " << key);
142  }
143  }
144 
145  return vars;
146 }

◆ readVectorVars()

std::vector< Prompt::Def::Var > Prompt::VarHolder::readVectorVars ( const std::vector< std::string > &  keys)

Definition at line 149 of file VarHolder.cxx.

152 {
153  //
154  // Read vector of variable names and convert to Var enums
155  //
156  std::vector<Prompt::Def::Var> vars;
157 
158  for(const std::string &key: keys) {
160  if(var != Prompt::Def::NONE) {
161  vars.push_back(var);
162  }
163  else {
164  asg::msgUserCode::ANA_MSG_WARNING("Prompt::Def::readVars - unknown variable name: " << key);
165  }
166  }
167 
168  return vars;
169 }

◆ registerAllVars()

int Prompt::VarHolder::registerAllVars ( )

Definition at line 228 of file VarHolder.cxx.

229 {
230  using namespace Prompt::Def;
231 
232  int result = 0;
233 
234  result += registerVar( NONE, "NONE");
235  result += registerVar( TrackJetNTrack, "TrackJetNTrack");
236  result += registerVar( DRlj, "DRlj");
237  result += registerVar( PtFrac, "PtFrac");
238  result += registerVar( PtRel, "PtRel");
239 
240  // track VarHolder
241  result += registerVar( LepTrackDR, "LepTrackDR");
242  result += registerVar( Pt, "Pt");
243  result += registerVar( AbsEta, "AbsEta");
244  result += registerVar( NumberOfPIXHits, "NumberOfPIXHits");
245  result += registerVar( NumberOfSCTHits, "NumberOfSCTHits");
246  result += registerVar( NumberOfSiHits, "NumberOfSiHits");
247  result += registerVar( NumberOfSharedSiHits, "NumberOfSharedSiHits");
248  result += registerVar( NumberOfSiHoles, "NumberOfSiHoles");
249  result += registerVar( NumberOfPixelHoles, "NumberOfPixelHoles");
250  result += registerVar( TrackJetDR, "TrackJetDR");
251  result += registerVar( TrackPtOverTrackJetPt, "TrackPtOverTrackJetPt");
252  result += registerVar( Z0Sin, "Z0Sin");
253  result += registerVar( D0Sig, "D0Sig");
254 
255  // PromptLeptonImproved
256  result += registerVar( MVAXBin, "MVAXBin");
257  result += registerVar( RawPt, "RawPt");
258  result += registerVar( PromptLeptonRNN_prompt, "PromptLeptonRNN_prompt");
259  result += registerVar( CaloClusterERel, "CaloClusterERel");
260  result += registerVar( Topoetcone30rel, "topoetcone30rel");
261  result += registerVar( Ptvarcone30rel, "ptvarcone30rel");
262  result += registerVar( Ptvarcone30_TightTTVA_pt500rel, "ptvarcone30_TightTTVA_pt500rel");
263  result += registerVar( CaloClusterSumEtRel, "CaloClusterSumEtRel");
264  result += registerVar( CandVertex_normDistToPriVtxLongitudinalBest, "CandVertex_normDistToPriVtxLongitudinalBest");
265  result += registerVar( CandVertex_normDistToPriVtxLongitudinalBest_ThetaCutVtx, "CandVertex_normDistToPriVtxLongitudinalBest_ThetaCutVtx");
266  result += registerVar( CandVertex_NPassVtx, "CandVertex_NPassVtx");
267 
268  return result;
269 }

◆ registerDynamicVar()

Prompt::Def::Var Prompt::VarHolder::registerDynamicVar ( const std::string &  name)

Definition at line 41 of file VarHolder.cxx.

42 {
43  unsigned last_key = Prompt::Def::NONE;
44 
45  for(const Prompt::VarMap::value_type &v: m_gPromptVars) {
46  if(name == v.second) {
47  asg::msgUserCode::ANA_MSG_WARNING("Def::registerDynamicVar - variable with this name already exists: " << name);
48 
49  return v.first;
50  }
51 
52  last_key = std::max<unsigned>(last_key, v.first);
53  }
54 
55  const Def::Var new_key = static_cast<Def::Var>(last_key+1);
56 
57 
58  if(!registerVar(new_key, name)) {
59  asg::msgUserCode::ANA_MSG_WARNING("Def::registerDynamicVar - WARNING - failed to register variable name=" << name);
60  return Prompt::Def::NONE;
61  }
62 
63  return new_key;
64 }

◆ registerVar()

bool Prompt::VarHolder::registerVar ( Prompt::Def::Var  var,
const std::string &  name 
)

Definition at line 21 of file VarHolder.cxx.

22 {
23  for(const VarMap::value_type &v: m_gPromptVars) {
24  if(name == v.second) {
25  asg::msgUserCode::ANA_MSG_WARNING("Def::registerVar - WARNING - variable with this name already exists: var=" << var << ", name=" << name);
26  return false;
27  }
28  }
29 
30  std::pair<VarMap::iterator, bool> vit = m_gPromptVars.insert(VarMap::value_type(var, name));
31 
32  if(!vit.second) {
33  asg::msgUserCode::ANA_MSG_WARNING("Def::registerVar - WARNING - variable with this key already exists: var=" << var << ", name=" << name);
34  return false;
35  }
36 
37  return true;
38 }

◆ replaceVar()

bool Prompt::VarHolder::replaceVar ( unsigned  key,
double  value 
)
inline

Definition at line 188 of file VarHolder.h.

Member Data Documentation

◆ m_fVars

VarEntryVec Prompt::VarHolder::m_fVars
private

Definition at line 153 of file VarHolder.h.

◆ m_gPromptVars

VarMap Prompt::VarHolder::m_gPromptVars
private

Definition at line 152 of file VarHolder.h.

◆ m_varEnums

std::vector<Prompt::Def::Var> Prompt::VarHolder::m_varEnums
private

Definition at line 155 of file VarHolder.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
NONE
@ NONE
Definition: sTGCenumeration.h:13
Prompt::VarHolder::registerAllVars
int registerAllVars()
Definition: VarHolder.cxx:228
Prompt::Def::RawPt
@ RawPt
Definition: VarHolder.h:94
Prompt::Def::LepTrackDR
@ LepTrackDR
Definition: VarHolder.h:75
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
Prompt::Def
Definition: VarHolder.h:45
Prompt::Def::NumberOfSCTHits
@ NumberOfSCTHits
Definition: VarHolder.h:79
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
get_generator_info.result
result
Definition: get_generator_info.py:21
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Prompt::Def::NumberOfSiHits
@ NumberOfSiHits
Definition: VarHolder.h:80
Prompt::Def::TrackJetNTrack
@ TrackJetNTrack
Definition: VarHolder.h:69
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
athena.value
value
Definition: athena.py:124
Prompt::Def::DRlj
@ DRlj
Definition: VarHolder.h:70
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
Prompt::Def::Z0Sin
@ Z0Sin
Definition: VarHolder.h:86
Prompt::Def::NumberOfPIXHits
@ NumberOfPIXHits
Definition: VarHolder.h:78
Prompt::Def::PtFrac
@ PtFrac
Definition: VarHolder.h:71
Prompt::Def::NONE
@ NONE
Definition: VarHolder.h:68
Prompt::Def::PromptLeptonRNN_prompt
@ PromptLeptonRNN_prompt
Definition: VarHolder.h:97
Prompt::VarHolder::getVar
double getVar(const unsigned key) const
Definition: VarHolder.h:275
Prompt::VarHolder::convert2Str
std::string convert2Str(const Prompt::Def::Var var) const
Definition: VarHolder.cxx:77
Prompt::Def::D0Sig
@ D0Sig
Definition: VarHolder.h:87
Prompt::Def::Ptvarcone30rel
@ Ptvarcone30rel
Definition: VarHolder.h:91
Prompt::Def::MVAXBin
@ MVAXBin
Definition: VarHolder.h:93
Prompt::Def::NumberOfSiHoles
@ NumberOfSiHoles
Definition: VarHolder.h:82
Prompt::VarHolder::getAllVarEnums
void getAllVarEnums()
Definition: VarHolder.cxx:67
Prompt::VarHolder::hasVar
bool hasVar(unsigned key) const
Definition: VarHolder.h:242
plotBeamSpotCompare.ivar
int ivar
Definition: plotBeamSpotCompare.py:383
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
Prompt::Def::StringTok
void StringTok(std::vector< std::string > &ls, const std::string &str, const std::string &tok)
Definition: VarHolder.cxx:195
Prompt::Def::CandVertex_NPassVtx
@ CandVertex_NPassVtx
Definition: VarHolder.h:100
Prompt::VarHolder::m_fVars
VarEntryVec m_fVars
Definition: VarHolder.h:153
Prompt::VarHolder::m_varEnums
std::vector< Prompt::Def::Var > m_varEnums
Definition: VarHolder.h:155
Prompt::Def::CaloClusterSumEtRel
@ CaloClusterSumEtRel
Definition: VarHolder.h:96
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Prompt::VarHolder::m_gPromptVars
VarMap m_gPromptVars
Definition: VarHolder.h:152
python.PyAthena.v
v
Definition: PyAthena.py:154
Prompt::Def::NumberOfSharedSiHits
@ NumberOfSharedSiHits
Definition: VarHolder.h:81
Prompt::Def::Pt
@ Pt
Definition: VarHolder.h:76
Prompt::VarHolder::registerVar
bool registerVar(Prompt::Def::Var var, const std::string &name)
Definition: VarHolder.cxx:21
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
Prompt::Def::TrackPtOverTrackJetPt
@ TrackPtOverTrackJetPt
Definition: VarHolder.h:85
Prompt::Def::TrackJetDR
@ TrackJetDR
Definition: VarHolder.h:84
Prompt::Def::Ptvarcone30_TightTTVA_pt500rel
@ Ptvarcone30_TightTTVA_pt500rel
Definition: VarHolder.h:92
Prompt::Def::NumberOfPixelHoles
@ NumberOfPixelHoles
Definition: VarHolder.h:83
Prompt::Def::CandVertex_normDistToPriVtxLongitudinalBest
@ CandVertex_normDistToPriVtxLongitudinalBest
Definition: VarHolder.h:98
Prompt::Def::PtRel
@ PtRel
Definition: VarHolder.h:72
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
Prompt::Def::Var
Var
Definition: VarHolder.h:57
Prompt::Def::AbsEta
@ AbsEta
Definition: VarHolder.h:77
Prompt::Def::CandVertex_normDistToPriVtxLongitudinalBest_ThetaCutVtx
@ CandVertex_normDistToPriVtxLongitudinalBest_ThetaCutVtx
Definition: VarHolder.h:99
Prompt::Def::Topoetcone30rel
@ Topoetcone30rel
Definition: VarHolder.h:90
Prompt::Def::CaloClusterERel
@ CaloClusterERel
Definition: VarHolder.h:95
Prompt::VarHolder::convert2Var
Prompt::Def::Var convert2Var(const std::string &var)
Definition: VarHolder.cxx:90
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
Prompt::VarHolder::asStr
std::string asStr(const uint32_t key, const double val)
Definition: VarHolder.cxx:178