ATLAS Offline Software
Loading...
Searching...
No Matches
JetKeyDescriptor.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
6#include "GaudiKernel/MsgStream.h"
7
9
10#include <algorithm>
11
12// DO NOT change these lines EVER!!!!!
14const JetKeyConstants::key_t JetKeyConstants::AssoCat = "JetAssociations";
17
18const size_t JetKeyDescriptorInstance::m_invalid = size_t(-1);
19const std::string JetKeyDescriptorInstance::m_notFound = "unknown";
20const std::vector<JetKeyDescriptorInstance::key_t> JetKeyDescriptorInstance::m_invalidKeys;
22
24 m_Stores(nullptr),
25 m_ConstStores(nullptr)
26{
27 // create a JetKeyDescriptorInstance :
28 if (create) createKeyStore();
29}
30
32= default;
33
35 if (m_ConstStores) {
36 throw std::runtime_error ("Attempt to modify const JetKeyDescriptor");
37 }
40}
41
46
48 const key_t& key,
49 bool createIfMissing)
50{
51 //std::cout <<" getIndex cat="<<cat<<" key="<<key<<" has store ="<< m_Stores << " if missing="<< createIfMissing << std::endl;
52 if ( ! bool(m_ConstStores) ) {
53 if ( createIfMissing )
55 else
56 return m_invalid;
57 }
58
59 // std::cout <<& m_Stores->m_catStore << " Cat store size="<< m_Stores->m_catStore.size() << std::endl;
60 // first find category
61 catlist_t::const_iterator
62 fCat(std::find(m_ConstStores->m_catStore.begin(),m_ConstStores->m_catStore.end(),cat));
63 if ( fCat == m_ConstStores->m_catStore.end() ) {
64 if ( createIfMissing )
65 {
66 if (!m_Stores) {
68 }
69 // cppcheck-suppress nullPointerRedundantCheck; false positive
70 m_Stores->m_catStore.push_back(cat);
71 keystore_t kStore; kStore.push_back(key);
72 // cppcheck-suppress nullPointerRedundantCheck; false positive
73 m_Stores->m_keyStore.push_back(std::move(kStore));
74 return 0;
75 }
76 else
77 return m_invalid;
78 }
79 else
80 {
81 size_t iCat = fCat - m_ConstStores->m_catStore.begin();
82
83 if ( iCat < m_ConstStores->m_keyStore.size() ) // really impossible!
84 {
85 keystore_t::const_iterator fKey(std::find((m_ConstStores->m_keyStore[iCat]).begin(),
86 (m_ConstStores->m_keyStore[iCat]).end(),
87 key));
88 if ( fKey == (m_ConstStores->m_keyStore[iCat]).end() )
89 if ( createIfMissing )
90 {
91 if (!m_Stores) {
93 }
94 // cppcheck-suppress nullPointerRedundantCheck; false positive
95 (m_Stores->m_keyStore[iCat]).push_back(key);
96 // cppcheck-suppress nullPointerRedundantCheck; false positive
97 return (m_Stores->m_keyStore[iCat]).size()-1;
98 }
99 else
100 return m_invalid;
101 else
102 {
103 return fKey - (m_ConstStores->m_keyStore[iCat]).begin();
104 }
105 }
106 // should never be reached!
107 return m_invalid;
108 }
109}
110
112 const key_t& key) const
113{
114 if ( ! bool(m_ConstStores) ) {
115 return m_invalid;
116 }
117
118 // first find category
119 catlist_t::const_iterator
120 fCat(std::find(m_ConstStores->m_catStore.begin(),m_ConstStores->m_catStore.end(),cat));
121 if ( fCat == m_ConstStores->m_catStore.end() )
122 return m_invalid;
123 else
124 {
125 size_t iCat = fCat - m_ConstStores->m_catStore.begin();
126
127 if ( iCat < m_ConstStores->m_keyStore.size() ) // really impossible!
128 {
129 keystore_t::const_iterator fKey(std::find((m_ConstStores->m_keyStore[iCat]).begin(),
130 (m_ConstStores->m_keyStore[iCat]).end(),
131 key));
132 if ( fKey == (m_ConstStores->m_keyStore[iCat]).end() )
133 return m_invalid;
134 else
135 {
136 return fKey - (m_ConstStores->m_keyStore[iCat]).begin();
137 }
138 }
139 // should never be reached!
140 return m_invalid;
141 }
142}
143
144void JetKeyDescriptorInstance::printOut(MsgStream& msgStream) const
145{
146 if ( ! bool(m_ConstStores) ) return;
147
148 msgStream << "Number of categories: " << m_ConstStores->m_catStore.size() << endmsg;
149 for ( size_t i=0;i<m_ConstStores->m_catStore.size();i++ )
150 {
151 msgStream << m_ConstStores->m_catStore[i] << " Number of keys: "
152 << (m_ConstStores->m_keyStore[i]).size() << endmsg;
153 for ( size_t j=0;j<(m_ConstStores->m_keyStore[i]).size();j++ )
154 {
155 msgStream << " index: " << j << " key <" << (m_ConstStores->m_keyStore[i])[j]
156 << ">" << endmsg;
157 }
158 }
159}
160
162 size_t index) const
163{
164 if ( ! bool(m_ConstStores) ) createKeyStore();
165 // find category
166 catlist_t::const_iterator fCat(std::find(m_ConstStores->m_catStore.begin(),
167 m_ConstStores->m_catStore.end(),
168 cat));
169 if ( fCat == m_ConstStores->m_catStore.end() ) return m_notFound;
170 // find key
171 size_t iCat(fCat-m_ConstStores->m_catStore.begin());
172 return index < (m_ConstStores->m_keyStore[iCat]).size()
173 ? (m_ConstStores->m_keyStore[iCat])[index]
174 : m_notFound;
175}
176
177const std::vector<JetKeyDescriptorInstance::key_t>&
179{
180 if ( ! bool(m_ConstStores) )
181 return m_invalidKeys;
182 catlist_t::const_iterator fCat(std::find(m_ConstStores->m_catStore.begin(),
183 m_ConstStores->m_catStore.end(),
184 cat));
185 if ( fCat != m_ConstStores->m_catStore.end() )
186 {
187 size_t aInd(fCat-m_ConstStores->m_catStore.begin());
188 return m_ConstStores->m_keyStore[aInd];
189 }
190 else
191 {
192 return m_invalidKeys;
193 }
194}
195
196// empty constructor for the converter
198{
199 // this constructor is called only from deregister
200 //(JetKeyDescriptorInstance::instance())->m_Stores = this;
201
202 // Set the first Author entry to be NoAuthor
203 JetKeyDescriptorInstance descInst(false);
204 descInst.m_Stores = this; // connect to this store
205 descInst.m_ConstStores = this; // connect to this store
206 descInst.getIndex(JetKeyConstants::InfoCat,"NoAuthor",true);
207
208 // notes about the above lines :
209 // The line is safe w.r.t T/P when reading file written before it is implemented
210 // (because the Cnv clears everything before reading the pers object).
211 // However in such cases, jets created after such reading will have their jetAuthor()
212 // pointing to an arbitrary string (usualy "AntiKt6H1Tower") rather than the now expected "NoAuthor"
213
214}
215
216
218{
219 // here, now delete the pointer to the data of the instance...
220 if ( (JetKeyDescriptorInstance::instance())->m_Stores == this )
221 (JetKeyDescriptorInstance::instance())->m_Stores = nullptr;
222 if ( (JetKeyDescriptorInstance::instance())->m_ConstStores == this )
223 (JetKeyDescriptorInstance::instance())->m_ConstStores = nullptr;
224}
225
#define endmsg
static const bool m_persistified
const JetKeyDescriptor * m_ConstStores
static const std::string m_notFound
std::vector< key_t > keystore_t
virtual ~JetKeyDescriptorInstance()
JetKeyDescriptor * m_Stores
JetKeyDescriptor * getKeyStore()
const std::vector< key_t > & getKeys(const category_t &cat) const
static JetKeyDescriptorInstance * instance()
size_t getIndex(const category_t &cat, const key_t &key, bool createIfMissing=true)
static const size_t m_invalid
JetKeyDescriptorInstance(bool create=true)
void printOut(MsgStream &msgStream) const
const key_t & getKey(const category_t &cat, size_t index) const
static const std::vector< key_t > m_invalidKeys
friend class JetKeyDescriptorInstance
Definition index.py:1
static const key_t ShapeCat
Index category for jet shapes.
static const key_t TagCat
Index category for jet tag info.
static const key_t InfoCat
Index category for general jet info.
JetKeyDescriptor::key_t key_t
static const key_t AssoCat
Index category for jet associations.