ATLAS Offline Software
JetKeyDescriptor.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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!!!!!
14 const JetKeyConstants::key_t JetKeyConstants::AssoCat = "JetAssociations";
17 
18 const size_t JetKeyDescriptorInstance::m_invalid = size_t(-1);
19 const std::string JetKeyDescriptorInstance::m_notFound = "unknown";
20 const 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  }
38  m_Stores = new JetKeyDescriptor();
40 }
41 
43  if( ! bool(m_Stores) ) createKeyStore();
44  return m_Stores;
45 }
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(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 
144 void 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 
177 const 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 
JetKeyDescriptorInstance::printOut
void printOut(MsgStream &msgStream) const
Definition: JetKeyDescriptor.cxx:144
JetKeyDescriptorInstance::m_Stores
JetKeyDescriptor * m_Stores
Definition: JetKeyDescriptor.h:155
JetKeyDescriptor::m_catStore
catlist_t m_catStore
Definition: JetKeyDescriptor.h:77
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
JetKeyDescriptor.h
JetKeyDescriptorInstance::JetKeyDescriptorInstance
JetKeyDescriptorInstance(bool create=true)
Definition: JetKeyDescriptor.cxx:23
JetKeyDescriptorInstance::~JetKeyDescriptorInstance
virtual ~JetKeyDescriptorInstance()
index
Definition: index.py:1
JetKeyDescriptor::JetKeyDescriptor
JetKeyDescriptor()
Definition: JetKeyDescriptor.cxx:197
JetKeyConstants::ShapeCat
static const key_t ShapeCat
Index category for jet shapes.
Definition: JetKeyDescriptor.h:88
JetKeyDescriptor::m_keyStore
storelist_t m_keyStore
Definition: JetKeyDescriptor.h:75
JetKeyDescriptorInstance::m_invalid
static const size_t m_invalid
Definition: JetKeyDescriptor.h:163
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
JetKeyConstants::TagCat
static const key_t TagCat
Index category for jet tag info.
Definition: JetKeyDescriptor.h:92
JetKeyDescriptorInstance::category_t
std::string category_t
Definition: JetKeyDescriptor.h:113
JetKeyDescriptorInstance::instance
static JetKeyDescriptorInstance * instance()
Definition: JetKeyDescriptor.h:123
JetKeyDescriptorInstance::key_t
std::string key_t
Definition: JetKeyDescriptor.h:114
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
JetKeyDescriptorInstance::m_invalidKeys
static const std::vector< key_t > m_invalidKeys
Definition: JetKeyDescriptor.h:165
JetKeyDescriptorInstance::getKeyStore
JetKeyDescriptor * getKeyStore()
Definition: JetKeyDescriptor.cxx:42
JetKeyDescriptorInstance::createKeyStore
void createKeyStore() const
Definition: JetKeyDescriptor.cxx:34
JetKeyConstants::AssoCat
static const key_t AssoCat
Index category for jet associations.
Definition: JetKeyDescriptor.h:90
JetKeyDescriptor::~JetKeyDescriptor
virtual ~JetKeyDescriptor()
Definition: JetKeyDescriptor.cxx:217
JetKeyDescriptorInstance::keystore_t
std::vector< key_t > keystore_t
Definition: JetKeyDescriptor.h:116
JetKeyDescriptorInstance::JetKeyDescriptor
friend class JetKeyDescriptor
Definition: JetKeyDescriptor.h:101
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
JetKeyDescriptorInstance::getKey
const key_t & getKey(const category_t &cat, size_t index) const
Definition: JetKeyDescriptor.cxx:161
JetKeyDescriptorInstance::m_persistified
static const bool m_persistified
Definition: JetKeyDescriptor.h:167
JetKeyConstants::InfoCat
static const key_t InfoCat
Index category for general jet info.
Definition: JetKeyDescriptor.h:94
JetKeyDescriptorInstance::getKeys
const std::vector< key_t > & getKeys(const category_t &cat) const
Definition: JetKeyDescriptor.cxx:178
JetKeyDescriptor
//////////////////////////////////////////////////
Definition: JetKeyDescriptor.h:44
JetKeyDescriptorInstance::m_notFound
static const std::string m_notFound
Definition: JetKeyDescriptor.h:164
JetKeyConstants::key_t
JetKeyDescriptor::key_t key_t
Definition: JetKeyDescriptor.h:85
JetKeyDescriptorInstance::getIndex
size_t getIndex(const category_t &cat, const key_t &key, bool createIfMissing=true)
Definition: JetKeyDescriptor.cxx:47
JetKeyDescriptorInstance
Definition: JetKeyDescriptor.h:100
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
JetKeyDescriptorInstance::m_ConstStores
const JetKeyDescriptor * m_ConstStores
Definition: JetKeyDescriptor.h:156