ATLAS Offline Software
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"
9 #include "TBEvent/TBEventInfo.h"
11 #include <fstream>
12 
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 
30 { }
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(),
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);
102  // return StatusCode::SUCCESS;
103  //}
104  setFilterPassed(true);
105  return StatusCode::SUCCESS;
106 
107 }
108 
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 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
TBXCryYTableRead::finalize
virtual StatusCode finalize() override
Definition: TBXCryYTableRead.cxx:38
TBXCryYTableRead::m_nRun
int m_nRun
Definition: TBXCryYTableRead.h:34
TBXCryYTableRead::~TBXCryYTableRead
virtual ~TBXCryYTableRead()
Definition: TBXCryYTableRead.cxx:29
TBEventInfo::getRunNum
unsigned int getRunNum() const
Definition: TBEventInfo.h:72
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
TBXCryYTableRead::getXcryoYtable
StatusCode getXcryoYtable(float &x, float &y, float &eBeam)
Get Xcryo and Ytable from a text file.
Definition: TBXCryYTableRead.cxx:109
TBEventInfo::getEventType
int getEventType() const
Definition: TBEventInfo.h:71
x
#define x
dq_defect_bulk_create_defects.line
line
Definition: dq_defect_bulk_create_defects.py:27
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TBXCryYTableRead::execute
virtual StatusCode execute() override
Definition: TBXCryYTableRead.cxx:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TBEventInfo::getCryoAngle
float getCryoAngle() const
Definition: TBEventInfo.h:76
TBXCryYTableRead::m_txtFileWithXY
std::string m_txtFileWithXY
TableY.
Definition: TBXCryYTableRead.h:39
TBEventInfo::getBeamParticle
const std::string & getBeamParticle() const
Definition: TBEventInfo.h:74
TBEventInfo::getEventNum
int getEventNum() const
Definition: TBEventInfo.h:69
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
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition: AthCommonDataStore.h:145
TBEventInfo::getEventClock
int getEventClock() const
Definition: TBEventInfo.h:70
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TBXCryYTableRead::TBXCryYTableRead
TBXCryYTableRead(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TBXCryYTableRead.cxx:13
run
Definition: run.py:1
TBXCryYTableRead::initialize
virtual StatusCode initialize() override
Definition: TBXCryYTableRead.cxx:32
AthAlgorithm
Definition: AthAlgorithm.h:47
PathResolver.h
TBXCryYTableRead.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
y
#define y
TBEventInfo
Definition: TBEventInfo.h:27
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Definition: PathResolver.cxx:221
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:23
TBXCryYTableRead::m_yTable
float m_yTable
CryoX.
Definition: TBXCryYTableRead.h:37
TBEventInfo::getBeamMomentum
float getBeamMomentum() const
Definition: TBEventInfo.h:73
TBXCryYTableRead::m_xCryo
float m_xCryo
Beam momentum.
Definition: TBXCryYTableRead.h:36
TBEventInfo.h
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
TBXCryYTableRead::m_beamMom
float m_beamMom
Run number.
Definition: TBXCryYTableRead.h:35
checker_macros.h
Define macros for attributes used to control the static checker.
TBXCryYTableRead::m_nEvent
int m_nEvent
Definition: TBXCryYTableRead.h:30
TBXCryYTableRead::m_first
bool m_first
Definition: TBXCryYTableRead.h:32