ATLAS Offline Software
InDetUpdateCaches.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
10 
11 
12 
13 // for getmem
14 #include <sys/types.h>
15 #include <unistd.h>
16 #include <string>
17 #include <fstream>
18 #include <sstream>
19 
20 
21 
22 InDetUpdateCaches::InDetUpdateCaches(const std::string& name, ISvcLocator* pSvcLocator) :
23  AthAlgorithm(name, pSvcLocator),
24  m_first(true){
25  // Get parameter values from jobOptions file
26  declareProperty("UpdateInInit", m_inInit = false);
27  declareProperty("UpdateInExec", m_inExec = true);
28 }
29 
30 
33  msg(MSG::INFO) << "initialize()" << endmsg;
34  StatusCode sc;
35  // Retrieve GeoModel managers
36  const InDetDD::SCT_DetectorManager * sctManager = nullptr;
37  sc=detStore()->retrieve(sctManager, "SCT");
38  if (sc.isFailure() || !sctManager) {
39  msg(MSG::WARNING) << "Could not find the SCT_DetectorManager" << endmsg;
40  } else {
41  msg(MSG::DEBUG) << "SCT_DetectorManager found" << endmsg;
42  m_detManagers.push_back(sctManager);
43  }
44  const InDetDD::PixelDetectorManager * pixelManager = nullptr;
45  sc=detStore()->retrieve(pixelManager, "Pixel");
46  if (sc.isFailure() || !pixelManager) {
47  msg(MSG::WARNING) << "Could not find the PixelDetectorManager" << endmsg;
48  } else {
49  msg(MSG::DEBUG) << "PixelDetectorManager found" << endmsg;
50  m_detManagers.push_back(pixelManager);
51  }
52  const InDetDD::TRT_DetectorManager * trtManager = nullptr;
53  sc=detStore()->retrieve(trtManager, "TRT");
54  if (sc.isFailure() || !trtManager) {
55  msg(MSG::WARNING) << "Could not find the TRT_DetectorManager" << endmsg;
56  } else {
57  msg(MSG::DEBUG) << "TRT_DetectorManager found" << endmsg;
58  m_detManagers.push_back(trtManager);
59  }
60  if (m_inInit) {
61  msg(MSG::DEBUG) << "Updating caches during initialize" << endmsg;
62  updateAll();
63  }
64  return StatusCode::SUCCESS;
65 }
66 
67 
70  if (m_first) {
71  if (m_inExec) {
72  msg(MSG::DEBUG) << "Updating caches during first execute" << endmsg;
73  updateAll();
74  }
75  m_first = false;
76  }
77  return StatusCode::SUCCESS;
78 }
79 
80 
83  return StatusCode::SUCCESS;
84 }
85 
86 
87 void
89  msg(MSG::DEBUG) << "Updating ..." << endmsg;
90  IChronoStatSvc* chrono = chronoSvc();
91  for (unsigned int i = 0; i < m_detManagers.size(); i++) {
93  msg(MSG::DEBUG) << "manager ..." << manager << endmsg;
94  if (manager) {
95  std::string chronoTag = manager->getName() + name();
96  float memStart = getMem();
97  chrono->chronoStart( chronoTag );
98  msg(MSG::DEBUG) << "Updating " << manager->getName() << " caches ..." << endmsg;
99  manager->updateAll();
100  msg(MSG::DEBUG) << "... done " << endmsg;
101  chrono->chronoStop(chronoTag);
102  float memUsed = getMem() - memStart;
103  float uTime = chrono->chronoDelta(chronoTag, IChronoStatSvc::USER)/1000.;
104  msg(MSG::DEBUG) << "Memory used by UpdatedCaches for " << manager->getName() << " = " << memUsed/1024.0 << " MB" << endmsg;
105  msg(MSG::DEBUG) << "Time used by UpdatedCaches for " << manager->getName() << " = " << uTime << " ms" << endmsg;
106  }
107  }
108 }
109 
110 
111 float
113  int pid=getpid();
114  std::ostringstream is;
115  is<<pid;
116  std::string spid=is.str();
117  std::string temp="cat /proc/"+spid+"/status | grep VmSize > mem.txt";
118  system(temp.c_str());
119  std::ifstream in("mem.txt");
120  std::string text,mem,text1;
121  in>>text>>mem>>text1;
122  system("rm -f mem.txt");
123  float memsize=atof(mem.c_str());
124  return memsize;
125 }
InDetUpdateCaches::finalize
StatusCode finalize()
Definition: InDetUpdateCaches.cxx:82
InDetUpdateCaches::InDetUpdateCaches
InDetUpdateCaches(const std::string &name, ISvcLocator *pSvcLocator)
Definition: InDetUpdateCaches.cxx:22
InDetDD::SCT_DetectorManager
Definition: SCT_DetectorManager.h:49
TRT_DetectorManager.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
InDetUpdateCaches::m_inExec
bool m_inExec
Definition: InDetUpdateCaches.h:36
InDetUpdateCaches::updateAll
void updateAll()
Definition: InDetUpdateCaches.cxx:88
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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
PixelDetectorManager.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
InDetDD::InDetDetectorManager
Definition: InDetDetectorManager.h:60
InDetUpdateCaches.h
AthAlgorithm
Definition: AthAlgorithm.h:47
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
InDetDD::PixelDetectorManager
Definition: PixelDetectorManager.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
InDetUpdateCaches::m_inInit
bool m_inInit
Definition: InDetUpdateCaches.h:35
InDetUpdateCaches::m_first
bool m_first
Definition: InDetUpdateCaches.h:31
InDetDD::TRT_DetectorManager
The Detector Manager for all TRT Detector elements, it acts as the interface to the detector elements...
Definition: TRT_DetectorManager.h:69
InDetUpdateCaches::execute
StatusCode execute()
Definition: InDetUpdateCaches.cxx:69
InDetUpdateCaches::m_detManagers
std::vector< const InDetDD::InDetDetectorManager * > m_detManagers
Definition: InDetUpdateCaches.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
makeTransCanvas.text
text
Definition: makeTransCanvas.py:11
python.Logging.manager
manager
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/Logging.py:92
SCT_DetectorManager.h
InDetUpdateCaches::getMem
float getMem()
Definition: InDetUpdateCaches.cxx:112
InDetUpdateCaches::initialize
StatusCode initialize()
Definition: InDetUpdateCaches.cxx:32