ATLAS Offline Software
Loading...
Searching...
No Matches
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//____________________________________________________________________
43bool 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//____________________________________________________________________
73QStringList VP1SGContentsHelper::getKeys(const CLID& id) const
74{
75 messageVerbose("getKeys(..) called for CLID = "+QString::number(id));
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}
uint32_t CLID
The Class ID type.
The Athena Transient Store API.
VP1HelperClassBase(IVP1System *sys=0, QString helpername="")
void messageVerbose(const QString &) const
void message(const QString &) const
static bool verbose()
Definition VP1Msg.h:31
VP1SGContentsHelper(IVP1System *, const bool detStore=false)
bool contains(const QString &key) const
QStringList getKeys() const
QList< CLID > getPossibleCLIDs() const