artdaq  v3_02_00
rootOutputConfigurationTools.cc
1 #include "art/Framework/Core/OutputFileGranularity.h"
2 #define BOUNDARY_GRANULARITY Granularity::InputFile
3 #include "art/Framework/IO/Root/RootOutputClosingCriteria.h"
4 #include "artdaq/ArtModules/RootDAQOutput/detail/rootOutputConfigurationTools.h"
5 #include "canvas/Utilities/Exception.h"
6 #include "messagefacility/MessageLogger/MessageLogger.h"
7 
8 using namespace art;
9 
10 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  {
41  result = false;
42  mf::LogWarning("FastCloning") << "Fast cloning deactivated due to presence of\n"
43  << "event selection configuration.";
44  }
45  if (fastCloning && maxCriterionSpecified(cc) && cc.granularity() < BOUNDARY_GRANULARITY)
46  {
47  result = false;
48  mf::LogWarning("FastCloning") << "Fast cloning deactivated due to request to allow\n"
49  << "output file switching at an Event, SubRun, or Run boundary.";
50  }
51  return result;
52 }
53 
54 bool
55 art::detail::shouldDropEvents(bool const dropAllEventsSet,
56  bool const dropAllEvents,
57  bool const dropAllSubRuns)
58 {
59  if (!dropAllSubRuns)
60  return dropAllEvents;
61 
62  if (dropAllEventsSet && !dropAllEvents)
63  {
64  throw art::Exception(errors::Configuration)
65  << "\nThe following FHiCL specification is illegal\n\n"
66  << " dropAllEvents : false \n"
67  << " dropAllSubRuns : true \n\n"
68  << "[1] Both can be 'true', "
69  << "[2] both can be 'false', or "
70  << "[3] 'dropAllEvents : true' and 'dropAllSubRuns : false' "
71  << "is allowed.\n\n";
72  }
73  return true;
74 }
75 
76 void
77 art::detail::validateFileNamePattern(bool const do_check, std::string const& pattern)
78 {
79  if (!do_check) return;
80 
81  if (pattern.find("%#") == std::string::npos)
82  throw Exception(errors::Configuration)
83  << "If you have specified the 'fileProperties' table in a RootOutput module configuration,\n"
84  << "then the file pattern '%#' MUST be present in the file name. For example:\n"
85  << " " << pattern.substr(0, pattern.find(".root")) << "_%#.root\n"
86  << "is a supported file name. Please change your file name to include the '%#' pattern.";
87 }
bool maxCriterionSpecified(ClosingCriteria const &cc)
Determine if a file-closing criteria has been provided.