ATLAS Offline Software
VP1SGAccessHelper.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "VP1Base/VP1Msg.h"
6 
7 template <typename T>
8 inline const T* VP1SGAccessHelper::retrieve( const QString& key ) const
9 {
10  if (VP1Msg::verbose())
11  messageVerbose("retrieve(..) called with key = "+key+" for type "+QString(typeid(T).name()));
12 
13  if (!storeGate()) {
14  message("ERROR Does not have StoreGate pointer. Returning null pointer.");
15  return 0;
16  }
17 
18  if (key.isEmpty()) {
19  message("ERROR retrieve called with empty key. Returning null pointer.");
20  return 0;
21  }
22 
23  if (!contains(ClassID_traits<T>::ID(),key)) {
24  messageDebug("WARNING retrieve called for key="+key+", which is not found in storeGate.");
25  return 0;
26  }
27 
28  const T* t(0);
29  bool exception = true;
30  // StatusCode sc;
31  try {
32  t = storeGate()->retrieve<const T>(key.toStdString());
33  exception = false;
34  } catch (const std::runtime_error& e) {
35  exception = true;
36  t = 0;
37  }
38  if (exception ) {
39  message("ERROR: Exception thrown during call to StoreGateSvc::retrieve(..) with key="+key);
40  // sc.isFailure();//To make sure it is checked.
41  return 0;
42  }
43  if (!t) {
44  message("ERROR: Failed StoreGateSvc::retrieve(..) with key="+key+" claimed to be succesful, but resulted in NULL pointer.");
45  return 0;
46  }
47  if (VP1Msg::verbose())
48  messageVerbose("Succesfully retrieved collection "+key);
49  return t;
50 }
51 
52 template <typename T>
53 inline bool VP1SGAccessHelper::retrieve( const T* & t, const QString& key ) const
54 {
55  t = retrieve<T>(key);
56  return t != 0;
57 }
58 
59 template <typename T>
60 inline bool VP1SGAccessHelper::retrieve(SG::ConstIterator<T>& begin, SG::ConstIterator<T>& end, bool silent )
61 {
62 
63  if (VP1Msg::verbose())
64  messageVerbose("retrieve(DataHandle<"+QString(typeid(T).name())+">,DataHandle<"
65  +QString(typeid(T).name())+">) called.");
66  if (!storeGate()) {
67  QString str("ERROR Does not have StoreGate pointer. Returning null pointer.");
68  silent ? messageVerbose(str) : message(str);
69  return false;
70  }
71 
72  bool exception = true;
73  StatusCode sc;
74  try {
75  sc = storeGate()->retrieve(begin,end);
76  exception = false;
77  } catch (const std::runtime_error& e) {
78  exception = true;
79  }
80  if (exception) {
81  QString str("ERROR: Exception thrown during call to StoreGateSvc::retrieve(DataHandle<"
82  +QString(typeid(T).name())+">,DataHandle<"+QString(typeid(T).name())+">)");
83  silent ? messageVerbose(str) : message(str);
84  sc.isFailure();//To make sure it is checked.
85  return false;
86  }
87  if (sc.isFailure()) {
88  QString str( "ERROR: Failed StoreGateSvc::retrieve(DataHandle<"
89  +QString(typeid(T).name())+">,DataHandle<"
90  +QString(typeid(T).name())+">)");
91  silent ? messageVerbose(str) : message(str);
92  return false;
93  }
94 
95  if (VP1Msg::verbose())
96  messageVerbose("Successfully retrieved datahandles to "+QString(typeid(T).name())+".");
97  return true;
98 }