ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Ath::DsoDb Class Reference

helper class to query rootmap files and extract their content More...

#include <DsoDb.h>

Collaboration diagram for Ath::DsoDb:

Public Types

typedef std::vector< std::string > Libs_t
 
typedef std::unordered_map< std::string, Libs_tDsoMap_t
 

Public Member Functions

 ~DsoDb ()
 Destructor: More...
 
const std::vector< std::string > & dso_files () const
 list of all dsomap/rootmap files we know about More...
 
const DsoMap_tpf () const
 repository of plugin factories More...
 
const DsoMap_tdb () const
 repository of components More...
 
bool has_type (const std::string &type_name) const
 
std::string load_type ATLAS_NOT_THREAD_SAFE (const std::string &type_name) const
 
std::vector< std::string > capabilities (const std::string &libname) const
 list of reflex-types associated with a library name More...
 
DsoMap_t duplicates (const std::string &libname, bool pedantic=false) const
 list of libraries hosting duplicate reflex-types More...
 
DsoMap_t dict_duplicates (bool pedantic=false) const
 table of dict-duplicates: {type: [lib1, lib2, ...]} More...
 
DsoMap_t pf_duplicates (bool pedantic=false) const
 table of plugin-factories-duplicates: {type: [lib1, lib2, ...]} More...
 
Libs_t libs (bool detailed=false) const
 list of all libraries we know about More...
 
DsoMap_t content (bool pedantic) const
 return the table {type: [lib1, ...]} - concatenation of all dict-entries and plugin-factories entries. More...
 

Static Public Member Functions

static std::vector< std::string > py_keys_from (const Ath::DsoDb::DsoMap_t &m)
 
static std::vector< std::vector< std::string > > py_vals_from (const Ath::DsoDb::DsoMap_t &m)
 
static const DsoDbinstance ()
 factory for the DsoDb More...
 

Private Member Functions

void build_repository ()
 initialize the repository of dso file names More...
 
void get_dups (DsoMap_t &dups, const DsoMap_t &db, bool pedantic) const
 get the duplicates for a given repository of components More...
 
RootType rflx_type ATLAS_NOT_THREAD_SAFE (const std::string &type_name) const
 load the reflex type after having loaded the hosting library More...
 
 DsoDb ()
 Default constructor: More...
 
 DsoDb (const DsoDb &rhs)
 Copy constructor: More...
 
DsoDboperator= (const DsoDb &rhs)
 Assignment operator: More...
 

Private Attributes

DsoMap_t m_pf
 repository of plugin factories More...
 
DsoMap_t m_db
 repository of components More...
 
std::vector< std::string > m_dsofiles
 list of dsofiles More...
 

Detailed Description

helper class to query rootmap files and extract their content

Definition at line 30 of file DsoDb.h.

Member Typedef Documentation

◆ DsoMap_t

typedef std::unordered_map<std::string, Libs_t> Ath::DsoDb::DsoMap_t

Definition at line 37 of file DsoDb.h.

◆ Libs_t

typedef std::vector<std::string> Ath::DsoDb::Libs_t

Definition at line 36 of file DsoDb.h.

Constructor & Destructor Documentation

◆ ~DsoDb()

Ath::DsoDb::~DsoDb ( )

Destructor:

Definition at line 255 of file DsoDb.cxx.

256 {}

◆ DsoDb() [1/2]

Ath::DsoDb::DsoDb ( )
private

Default constructor:

Definition at line 245 of file DsoDb.cxx.

245  :
246  m_pf(),
247  m_db(),
248  m_dsofiles()
249 {
251 }

◆ DsoDb() [2/2]

Ath::DsoDb::DsoDb ( const DsoDb rhs)
private

Copy constructor:

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE() [1/2]

std::string load_type Ath::DsoDb::ATLAS_NOT_THREAD_SAFE ( const std::string &  type_name) const

◆ ATLAS_NOT_THREAD_SAFE() [2/2]

RootType rflx_type Ath::DsoDb::ATLAS_NOT_THREAD_SAFE ( const std::string &  type_name) const
private

load the reflex type after having loaded the hosting library

◆ build_repository()

void Ath::DsoDb::build_repository ( )
private

initialize the repository of dso file names

Definition at line 292 of file DsoDb.cxx.

293 {
294  // std::cerr << "::build_repository...\n";
295 
296  typedef boost::tokenizer<boost::char_separator<char> > Tokenizer_t;
297  typedef std::vector<fs::path> Paths_t;
298 
299  std::set<std::string> dsofiles;
300 
301  std::string dsopath = System::getEnv("LD_LIBRARY_PATH");
302  std::string rootsys = System::getEnv("ROOTSYS");
303 
304  Tokenizer_t tok(dsopath, boost::char_separator<char>(":"));
305 
306  for (Tokenizer_t::iterator itr = tok.begin(), iend = tok.end();
307  itr != iend;
308  ++itr) {
309  //std::cerr << "--[" << *itr << "]...\n";
310  if (itr->starts_with(rootsys)) {
311  continue;
312  }
313  fs::path p(*itr);
314  if (!std::filesystem::exists(*itr)) {
315  continue;
316  }
317  Paths_t dir_content {fs::directory_iterator(p),
318  fs::directory_iterator()};
319  std::sort(dir_content.begin(),
320  dir_content.end());
321  for (Paths_t::iterator ipath = dir_content.begin(),
322  ipath_end = dir_content.end();
323  ipath != ipath_end;
324  ++ipath) {
325  const fs::path& dsomap = *ipath;
326 
327  bool is_components = false;
328  if (dsomap.extension() == Components)
329  is_components = true;
330  else if (dsomap.extension() != RootMap)
331  continue;
332 
333  if (!fs::exists(dsomap)) continue;
334 
335  //std::cerr << "=== [" << dso << "] ===\n";
336  dsofiles.insert(dsomap.c_str());
337  std::ifstream f(dsomap.c_str());
338  int line_nbr = -1;
339  std::string lastlib;
340  while (f) {
341  line_nbr += 1;
342  std::string line;
343  std::getline(f, line);
345 
346  std::string libname;
347  std::string dso_key;
348  if ( line.empty() )
349  continue;
350 
351  else if (line.compare (0, 8, "Library.")==0) {
352  Strings_t ll;
354  boost::is_any_of(" "),
355  boost::token_compress_on);
356  if (ll.size() < 2) {
357  std::cerr << "DsoDb:: **error** could not parse "
358  << dsomap << ":" << line_nbr
359  << "\n"
360  << "DsoDb:: (some) reflex-dicts may fail to be autoloaded"
361  << "\n";
362  continue;
363  }
364  libname = ll[1];
365  if (::is_rootcint_dict(libname)) {
366  continue;
367  }
368  dso_key = ll[0];
369  libname = ::getlibname(libname);
370  boost::algorithm::replace_all(dso_key, "Library.", "");
371  boost::algorithm::replace_all(dso_key, ":", "");
372  std::replace(dso_key.begin(), dso_key.end(), '@', ':');
373  std::replace(dso_key.begin(), dso_key.end(), '-', ' ');
374  }
375 
376  else if (line[0] == '[') {
377  libname = line.substr (1, line.size()-2);
378  boost::algorithm::trim (libname);
379  if (::is_rootcint_dict(libname)) {
380  lastlib.clear();
381  continue;
382  }
383  if (!libname.empty())
384  lastlib = ::getlibname (libname);
385  continue;
386  }
387 
388  else if (line.compare(0, 8, "# --End ")==0) {
389  lastlib.clear();
390  continue;
391  }
392 
393  else if (line.compare(0, 6, "class ")==0) {
394  libname = lastlib;
395  line.erase (0, 6);
396  dso_key = line;
397  }
398 
399  else if (is_components && line.compare(0, 3, "lib") ==0) {
400  std::string::size_type pos = line.find (':');
401  if (pos == std::string::npos) continue;
402  libname = line.substr(0, pos);
403  line.erase (0, pos+1);
404  dso_key = line;
405 
406  if (dso_key.compare(0, 6, "_PERS_")==0 ||
407  dso_key.compare(0, 7, "_TRANS_")==0)
408  continue;
409 
410  if (libname.find ("AthenaPoolPoolCnv") != std::string::npos)
411  continue;
412  }
413 
414  if (libname.empty() || dso_key.empty()) continue;
415 
416  const std::string fullpath_libname = to_string(dsomap.parent_path() / fs::path(libname));
417 
418  // std::cerr << " [" << line << "] -> [" << dso_key << "] [" << libname << "]\n";
419 
420  DsoMap_t *db = NULL;
421  if (dso_key.starts_with(PluginNs) || is_components) {
422  db = &m_pf;
423  } else {
424  db = &m_db;
425  }
426  if (db->find(dso_key) == db->end()) {
427  db->insert(std::make_pair(dso_key, Strings_t()));
428  }
429  (*db)[dso_key].push_back(fullpath_libname);
430  }
431  // std::cerr << "=== [" << dso << "] === [EOF]\n";
432  }
433  //std::cerr << "--[" << *itr << "]... [done]\n";
434  }
435 
436  m_dsofiles.reserve(dsofiles.size());
437  std::copy(dsofiles.begin(), dsofiles.end(), std::back_inserter(m_dsofiles));
438 
439  // std::cerr << "::build_repository... [done]\n";
440  return;
441 }

◆ capabilities()

std::vector< std::string > Ath::DsoDb::capabilities ( const std::string &  libname) const

list of reflex-types associated with a library name

Definition at line 444 of file DsoDb.cxx.

445 {
446  fs::path p(libname_);
447 
448  const std::string libname = ::getlibname(to_string(p.filename()));
449  std::set<std::string> caps;
450  const DsoMap_t* dbs[] = { &m_pf, &m_db };
451 
452  for (std::size_t i = 0, imax = 2; i < imax; ++i) {
453  const DsoMap_t* db = dbs[i];
454  for (DsoMap_t::const_iterator idb = db->begin(), iend=db->end();
455  idb != iend;
456  ++idb) {
457  for (Libs_t::const_iterator ilib = idb->second.begin(),
458  ilibend = idb->second.end();
459  ilib != ilibend;
460  ++ilib) {
461  fs::path lib(*ilib);
462  if (to_string(lib.filename()) == libname) {
463  caps.insert(idb->first);
464  }
465  }
466  }
467  }
468 
469  return std::vector<std::string>(caps.begin(), caps.end());
470 }

◆ content()

DsoDb::DsoMap_t Ath::DsoDb::content ( bool  pedantic) const

return the table {type: [lib1, ...]} - concatenation of all dict-entries and plugin-factories entries.

Parameters
<tt>pedantic</tt>if true, retrieves the library's full path

Definition at line 558 of file DsoDb.cxx.

559 {
560  DsoMap_t db;
561 
562  const DsoMap_t* dbs[] = { &m_pf, &m_db };
563  for (std::size_t i = 0, imax = 2; i < imax; ++i) {
564  const DsoMap_t& d = *dbs[i];
565  for (DsoMap_t::const_iterator idb = d.begin(), idbend=d.end();
566  idb != idbend;
567  ++idb) {
568  if (pedantic) {
569  db[idb->first] = idb->second;
570  } else {
571  Libs_t libs;
572  std::set<std::string> baselibs;
573  for (Libs_t::const_iterator
574  ilib = idb->second.begin(),
575  ilibend= idb->second.end();
576  ilib != ilibend;
577  ++ilib) {
578  const std::string baselib = to_string(fs::path(*ilib).filename());
579  if (baselibs.find(baselib) == baselibs.end()) {
580  libs.push_back(*ilib);
581  baselibs.insert(baselib);
582  }
583  }
584  db[idb->first] = std::move(libs);
585  }
586  }
587  }
588 
589  return db;
590 }

◆ db()

const DsoMap_t& Ath::DsoDb::db ( ) const
inline

repository of components

Definition at line 94 of file DsoDb.h.

94 { return m_db; }

◆ dict_duplicates()

DsoDb::DsoMap_t Ath::DsoDb::dict_duplicates ( bool  pedantic = false) const

table of dict-duplicates: {type: [lib1, lib2, ...]}

Definition at line 509 of file DsoDb.cxx.

510 {
511  DsoMap_t dups;
513  return dups;
514 }

◆ dso_files()

const std::vector<std::string>& Ath::DsoDb::dso_files ( ) const
inline

list of all dsomap/rootmap files we know about

Definition at line 87 of file DsoDb.h.

88  { return m_dsofiles; }

◆ duplicates()

DsoDb::DsoMap_t Ath::DsoDb::duplicates ( const std::string &  libname,
bool  pedantic = false 
) const

list of libraries hosting duplicate reflex-types

Definition at line 474 of file DsoDb.cxx.

475 {
476  DsoMap_t dups;
477  const std::string basename_lib = to_string(fs::path(libname).filename());
478  std::vector<std::string> caps = this->capabilities(libname);
479  const DsoMap_t* dbs[] = { &m_pf, &m_db };
480 
481  for (std::size_t i = 0, imax = 2; i < imax; ++i) {
482  DsoMap_t dup_db;
483  this->get_dups(dup_db, *dbs[i], pedantic);
484  for (DsoMap_t::const_iterator
485  idb = dup_db.begin(),
486  idbend = dup_db.end();
487  idb != idbend;
488  ++idb) {
489  if (std::find(caps.begin(), caps.end(), idb->first) != caps.end()) {
490  for (Libs_t::const_iterator
491  ilib = idb->second.begin(),
492  ilibend=idb->second.end();
493  ilib != ilibend;
494  ++ilib) {
495  fs::path p(*ilib);
496  const std::string basename = to_string(p.filename());
497  if (basename != libname) {
498  dups[idb->first].push_back(*ilib);
499  }
500  }
501  }
502  }
503  }
504  return dups;
505 }

◆ get_dups()

void Ath::DsoDb::get_dups ( DsoMap_t dups,
const DsoMap_t db,
bool  pedantic 
) const
private

get the duplicates for a given repository of components

Definition at line 594 of file DsoDb.cxx.

595 {
596  for (DsoMap_t::const_iterator idb = db.begin(), iend = db.end();
597  idb != iend;
598  ++idb) {
599  if (idb->second.size() == 1) {
600  continue;
601  }
602  Libs_t libs;
603  if (pedantic) {
604  libs = idb->second;
605  } else {
606  std::unordered_set<std::string> baselibs;
607  for (Libs_t::const_iterator
608  ilib = idb->second.begin(),
609  ilend= idb->second.end();
610  ilib != ilend;
611  ++ilib)
612  {
613  fs::path p(*ilib);
614  if (! baselibs.emplace (to_string(p.filename())) . second) {
615  // String wasn't in the set.
616  libs.push_back(*ilib);
617  }
618  }
619  }
620  if (libs.size() > 1) {
621  dups[idb->first] = std::move(libs);
622  }
623  }
624 }

◆ has_type()

bool Ath::DsoDb::has_type ( const std::string &  type_name) const

Definition at line 263 of file DsoDb.cxx.

264 {
265  if (s_cxx_builtins().find(type_name) != s_cxx_builtins().end()) {
266  return true;
267  }
268  const std::string n = ::to_rootmap_name(type_name);
269  if ( m_db.find(n) != m_db.end() ||
270  m_pf.find(n) != m_pf.end() ) {
271  return true;
272  }
273  return false;
274 }

◆ instance()

const DsoDb * Ath::DsoDb::instance ( )
static

factory for the DsoDb

Definition at line 237 of file DsoDb.cxx.

238 {
239  static const DsoDb db;
240  return &db;
241 }

◆ libs()

DsoDb::Libs_t Ath::DsoDb::libs ( bool  detailed = false) const

list of all libraries we know about

Parameters
<tt>detailed</tt>if true, prints the full path to the library

Definition at line 528 of file DsoDb.cxx.

529 {
530  std::set<std::string> libs;
531  const DsoMap_t* dbs[] = { &m_pf, &m_db };
532 
533  for (std::size_t i = 0, imax = 2; i < imax; ++i) {
534  const DsoMap_t& db = *dbs[i];
535  for (DsoMap_t::const_iterator idb = db.begin(), iend=db.end();
536  idb != iend;
537  ++idb) {
538  for (Libs_t::const_iterator
539  ilib = idb->second.begin(),
540  ilibend=idb->second.end();
541  ilib != ilibend;
542  ++ilib) {
543  if (detailed) {
544  libs.insert(*ilib);
545  } else {
546  libs.insert(to_string(fs::path(*ilib).filename()));
547  }
548  }
549  }
550  }
551  return Libs_t(libs.begin(), libs.end());
552 }

◆ operator=()

DsoDb& Ath::DsoDb::operator= ( const DsoDb rhs)
private

Assignment operator:

◆ pf()

const DsoMap_t& Ath::DsoDb::pf ( ) const
inline

repository of plugin factories

Definition at line 91 of file DsoDb.h.

91 { return m_pf; }

◆ pf_duplicates()

DsoDb::DsoMap_t Ath::DsoDb::pf_duplicates ( bool  pedantic = false) const

table of plugin-factories-duplicates: {type: [lib1, lib2, ...]}

Definition at line 518 of file DsoDb.cxx.

519 {
520  DsoMap_t dups;
522  return dups;
523 }

◆ py_keys_from()

static std::vector<std::string> Ath::DsoDb::py_keys_from ( const Ath::DsoDb::DsoMap_t m)
inlinestatic

Definition at line 43 of file DsoDb.h.

44  {
45  std::vector<std::string> k;
46  k.reserve(m.size());
47  for (Ath::DsoDb::DsoMap_t::const_iterator i = m.begin(), e = m.end();
48  i != e;
49  ++i) {
50  k.push_back(i->first);
51  }
52  return k;
53  }

◆ py_vals_from()

static std::vector<std::vector<std::string> > Ath::DsoDb::py_vals_from ( const Ath::DsoDb::DsoMap_t m)
inlinestatic

Definition at line 57 of file DsoDb.h.

58  {
59  std::vector<Libs_t> v;
60  v.reserve(m.size());
61  for (Ath::DsoDb::DsoMap_t::const_iterator i = m.begin(), e = m.end();
62  i != e;
63  ++i) {
64  v.push_back(i->second);
65  }
66  return v;
67  }

Member Data Documentation

◆ m_db

DsoMap_t Ath::DsoDb::m_db
private

repository of components

Definition at line 153 of file DsoDb.h.

◆ m_dsofiles

std::vector<std::string> Ath::DsoDb::m_dsofiles
private

list of dsofiles

Definition at line 156 of file DsoDb.h.

◆ m_pf

DsoMap_t Ath::DsoDb::m_pf
private

repository of plugin factories

Definition at line 150 of file DsoDb.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
checkFileSG.line
line
Definition: checkFileSG.py:75
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
Ath::DsoDb::m_pf
DsoMap_t m_pf
repository of plugin factories
Definition: DsoDb.h:150
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
checkPlugins.dups
dups
Definition: checkPlugins.py:156
trim
std::string trim(const std::string &str, const std::string &whitespace=" \t")
Definition: BTaggingTruthTaggingTool.cxx:1149
checkPlugins.pedantic
pedantic
Definition: checkPlugins.py:156
hist_file_dump.d
d
Definition: hist_file_dump.py:137
Ath::DsoDb::m_dsofiles
std::vector< std::string > m_dsofiles
list of dsofiles
Definition: DsoDb.h:156
Ath::DsoDb::db
const DsoMap_t & db() const
repository of components
Definition: DsoDb.h:94
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
Ath::DsoDb::capabilities
std::vector< std::string > capabilities(const std::string &libname) const
list of reflex-types associated with a library name
Definition: DsoDb.cxx:444
Ath::DsoDb::Libs_t
std::vector< std::string > Libs_t
Definition: DsoDb.h:36
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
Ath::DsoDb::libs
Libs_t libs(bool detailed=false) const
list of all libraries we know about
Definition: DsoDb.cxx:528
Ath::DsoDb::DsoMap_t
std::unordered_map< std::string, Libs_t > DsoMap_t
Definition: DsoDb.h:37
imax
int imax(int i, int j)
Definition: TileLaserTimingTool.cxx:33
Ath::DsoDb::get_dups
void get_dups(DsoMap_t &dups, const DsoMap_t &db, bool pedantic) const
get the duplicates for a given repository of components
Definition: DsoDb.cxx:594
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
Ath::DsoDb::m_db
DsoMap_t m_db
repository of components
Definition: DsoDb.h:153
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
python.PyAthena.v
v
Definition: PyAthena.py:157
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
Ath::DsoDb::DsoDb
DsoDb()
Default constructor:
Definition: DsoDb.cxx:245
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
Ath::DsoDb::build_repository
void build_repository()
initialize the repository of dso file names
Definition: DsoDb.cxx:292
calibdata.copy
bool copy
Definition: calibdata.py:27
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
BchCleanup.idb
idb
Definition: BchCleanup.py:152
fitman.k
k
Definition: fitman.py:528
DiTauMassTools::TauTypes::ll
@ ll
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:49
beamspotman.basename
basename
Definition: beamspotman.py:640