ATLAS Offline Software
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 
8 const 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 
20 BeamSpotCondAlg::BeamSpotCondAlg( const std::string& name, ISvcLocator* pSvcLocator )
21  : AthReentrantAlgorithm( name, pSvcLocator )
22 { }
23 
24 
26 
27 
29 {
30  ATH_MSG_DEBUG ("Initializing " << name() << "...");
31 
34 
35  return StatusCode::SUCCESS;
36 }
37 
38 StatusCode 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;
56  writeCdo = new InDet::BeamSpotData( m_status, m_posX, m_posY, m_posZ,
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 
BeamSpotCondAlg::m_tiltX
Gaudi::Property< float > m_tiltX
Definition: BeamSpotCondAlg.h:45
beamspotman.sigmaZ
sigmaZ
Definition: beamspotman.py:1625
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
BeamSpotCondAlg::m_posY
Gaudi::Property< float > m_posY
Definition: BeamSpotCondAlg.h:40
BeamSpotCondAlg::m_writeKey
SG::WriteCondHandleKey< InDet::BeamSpotData > m_writeKey
Definition: BeamSpotCondAlg.h:34
beamspotman.tiltY
tiltY
Definition: beamspotman.py:1627
BeamSpotCondAlg::m_sigmaX
Gaudi::Property< float > m_sigmaX
Definition: BeamSpotCondAlg.h:42
beamspotman.tiltX
tiltX
Definition: beamspotman.py:1626
beamspotman.sigmaXY
sigmaXY
Definition: beamspotman.py:1628
beamspotman.posX
posX
Definition: beamspotman.py:1624
BeamSpotCondAlg::m_useDB
Gaudi::Property< bool > m_useDB
Definition: BeamSpotCondAlg.h:37
beamspotman.sigmaX
sigmaX
Definition: beamspotman.py:1625
beamspotman.sigmaY
sigmaY
Definition: beamspotman.py:1625
BeamSpotCondAlg::m_sigmaY
Gaudi::Property< float > m_sigmaY
Definition: BeamSpotCondAlg.h:43
BeamSpotCondAlg::m_status
Gaudi::Property< int > m_status
Definition: BeamSpotCondAlg.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
BeamSpotCondAlg::initialize
virtual StatusCode initialize() override final
Definition: BeamSpotCondAlg.cxx:28
BeamSpotCondAlg::m_sigmaXY
Gaudi::Property< float > m_sigmaXY
Definition: BeamSpotCondAlg.h:47
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.posZ
posZ
Definition: beamspotman.py:1624
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
BeamSpotCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: BeamSpotCondAlg.cxx:38
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
BeamSpotCondAlg::~BeamSpotCondAlg
virtual ~BeamSpotCondAlg()
BeamSpotCondAlg::m_posX
Gaudi::Property< float > m_posX
Definition: BeamSpotCondAlg.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
BeamSpotCondAlg::alwaysValid
static const EventIDRange alwaysValid
Definition: BeamSpotCondAlg.h:27
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
BeamSpotCondAlg::m_readKey
SG::ReadCondHandleKey< AthenaAttributeList > m_readKey
Definition: BeamSpotCondAlg.h:31
beamspotman.posY
posY
Definition: beamspotman.py:1624
BeamSpotCondAlg::m_tiltY
Gaudi::Property< float > m_tiltY
Definition: BeamSpotCondAlg.h:46
BeamSpotCondAlg::m_sigmaZ
Gaudi::Property< float > m_sigmaZ
Definition: BeamSpotCondAlg.h:44
InDet::BeamSpotData
Definition: BeamSpotData.h:21
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
merge.status
status
Definition: merge.py:17
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
BeamSpotCondAlg::m_posZ
Gaudi::Property< float > m_posZ
Definition: BeamSpotCondAlg.h:41
BeamSpotCondAlg::BeamSpotCondAlg
BeamSpotCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: BeamSpotCondAlg.cxx:20
BeamSpotCondAlg.h