LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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

using art::FileCatalogMetadata::collection_type = std::vector<std::pair<std::string, std::string>>

Definition at line 23 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.

References addMetadataString(), and mdToInherit_.

37  : checkSyntax_{config().checkSyntax()}
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)
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.

References checkSyntax_, art::errors::DataCorruption, md_, mutex_, and parser().

Referenced by addMetadataString().

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::recursive_mutex mutex_
CommandLineParser * parser(0)
double value
Definition: spectrum.C:18
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void art::FileCatalogMetadata::addMetadataString ( std::string const &  key,
std::string const &  value 
)

Definition at line 72 of file FileCatalogMetadata.cc.

References addMetadata().

Referenced by FileCatalogMetadata(), and setMetadataFromInput().

73  {
74  addMetadata(key, cet::canonical_string(value));
75  }
double value
Definition: spectrum.C:18
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.

References md_, and mutex_.

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

Definition at line 99 of file FileCatalogMetadata.cc.

References addMetadataString(), imd_, mdToInherit_, mutex_, and value.

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)
std::recursive_mutex mutex_
double value
Definition: spectrum.C:18
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.

References checkSyntax_.

67  {
68  return checkSyntax_;
69  }

Member Data Documentation

bool const art::FileCatalogMetadata::checkSyntax_
private

Definition at line 136 of file FileCatalogMetadata.h.

Referenced by addMetadata(), and wantCheckSyntax().

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

Definition at line 146 of file FileCatalogMetadata.h.

Referenced by setMetadataFromInput().

collection_type art::FileCatalogMetadata::md_ {}
private

Definition at line 143 of file FileCatalogMetadata.h.

Referenced by addMetadata(), and getMetadata().

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

Definition at line 140 of file FileCatalogMetadata.h.

Referenced by FileCatalogMetadata(), and setMetadataFromInput().

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

Definition at line 132 of file FileCatalogMetadata.h.

Referenced by addMetadata(), getMetadata(), and setMetadataFromInput().


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