ATLAS Offline Software
Loading...
Searching...
No Matches
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_t > DsoMap_t

Public Member Functions

 ~DsoDb ()
 Destructor:
const std::vector< std::string > & dso_files () const
 list of all dsomap/rootmap files we know about
const DsoMap_t & pf () const
 repository of plugin factories
const DsoMap_t & db () const
 repository of components
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
DsoMap_t duplicates (const std::string &libname, bool pedantic=false) const
 list of libraries hosting duplicate reflex-types
DsoMap_t dict_duplicates (bool pedantic=false) const
 table of dict-duplicates: {type: [lib1, lib2, ...]}
DsoMap_t pf_duplicates (bool pedantic=false) const
 table of plugin-factories-duplicates: {type: [lib1, lib2, ...]}
Libs_t libs (bool detailed=false) const
 list of all libraries we know about
DsoMap_t content (bool pedantic) const
 return the table {type: [lib1, ...]} - concatenation of all dict-entries and plugin-factories entries.

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 DsoDb * instance ()
 factory for the DsoDb

Private Member Functions

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

Private Attributes

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

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 253 of file DsoDb.cxx.

254{}

◆ DsoDb() [1/2]

Ath::DsoDb::DsoDb ( )
private

Default constructor:

Definition at line 243 of file DsoDb.cxx.

243 :
244 m_pf(),
245 m_db(),
246 m_dsofiles()
247{
249}
DsoMap_t m_db
repository of components
Definition DsoDb.h:153
std::vector< std::string > m_dsofiles
list of dsofiles
Definition DsoDb.h:156
void build_repository()
initialize the repository of dso file names
Definition DsoDb.cxx:290
DsoMap_t m_pf
repository of plugin factories
Definition DsoDb.h:150

◆ DsoDb() [2/2]

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

Copy constructor:

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE() [1/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

◆ ATLAS_NOT_THREAD_SAFE() [2/2]

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

◆ build_repository()

void Ath::DsoDb::build_repository ( )
private

initialize the repository of dso file names

Definition at line 290 of file DsoDb.cxx.

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

◆ 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 432 of file DsoDb.cxx.

433{
434 fs::path p(libname_);
435
436 const std::string libname = ::getlibname(to_string(p.filename()));
437 std::set<std::string> caps;
438 const DsoMap_t* dbs[] = { &m_pf, &m_db };
439
440 for (std::size_t i = 0, imax = 2; i < imax; ++i) {
441 const DsoMap_t* db = dbs[i];
442 for (DsoMap_t::const_iterator idb = db->begin(), iend=db->end();
443 idb != iend;
444 ++idb) {
445 for (Libs_t::const_iterator ilib = idb->second.begin(),
446 ilibend = idb->second.end();
447 ilib != ilibend;
448 ++ilib) {
449 fs::path lib(*ilib);
450 if (to_string(lib.filename()) == libname) {
451 caps.insert(idb->first);
452 }
453 }
454 }
455 }
456
457 return std::vector<std::string>(caps.begin(), caps.end());
458}
int imax(int i, int j)

◆ 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
`pedantic`if true, retrieves the library's full path

Definition at line 546 of file DsoDb.cxx.

547{
548 DsoMap_t db;
549
550 const DsoMap_t* dbs[] = { &m_pf, &m_db };
551 for (std::size_t i = 0, imax = 2; i < imax; ++i) {
552 const DsoMap_t& d = *dbs[i];
553 for (DsoMap_t::const_iterator idb = d.begin(), idbend=d.end();
554 idb != idbend;
555 ++idb) {
556 if (pedantic) {
557 db[idb->first] = idb->second;
558 } else {
559 Libs_t libs;
560 std::set<std::string> baselibs;
561 for (Libs_t::const_iterator
562 ilib = idb->second.begin(),
563 ilibend= idb->second.end();
564 ilib != ilibend;
565 ++ilib) {
566 const std::string baselib = to_string(fs::path(*ilib).filename());
567 if (baselibs.find(baselib) == baselibs.end()) {
568 libs.push_back(*ilib);
569 baselibs.insert(std::move(baselib));
570 }
571 }
572 db[idb->first] = std::move(libs);
573 }
574 }
575 }
576
577 return db;
578}
std::vector< std::string > Libs_t
Definition DsoDb.h:36
Libs_t libs(bool detailed=false) const
list of all libraries we know about
Definition DsoDb.cxx:516

◆ 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 497 of file DsoDb.cxx.

498{
500 get_dups(dups, m_db, pedantic);
501 return dups;
502}
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:582

◆ 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 462 of file DsoDb.cxx.

463{
465 const std::string basename_lib = to_string(fs::path(libname).filename());
466 std::vector<std::string> caps = this->capabilities(libname);
467 const DsoMap_t* dbs[] = { &m_pf, &m_db };
468
469 for (std::size_t i = 0, imax = 2; i < imax; ++i) {
470 DsoMap_t dup_db;
471 this->get_dups(dup_db, *dbs[i], pedantic);
472 for (DsoMap_t::const_iterator
473 idb = dup_db.begin(),
474 idbend = dup_db.end();
475 idb != idbend;
476 ++idb) {
477 if (std::find(caps.begin(), caps.end(), idb->first) != caps.end()) {
478 for (Libs_t::const_iterator
479 ilib = idb->second.begin(),
480 ilibend=idb->second.end();
481 ilib != ilibend;
482 ++ilib) {
483 fs::path p(*ilib);
484 const std::string basename = to_string(p.filename());
485 if (basename != libname) {
486 dups[idb->first].push_back(*ilib);
487 }
488 }
489 }
490 }
491 }
492 return dups;
493}
std::vector< std::string > capabilities(const std::string &libname) const
list of reflex-types associated with a library name
Definition DsoDb.cxx:432
std::string basename(std::string name)
Definition utils.cxx:207

◆ 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 582 of file DsoDb.cxx.

583{
584 for (DsoMap_t::const_iterator idb = db.begin(), iend = db.end();
585 idb != iend;
586 ++idb) {
587 if (idb->second.size() == 1) {
588 continue;
589 }
590 Libs_t libs;
591 if (pedantic) {
592 libs = idb->second;
593 } else {
594 std::unordered_set<std::string> baselibs;
595 for (Libs_t::const_iterator
596 ilib = idb->second.begin(),
597 ilend= idb->second.end();
598 ilib != ilend;
599 ++ilib)
600 {
601 fs::path p(*ilib);
602 if (! baselibs.emplace (to_string(p.filename())) . second) {
603 // String wasn't in the set.
604 libs.push_back(*ilib);
605 }
606 }
607 }
608 if (libs.size() > 1) {
609 dups[idb->first] = std::move(libs);
610 }
611 }
612}

◆ has_type()

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

Definition at line 261 of file DsoDb.cxx.

262{
263 if (s_cxx_builtins().find(type_name) != s_cxx_builtins().end()) {
264 return true;
265 }
266 const std::string n = ::to_rootmap_name(type_name);
267 if ( m_db.find(n) != m_db.end() ||
268 m_pf.find(n) != m_pf.end() ) {
269 return true;
270 }
271 return false;
272}
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140

◆ instance()

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

factory for the DsoDb

Definition at line 235 of file DsoDb.cxx.

236{
237 static const DsoDb db;
238 return &db;
239}
DsoDb()
Default constructor:
Definition DsoDb.cxx:243

◆ libs()

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

list of all libraries we know about

Parameters
`detailed`if true, prints the full path to the library

Definition at line 516 of file DsoDb.cxx.

517{
518 std::set<std::string> libs;
519 const DsoMap_t* dbs[] = { &m_pf, &m_db };
520
521 for (std::size_t i = 0, imax = 2; i < imax; ++i) {
522 const DsoMap_t& db = *dbs[i];
523 for (DsoMap_t::const_iterator idb = db.begin(), iend=db.end();
524 idb != iend;
525 ++idb) {
526 for (Libs_t::const_iterator
527 ilib = idb->second.begin(),
528 ilibend=idb->second.end();
529 ilib != ilibend;
530 ++ilib) {
531 if (detailed) {
532 libs.insert(*ilib);
533 } else {
534 libs.insert(to_string(fs::path(*ilib).filename()));
535 }
536 }
537 }
538 }
539 return Libs_t(libs.begin(), libs.end());
540}

◆ 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 506 of file DsoDb.cxx.

507{
509 get_dups(dups, m_pf, pedantic);
510 return dups;
511}

◆ py_keys_from()

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()

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: