The Gaudi Framework  master (37c0b60a)
Catalog.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2020 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #include "Catalog.h"
12 #include <fmt/format.h>
13 
14 namespace gp = Gaudi::Parsers;
15 namespace {
16  constexpr struct select1st_t {
17  template <typename S, typename T>
18  const S& operator()( const std::pair<S, T>& p ) const {
19  return p.first;
20  }
21  template <typename S, typename T>
22  S& operator()( std::pair<S, T>& p ) const {
23  return p.first;
24  }
25  } select1st{};
26 } // namespace
27 
30  std::transform( std::begin( catalog_ ), std::end( catalog_ ), std::back_inserter( result ), select1st );
31  return result;
32 }
33 // ============================================================================
34 bool gp::Catalog::Add( Property* property ) {
35  assert( property );
36  auto it = catalog_.find( property->ClientName() );
37  if ( it == catalog_.end() ) {
38  CatalogSet::mapped_type properties;
39  properties.insert( property );
40  catalog_.emplace( property->ClientName(), properties );
41  return true;
42  }
43  it->second.erase( *property );
44  it->second.insert( property );
45  // TODO: check return value
46  return true;
47 }
48 // ============================================================================
49 gp::Property* gp::Catalog::Find( std::string_view client, std::string_view name ) {
50  auto it = catalog_.find( client );
51  if ( it == catalog_.end() ) return nullptr;
52 
53  auto pit = std::find_if( it->second.begin(), it->second.end(),
54  [&]( const Property& property ) { return name == property.NameInClient(); } );
55 
56  return ( pit != it->second.end() ) ? &*pit : nullptr;
57 }
58 // ============================================================================
60  std::string result;
61  for ( const auto& client : catalog_ ) {
62  for ( const auto& current : client.second ) { result += current.ToString() + "\n"; }
63  }
64  return result;
65 }
66 // ============================================================================
67 // print the content of the catalogue to std::ostream
68 // ============================================================================
70  o << R"(// ==================================================================================
71 // Parser catalog
72 // ==================================================================================
73 )";
74 
75  size_t nComponents = 0;
76  size_t nProperties = 0;
77 
78  for ( const auto& client : catalog_ ) {
79  o << fmt::format( "// Properties of {:<25} # = {}", fmt::format( "'{}'", client.first ), client.second.size() );
80  ++nComponents;
81  nProperties += client.second.size();
82  for ( const auto& current : client.second ) {
83  o << fmt::format( "{:<44} = {} ;", current.FullName(), current.ValueAsString() );
84  }
85  }
86  o << fmt::format( R"(// ==================================================================================
87 // End parser catalog #Components={} #Properties={}
88 // ==================================================================================
89 )",
90  nComponents, nProperties );
91  return o;
92 }
Gaudi::Parsers::Property::ClientName
const std::string & ClientName() const
Definition: Property.cpp:23
Gaudi::Parsers::Catalog::ClientNames
std::vector< std::string > ClientNames() const
Definition: Catalog.cpp:28
Gaudi::Parsers::Property
Definition: Property.h:27
std::string
STL class.
Gaudi::Parsers::Catalog::Find
Property * Find(std::string_view client, std::string_view name)
Definition: Catalog.cpp:49
std::pair
std::vector< std::string >
std::find_if
T find_if(T... args)
std::string::size
T size(T... args)
std::back_inserter
T back_inserter(T... args)
Gaudi::Parsers::Catalog::fillStream
std::ostream & fillStream(std::ostream &out) const
print the content of the catalogue to std::ostream
Definition: Catalog.cpp:69
Gaudi::Parsers::Catalog::Add
bool Add(Property *property)
Definition: Catalog.cpp:34
std::ostream
STL class.
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
std::transform
T transform(T... args)
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:68
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
std::begin
T begin(T... args)
Gaudi::Parsers
Definition: DODBasicMapper.cpp:17
std::end
T end(T... args)
Catalog.h
Gaudi::Parsers::Catalog::ToString
std::string ToString() const
Definition: Catalog.cpp:59
Gaudi::Parsers::Catalog::catalog_
CatalogSet catalog_
Definition: Catalog.h:63