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_tDsoMap_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_tpf () const
 repository of plugin factories
const DsoMap_tdb () 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 DsoDbinstance ()
 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:
DsoDboperator= (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 252 of file DsoDb.cxx.

253{}

◆ DsoDb() [1/2]

Ath::DsoDb::DsoDb ( )
private

Default constructor:

Definition at line 242 of file DsoDb.cxx.

242 :
243 m_pf(),
244 m_db(),
245 m_dsofiles()
246{
248}
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:289
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 289 of file DsoDb.cxx.

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

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

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

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

507{
509 get_dups(dups, m_db, pedantic);
510 return dups;
511}
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:591

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

472{
474 const std::string basename_lib = to_string(fs::path(libname).filename());
475 std::vector<std::string> caps = this->capabilities(libname);
476 const DsoMap_t* dbs[] = { &m_pf, &m_db };
477
478 for (std::size_t i = 0, imax = 2; i < imax; ++i) {
479 DsoMap_t dup_db;
480 this->get_dups(dup_db, *dbs[i], pedantic);
481 for (DsoMap_t::const_iterator
482 idb = dup_db.begin(),
483 idbend = dup_db.end();
484 idb != idbend;
485 ++idb) {
486 if (std::find(caps.begin(), caps.end(), idb->first) != caps.end()) {
487 for (Libs_t::const_iterator
488 ilib = idb->second.begin(),
489 ilibend=idb->second.end();
490 ilib != ilibend;
491 ++ilib) {
492 fs::path p(*ilib);
493 const std::string basename = to_string(p.filename());
494 if (basename != libname) {
495 dups[idb->first].push_back(*ilib);
496 }
497 }
498 }
499 }
500 }
501 return dups;
502}
std::vector< std::string > capabilities(const std::string &libname) const
list of reflex-types associated with a library name
Definition DsoDb.cxx:441
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 591 of file DsoDb.cxx.

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

◆ has_type()

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

Definition at line 260 of file DsoDb.cxx.

261{
262 if (s_cxx_builtins().find(type_name) != s_cxx_builtins().end()) {
263 return true;
264 }
265 const std::string n = ::to_rootmap_name(type_name);
266 if ( m_db.find(n) != m_db.end() ||
267 m_pf.find(n) != m_pf.end() ) {
268 return true;
269 }
270 return false;
271}
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 234 of file DsoDb.cxx.

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

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

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

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

516{
518 get_dups(dups, m_pf, pedantic);
519 return dups;
520}

◆ 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: