ATLAS Offline Software
Loading...
Searching...
No Matches
ToolWithConstantsTestTool.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
3 */
10
11
16#include "GaudiKernel/ServiceHandle.h"
17
18
19namespace CaloUtils {
20
21
29{
30 ATH_CHECK( base_class::initialize() );
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 EventContext ctx;
52
53 {
54 auto tc = std::make_unique<CaloRec::ToolConstants>();
55 tc->version (2);
56 tc->clsname (name());
57 tc->newrep (name(), "test.cb1", "0");
58 tc->newrep (name(), "test.ca2", "[[4, 5], [10, 9], [2.5, 1]]");
59 ATH_CHECK( cc->insert (range(0, 1), std::move (tc), ctx) );
60 }
61
62 {
63 auto tc = std::make_unique<CaloRec::ToolConstants>();
64 tc->version (2);
65 tc->clsname (name());
66 tc->newrep (name(), "test.cb1", "1");
67 tc->newrep (name(), "test.ca1", "[10, 9, 8, 7]");
68 tc->newrep (name(), "test.ca2", "[[14, 15], [1, 19], [12.5, 11]]");
69 ATH_CHECK( cc->insert (range(1, 2), std::move (tc), ctx) );
70 }
71
72 {
73 auto tc = std::make_unique<CaloRec::ToolConstants>();
74 tc->version (3);
75 tc->clsname (name());
76 tc->newrep (name(), "test.cb1", "1");
77 tc->newrep (name(), "test.caa", "[10, 9, 8, 7]");
78 tc->newrep (name(), "test.ca2", "[[14, 15], [1, 19], [12.5, 11]]");
79 ATH_CHECK( cc->insert (range(2, 3), std::move (tc), ctx) );
80 }
81
82 {
83 auto tc = std::make_unique<CaloRec::ToolConstants>();
84 tc->version (2);
85 tc->clsname (name());
86 ATH_CHECK( cc->insert (range(3, 4), std::move (tc), ctx) );
87 }
88
89 ATH_CHECK( condStore->record (std::move (cc), m_condKey) );
90
91 return StatusCode::SUCCESS;
92}
93
94
100StatusCode
101ToolWithConstantsTestTool::execute (const EventContext& ctx) const
102{
103 Context myctx = context (ctx);
104#define CHECKCONST(V) \
105 do { \
106 try { \
107 auto val = V (myctx); \
108 ATH_MSG_INFO (#V << " " << val); \
109 } \
110 catch (const std::exception& e) { \
111 ATH_MSG_INFO (#V << " " << e.what()); \
112 } \
113 } while(0)
119 return StatusCode::SUCCESS;
120}
121
122
127{
128 return 2;
129}
130
131
135void ToolWithConstantsTestTool::testWriteConstants (const EventContext& ctx) const
136{
137 std::ostringstream ss;
138 this->writeConstants (ss, name(), ctx);
139 ATH_MSG_INFO (ss.str());
140}
141
142
143} // namespace CaloUtils
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
read-copy-update (RCU) style synchronization for Athena.
static Double_t ss
static Double_t tc
#define CHECKCONST(V)
StatusCode execute(const EventContext &ctx) const
Gaudi execute method.
void testWriteConstants(const EventContext &ctx) const
For testing writeConstants().
virtual int toolVersion() const override
A non-default tool version, for testing.
StatusCode initialize() override
Gaudi initialize method.
Hold mapping of ranges to condition objects.
Definition CondCont.h:889
virtual void writeConstants(std::ostream &stream, const std::string &name, const EventContext &ctx) const
Dump method (for debugging).
Context context(const EventContext &ctx) const
Create a Context object.
::StatusCode StatusCode
StatusCode definition for legacy code.