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