ATLAS Offline Software
Loading...
Searching...
No Matches
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"
11#include <fstream>
12
13TBXCryYTableRead::TBXCryYTableRead(const std::string& name,
14 ISvcLocator* pSvcLocator) :
15 AthAlgorithm(name, pSvcLocator),
16 m_nEvent(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"),
25{
27}
28
31
33{
34 return StatusCode::SUCCESS;
35}
36
37
39{
40 return StatusCode::SUCCESS;
41}
42
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() ) {
54 ( "Cannot retrieve TBEventInfo from StoreGate" );
55 setFilterPassed(false);
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(),
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);
102 // return StatusCode::SUCCESS;
103 //}
104 setFilterPassed(true);
105 return StatusCode::SUCCESS;
106
107}
108
109StatusCode 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
#define y
#define x
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
float getBeamMomentum() const
Definition TBEventInfo.h:73
float getCryoAngle() const
Definition TBEventInfo.h:76
int getEventNum() const
Definition TBEventInfo.h:69
const std::string & getBeamParticle() const
Definition TBEventInfo.h:74
int getEventClock() const
Definition TBEventInfo.h:70
int getEventType() const
Definition TBEventInfo.h:71
unsigned int getRunNum() const
Definition TBEventInfo.h:72
virtual StatusCode finalize() override
StatusCode getXcryoYtable(float &x, float &y, float &eBeam)
Get Xcryo and Ytable from a text file.
virtual StatusCode execute() override
TBXCryYTableRead(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
float m_xCryo
Beam momentum.
float m_beamMom
Run number.
TBEventInfo * m_eventinfo
std::string m_txtFileWithXY
TableY.
Definition run.py:1