LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
TFileService.h
Go to the documentation of this file.
1 #ifndef art_Framework_Services_Optional_TFileService_h
2 #define art_Framework_Services_Optional_TFileService_h
3 
4 // ======================================================================
5 //
6 // TFileService
7 //
8 // ======================================================================
9 
16 #include "fhiclcpp/types/Atom.h"
17 #include "fhiclcpp/types/Name.h"
19 
20 namespace art {
21  class ActivityRegistry; // declaration only
22  class ModuleDescription; // declaration only
23  class TFileService; // defined below
24 }
25 namespace fhicl {
26  class ParameterSet; // declaration only
27 }
28 
29 // ----------------------------------------------------------------------
30 
32  // non-copyable:
33  TFileService(TFileService const&) = delete;
34  TFileService operator=(TFileService const&) = delete;
35 
36 public:
37  static constexpr const char* default_tmpDir = "<parent-path-of-filename>";
38 
39  struct Config {
40  fhicl::Atom<bool> closeFileFast{fhicl::Name("closeFileFast"), true};
41  fhicl::Atom<std::string> fileName{fhicl::Name("fileName")};
42  fhicl::Atom<std::string> tmpDir{fhicl::Name("tmpDir"), default_tmpDir};
44  fhicl::Name("fileProperties")};
45  };
46 
47  // c'tor:
50 
51  // d'tor:
52  ~TFileService();
53 
55 
56  void registerFileSwitchCallback(Callback_t c);
57 
58  template <typename T>
59  void registerFileSwitchCallback(T* provider, void (T::*)());
60 
61  // accessor:
62  TFile&
63  file() const
64  {
65  return *file_;
66  }
67 
68 private:
69  bool const closeFileFast_;
71  PostCloseFileRenamer fRenamer_{fstats_};
72  std::string filePattern_;
73  std::string uniqueFilename_;
74  std::string tmpDir_;
75 
76  // File-switching mechanics
77  std::string lastClosedFile_{};
78  Granularity currentGranularity_{Granularity::Unset};
79  std::chrono::steady_clock::time_point beginTime_{};
80  // Do not use default-constructed "ClosingCriteria" as that will be
81  // sure to trigger a file switch at the first call of
82  // requestsToCloseFile_().
83  ClosingCriteria fileSwitchCriteria_{ClosingCriteria::Config{}};
86 
87  // set current directory according to module name and prepare to create
88  // directory
89  void setDirectoryName_(art::ModuleDescription const& desc);
90  void openFile_();
91  void closeFile_();
92  void maybeSwitchFiles_();
93  bool requestsToCloseFile_();
94  std::string fileNameAtOpen_();
95  std::string fileNameAtClose_(std::string const&);
96 }; // TFileService
97 
98 // ======================================================================
99 
100 template <typename T>
101 void
103 {
104  auto cb = [provider, f] { return (provider->*f)(); };
105  registerFileSwitchCallback(cb);
106 }
107 
109 #endif /* art_Framework_Services_Optional_TFileService_h */
110 
111 // Local Variables:
112 // mode: c++
113 // End:
std::string tmpDir_
Definition: TFileService.h:74
std::function< void()> Callback_t
void registerFileSwitchCallback(Callback_t c)
TFile & file() const
Definition: TFileService.h:63
#define DECLARE_ART_SERVICE(svc, scope)
Definition: ServiceMacros.h:91
bool const closeFileFast_
Definition: TFileService.h:69
FileStatsCollector fstats_
Definition: TFileService.h:70
TFile f
Definition: plotHisto.C:6
OutputFileStatus
parameter set interface
std::string uniqueFilename_
Definition: TFileService.h:73
std::string filePattern_
Definition: TFileService.h:72
HLT enums.