ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
TestBeam
TBRec
src
TBXCryYTableRead.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// class TBXCryYTableRead
6
7
#include "
TBXCryYTableRead.h
"
8
#include "
PathResolver/PathResolver.h
"
9
#include "
TBEvent/TBEventInfo.h
"
10
#include "
CxxUtils/checker_macros.h
"
11
#include <fstream>
12
13
TBXCryYTableRead::TBXCryYTableRead
(
const
std::string& name,
14
ISvcLocator* pSvcLocator) :
15
AthAlgorithm
(name, pSvcLocator),
16
m_nEvent
(0),
17
m_nEventRandomTrigger
(0),
18
m_first
(true),
19
m_nRun
(0),
20
m_beamMom
(0),
21
m_xCryo
(0),
22
m_yTable
(0),
23
m_txtFileWithXY
(
"xcryo_ytable.txt"
),
24
m_eventinfo
(0)
25
{
26
declareProperty
(
"FileName"
,
m_txtFileWithXY
);
27
}
28
29
TBXCryYTableRead::~TBXCryYTableRead
()
30
{ }
31
32
StatusCode
TBXCryYTableRead::initialize
()
33
{
34
return
StatusCode::SUCCESS;
35
}
36
37
38
StatusCode
TBXCryYTableRead::finalize
()
39
{
40
return
StatusCode::SUCCESS;
41
}
42
43
StatusCode
TBXCryYTableRead::execute
(
const
EventContext& ctx)
44
{
45
m_nEvent
++;
46
ATH_MSG_DEBUG
(
"Executing TBXCryYTableRead "
);
47
48
StatusCode
sc
;
49
// Retrieve Event Info from file
50
const
TBEventInfo
* theEventInfo =
nullptr
;
51
sc
=
evtStore
()->retrieve(theEventInfo,
"TBEventInfo"
);
52
if
(
sc
.isFailure() ) {
53
ATH_MSG_ERROR
54
(
"Cannot retrieve TBEventInfo from StoreGate"
);
55
setFilterPassed
(
false
, ctx);
56
return
StatusCode::SUCCESS;
57
}
58
59
// Do first event initialization (run header filling)
60
if
(
m_first
) {
61
m_first
=
false
;
62
// Fill run header
63
m_nRun
= theEventInfo->
getRunNum
();
64
m_beamMom
= theEventInfo->
getBeamMomentum
();
65
ATH_MSG_DEBUG
(
"Run, mom. from EventInfo: "
<<
m_nRun
<<
","
<<
m_beamMom
);
66
// Get xcryo and ytable from a file
67
float
xFile, yFile, eFile;
68
ATH_CHECK
(
getXcryoYtable
(xFile, yFile, eFile));
69
if
(
m_beamMom
!= eFile) {
70
ATH_MSG_WARNING
(
"Energy from file: "
<<eFile<<
" is different than from bytestream: "
<<
m_beamMom
<<
" !!!"
);
71
ATH_MSG_WARNING
(
"Using value from file !!!"
);
72
m_beamMom
= eFile;
73
}
74
m_xCryo
= xFile;
75
m_yTable
= yFile;
76
}
77
78
// Now change the TBEventInfo
79
// unfortunatelly no copy constructor....
80
// m_eventinfo = new TBEventInfo(theEventInfo->getEventNum(), theEventInfo->getEventClock(),
81
// theEventInfo->getEventType(), m_nRun, m_beamMom,
82
// theEventInfo->getBeamParticle(), m_xCryo, theEventInfo->getCryoAngle(),
83
// m_yTable);
84
ATH_MSG_DEBUG
(
"Filling TBEvent info with cryoX,tableY: "
<<
m_xCryo
<<
","
<<
m_yTable
);
85
// FIXME: const violation!
86
TBEventInfo
* ei_nc
ATLAS_THREAD_SAFE
=
const_cast<
TBEventInfo
*
>
(theEventInfo);
87
*ei_nc =
88
TBEventInfo
(theEventInfo->
getEventNum
(),
89
theEventInfo->
getEventClock
(),
90
theEventInfo->
getEventType
(),
91
theEventInfo->
getRunNum
(),
92
m_beamMom
,
93
theEventInfo->
getBeamParticle
(),
94
m_xCryo
,
95
theEventInfo->
getCryoAngle
(),
96
m_yTable
);
97
98
//sc = m_eventStore->record(m_eventinfo,"TBEventInfo");
99
//if ( sc.isFailure( ) ) {
100
// ATH_MSG_FATAL( "Cannot record new TBEventInfo " );
101
// setFilterPassed(false, ctx);
102
// return StatusCode::SUCCESS;
103
//}
104
setFilterPassed
(
true
, ctx);
105
return
StatusCode::SUCCESS;
106
107
}
108
109
StatusCode
TBXCryYTableRead::getXcryoYtable
(
float
&
x
,
float
&
y
,
float
&e) {
110
111
ATH_MSG_DEBUG
(
"in getXcryoYtable(float x, float y)"
);
112
113
std::ifstream xyFile;
114
std::string line;
115
std::string filename =
PathResolver::find_file
(
m_txtFileWithXY
,
"DATAPATH"
);
116
xyFile.open(filename.c_str());
117
if
(!xyFile.is_open()) {
118
ATH_MSG_ERROR
(
"File "
<<
m_txtFileWithXY
<<
" fail to open in $DATAPATH"
);
119
return
StatusCode::FAILURE;
120
}
121
122
ATH_MSG_DEBUG
(
"Asking for run: "
<<
m_nRun
);
123
while
( getline(xyFile, line,
'\n'
) ) {
124
int
run
;
125
std::istringstream buf(line);
126
e = 0;
127
buf >>
run
>>
x
>>
y
>> e;
128
ATH_MSG_DEBUG
(
"run,x,y,e= "
<<
run
<<
" "
<<
x
<<
" "
<<
y
<<
" "
<<e);
129
if
(
run
==
m_nRun
&& xyFile.good())
return
StatusCode::SUCCESS;
130
}
131
132
return
StatusCode::FAILURE;
133
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x,...)
Definition
AthMsgStreamMacros.h:46
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
PathResolver.h
TBEventInfo.h
TBXCryYTableRead.h
y
#define y
x
#define x
checker_macros.h
Define macros for attributes used to control the static checker.
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition
checker_macros.h:211
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::setFilterPassed
virtual void setFilterPassed(bool state, const EventContext &ctx) const
Definition
AthCommonAlgorithm.h:99
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Definition
PathResolver.cxx:220
TBEventInfo
Definition
TBEventInfo.h:27
TBEventInfo::getBeamMomentum
float getBeamMomentum() const
Definition
TBEventInfo.h:73
TBEventInfo::getCryoAngle
float getCryoAngle() const
Definition
TBEventInfo.h:76
TBEventInfo::getEventNum
int getEventNum() const
Definition
TBEventInfo.h:69
TBEventInfo::getBeamParticle
const std::string & getBeamParticle() const
Definition
TBEventInfo.h:74
TBEventInfo::getEventClock
int getEventClock() const
Definition
TBEventInfo.h:70
TBEventInfo::getEventType
int getEventType() const
Definition
TBEventInfo.h:71
TBEventInfo::getRunNum
unsigned int getRunNum() const
Definition
TBEventInfo.h:72
TBXCryYTableRead::finalize
virtual StatusCode finalize() override
Definition
TBXCryYTableRead.cxx:38
TBXCryYTableRead::getXcryoYtable
StatusCode getXcryoYtable(float &x, float &y, float &eBeam)
Get Xcryo and Ytable from a text file.
Definition
TBXCryYTableRead.cxx:109
TBXCryYTableRead::m_nEvent
int m_nEvent
Definition
TBXCryYTableRead.h:30
TBXCryYTableRead::m_nEventRandomTrigger
int m_nEventRandomTrigger
Definition
TBXCryYTableRead.h:31
TBXCryYTableRead::TBXCryYTableRead
TBXCryYTableRead(const std::string &name, ISvcLocator *pSvcLocator)
Definition
TBXCryYTableRead.cxx:13
TBXCryYTableRead::m_first
bool m_first
Definition
TBXCryYTableRead.h:32
TBXCryYTableRead::initialize
virtual StatusCode initialize() override
Definition
TBXCryYTableRead.cxx:32
TBXCryYTableRead::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
TBXCryYTableRead.cxx:43
TBXCryYTableRead::~TBXCryYTableRead
virtual ~TBXCryYTableRead()
Definition
TBXCryYTableRead.cxx:29
TBXCryYTableRead::m_xCryo
float m_xCryo
Beam momentum.
Definition
TBXCryYTableRead.h:36
TBXCryYTableRead::m_beamMom
float m_beamMom
Run number.
Definition
TBXCryYTableRead.h:35
TBXCryYTableRead::m_eventinfo
TBEventInfo * m_eventinfo
Definition
TBXCryYTableRead.h:41
TBXCryYTableRead::m_nRun
int m_nRun
Definition
TBXCryYTableRead.h:34
TBXCryYTableRead::m_txtFileWithXY
std::string m_txtFileWithXY
TableY.
Definition
TBXCryYTableRead.h:39
TBXCryYTableRead::m_yTable
float m_yTable
CryoX.
Definition
TBXCryYTableRead.h:37
run
int run(int argc, char *argv[])
Definition
ttree2hdf5.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0