ATLAS Offline Software
Loading...
Searching...
No Matches
BeamSpotCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4// BeamSpot_ConditionsAlgs includes
5#include "BeamSpotCondAlg.h"
6#include "CoralBase/AttributeListException.h"
7
8const EventIDRange BeamSpotCondAlg::alwaysValid { EventIDBase { 1,
9 EventIDBase::UNDEFEVT,
10 EventIDBase::UNDEFNUM,
11 EventIDBase::UNDEFNUM,
12 0 },
13 EventIDBase { EventIDBase::UNDEFNUM - 1,
14 EventIDBase::UNDEFEVT,
15 EventIDBase::UNDEFNUM,
16 EventIDBase::UNDEFNUM,
17 EventIDBase::UNDEFNUM - 1 }
18 };
19
20BeamSpotCondAlg::BeamSpotCondAlg( const std::string& name, ISvcLocator* pSvcLocator )
21 : AthCondAlgorithm( name, pSvcLocator )
22{ }
23
24
26
27
29{
30 ATH_MSG_DEBUG ("Initializing " << name() << "...");
31
32 ATH_CHECK( m_readKey.initialize() );
33 ATH_CHECK( m_writeKey.initialize() );
34
35 return StatusCode::SUCCESS;
36}
37
38StatusCode BeamSpotCondAlg::execute(const EventContext& ctx) const
39{
40 ATH_MSG_DEBUG ("Executing " << name() << "...");
41
43 if ( writeHandle.isValid() )
44 {
45 ATH_MSG_DEBUG( "CondHandle " << writeHandle.fullKey() << " is already valid " <<
46 "Forcing update of Store contents" );
47 return StatusCode::SUCCESS;
48 }
49
50 EventIDRange rangeW;
51 InDet::BeamSpotData* writeCdo = nullptr;
52
53 if ( !m_useDB )
54 {
55 rangeW = alwaysValid;
59 }
60 else
61 {
62
64
65 const AthenaAttributeList* raw { *readHandle };
66 if ( raw == nullptr )
67 {
68 ATH_MSG_ERROR("Beam Spot data for key " << m_readKey.fullKey() << " not found");
69 return StatusCode::FAILURE;
70 }
71
72 int status { (*raw)["status"].data<int>() };
73 float posX { (*raw)["posX"].data<float>() };
74 float posY { (*raw)["posY"].data<float>() };
75 float posZ { (*raw)["posZ"].data<float>() };
76 float sigmaX { (*raw)["sigmaX"].data<float>() };
77 float sigmaY { (*raw)["sigmaY"].data<float>() };
78 float sigmaZ { (*raw)["sigmaZ"].data<float>() };
79 float tiltX { (*raw)["tiltX"].data<float>() };
80 float tiltY { (*raw)["tiltY"].data<float>() };
81 float sigmaXY { m_sigmaXY };
82 try
83 {
84 sigmaXY = (*raw)["sigmaXY"].data<float>();
85 }
86 catch (coral::AttributeListException& e)
87 {
88 ATH_MSG_DEBUG( "No sigmaXY value present in database, using default value of " << sigmaXY );
89 }
90
91 ATH_MSG_INFO( "Read from condDB"
92 << " status " << status
93 << " pos (" << posX << "," << posY << "," << posZ << ")"
94 << " sigma (" << sigmaX << "," << sigmaY << "," << sigmaZ << ")"
95 << " tilt (" << tiltX << "," << tiltY << ")"
96 << " sigmaXY " << sigmaXY );
97
98 if ( !readHandle.range(rangeW) )
99 {
100 ATH_MSG_ERROR( "Failed to retrieve validity range for " << readHandle.key() );
101 return StatusCode::FAILURE;
102 }
103
104 writeCdo = new InDet::BeamSpotData( status, posX, posY, posZ,
105 sigmaX, sigmaY, sigmaZ,
106 tiltX, tiltY, sigmaXY );
107 }
108
109 if ( writeHandle.record( rangeW, writeCdo ).isFailure() )
110 {
111 ATH_MSG_ERROR( "Could not record InDet::BeamSpotData " << writeHandle.key() <<
112 " with EventRange " << rangeW << " into conditions store." );
113 return StatusCode::FAILURE;
114 }
115
116 ATH_MSG_INFO( "Recorded new InDet::BeamSpotData to " << writeHandle.key() << " with range " << rangeW <<
117 " into conditions store." );
118
119 return StatusCode::SUCCESS;
120}
121
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Base class for conditions algorithms.
An AttributeList represents a logical row of attributes in a metadata table.
virtual StatusCode execute(const EventContext &ctx) const override final
Gaudi::Property< float > m_tiltX
Gaudi::Property< float > m_posY
Gaudi::Property< float > m_sigmaY
Gaudi::Property< float > m_sigmaXY
Gaudi::Property< int > m_status
Gaudi::Property< float > m_sigmaX
Gaudi::Property< float > m_posZ
Gaudi::Property< float > m_tiltY
SG::WriteCondHandleKey< InDet::BeamSpotData > m_writeKey
virtual ~BeamSpotCondAlg()
BeamSpotCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
static const EventIDRange alwaysValid
SG::ReadCondHandleKey< AthenaAttributeList > m_readKey
Gaudi::Property< bool > m_useDB
Gaudi::Property< float > m_posX
virtual StatusCode initialize() override final
Gaudi::Property< float > m_sigmaZ
bool range(EventIDRange &r)
const std::string & key() const
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const