ATLAS Offline Software
ToolWithConstantsTestTool.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3  */
13 #include "StoreGate/StoreGateSvc.h"
14 #include "AthenaKernel/IRCUSvc.h"
16 #include "GaudiKernel/ServiceHandle.h"
17 
18 
19 namespace CaloUtils {
20 
21 
29 {
31  if (m_condKey.empty()) {
32  return StatusCode::SUCCESS;
33  }
34 
35  ServiceHandle<StoreGateSvc> condStore ("ConditionStore", name());
36  ATH_CHECK( condStore.retrieve() );
37 
38  ServiceHandle<Athena::IRCUSvc> rcusvc ("Athena::RCUSvc", name());
39  ATH_CHECK( rcusvc.retrieve() );
40 
41  using CondCont_t = CondCont<CaloRec::ToolConstants>;
43  auto cc = std::make_unique<CondCont_t> (*rcusvc.get(), id);
44 
45  auto lbn = [&](int l) { return EventIDBase (m_runNumber,
46  EventIDBase::UNDEFEVT,
47  EventIDBase::UNDEFNUM,
48  EventIDBase::UNDEFNUM,
49  l); };
50  auto range = [&](int l1, int l2) { return EventIDRange (lbn(l1), lbn(l2)); };
51 
52  {
53  auto tc = std::make_unique<CaloRec::ToolConstants>();
54  tc->version (2);
55  tc->clsname (name());
56  tc->newrep (name(), "test.cb1", "0");
57  tc->newrep (name(), "test.ca2", "[[4, 5], [10, 9], [2.5, 1]]");
58  ATH_CHECK( cc->insert (range(0, 1), std::move (tc)) );
59  }
60 
61  {
62  auto tc = std::make_unique<CaloRec::ToolConstants>();
63  tc->version (2);
64  tc->clsname (name());
65  tc->newrep (name(), "test.cb1", "1");
66  tc->newrep (name(), "test.ca1", "[10, 9, 8, 7]");
67  tc->newrep (name(), "test.ca2", "[[14, 15], [1, 19], [12.5, 11]]");
68  ATH_CHECK( cc->insert (range(1, 2), std::move (tc)) );
69  }
70 
71  {
72  auto tc = std::make_unique<CaloRec::ToolConstants>();
73  tc->version (3);
74  tc->clsname (name());
75  tc->newrep (name(), "test.cb1", "1");
76  tc->newrep (name(), "test.caa", "[10, 9, 8, 7]");
77  tc->newrep (name(), "test.ca2", "[[14, 15], [1, 19], [12.5, 11]]");
78  ATH_CHECK( cc->insert (range(2, 3), std::move (tc)) );
79  }
80 
81  {
82  auto tc = std::make_unique<CaloRec::ToolConstants>();
83  tc->version (2);
84  tc->clsname (name());
85  ATH_CHECK( cc->insert (range(3, 4), std::move (tc)) );
86  }
87 
88  ATH_CHECK( condStore->record (std::move (cc), m_condKey) );
89 
90  return StatusCode::SUCCESS;
91 }
92 
93 
100 ToolWithConstantsTestTool::execute (const EventContext& ctx) const
101 {
102  Context myctx = context (ctx);
103 #define CHECKCONST(V) \
104  do { \
105  try { \
106  auto val = V (myctx); \
107  ATH_MSG_INFO (#V << " " << val); \
108  } \
109  catch (const std::exception& e) { \
110  ATH_MSG_INFO (#V << " " << e.what()); \
111  } \
112  } while(0)
113  CHECKCONST (m_cf1);
114  CHECKCONST (m_ci1);
115  CHECKCONST (m_cb1);
116  CHECKCONST (m_ca1);
117  CHECKCONST (m_ca2);
118  return StatusCode::SUCCESS;
119 }
120 
121 
126 {
127  return 2;
128 }
129 
130 
134 void ToolWithConstantsTestTool::testWriteConstants (const EventContext& ctx) const
135 {
136  std::ostringstream ss;
137  this->writeConstants (ss, name(), ctx);
138  ATH_MSG_INFO (ss.str());
139 }
140 
141 
142 } // namespace CaloUtils
CaloUtils::ToolWithConstantsTestTool::execute
StatusCode execute(const EventContext &ctx) const
Gaudi execute method.
Definition: ToolWithConstantsTestTool.cxx:100
ToolWithConstantsTestTool.h
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloUtils
Definition: ToolWithConstantsTestTool.h:21
CaloUtils::ToolWithConstantsTestTool::m_runNumber
IntegerProperty m_runNumber
Definition: ToolWithConstantsTestTool.h:56
CaloUtils::ToolWithConstantsTestTool::m_cf1
Constant< float > m_cf1
Definition: ToolWithConstantsTestTool.h:58
CaloUtils::ToolWithConstantsTestTool::toolVersion
virtual int toolVersion() const override
A non-default tool version, for testing.
Definition: ToolWithConstantsTestTool.cxx:125
CaloUtils::ToolWithConstantsTestTool::m_condKey
StringProperty m_condKey
Definition: ToolWithConstantsTestTool.h:53
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
CaloUtils::ToolWithConstants< AthAlgTool >::writeConstants
virtual void writeConstants(std::ostream &stream, const std::string &name, const EventContext &ctx) const
Dump method (for debugging)
CaloUtils::ToolWithConstantsTestTool::m_cb1
Constant< bool > m_cb1
Definition: ToolWithConstantsTestTool.h:60
IRCUSvc.h
read-copy-update (RCU) style synchronization for Athena.
CaloUtils::ToolWithConstants::initialize
virtual StatusCode initialize() override
Initialize method.
skel.l2
l2
Definition: skel.GENtoEVGEN.py:426
ClassID_traits.h
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
CaloUtils::ToolWithConstantsTestTool::m_ca1
Constant< CaloRec::Array< 1 > > m_ca1
Definition: ToolWithConstantsTestTool.h:61
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloUtils::ToolWithConstantsTestTool::initialize
StatusCode initialize() override
Gaudi initialize method.
Definition: ToolWithConstantsTestTool.cxx:28
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CaloUtils::ToolWithConstants< AthAlgTool >::context
Context context(const EventContext &ctx) const
Create a Context object.
CHECKCONST
#define CHECKCONST(V)
CondCont< CaloRec::ToolConstants >
CaloUtils::ToolWithConstantsTestTool::m_ca2
Constant< CaloRec::Array< 2 > > m_ca2
Definition: ToolWithConstantsTestTool.h:62
CaloUtils::ToolConstantsContext
Context object for retrieving ToolConstant values.
Definition: ToolWithConstants.h:61
skel.l1
l1
Definition: skel.GENtoEVGEN.py:425
StoreGateSvc.h
python.handimod.cc
int cc
Definition: handimod.py:523
CaloUtils::ToolWithConstantsTestTool::m_ci1
Constant< int > m_ci1
Definition: ToolWithConstantsTestTool.h:59
LB_AnalMapSplitter.lbn
lbn
Definition: LB_AnalMapSplitter.py:28
ServiceHandle< StoreGateSvc >
CaloUtils::ToolWithConstantsTestTool::testWriteConstants
void testWriteConstants(const EventContext &ctx) const
For testing writeConstants().
Definition: ToolWithConstantsTestTool.cxx:134