CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMFileIterator.h
Go to the documentation of this file.
1 #ifndef IOPool_DQMStreamer_DQMFilerIterator_h
2 #define IOPool_DQMStreamer_DQMFilerIterator_h
3 
7 
8 #include "boost/filesystem.hpp"
9 
10 #include <map>
11 #include <unordered_set>
12 #include <chrono>
13 
14 #include "DQMMonitoringService.h"
15 
16 namespace dqmservices {
17 
19  public:
20  struct LumiEntry {
23 
24  unsigned int file_ls;
25  std::size_t n_events_processed;
26  std::size_t n_events_accepted;
28 
29  static LumiEntry load_json(const std::string& run_path, const std::string& filename, int lumiNumber,
30  int datafn_position);
31 
32  std::string get_data_path() const;
33  std::string get_json_path() const;
35  };
36 
37  struct EorEntry {
38  bool loaded = false;
41 
42  std::size_t n_events;
43  std::size_t n_lumi;
44 
46  };
47 
48  enum State {
49  OPEN = 0,
50  EOR_CLOSING = 1, // EoR file found, but lumis are still pending
51  EOR = 2,
52  };
53 
56  void initialise(int run, const std::string&, const std::string&);
57 
58  State state();
59 
60  /* methods to iterate the actual files */
61 
62  /* nextLumiNumber_ is the first unprocessed lumi number
63  * lumiReady() returns if the next lumi is ready to be loaded
64  * open() opens a file and advances the pointer to the next lumi
65  *
66  * front() a reference to the description (LumiEntry)
67  * pop() advances to the next lumi
68  */
69  bool lumiReady();
70  LumiEntry open();
71 
72  void pop();
73 
74  /* control */
75  void reset();
76  void update_state();
77 
78  /* misc helpers for input sources */
79  void logFileAction(const std::string& msg,
80  const std::string& fileName = "") const;
81  void logLumiState(const LumiEntry& lumi, const std::string& msg);
82 
83  void delay();
84 
85  unsigned int runNumber();
86  unsigned int lastLumiFound();
87  void advanceToLumi(unsigned int lumi, std::string reason);
88 
90 
91  private:
92  unsigned int runNumber_;
95  unsigned long delayMillis_;
99 
100  // file name position in the json file
101  unsigned int datafnPosition_;
102  std::vector<std::string> runPath_;
103 
106 
107  unsigned int nextLumiNumber_;
108  std::map<unsigned int, LumiEntry> lumiSeen_;
109  std::unordered_set<std::string> filesSeen_;
110 
111  /* this should be different,
112  * since time between hosts might be not in sync */
113  std::time_t runPathMTime_;
114  std::chrono::high_resolution_clock::time_point runPathLastCollect_;
115 
116  /* this is for missing lumi files */
117  std::chrono::high_resolution_clock::time_point lastLumiLoad_;
118 
119  std::time_t mtimeHash() const;
120  void collect(bool ignoreTimers);
121  void monUpdateLumi(const LumiEntry& lumi);
122 
123  /* this is for monitoring */
125 };
126 
127 } /* end of namespace */
128 
129 #endif
edm::Service< DQMMonitoringService > mon_
void logLumiState(const LumiEntry &lumi, const std::string &msg)
tuple lumi
Definition: fjr2json.py:35
void initialise(int run, const std::string &, const std::string &)
std::map< unsigned int, LumiEntry > lumiSeen_
static LumiEntry load_json(const std::string &run_path, const std::string &filename, int lumiNumber, int datafn_position)
tuple d
Definition: ztail.py:151
DQMFileIterator(edm::ParameterSet const &pset)
std::vector< std::string > runPath_
void logFileAction(const std::string &msg, const std::string &fileName="") const
std::chrono::high_resolution_clock::time_point lastLumiLoad_
static EorEntry load_json(const std::string &run_path, const std::string &filename)
void monUpdateLumi(const LumiEntry &lumi)
std::chrono::high_resolution_clock::time_point runPathLastCollect_
std::unordered_set< std::string > filesSeen_
State
Definition: hltDiff.cc:286
std::time_t mtimeHash() const
void advanceToLumi(unsigned int lumi, std::string reason)
static void fillDescription(edm::ParameterSetDescription &d)
void collect(bool ignoreTimers)