CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMFileIterator.cc
Go to the documentation of this file.
1 #include "DQMFileIterator.h"
3 
4 #include <queue>
5 #include <boost/regex.hpp>
6 #include <boost/format.hpp>
7 #include <boost/range.hpp>
8 #include <boost/filesystem.hpp>
9 #include <boost/algorithm/string/predicate.hpp>
10 
11 namespace edm {
12 
14  const std::string& filename, int lumiNumber) {
15  boost::property_tree::ptree pt;
16  read_json(filename, pt);
17 
19 
20  // We rely on n_events to be the first item on the array...
21  lumi.n_events = std::next(pt.get_child("data").begin(), 1)->second
22  .get_value<std::size_t>();
23  lumi.datafilename = std::next(pt.get_child("data").begin(), 2)->second
24  .get_value<std::string>();
25  lumi.definition = pt.get<std::string>("definition");
26  lumi.source = pt.get<std::string>("source");
27 
28  lumi.ls = lumiNumber;
29  return lumi;
30 }
31 
33  const std::string& filename) {
34  boost::property_tree::ptree pt;
35  read_json(filename, pt);
36 
37  EorEntry eor;
38 
39  // We rely on n_events to be the first item on the array...
40  eor.n_events = std::next(pt.get_child("data").begin(), 1)->second
41  .get_value<std::size_t>();
42  eor.n_lumi = std::next(pt.get_child("data").begin(), 2)->second
43  .get_value<std::size_t>();
44  eor.datafilename = std::next(pt.get_child("data").begin(), 2)->second
45  .get_value<std::string>();
46  eor.definition = pt.get<std::string>("definition");
47  eor.source = pt.get<std::string>("source");
48  eor.loaded = true;
49 
50  return eor;
51 }
52 
55 
57  run_ = run;
59  run_path_ = str(boost::format("%s/run%06d") % path % run_);
60 
61  eor_.loaded = false;
62  state_ = State::OPEN;
63  lastLumiSeen_ = 0;
64 
65  while (!queue_.empty()) {
66  queue_.pop();
67  }
68 
69  update_state();
70 }
71 
73 
75  return queue_.front();
76 }
77 
78 void DQMFileIterator::pop() { return queue_.pop(); }
79 
81  update_state();
82  return !queue_.empty();
83 }
84 
86  return str(boost::format("%s/run%06d_ls%04d%s.jsn") % run_path_ % run_ % lumi % streamLabel_);
87 }
88 
90  return str(boost::format("%s/run%06d_ls0000_EoR.jsn") % run_path_ % run_);
91 }
92 
94  if (boost::starts_with(lumi.datafilename, "/")) return lumi.datafilename;
95 
97  p /= lumi.datafilename;
98  return p.string();
99 }
100 
102  // search filesystem to find available lumi section files
103  // or the end of run file
104 
106  auto last_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
107  now - last_collect_).count();
108 
109  if (last_ms < 100) return;
110 
111  last_collect_ = now;
112 
113  if (!eor_.loaded) {
114  // end of run is not yet read
115  std::string fn_eor = make_path_eor();
116  edm::LogAbsolute("DQMStreamerReader") << "Checking eor file: " << fn_eor;
117 
118  if (boost::filesystem::exists(fn_eor)) {
119  eor_ = EorEntry::load_json(fn_eor);
120 
121  edm::LogAbsolute("DQMStreamerReader") << "Loaded eor file: " << fn_eor;
122  }
123  }
124 
125  int nextLumi = lastLumiSeen_; // initiate lumi
126  for (;;) {
127  nextLumi += 1;
128 
129  std::string fn = make_path_jsn(nextLumi);
130  edm::LogAbsolute("DQMStreamerReader") << "Checking json file: " << fn;
131  if (!boost::filesystem::exists(fn)) {
132  // file not yet available
133  break;
134  }
135 
136  LumiEntry lumi = LumiEntry::load_json(fn, nextLumi);
137  lastLumiSeen_ = nextLumi;
138  queue_.push(lumi);
139 
140  edm::LogAbsolute("DQMStreamerReader") << "Loaded json file: " << fn;
141  }
142 }
143 
145  collect();
146 
147  // now update the state
148  State old_state = state_;
149 
150  if ((state_ == State::OPEN) && (eor_.loaded)) {
151  state_ = State::EOR_CLOSING;
152  }
153 
154  if (state_ == State::EOR_CLOSING) {
155  if (int(eor_.n_lumi) <= lastLumiSeen_) {
156  // last lumi number is also the number of lumis
157  // ie lumi start from 1
158  state_ = State::EOR;
159  }
160  }
161 
162  if (state_ != old_state) {
163  edm::LogAbsolute("DQMStreamerReader")
164  << "Streamer state changed: " << old_state << " -> " << state_;
165  }
166 }
167 
168 } /* end of namespace */
void initialise(int run, const std::string &, const std::string &)
std::string make_path_data(const LumiEntry &lumi)
std::string make_path_jsn(int lumi)
tuple lumi
Definition: fjr2json.py:35
string format
Some error handling for the usage.
std::string make_path_eor()
std::chrono::high_resolution_clock::time_point last_collect_
U second(std::pair< T, U > const &p)
const LumiEntry & front()
std::string streamLabel_
static EorEntry load_json(const std::string &filename)
tuple filename
Definition: lut2db_cfg.py:20
std::queue< LumiEntry > queue_
static LumiEntry load_json(const std::string &filename, int lumiNumber)