ATLAS Offline Software
Loading...
Searching...
No Matches
ToolWithConstantsTestTool.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3 */
10
11
16#include "GaudiKernel/ServiceHandle.h"
17
18
19namespace 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
99StatusCode
100ToolWithConstantsTestTool::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)
118 return StatusCode::SUCCESS;
119}
120
121
126{
127 return 2;
128}
129
130
134void 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
#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.
Context context(const EventContext &ctx) const
CaloUtils::ToolConstantsContext Context
virtual StatusCode initialize() override
Initialize method.
virtual void writeConstants(std::ostream &stream, const std::string &name, const EventContext &ctx) const
Hold mapping of ranges to condition objects.
Definition CondCont.h:889
::StatusCode StatusCode
StatusCode definition for legacy code.