Classes | Public Types | Public Member Functions | Private Attributes | List of all members
art::FileCatalogMetadata Class Reference

#include <FileCatalogMetadata.h>

Classes

struct  Config
 
class  InheritedMetadata
 

Public Types

using collection_type = std::vector< std::pair< std::string, std::string >>
 
using value_type = collection_type::value_type
 
using Parameters = ServiceTable< Config >
 

Public Member Functions

 FileCatalogMetadata (Parameters const &config)
 
void addMetadata (std::string const &key, std::string const &value)
 
void addMetadataString (std::string const &key, std::string const &value)
 
void getMetadata (collection_type &coll) const
 
void setMetadataFromInput (collection_type const &coll)
 
bool wantCheckSyntax () const noexcept
 

Private Attributes

std::recursive_mutex mutex_ {}
 
bool const checkSyntax_
 
std::vector< std::string > const mdToInherit_
 
collection_type md_ {}
 
std::unique_ptr< InheritedMetadataimd_ {}
 

Detailed Description

Definition at line 21 of file FileCatalogMetadata.h.

Member Typedef Documentation

Definition at line 23 of file FileCatalogMetadata.h.

Definition at line 63 of file FileCatalogMetadata.h.

using art::FileCatalogMetadata::value_type = collection_type::value_type

Definition at line 24 of file FileCatalogMetadata.h.

Constructor & Destructor Documentation

art::FileCatalogMetadata::FileCatalogMetadata ( FileCatalogMetadata::Parameters const &  config)
explicit

Definition at line 35 of file FileCatalogMetadata.cc.

38  , mdToInherit_{maybeTranslate(config().metadataFromInput())}
39  {
40  if (auto appFam = config().applicationFamily()) {
41  addMetadataString("application.family", *appFam);
42  }
43  if (auto appVer = config().applicationVersion()) {
44  addMetadataString("application.version", *appVer);
45  }
46 
47  // Always write out fileType -- either by inheriting from the input
48  // file or by overriding via the FHiCL parameter "fileType".
49  if (!search_translated_all(mdToInherit_, "file_type")) {
50  addMetadataString("file_type", config().fileType());
51  }
52  string rt;
53  if (!search_translated_all(mdToInherit_, "run_type") &&
54  config().runType(rt)) {
55  addMetadataString("art.run_type", rt);
56  }
57  if (auto grp = config().group()) {
58  addMetadataString("group", *grp);
59  }
60  if (auto pid = config().processID()) {
61  addMetadataString("process_id", *pid);
62  }
63  }
void addMetadataString(std::string const &key, std::string const &value)
static Config * config
Definition: config.cpp:1054
std::vector< std::string > const mdToInherit_

Member Function Documentation

void art::FileCatalogMetadata::addMetadata ( std::string const &  key,
std::string const &  value 
)

Definition at line 78 of file FileCatalogMetadata.cc.

79  {
80  if (checkSyntax_) {
81  string checkString("{ ");
82  checkString += cet::canonical_string(key) + " : " + value + " }";
83  boost::json::error_code ec;
85  auto const n_parsed_chars = p.write_some(checkString, ec);
86  if (ec) {
88  << "FileCatalogMetadata::addMetadata() JSON " << ec.message() << ":\n"
89  << "Faulty key/value clause:\n"
90  << checkString << "\n"
91  << (n_parsed_chars ? string(n_parsed_chars, '-') : "") << "^\n";
92  }
93  }
94  std::lock_guard sentry{mutex_};
95  md_.emplace_back(key, value);
96  }
std::string string
Definition: nybbler.cc:12
def key(type, name=None)
Definition: graph.py:13
std::recursive_mutex mutex_
p
Definition: test.py:223
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool canonical_string(std::string const &str, std::string &result)
void art::FileCatalogMetadata::addMetadataString ( std::string const &  key,
std::string const &  value 
)

Definition at line 72 of file FileCatalogMetadata.cc.

73  {
75  }
def key(type, name=None)
Definition: graph.py:13
bool canonical_string(std::string const &str, std::string &result)
void addMetadata(std::string const &key, std::string const &value)
void art::FileCatalogMetadata::getMetadata ( collection_type coll) const

Definition at line 117 of file FileCatalogMetadata.cc.

118  {
119  std::lock_guard sentry{mutex_};
120  cet::copy_all(md_, back_inserter(coll));
121  }
std::recursive_mutex mutex_
auto copy_all(FwdCont &, FwdIter)
void art::FileCatalogMetadata::setMetadataFromInput ( collection_type const &  coll)

Definition at line 99 of file FileCatalogMetadata.cc.

100  {
101  if (mdToInherit_.empty()) {
102  return;
103  }
104 
105  std::lock_guard sentry{mutex_};
106  if (!imd_) {
107  imd_ = make_unique<InheritedMetadata>(mdToInherit_, mdFromInput);
108  } else {
109  imd_->check_values(mdFromInput);
110  }
111  for (auto const& [key, value] : imd_->entries()) {
112  addMetadataString(oldToNew(key), value);
113  }
114  }
void addMetadataString(std::string const &key, std::string const &value)
def key(type, name=None)
Definition: graph.py:13
std::recursive_mutex mutex_
std::unique_ptr< InheritedMetadata > imd_
std::vector< std::string > const mdToInherit_
bool art::FileCatalogMetadata::wantCheckSyntax ( ) const
noexcept

Definition at line 66 of file FileCatalogMetadata.cc.

67  {
68  return checkSyntax_;
69  }

Member Data Documentation

bool const art::FileCatalogMetadata::checkSyntax_
private

Definition at line 136 of file FileCatalogMetadata.h.

std::unique_ptr<InheritedMetadata> art::FileCatalogMetadata::imd_ {}
private

Definition at line 146 of file FileCatalogMetadata.h.

collection_type art::FileCatalogMetadata::md_ {}
private

Definition at line 143 of file FileCatalogMetadata.h.

std::vector<std::string> const art::FileCatalogMetadata::mdToInherit_
private

Definition at line 140 of file FileCatalogMetadata.h.

std::recursive_mutex art::FileCatalogMetadata::mutex_ {}
mutableprivate

Definition at line 132 of file FileCatalogMetadata.h.


The documentation for this class was generated from the following files: