ATLAS Offline Software
CBNT_TBRecBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "CBNT_TBRecBase.h"
6 
9 #include "GaudiKernel/ITHistSvc.h"
10 
11 
12 CBNT_TBRecBase::CBNT_TBRecBase(const std::string& name, ISvcLocator* pSvcLocator):
13  AthAlgorithm(name, pSvcLocator), m_initialized(false), m_nt(NULL), m_log(NULL),
14  m_emId(NULL), m_hecId(NULL), m_fcalId(NULL),m_onlineId(NULL)
15 {
16 }
17 
19  delete m_log;
20 }
21 
23  m_log=new MsgStream(msgSvc(), name());
24 
25  *m_log << MSG::DEBUG << "Initializing CBNT_TBRecBase base class" << endmsg;
26 
27  const CaloCell_ID* idHelper = nullptr;
28  ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
29  m_emId=idHelper->em_idHelper();
30  m_fcalId=idHelper->fcal_idHelper();
31  m_hecId=idHelper->hec_idHelper();
32 
33 
34  if (!m_emId) {
35  (*m_log) << MSG::ERROR << "Could not access lar EM ID helper" << endmsg;
36  return StatusCode::FAILURE;
37  }
38  if (!m_fcalId) {
39  (*m_log) << MSG::ERROR << "Could not access lar FCAL ID helper" << endmsg;
40  return StatusCode::FAILURE;
41  }
42  if (!m_hecId) {
43  (*m_log) << MSG::ERROR << "Could not access lar HEC ID helper" << endmsg;
44  return StatusCode::FAILURE;
45  }
46 
47  StatusCode sc = detStore()->retrieve(m_onlineId, "LArOnlineID");
48  if (sc.isFailure()) {
49  (*m_log) << MSG::ERROR << "Could not get LArOnlineID helper !" << endmsg;
50  return StatusCode::FAILURE;
51  }
52  else {
53  (*m_log) << MSG::DEBUG << " Found the LArOnlineID helper. " << endmsg;
54  }
55 
56 
57  m_initialized=true;
58  return StatusCode::SUCCESS;
59 }
60 
62 
63  StatusCode sc;
64 
65  if(!m_initialized) {
66 
67  if (m_ntpath.size()==0 || m_ntTitle.size()==0) {
68  *m_log << MSG::ERROR << "Need to set variable 'm_ntpath' and 'm_ntTitle' in constructor of deriving class!" << endmsg;
69  return StatusCode::FAILURE;
70  }
71 
72  size_t i=m_ntpath.rfind('/');
73  if (i==std::string::npos) {
74  *m_log << MSG::ERROR << "Expected at least on '/' in path " << m_ntpath << endmsg;
75  return StatusCode::FAILURE;
76  }
77  std::string basepath(m_ntpath.begin(),m_ntpath.begin()+i);
78  //std::cout << "Basepath" << basepath << std::endl;
79 
80  // retrive pointer to THistSvc
81  ITHistSvc * tHistSvc = 0;
82  sc = Gaudi::svcLocator()->service("THistSvc", tHistSvc);
83  if (sc.isFailure()) {
84  *m_log << MSG::ERROR << "Unable to retrieve pointer to THistSvc" << endmsg;
85  return sc;
86  }
87  // get TTree
88  sc = tHistSvc->getTree(m_ntpath,m_nt);
89  if (sc.isFailure()) {
90  *m_log << MSG::ERROR << "Unable to retrieve TTree : " << m_ntpath << endmsg;
91  return sc;
92  }
93  /*
94  NTupleFilePtr file1(ntupleSvc(),basepath);
95  if (!file1){
96  (*m_log) << MSG::ERROR << "Could not get NTupleFilePtr with path " << basepath << " failed" << endmsg;
97  return StatusCode::FAILURE;
98  }
99  NTuplePtr nt(ntupleSvc(),m_ntpath);
100  if (!nt) {
101  nt=ntupleSvc()->book(m_ntpath,CLID_ColumnWiseTuple,m_ntTitle);
102  }
103  if (!nt){
104  (*m_log) << MSG::ERROR << "Booking of NTuple at "<< m_ntpath << " and name " << m_ntTitle << " failed" << endmsg;
105  return StatusCode::FAILURE;
106  }
107  m_nt=nt;
108  */
109  //std::cout << "Ntuple ptr:" << m_nt << std::endl;
110 
111  // subalgorithm initialisation
112  try {
113  sc = this->CBNT_initialize();
114  }
115  catch( const std::exception& Exception ) {
116  *m_log << MSG::ERROR << " Standard exception "
117  << Exception.what()
118  << " caught from sub-algorithm::CBNT_initialize () :" << endmsg ;
119  }
120  catch (...) {
121  *m_log << MSG::ERROR << " Unknown exception "
122  << " caught from sub-algorithm::CBNT_initialize () :" << endmsg ;
123  }
124 
125  if (sc.isFailure())
126  {
127  *m_log << MSG::ERROR << "CBNT_initialize() failed" << endmsg;
128  return sc;
129  }
130 
131  m_initialized=true;
132  }
133 
134  // clear data members
135  try {
136  sc = this->CBNT_clear();
137  }
138  catch( const std::exception& Exception ) {
139  *m_log << MSG::ERROR << " Standard exception "
140  << Exception.what()
141  << " caught from sub-algorithm::CBNT_clear () :" << endmsg ;
142  }
143  catch (...) {
144  *m_log << MSG::ERROR << " Unknown exception "
145  << " caught from sub-algorithm::CBNT_clear () :" << endmsg ;
146  }
147 
148  if (sc.isFailure()) {
149  *m_log << MSG::ERROR << "CBNT_clear() failed" << endmsg;
150  return sc;
151  }
152 
153  return StatusCode::SUCCESS ;
154 }
155 
156 
158 
159  StatusCode sc;
160 
161  // run pre-execution
162  try {
163  sc = this->pre_execute();
164  }
165 
166  catch( const std::exception& Exception ) {
167  *m_log << MSG::ERROR << " Standard exception "
168  << Exception.what()
169  << " caught from sub-algorithm::CBNT_pre_execute (). Disable !" << endmsg ;
170  sc = this->setProperty(BooleanProperty( "Enable",false ) );
171  return StatusCode::FAILURE;
172 
173  }
174  catch (...) {
175  *m_log << MSG::ERROR << " Unknown exception "
176  << " caught from sub-algorithm::CBNT_pre_execute (). Disable !" << endmsg ;
177  sc = this->setProperty(BooleanProperty( "Enable",false ) );
178  return StatusCode::FAILURE;
179  }
180 
181  if (sc.isFailure()) {
182  *m_log << MSG::ERROR << "CBNT_pre_execute() failed. Disable !" << endmsg;
183  sc = this->setProperty(BooleanProperty( "Enable",false ) );
184  return sc;
185  }
186 
187  // now subalgorithm execution
188  try {
189  sc = this->CBNT_execute();
190  }
191 
192  catch( const std::exception& Exception ) {
193  *m_log << MSG::ERROR << " Standard exception "
194  << Exception.what()
195  << " caught from sub-algorithm::CBNT_execute () :" << endmsg ;
196  return StatusCode::FAILURE;
197  }
198  catch (...) {
199  *m_log << MSG::ERROR << " Unknown exception "
200  << " caught from sub-algorithm::CBNT_execute () :" << endmsg ;
201  return StatusCode::FAILURE;
202  }
203 
204  return sc;
205 }
206 
207 
209 
210  StatusCode sc;
211 
212  //now subalgorithm finalisation
213  try {
214  sc = this->CBNT_finalize();
215  }
216  catch( const std::exception& Exception ) {
217  *m_log << MSG::ERROR << " Standard exception "
218  << Exception.what()
219  << " caught from sub-algorithm::CBNT_finalize () :" << endmsg ;
220  }
221  catch (...) {
222  *m_log << MSG::ERROR << " Unknown exception "
223  << " caught from sub-algorithm::CBNT_finalize () :" << endmsg ;
224  }
225 
226  return sc;
227 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CBNT_TBRecBase::CBNT_finalize
virtual StatusCode CBNT_finalize()
Definition: CBNT_TBRecBase.h:36
CBNT_TBRecBase::m_nt
TTree * m_nt
Definition: CBNT_TBRecBase.h:61
CBNT_TBRecBase::m_initialized
bool m_initialized
Definition: CBNT_TBRecBase.h:40
CaloCell_ID::em_idHelper
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition: CaloCell_ID.h:63
CBNT_TBRecBase::m_onlineId
const LArOnlineID * m_onlineId
Definition: CBNT_TBRecBase.h:68
CBNT_TBRecBase::CBNT_clear
virtual StatusCode CBNT_clear()
Definition: CBNT_TBRecBase.h:37
CBNT_TBRecBase::CBNT_initialize
virtual StatusCode CBNT_initialize()
Definition: CBNT_TBRecBase.h:34
CBNT_TBRecBase::CBNT_execute
virtual StatusCode CBNT_execute()
Definition: CBNT_TBRecBase.h:35
CBNT_TBRecBase.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
CaloCell_ID.h
CaloCell_ID::hec_idHelper
const LArHEC_ID * hec_idHelper() const
access to HEC idHelper
Definition: CaloCell_ID.h:69
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CBNT_TBRecBase::m_emId
const LArEM_ID * m_emId
Definition: CBNT_TBRecBase.h:65
CBNT_TBRecBase::m_fcalId
const LArFCAL_ID * m_fcalId
Definition: CBNT_TBRecBase.h:67
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
lumiFormat.i
int i
Definition: lumiFormat.py:92
CBNT_TBRecBase::m_log
MsgStream * m_log
Definition: CBNT_TBRecBase.h:63
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
calibdata.exception
exception
Definition: calibdata.py:496
CBNT_TBRecBase::execute
virtual StatusCode execute() override
Definition: CBNT_TBRecBase.cxx:157
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
CBNT_TBRecBase::CBNT_TBRecBase
CBNT_TBRecBase(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CBNT_TBRecBase.cxx:12
CBNT_TBRecBase::m_hecId
const LArHEC_ID * m_hecId
Definition: CBNT_TBRecBase.h:66
AthAlgorithm
Definition: AthAlgorithm.h:47
beamspotman.basepath
string basepath
Definition: beamspotman.py:1018
CBNT_TBRecBase::initialize
virtual StatusCode initialize() override
Definition: CBNT_TBRecBase.cxx:22
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CBNT_TBRecBase::~CBNT_TBRecBase
virtual ~CBNT_TBRecBase()
Definition: CBNT_TBRecBase.cxx:18
CBNT_TBRecBase::finalize
virtual StatusCode finalize() override
Definition: CBNT_TBRecBase.cxx:208
DEBUG
#define DEBUG
Definition: page_access.h:11
CBNT_TBRecBase::pre_execute
virtual StatusCode pre_execute()
Definition: CBNT_TBRecBase.cxx:61
CBNT_TBRecBase::m_ntTitle
std::string m_ntTitle
Definition: CBNT_TBRecBase.h:58
CBNT_TBRecBase::m_ntpath
std::string m_ntpath
Definition: CBNT_TBRecBase.h:58
CaloCell_ID::fcal_idHelper
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition: CaloCell_ID.h:75
LArOnlineID.h