LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 = typename 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
 

Static Private Member Functions

static std::mutex & service_mutex ()
 

Private Attributes

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

Detailed Description

Definition at line 39 of file FileCatalogMetadata.h.

Member Typedef Documentation

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

Definition at line 41 of file FileCatalogMetadata.h.

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

Definition at line 42 of file FileCatalogMetadata.h.

Constructor & Destructor Documentation

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

Definition at line 25 of file FileCatalogMetadata_service.cc.

References addMetadataString(), IGNORE_FALLTHROUGH_END::maybeTranslate(), mdToInherit_, and IGNORE_FALLTHROUGH_END::search_translated_all().

27  : checkSyntax_{config().checkSyntax()}
28  , mdToInherit_{maybeTranslate(config().metadataFromInput())}
29 {
30  std::string appFam;
31  if (config().applicationFamily(appFam)) {
32  addMetadataString("applicationFamily", appFam);
33  }
34 
35  std::string appVer;
36  if (config().applicationVersion(appVer)) {
37  addMetadataString("applicationVersion", appVer);
38  }
39 
40  // Always write out fileType -- either by inheriting from the input
41  // file or by overriding via the FHiCL parameter "fileType".
42  if (!search_translated_all(mdToInherit_, "file_type")) {
43  addMetadataString("file_type", config().fileType());
44  }
45 
46  std::string rt;
47  if (!search_translated_all(mdToInherit_, "run_type") &&
48  config().runType(rt)) {
49  addMetadataString("run_type", rt);
50  }
51 
52  std::string g;
53  if (config().group(g)) {
54  addMetadataString("group", g);
55  }
56 
57  std::string pid;
58  if (config().processID(pid)) {
59  addMetadataString("process_id", pid);
60  }
61 }
std::vector< std::string > mdToInherit_
bool search_translated_all(std::vector< std::string > const &s, std::string const &md)
void addMetadataString(std::string const &key, std::string const &value)
std::vector< std::string > maybeTranslate(std::vector< std::string > names)

Member Function Documentation

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

Definition at line 64 of file FileCatalogMetadata_service.cc.

References checkSyntax_, d, art::errors::DataCorruption, DEFINE_ART_SERVICE, md_, service_mutex(), and fhicl::detail::atom::value().

Referenced by addMetadataString(), and util::FileCatalogMetadataExtras::postBeginJob().

66 {
67  if (checkSyntax_) {
68  // rapidjson claims to be largely re-entrant, according to
69  // https://github.com/miloyip/rapidjson/issues/141. Therefore, we
70  // do not worry about locking this part of the function.
71  rapidjson::Document d;
72  std::string checkString("{ ");
73  checkString += cet::canonical_string(key);
74  checkString += " : ";
75  checkString += value;
76  checkString += " }";
77  if (d.Parse(checkString.c_str()).HasParseError()) {
78  auto const nSpaces = d.GetErrorOffset();
80  << "art::FileCatalogMetadata::addMetadata() JSON syntax error:\n"
81  << rapidjson::GetParseError_En(d.GetParseError())
82  << " Faulty key/value clause:\n"
83  << checkString << "\n"
84  << (nSpaces ? std::string(nSpaces, '-') : "") << "^\n";
85  }
86  }
87  std::lock_guard<std::mutex> lock{service_mutex()};
88  md_.emplace_back(key, value);
89 }
Float_t d
Definition: plot.C:237
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string value(boost::any const &)
static std::mutex & service_mutex()
void art::FileCatalogMetadata::addMetadataString ( std::string const &  key,
std::string const &  value 
)
inline

Definition at line 165 of file FileCatalogMetadata.h.

References addMetadata().

Referenced by FileCatalogMetadata(), and setMetadataFromInput().

167 {
168  // No lock here -- it is held by addMetadata
169  addMetadata(key, cet::canonical_string(value));
170 }
std::string value(boost::any const &)
void addMetadata(std::string const &key, std::string const &value)
void art::FileCatalogMetadata::getMetadata ( collection_type coll) const
inline

Definition at line 194 of file FileCatalogMetadata.h.

References DECLARE_ART_SERVICE, art::LEGACY, md_, and service_mutex().

Referenced by util::FileCatalogMetadataExtras::postBeginJob().

195 {
196  std::lock_guard<std::mutex> lock{service_mutex()};
197  cet::copy_all(md_, std::back_inserter(coll));
198 }
static std::mutex & service_mutex()
static std::mutex& art::FileCatalogMetadata::service_mutex ( )
inlinestaticprivate

Definition at line 157 of file FileCatalogMetadata.h.

Referenced by addMetadata(), and getMetadata().

158  {
159  static std::mutex m;
160  return m;
161  };
void art::FileCatalogMetadata::setMetadataFromInput ( collection_type const &  coll)
inline

Definition at line 173 of file FileCatalogMetadata.h.

References addMetadataString(), imd_, and mdToInherit_.

175 {
176  CET_ASSERT_ONLY_ONE_THREAD();
177  if (mdToInherit_.empty()) {
178  return;
179  }
180 
181  if (!imd_) {
182  imd_ = std::make_unique<InheritedMetadata>(mdToInherit_, mdFromInput);
183  } else {
184  imd_->check_values(mdFromInput);
185  }
186 
187  OldToNew const translator;
188  for (auto const& pr : imd_->entries()) {
189  addMetadataString(translator(pr.first), pr.second);
190  }
191 }
std::vector< std::string > mdToInherit_
void addMetadataString(std::string const &key, std::string const &value)
std::unique_ptr< InheritedMetadata > imd_
bool art::FileCatalogMetadata::wantCheckSyntax ( ) const
inline

Definition at line 97 of file FileCatalogMetadata.h.

References checkSyntax_.

98  {
99  return checkSyntax_;
100  }

Member Data Documentation

bool const art::FileCatalogMetadata::checkSyntax_
private

Definition at line 103 of file FileCatalogMetadata.h.

Referenced by addMetadata(), and wantCheckSyntax().

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

Definition at line 150 of file FileCatalogMetadata.h.

Referenced by setMetadataFromInput().

collection_type art::FileCatalogMetadata::md_ {}
private

Definition at line 104 of file FileCatalogMetadata.h.

Referenced by addMetadata(), and getMetadata().

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

Definition at line 151 of file FileCatalogMetadata.h.

Referenced by FileCatalogMetadata(), and setMetadataFromInput().


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