7 #include "cetlib/split.h" 28 split_to_pair(
string const& to_split)
32 cet::split(to_split,
':', std::back_inserter(tmp));
42 <<
"Expected \"key:value\", got multiple \":\".\n";
47 check_metadata_options(bpo::variables_map
const& vm)
49 auto check_for_conflicting_options =
50 [&vm](
string const& firstOpt, std::initializer_list<string> opts) {
51 for (
auto const& opt : opts) {
52 if (vm.count(opt) + vm.count(firstOpt) > 1)
54 <<
"The options '--" << opt <<
"' and '--" << firstOpt
55 <<
"' are mutually exclusive.";
59 check_for_conflicting_options(
60 "sam-file-type", {
"sam-inherit-metadata",
"sam-inherit-file-type"});
61 check_for_conflicting_options(
62 "sam-run-type", {
"sam-inherit-metadata",
"sam-inherit-run-type"});
66 fill_tiers_streams(bpo::variables_map
const& vm,
71 auto const& table = raw_config.
get<
table_t const&>(
"outputs");
72 string const outputs_stem{
"outputs"};
73 string const tier_spec_stem{
"dataTier"};
74 string const stream_name_stem{
"streamName"};
75 vector<string> data_tiers((vm.count(
"sam-data-tier") > 0) ?
76 vm[
"sam-data-tier"].as<vector<string>>() :
78 vector<string> stream_names((vm.count(
"sam-stream-name") > 0) ?
79 vm[
"sam-stream-name"].as<vector<string>>() :
81 std::map<string, string> sep_tiers, sep_streams;
82 for (
auto const& tier : data_tiers) {
83 sep_tiers.insert(split_to_pair(tier));
85 for (
auto const& stream : stream_names) {
86 sep_streams.insert(split_to_pair(stream));
88 auto const def_tier_it(sep_tiers.find(
"_default"));
89 auto const def_tier((def_tier_it != sep_tiers.end()) ? def_tier_it->second :
91 auto const def_stream_it(sep_streams.find(
"_default"));
92 auto const def_stream(
93 (def_stream_it != sep_streams.end()) ? def_stream_it->second :
"");
94 for (
auto const& output : table) {
96 raw_config,
fhicl_key(outputs_stem, output.first,
"module_type"))) {
99 auto const& tier_spec_key =
100 fhicl_key(outputs_stem, output.first, tier_spec_stem);
101 auto const& stream_name_key =
102 fhicl_key(outputs_stem, output.first, stream_name_stem);
103 auto tiers_it(sep_tiers.find(output.first));
105 if (tiers_it != sep_tiers.end()) {
106 tier = tiers_it->second;
111 raw_config.
put(tier_spec_key, tier);
113 auto streams_it(sep_streams.find(output.first));
115 if (streams_it != sep_streams.end()) {
116 stream = streams_it->second;
118 stream = (!def_stream.empty()) ? def_stream : output.first;
120 if (!stream.empty()) {
121 raw_config.
put(stream_name_key, stream);
124 outputs_stem, output.first,
"module_type")) ==
"RootOutput") {
128 <<
"Output \"" << output.first <<
"\" must be configured with " 129 << tier_spec_stem <<
" (--sam-data-tier=" << output.first
130 <<
":<tier>) and " << stream_name_stem
131 <<
" (--sam-stream-name=" << output.first <<
":<stream>).\n";
142 auto const& ev = table.
find(
"outputs");
155 string const key_stem{
"services.FileCatalogMetadata."};
156 vector<string> missingItems;
158 missingItems.emplace_back(key_stem +
159 "applicationFamily (--sam-application-family)");
162 missingItems.emplace_back(
163 key_stem +
"applicationVersion (--sam-application-version)");
166 missingItems.emplace_back(key_stem +
"group (--sam-group)");
168 if (!missingItems.empty()) {
170 e <<
"SAM metadata information is required -- missing metadata:\n";
171 for (
auto const&
s : missingItems) {
180 bpo::options_description& desc)
183 bpo::options_description sam_options{
"SAM options"};
184 auto options = sam_options.add_options();
186 options,
"sam-web-uri", bpo::value<string>(),
"URI for SAM web service.");
187 add_opt(options,
"sam-process-id", bpo::value<string>(),
"SAM process ID.");
189 "sam-application-family",
191 "SAM application family.");
195 "SAM application family.");
197 "sam-application-version",
199 "SAM application version.");
203 "SAM application version.");
204 add_opt(options,
"sam-group", bpo::value<string>(),
"SAM group.");
207 bpo::value<string>(),
208 "File type for SAM metadata.");
212 "SAM data tier (<spec-label>:<tier-spec>).");
215 bpo::value<string>(),
216 "Global run-type for SAM metadata.");
220 "SAM stream name (<module-label>:<stream-name>).");
222 "sam-inherit-metadata",
223 "Input file provides the file type and run type.");
225 options,
"sam-inherit-file-type",
"Input file provides the file type.");
226 add_opt(options,
"sam-inherit-run-type",
"Input file provides the run type.");
227 desc.add(sam_options);
239 bpo::variables_map
const& vm,
242 std::string
const services{
"services"};
243 auto const& ciLocation =
fhicl_key(services,
"CatalogInterface");
244 auto const& ftLocation =
fhicl_key(services,
"FileTransfer");
245 auto const& fcmdLocation =
fhicl_key(services,
"FileCatalogMetadata");
251 if (vm.count(
"sam-web-uri") > 0) {
253 vm[
"sam-web-uri"].as<string>());
255 if (vm.count(
"sam-process-id") > 0) {
257 raw_config.
put(
"source.fileNames",
258 vector<string>{vm[
"sam-process-id"].as<
string>()});
261 vm[
"sam-process-id"].as<string>());
265 raw_config,
fhicl_key(fcmdLocation,
"processID"))) {
267 <<
"configurations " <<
fhicl_key(ciLocation,
"webURI")
268 <<
" (--sam-web-uri) and\n" 270 <<
" (--sam-process-id) must be specified\n" 271 <<
"together or not at all.\n";
273 bool const wantSAMweb{
280 if (vm.count(
"sam-group") > 0) {
282 vm[
"sam-group"].as<string>());
288 check_metadata_options(vm);
290 string const mdFromInput{
"metadataFromInput"};
291 bool specifyDataTier{
false};
295 if (vm.count(
"sam-inherit-metadata") > 0) {
297 vector<string>{
"fileType",
"runType"});
298 specifyDataTier =
true;
303 if (vm.count(
"sam-inherit-file-type") > 0) {
304 md.emplace_back(
"fileType");
305 specifyDataTier =
true;
308 if (vm.count(
"sam-inherit-run-type") > 0) {
309 md.emplace_back(
"runType");
313 raw_config.
put(
fhicl_key(fcmdLocation, mdFromInput), md);
317 if (vm.count(
"sam-run-type") > 0) {
319 vm[
"sam-run-type"].as<string>());
321 if (vm.count(
"sam-file-type") > 0) {
323 vm[
"sam-file-type"].as<string>());
325 bool const requireMetadata =
326 have_outputs(raw_config) &&
329 fhicl_key(fcmdLocation,
"applicationFamily")) ||
331 fhicl_key(fcmdLocation,
"applicationVersion")) ||
336 if (requireMetadata) {
337 fill_tiers_streams(vm, raw_config);
338 maybeThrowOnMissingMetadata(raw_config);
343 process_name = raw_config.
get<
string>(
"process_name");
345 if (requireMetadata && process_name.empty()) {
347 <<
"Non-empty / default process_name required for SAM metadata.\n";
350 raw_config.
put(
fhicl_key(ciLocation,
"service_provider"),
351 "IFCatalogInterface");
352 raw_config.
put(
fhicl_key(ftLocation,
"service_provider"),
"IFFileTransfer");
FileCatalogOptionsHandler(bpo::options_description &desc)
bool exists_outside_prolog(fhicl::intermediate_table const &config, std::string const &key)
void add_opt(T &t, Args &&...args)
int doProcessOptions(bpo::variables_map const &vm, fhicl::intermediate_table &raw_config) override
int doCheckOptions(bpo::variables_map const &vm) override
void ensureTable(fhicl::intermediate_table &table, std::string const &fhicl_spec)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
shims::map< std::string, extended_value > table_t
std::enable_if_t< std::is_convertible< T, std::string >::value, std::string > fhicl_key(T const &name)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::string value(boost::any const &)
std::pair< std::string const, std::string > string_pair_t