ATLAS Offline Software
JetStoreHelper.h
Go to the documentation of this file.
1 // emacs, this is -*- C++ -*-
2 
3 /*
4  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef JETEVENT_JETSTOREHELPER_H
8 #define JETEVENT_JETSTOREHELPER_H
9 
10 #include "GaudiKernel/Bootstrap.h"
11 #include "GaudiKernel/Service.h"
12 #include "GaudiKernel/MsgStream.h"
13 
14 #include "StoreGate/StoreGateSvc.h"
15 
16 #include <string>
17 #include <typeinfo>
18 
20 {
21 
22  inline static bool getStoreGate(StoreGateSvc*& pSG)
23  {
24  return (Gaudi::svcLocator()->service("StoreGate",pSG)).isSuccess();
25  }
26 
27  template<class STORE>
28  static bool recordStore(STORE* store,const std::string& key)
29  {
30  StoreGateSvc* pSG = 0;
31  return getStoreGate(pSG)
32  ? (pSG->record(store,key)).isSuccess()
33  : false;
34  }
35 
36  template<class STORE>
37  static bool retrieveStore(STORE*& store,const std::string& key,
38  const std::string& msg)
39  {
40  IMessageSvc* msgSvc = 0;
41  if ( (Gaudi::svcLocator()->service("MessageSvc",msgSvc)).isFailure() )
42  return false;
43  MsgStream report(msgSvc,msg);
44  return retrieveStore(store,key,report);
45  }
46 
47  template<class STORE>
48  static bool retrieveStore(STORE*& store,const std::string& key,
49  MsgStream& report)
50  {
51  // allocate StoreGate service
52  StoreGateSvc* pSG = 0;
53  if ( (Gaudi::svcLocator()->service("StoreGate",pSG)).isFailure() )
54  {
55  report << MSG::WARNING
56  << "cannot retrieve StoreGate service"
57  << endmsg;
58  return false;
59  }
60  //
61  if ( (pSG->retrieve(store,key)).isFailure() )
62  {
63  std::string tStr(typeid(store).name()); stringFilter(tStr);
64  report << MSG::WARNING
65  << "cannot retrieve store type \042"
66  << tStr << "\042 with key <"
67  << key << ">" << endmsg;
68  return false;
69  }
70  //
71  return true;
72  }
73 
74  static void stringFilter(std::string& str)
75  {
76  std::string::iterator fStr(str.begin());
77  while ( fStr != str.end() )
78  {
79  if ( *fStr >= '0' && *fStr <= '9' )
80  {
81  fStr = str.erase(fStr);
82  }
83  else
84  {
85  ++fStr;
86  }
87  }
88  }
89 
90 };
91 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
StoreGateSvc::record
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
JetStoreHelper::retrieveStore
static bool retrieveStore(STORE *&store, const std::string &key, MsgStream &report)
Definition: JetStoreHelper.h:48
JetStoreHelper::getStoreGate
static bool getStoreGate(StoreGateSvc *&pSG)
Definition: JetStoreHelper.h:22
checkTP.report
report
Definition: checkTP.py:127
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
JetStoreHelper::retrieveStore
static bool retrieveStore(STORE *&store, const std::string &key, const std::string &msg)
Definition: JetStoreHelper.h:37
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
JetStoreHelper::recordStore
static bool recordStore(STORE *store, const std::string &key)
Definition: JetStoreHelper.h:28
JetStoreHelper
Definition: JetStoreHelper.h:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
str
Definition: BTagTrackIpAccessor.cxx:11
StoreGateSvc.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
JetStoreHelper::stringFilter
static void stringFilter(std::string &str)
Definition: JetStoreHelper.h:74
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37