ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
top::AnalysisTrackingHelper Class Reference

Helper for collecting data for analysis tracking. More...

#include <AnalysisTrackingHelper.h>

Collaboration diagram for top::AnalysisTrackingHelper:

Classes

struct  InputFileInfo
 

Public Member Functions

 AnalysisTrackingHelper ()
 
 ~AnalysisTrackingHelper ()
 
void addInputFile (std::string const &path, unsigned long long entriesProcessed)
 Notify helper that an input file was processed. More...
 
void setTopConfig (std::shared_ptr< TopConfig > const &topConfig)
 Notify helper about configuration options. More...
 
void writeTree (std::string const &treename)
 Store tracking data in current TFile. More...
 

Private Member Functions

void finish ()
 

Private Attributes

std::string m_json
 
bool m_finished
 
std::shared_ptr< TopConfigm_topConfig
 
std::vector< InputFileInfom_inputFiles
 

Detailed Description

Helper for collecting data for analysis tracking.

Definition at line 20 of file AnalysisTrackingHelper.h.

Constructor & Destructor Documentation

◆ AnalysisTrackingHelper()

top::AnalysisTrackingHelper::AnalysisTrackingHelper ( )

Definition at line 59 of file AnalysisTrackingHelper.cxx.

59  :
60  m_finished(false)
61  { }

◆ ~AnalysisTrackingHelper()

top::AnalysisTrackingHelper::~AnalysisTrackingHelper ( )

Definition at line 64 of file AnalysisTrackingHelper.cxx.

64 { }

Member Function Documentation

◆ addInputFile()

void top::AnalysisTrackingHelper::addInputFile ( std::string const path,
unsigned long long  entriesProcessed 
)

Notify helper that an input file was processed.

Parameters
pathPath to the input file.
entriesProcessedNumber of entries that were processed.

Definition at line 67 of file AnalysisTrackingHelper.cxx.

67  {
68  top::check(!m_finished, "AnalysisTrackingHelper::addInputFile called on finished instance");
69  char* fullpath = realpath(path.c_str(), NULL);
70  BOOST_SCOPE_EXIT(fullpath) {
71  free(fullpath);
72  } BOOST_SCOPE_EXIT_END
73  m_inputFiles.emplace_back((fullpath == nullptr ? path.c_str() : fullpath), entriesProcessed);
74  }

◆ finish()

void top::AnalysisTrackingHelper::finish ( )
private

Definition at line 91 of file AnalysisTrackingHelper.cxx.

91  {
92  std::ostringstream out;
93 
94  std::string const json_null("null");
95  out << "{\n";
96  {
97  // Store settings from configuration file:
98  out << json_dump("configSettings") << ": {";
99  auto const& config = *top::ConfigurationSettings::get();
100  char const* sep = "\n ";
101  for (auto&& kv : config.stringData()) {
102  if (!kv.second.m_set) continue;
103  out << sep << json_dump(kv.first) << ": " << json_dump(kv.second.m_data);
104  sep = ",\n ";
105  }
106  out << "},\n";
107  }
108  {
109  // Store small subset of environment variables:
110  out << json_dump("environment") << ": {";
111  char const* sep = "\n ";
112  auto dumpEnvVar = [&](char const* name) {
113  char const* value = std::getenv(name);
114 
115  out << sep << json_dump(name) << ": " << (value == nullptr ? json_null : json_dump(value));
116  sep = ",\n ";
117  };
118  dumpEnvVar("AnalysisBase_DIR");
119  dumpEnvVar("AnalysisBase_VERSION");
120  dumpEnvVar("AnalysisBaseExternals_DIR");
121  dumpEnvVar("AnalysisBaseExternals_VERSION");
122  dumpEnvVar("AnalysisTop_DIR");
123  dumpEnvVar("AnalysisTop_VERSION");
124  dumpEnvVar("AtlasVersion");
125  dumpEnvVar("HOSTNAME");
126  dumpEnvVar("PanDA_TaskID");
127  dumpEnvVar("PandaID");
128  out << "},\n";
129  }
130  {
131  // Store metadata of inputs:
132  out << json_dump("inputConfig") << ": {\n";
133  out << " " << json_dump("derivationFormat") << ": " << json_dump(m_topConfig->getDerivationStream()) << ",\n";
134  out << " " << json_dump("dsid") << ": " << json_dump(m_topConfig->getDSID()) << ",\n";
135  out << " " << json_dump("isMC") << ": " << json_dump(m_topConfig->isMC()) << ",\n";
136  out << " " << json_dump("isAtlFast2") << ": " << json_dump(m_topConfig->isAFII()) << "\n";
137  out << " " << json_dump("BtagCDIPath") << ": " << json_dump(m_topConfig->bTaggingCDIPath()) << "\n";
138  out << "},\n";
139  }
140  {
141  // List paths of loaded libraries, grouping them by directory:
142  bool ok;
143  std::map<std::string, std::set<std::string> > libs;
144  try {
145  boost::regex reLine("\\s*(?:\\S+\\s+){5}(/.*)");
146  boost::cmatch m;
147  std::ifstream stream("/proc/self/maps", std::ios_base::in | std::ios_base::binary);
148  for (std::string line; std::getline(stream, line); ) {
149  if (boost::regex_match(line.c_str(), m, reLine)) {
150  std::string const& path = m[1];
151  size_t i = path.rfind('/');
152  assert(i != std::string::npos);
153  std::string const& basename = path.substr(i + 1);
154  if (basename.starts_with( "lib")) {
155  std::string dirpath = path.substr(0, (i ? i : 1));
156  libs[dirpath].insert(basename);
157  }
158  }
159  }
160  stream.close();
161  ok = true;
162  }
163  catch (std::exception const&) {
164  ok = false;
165  }
166  // Store sorted list of loaded libraries (if listing was successful):
167  if (ok) {
168  out << json_dump("images") << ": [";
169  char const* sep1 = "\n ";
170  for (auto&& lib : libs) {
171  out << sep1 << "[" << json_dump(lib.first) << ", [";
172  sep1 = ",\n ";
173  char const* sep2 = "\n ";
174  for (auto&& basename : lib.second) {
175  out << sep2 << json_dump(basename);
176  sep2 = ",\n ";
177  }
178  out << "]]";
179  }
180  out << "],\n";
181  }
182  }
183  {
184  // Store information about processed input files:
185  out << json_dump("inputFiles") << ": [";
186  char const* sep = "\n ";
187  for (auto const& inputFile : m_inputFiles) {
188  out << sep << "[" << json_dump(inputFile.path) << "," << json_dump(inputFile.entriesProcessed) << "]";
189  sep = ",\n ";
190  }
191  out << "],\n";
192  }
193  {
194  // Store various PerfStats:
195  auto&& readStats = xAOD::IOStats::instance().stats();
196  out << json_dump("perfStats") << ": {\n";
197  {
198  out << " " << json_dump("readEntriesByContainer") << ": {";
199  char const* sep = "\n ";
200  for (auto&& kv : readStats.containers()) {
201  xAOD::BranchStats const& bs = kv.second;
202  if (std::string(bs.GetName()).ends_with("TDS") || std::string(bs.GetName()).ends_with("Aux.")) continue;
203  if (bs.readEntries()) {
204  out << sep << json_dump(bs.GetName()) << ": " << json_dump(bs.readEntries());
205  sep = ",\n ";
206  }
207  }
208  out << "},\n";
209  }
210  {
211  out << " " << json_dump("readEntriesByBranch") << ": {";
212  char const* sep = "\n ";
213  for (auto&& kv : readStats.branches()) {
214  for (xAOD::BranchStats const* bs : kv.second) {
215  if (bs && bs->readEntries()) {
216  out << sep << json_dump(bs->GetName()) << ": " << json_dump(bs->readEntries());
217  sep = ",\n ";
218  }
219  }
220  }
221  out << "},\n";
222  }
223  out << " " << json_dump("totalEntries") << ": " << json_dump(readStats.nEvents()) << "},\n";
224  }
225  {
226  // Store configuration of all (CP) tools:
227  out << json_dump("toolConfig") << ": {";
228  PropertyValueJsonDumper json_dump_prop;
229  char const* toolsep = "\n ";
230  for (std::string const& toolname : listToolStore()) {
231  auto&& tool = asg::ToolStore::get<asg::AsgTool>(toolname);
232  if (tool == nullptr) continue;
233  if (tool->name().starts_with( "top::")) continue;
234  out << toolsep << json_dump(tool->name()) << ": {";
235  auto&& props = *tool->getPropertyMgr();
236  char const* propsep = "\n ";
237  for (auto&& prop : props.getProperties()) {
238  if (!prop.second->isValid()) continue;
239  auto&& jvalue = json_dump_prop(prop.second);
240  if (jvalue == std::nullopt) continue;
241  out << propsep << json_dump(prop.first) << ": " << *jvalue;
242  propsep = ",\n ";
243  }
244  out << "}";
245  toolsep = ",\n ";
246  }
247  out << "},\n";
248  }
249  out << json_dump("format") << ": " << json_dump(1) << "\n}\n";
250  out.str().swap(m_json);
251  m_finished = true;
252  }

◆ setTopConfig()

void top::AnalysisTrackingHelper::setTopConfig ( std::shared_ptr< TopConfig > const topConfig)

Notify helper about configuration options.

Parameters
topConfigPointer to the TopConfig object.

Definition at line 76 of file AnalysisTrackingHelper.cxx.

76  {
77  top::check(!m_finished, "AnalysisTrackingHelper::setTopConfig called on finished instance");
78  m_topConfig = topConfig;
79  }

◆ writeTree()

void top::AnalysisTrackingHelper::writeTree ( std::string const treename)

Store tracking data in current TFile.

Parameters
treenameName of the TTree used to store the data.
Remarks
It's your responsibility to call TFile::cd() before this function.

Definition at line 81 of file AnalysisTrackingHelper.cxx.

81  {
82  finish();
83  TTree* t = new TTree(treename.c_str(), "");
84  t->SetAutoSave(0);
85  t->SetAutoFlush(0);
86  t->Branch("jsonData", &m_json, 262144);
87  t->Fill();
88  t->Write();
89  }

Member Data Documentation

◆ m_finished

bool top::AnalysisTrackingHelper::m_finished
private

Definition at line 63 of file AnalysisTrackingHelper.h.

◆ m_inputFiles

std::vector<InputFileInfo> top::AnalysisTrackingHelper::m_inputFiles
private

Definition at line 65 of file AnalysisTrackingHelper.h.

◆ m_json

std::string top::AnalysisTrackingHelper::m_json
private

Definition at line 62 of file AnalysisTrackingHelper.h.

◆ m_topConfig

std::shared_ptr<TopConfig> top::AnalysisTrackingHelper::m_topConfig
private

Definition at line 64 of file AnalysisTrackingHelper.h.


The documentation for this class was generated from the following files:
checkFileSG.line
line
Definition: checkFileSG.py:75
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
LArG4ShowerLibProcessing.libs
list libs
Definition: LArG4ShowerLibProcessing.py:50
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
athena.value
value
Definition: athena.py:122
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
top::AnalysisTrackingHelper::m_inputFiles
std::vector< InputFileInfo > m_inputFiles
Definition: AnalysisTrackingHelper.h:65
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
top::AnalysisTrackingHelper::m_json
std::string m_json
Definition: AnalysisTrackingHelper.h:62
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
lumiFormat.i
int i
Definition: lumiFormat.py:92
xAOD::BranchStats::readEntries
::Long64_t readEntries() const
Get how many entries were read from this branch.
top::ConfigurationSettings::get
static ConfigurationSettings * get(bool reset=false)
Design patterns 101.
Definition: ConfigurationSettings.cxx:714
calibdata.exception
exception
Definition: calibdata.py:496
xAOD::BranchStats
Class describing the access statistics of one (sub-)branch.
Definition: ReadStats.h:43
top::AnalysisTrackingHelper::finish
void finish()
Definition: AnalysisTrackingHelper.cxx:91
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
grepfile.sep
sep
Definition: grepfile.py:38
top::AnalysisTrackingHelper::m_finished
bool m_finished
Definition: AnalysisTrackingHelper.h:63
python.hypoToolDisplay.toolname
def toolname(tool)
Definition: hypoToolDisplay.py:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
python.diffTAGTree.treename
treename
Definition: diffTAGTree.py:140
top::json_dump
std::string json_dump(std::string const &value)
Escape string for use in JSON format.
Definition: JsonUtils.cxx:13
top::AnalysisTrackingHelper::m_topConfig
std::shared_ptr< TopConfig > m_topConfig
Definition: AnalysisTrackingHelper.h:64
beamspotman.fullpath
string fullpath
Definition: beamspotman.py:1039
beamspotman.basename
basename
Definition: beamspotman.py:640