ATLAS Offline Software
TBXCryYTableRead.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // class TBXCryYTableRead
6 
7 #include "TBXCryYTableRead.h"
9 #include "TBEvent/TBEventInfo.h"
10 #include <fstream>
11 
13  ISvcLocator* pSvcLocator) :
14  AthAlgorithm(name, pSvcLocator),
15  m_nEvent(0),
16  m_nEventRandomTrigger(0),
17  m_first(true),
18  m_nRun(0),
19  m_beamMom(0),
20  m_xCryo(0),
21  m_yTable(0),
22  m_txtFileWithXY("xcryo_ytable.txt"),
23  m_eventinfo(0)
24 {
25  declareProperty("FileName",m_txtFileWithXY);
26 }
27 
29 { }
30 
32 {
33  return StatusCode::SUCCESS;
34 }
35 
36 
38 {
39  return StatusCode::SUCCESS;
40 }
41 
43 {
44  m_nEvent++;
45  ATH_MSG_DEBUG ( "Executing TBXCryYTableRead " );
46 
47  StatusCode sc;
48  // Retrieve Event Info from file
49  const TBEventInfo* theEventInfo = nullptr;
50  sc = evtStore()->retrieve(theEventInfo,"TBEventInfo");
51  if ( sc.isFailure() ) {
53  ( "Cannot retrieve TBEventInfo from StoreGate" );
54  setFilterPassed(false);
55  return StatusCode::SUCCESS;
56  }
57 
58  // Do first event initialization (run header filling)
59  if (m_first) {
60  m_first = false;
61  // Fill run header
62  m_nRun = theEventInfo->getRunNum();
63  m_beamMom = theEventInfo->getBeamMomentum();
64  ATH_MSG_DEBUG ( "Run, mom. from EventInfo: "<<m_nRun<<","<<m_beamMom);
65  // Get xcryo and ytable from a file
66  float xFile, yFile, eFile;
67  ATH_CHECK(getXcryoYtable(xFile, yFile, eFile));
68  if(m_beamMom != eFile) {
69  ATH_MSG_WARNING ( "Energy from file: "<<eFile<<" is different than from bytestream: "<<m_beamMom<<" !!!");
70  ATH_MSG_WARNING ( "Using value from file !!!");
71  m_beamMom = eFile;
72  }
73  m_xCryo = xFile;
74  m_yTable = yFile;
75  }
76 
77  // Now change the TBEventInfo
78  // unfortunatelly no copy constructor....
79 // m_eventinfo = new TBEventInfo(theEventInfo->getEventNum(), theEventInfo->getEventClock(),
80 // theEventInfo->getEventType(), m_nRun, m_beamMom,
81 // theEventInfo->getBeamParticle(), m_xCryo, theEventInfo->getCryoAngle(),
82 // m_yTable);
83  ATH_MSG_DEBUG ( "Filling TBEvent info with cryoX,tableY: "<<m_xCryo<<","<<m_yTable);
84  // FIXME: const violation!
85  *const_cast<TBEventInfo*>(theEventInfo) =
86  TBEventInfo (theEventInfo->getEventNum(),
87  theEventInfo->getEventClock(),
88  theEventInfo->getEventType(),
89  theEventInfo->getRunNum(),
90  m_beamMom,
91  theEventInfo->getBeamParticle(),
92  m_xCryo,
93  theEventInfo->getCryoAngle(),
94  m_yTable);
95 
96  //sc = m_eventStore->record(m_eventinfo,"TBEventInfo");
97  //if ( sc.isFailure( ) ) {
98  // ATH_MSG_FATAL( "Cannot record new TBEventInfo " );
99  // setFilterPassed(false);
100  // return StatusCode::SUCCESS;
101  //}
102  setFilterPassed(true);
103  return StatusCode::SUCCESS;
104 
105 }
106 
108 
109  ATH_MSG_DEBUG ( "in getXcryoYtable(float x, float y)" );
110 
111  std::ifstream xyFile;
112  std::string line;
113  std::string filename = PathResolver::find_file(m_txtFileWithXY, "DATAPATH");
114  xyFile.open(filename.c_str());
115  if (!xyFile.is_open()) {
116  ATH_MSG_ERROR ( "File " << m_txtFileWithXY << " fail to open in $DATAPATH");
117  return StatusCode::FAILURE;
118  }
119 
120  ATH_MSG_DEBUG ( "Asking for run: "<<m_nRun);
121  while ( getline(xyFile, line, '\n') ) {
122  int run;
123  std::istringstream buf(line);
124  e = 0;
125  buf >> run >> x >> y >> e;
126  ATH_MSG_DEBUG ( "run,x,y,e= "<<run<<" "<<x<<" "<<y<<" "<<e);
127  if (run == m_nRun && xyFile.good()) return StatusCode::SUCCESS;
128  }
129 
130  return StatusCode::FAILURE;
131 }
TBXCryYTableRead::finalize
virtual StatusCode finalize() override
Definition: TBXCryYTableRead.cxx:37
TBXCryYTableRead::m_nRun
int m_nRun
Definition: TBXCryYTableRead.h:33
checkFileSG.line
line
Definition: checkFileSG.py:75
TBXCryYTableRead::~TBXCryYTableRead
virtual ~TBXCryYTableRead()
Definition: TBXCryYTableRead.cxx:28
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TBEventInfo::getRunNum
unsigned int getRunNum() const
Definition: TBEventInfo.h:67
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:107
TBEventInfo::getEventType
int getEventType() const
Definition: TBEventInfo.h:66
x
#define x
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:42
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TBEventInfo::getCryoAngle
float getCryoAngle() const
Definition: TBEventInfo.h:71
TBXCryYTableRead::m_txtFileWithXY
std::string m_txtFileWithXY
TableY.
Definition: TBXCryYTableRead.h:38
TBEventInfo::getEventNum
int getEventNum() const
Definition: TBEventInfo.h:64
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
TBEventInfo::getEventClock
int getEventClock() const
Definition: TBEventInfo.h:65
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TBXCryYTableRead::TBXCryYTableRead
TBXCryYTableRead(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TBXCryYTableRead.cxx:12
TBEventInfo::getBeamParticle
std::string getBeamParticle() const
Definition: TBEventInfo.h:69
run
Definition: run.py:1
TBXCryYTableRead::initialize
virtual StatusCode initialize() override
Definition: TBXCryYTableRead.cxx:31
AthAlgorithm
Definition: AthAlgorithm.h:47
PathResolver.h
TBXCryYTableRead.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
y
#define y
TBEventInfo
Definition: TBEventInfo.h:27
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
TBXCryYTableRead::m_yTable
float m_yTable
CryoX.
Definition: TBXCryYTableRead.h:36
TBEventInfo::getBeamMomentum
float getBeamMomentum() const
Definition: TBEventInfo.h:68
TBXCryYTableRead::m_xCryo
float m_xCryo
Beam momentum.
Definition: TBXCryYTableRead.h:35
TBEventInfo.h
TBXCryYTableRead::m_beamMom
float m_beamMom
Run number.
Definition: TBXCryYTableRead.h:34
TBXCryYTableRead::m_nEvent
int m_nEvent
Definition: TBXCryYTableRead.h:29
TBXCryYTableRead::m_first
bool m_first
Definition: TBXCryYTableRead.h:31