artdaq  v3_01_00
rootOutputConfigurationTools.cc
1 #if ART_HEX_VERSION >= 0x20703
2 # include "art/Framework/Core/OutputFileGranularity.h"
3 # define BOUNDARY_GRANULARITY Granularity::InputFile
4 #else
5 # include "art/Framework/Core/OutputFileSwitchBoundary.h"
6 # define BOUNDARY_GRANULARITY Boundary::InputFile
7 #endif
8 #include "art/Framework/IO/Root/RootOutputClosingCriteria.h"
9 #include "artdaq/ArtModules/RootDAQOutput/detail/rootOutputConfigurationTools.h"
10 #include "canvas/Utilities/Exception.h"
11 #include "messagefacility/MessageLogger/MessageLogger.h"
12 
13 using namespace art;
14 
15 namespace {
21  bool maxCriterionSpecified(ClosingCriteria const& cc)
22  {
23  auto fp = std::mem_fn(&ClosingCriteria::fileProperties);
24  return
25  fp(cc).nEvents() != Defaults::unsigned_max() ||
26  fp(cc).nSubRuns() != Defaults::unsigned_max() ||
27  fp(cc).nRuns() != Defaults::unsigned_max() ||
28  fp(cc).size() != Defaults::size_max() ||
29  fp(cc).age().count() != Defaults::seconds_max();
30  }
31 }
32 
33 bool
34 art::detail::shouldFastClone(bool const fastCloningSet,
35  bool const fastCloning,
36  bool const wantAllEvents,
37  ClosingCriteria const& cc)
38 {
39  bool result {fastCloning};
40  mf::LogInfo("FastCloning") << "Initial fast cloning configuration "
41  << (fastCloningSet ? "(user-set): " : "(from default): ")
42  << std::boolalpha << fastCloning;
43 
44  if (fastCloning && !wantAllEvents) {
45  result = false;
46  mf::LogWarning("FastCloning") << "Fast cloning deactivated due to presence of\n"
47  << "event selection configuration.";
48  }
49  if (fastCloning && maxCriterionSpecified(cc) && cc.granularity() < BOUNDARY_GRANULARITY) {
50  result = false;
51  mf::LogWarning("FastCloning") << "Fast cloning deactivated due to request to allow\n"
52  << "output file switching at an Event, SubRun, or Run boundary.";
53  }
54  return result;
55 }
56 
57 bool
58 art::detail::shouldDropEvents(bool const dropAllEventsSet,
59  bool const dropAllEvents,
60  bool const dropAllSubRuns)
61 {
62  if (!dropAllSubRuns)
63  return dropAllEvents;
64 
65  if (dropAllEventsSet && !dropAllEvents) {
66  throw art::Exception(errors::Configuration)
67  << "\nThe following FHiCL specification is illegal\n\n"
68  << " dropAllEvents : false \n"
69  << " dropAllSubRuns : true \n\n"
70  << "[1] Both can be 'true', "
71  << "[2] both can be 'false', or "
72  << "[3] 'dropAllEvents : true' and 'dropAllSubRuns : false' "
73  << "is allowed.\n\n";
74  }
75  return true;
76 }
77 
78 void
79 art::detail::validateFileNamePattern(bool const do_check, std::string const& pattern)
80 {
81  if (!do_check) return;
82 
83  if (pattern.find("%#") == std::string::npos)
84  throw Exception(errors::Configuration)
85  << "If you have specified the 'fileProperties' table in a RootOutput module configuration,\n"
86  << "then the file pattern '%#' MUST be present in the file name. For example:\n"
87  << " " << pattern.substr(0,pattern.find(".root")) << "_%#.root\n"
88  << "is a supported file name. Please change your file name to include the '%#' pattern.";
89 }
bool maxCriterionSpecified(ClosingCriteria const &cc)
Determine if a file-closing criteria has been provided.