ATLAS Offline Software
VP1SGContentsHelper.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 
7 // //
8 // Implementation of class VP1SGContentsHelper //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: March 2008 //
12 // //
14 
16 #include "VP1Base/IVP1System.h"
17 #include "VP1Base/VP1Msg.h"
18 #include "StoreGate/StoreGateSvc.h" //
19 #include <stdexcept>
20 #include <QStringList>
21 // //
23 
24 //____________________________________________________________________
26  : VP1HelperClassBase(sys,"VP1SGContentsHelper"), m_sg(sys?(detStore?sys->detectorStore():sys->storeGate()):0)
27 {
28  if (!sys)
29  message("ERROR: Received null system pointer (won't be able to get storeGate pointer either)");
30  else if (!m_sg)
31  message("ERROR: Could not get "+QString(detStore?"storeGate":"detectorStore")+" pointer from system");
32 }
33 
34 //____________________________________________________________________
36  : VP1HelperClassBase(0,"VP1SGContentsHelper"), m_sg(sg)
37 {
38  if (!sg)
39  message("ERROR: Received null storegate pointer");
40 }
41 
42 //____________________________________________________________________
43 bool VP1SGContentsHelper::contains( const CLID& id, const QString& key ) const
44 {
45  if (VP1Msg::verbose())
46  messageVerbose("contains(..) called for key = "+key);
47  if (!m_sg) {
48  message("ERROR: Does not have StoreGate pointer - returning false.");
49  return false;
50  }
51  if (key.isEmpty()) {
52  message("ERROR: Passed key is empty. Returning false.");
53  return false;
54  }
55  bool contains = false;
56  bool exception = true;
57  try {
58  contains = m_sg->contains(id,key.toStdString());
59  exception = false;
60  } catch (const std::runtime_error& e) {
61  exception = true;
62  }
63  if (exception) {
64  message("ERROR: Exception thrown during call to StoreGateSvc::contains(..). Returning false.");
65  return false;
66  }
67  if (VP1Msg::verbose())
68  messageVerbose("contains(..) returning "+QString(contains?"true":"false"));
69  return contains;
70 }
71 
72 //____________________________________________________________________
73 QStringList VP1SGContentsHelper::getKeys(const CLID& id) const
74 {
75  messageVerbose("getKeys(..) called");
76  if (!m_sg) {
77  message("ERROR: Does not have StoreGate pointer - returning empty key list");
78  return QStringList();
79  }
80  QStringList l;
81 
82  std::vector<std::string> keys;
83 
84  bool exception = true;
85  try {
86  m_sg->keys(id, keys);
87  exception = false;
88  } catch (const std::runtime_error& e) {
89  exception = true;
90  }
91  if (exception) {
92  message("ERROR: Exception thrown during call to StoreGateSvc::keys(..)");
93  return QStringList();
94  }
95  std::vector<std::string>::const_iterator it(keys.begin()), itE(keys.end());
96  for (;it!=itE;++it) {
97  if (it->empty())
98  continue;
99  if (contains(id,it->c_str()))
100  l << it->c_str();
101  else if (VP1Msg::verbose())
102  messageVerbose("NB: StoreGateSvc::keys() included '"+QString(it->c_str())
103  +"' but StoreGateSvc::contains("+QString(it->c_str())+") returns false." );
104  }
105  if (VP1Msg::verbose()) {
106  messageVerbose("returning "+QString::number(l.count())+" keys:");
107  messageVerbose(" => ",l);
108  }
109  return l;
110 }
111 
112 //____________________________________________________________________
114 {
115  messageVerbose("getPossibleCLIDs(..) called");
116  QList<CLID> l;
117  if (!m_sg) {
118  message("ERROR: Does not have StoreGate pointer - returning empty key list");
119  return l;
120  }
121 
122  for (CLID id : m_sg->clids())
123  l << id;
124  return l;
125 }
StoreGateSvc::contains
bool contains(const TKEY &key) const
Look up a keyed object in TDS (compare also tryRetrieve) returns false if object not available in TDS...
VP1Msg.h
VP1SGContentsHelper::VP1SGContentsHelper
VP1SGContentsHelper(IVP1System *, const bool detStore=false)
Definition: VP1SGContentsHelper.cxx:25
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
skel.it
it
Definition: skel.GENtoEVGEN.py:423
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
StoreGateSvc::clids
std::vector< CLID > clids(const TKEY &key) const
Retrieve all the CLID s (including symlinks) of the object recorded in StoreGate with the given "key"...
StoreGateSvc::keys
void keys(std::vector< std::string > &vkeys, bool includeAlias=false, bool onlyValid=true) const
provide list of all StoreGate keys associated with an object.
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
TruthTest.itE
itE
Definition: TruthTest.py:25
VP1SGContentsHelper::getKeys
QStringList getKeys() const
Definition: VP1SGContentsHelper.h:55
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
IVP1System
Definition: IVP1System.h:36
calibdata.exception
exception
Definition: calibdata.py:496
VP1SGContentsHelper::m_sg
StoreGateSvc * m_sg
Definition: VP1SGContentsHelper.h:45
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
VP1HelperClassBase
Definition: VP1HelperClassBase.h:28
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
python.selection.number
number
Definition: selection.py:20
VP1SGContentsHelper::contains
bool contains(const QString &key) const
Definition: VP1SGContentsHelper.h:61
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
VP1HelperClassBase::message
void message(const QString &) const
Definition: VP1HelperClassBase.cxx:49
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
VP1Msg::verbose
static bool verbose()
Definition: VP1Msg.h:31
StoreGateSvc.h
VP1SGContentsHelper::getPossibleCLIDs
QList< CLID > getPossibleCLIDs() const
Definition: VP1SGContentsHelper.cxx:113
IVP1System.h
VP1SGContentsHelper.h
python.PyKernel.storeGate
storeGate
Definition: PyKernel.py:40
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37