CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
dqmservices::DQMFileIterator Class Reference

#include <DQMFileIterator.h>

Classes

struct  EorEntry
 
struct  LumiEntry
 

Public Types

enum  State { OPEN = 0, EOR_CLOSING = 1, EOR = 2 }
 

Public Member Functions

void advanceToLumi (unsigned int lumi, std::string reason)
 
void delay ()
 
 DQMFileIterator (edm::ParameterSet const &pset)
 
void initialise (int run, const std::string &, const std::string &)
 
unsigned int lastLumiFound ()
 
void logFileAction (const std::string &msg, const std::string &fileName="") const
 
void logLumiState (const LumiEntry &lumi, const std::string &msg)
 
bool lumiReady ()
 
std::string make_path (const std::string &fn)
 
LumiEntry open ()
 
void pop ()
 
void reset ()
 
unsigned int runNumber ()
 
State state ()
 
void update_state ()
 
 ~DQMFileIterator ()
 

Static Public Member Functions

static void fillDescription (edm::ParameterSetDescription &d)
 

Private Member Functions

void collect (bool ignoreTimers)
 
void monUpdateLumi (const LumiEntry &lumi)
 

Private Attributes

unsigned int datafnPosition_
 
unsigned long delayMillis_
 
EorEntry eor_
 
std::unordered_set< std::string > filesSeen_
 
long forceFileCheckTimeoutMillis_
 
std::chrono::high_resolution_clock::time_point lastLumiLoad_
 
std::map< unsigned int, LumiEntrylumiSeen_
 
edm::Service
< DQMMonitoringService
mon_
 
unsigned int nextLumiNumber_
 
long nextLumiTimeoutMillis_
 
std::string runInputDir_
 
unsigned int runNumber_
 
std::string runPath_
 
std::chrono::high_resolution_clock::time_point runPathLastCollect_
 
std::time_t runPathMTime_
 
State state_
 
std::string streamLabel_
 

Detailed Description

Definition at line 18 of file DQMFileIterator.h.

Member Enumeration Documentation

Enumerator
OPEN 
EOR_CLOSING 
EOR 

Definition at line 43 of file DQMFileIterator.h.

43  {
44  OPEN = 0,
45  EOR_CLOSING = 1, // EoR file found, but lumis are still pending
46  EOR = 2,
47  };

Constructor & Destructor Documentation

dqmservices::DQMFileIterator::DQMFileIterator ( edm::ParameterSet const &  pset)

Definition at line 58 of file DQMFileIterator.cc.

References datafnPosition_, delayMillis_, forceFileCheckTimeoutMillis_, edm::ParameterSet::getUntrackedParameter(), nextLumiTimeoutMillis_, reset(), runInputDir_, runNumber_, streamLabel_, and AlCaHLTBitMon_QueryRunRegistry::string.

59  : state_(EOR) {
60 
61  runNumber_ = pset.getUntrackedParameter<unsigned int>("runNumber");
62  datafnPosition_ = pset.getUntrackedParameter<unsigned int>("datafnPosition");
63  runInputDir_ = pset.getUntrackedParameter<std::string>("runInputDir");
64  streamLabel_ = pset.getUntrackedParameter<std::string>("streamLabel");
65  delayMillis_ = pset.getUntrackedParameter<uint32_t>("delayMillis");
67  pset.getUntrackedParameter<int32_t>("nextLumiTimeoutMillis");
68 
70  reset();
71 }
dqmservices::DQMFileIterator::~DQMFileIterator ( )

Definition at line 73 of file DQMFileIterator.cc.

73 {}

Member Function Documentation

void dqmservices::DQMFileIterator::advanceToLumi ( unsigned int  lumi,
std::string  reason 
)

Definition at line 125 of file DQMFileIterator.cc.

References asciidump::doc, getDQMSummary::iter, lastLumiLoad_, fjr2json::lumi, lumiSeen_, mon_, monUpdateLumi(), nextLumiNumber_, and fileCollector::now.

Referenced by open(), dqmservices::DQMStreamerReader::reset_(), and update_state().

125  {
126  using boost::property_tree::ptree;
127  using boost::str;
128 
129  unsigned int currentLumi = nextLumiNumber_;
130 
133 
134  auto iter = lumiSeen_.lower_bound(currentLumi);
135 
136  while ((iter != lumiSeen_.end()) && ((iter->first) < nextLumiNumber_)) {
137  iter->second.state = reason;
138  monUpdateLumi(iter->second);
139 
140  ++iter;
141  }
142 
143  if (mon_.isAvailable()) {
144  // report the successful lumi file open
145  ptree doc;
146  doc.put("next_lumi", nextLumiNumber_);
147  mon_->outputUpdate(doc);
148  }
149 }
edm::Service< DQMMonitoringService > mon_
tuple lumi
Definition: fjr2json.py:35
std::map< unsigned int, LumiEntry > lumiSeen_
tuple doc
Definition: asciidump.py:381
std::chrono::high_resolution_clock::time_point lastLumiLoad_
void monUpdateLumi(const LumiEntry &lumi)
void dqmservices::DQMFileIterator::collect ( bool  ignoreTimers)
private

Definition at line 168 of file DQMFileIterator.cc.

References prof2calltree::count, datafnPosition_, alignCSCRings::e, eor_, cppFunctionSkipper::exception, lut2db_cfg::filename, filesSeen_, personalPlayback::fn, forceFileCheckTimeoutMillis_, diffTwoXMLs::label, dqmservices::DQMFileIterator::LumiEntry::load_json(), dqmservices::DQMFileIterator::EorEntry::loaded, logFileAction(), fjr2json::lumi, lumiSeen_, monUpdateLumi(), visualization-live-secondInstance_cfg::msg, dqmservices::DQMFileIterator::EorEntry::n_lumi, fileCollector::now, query::result, DTTTrigCorrFirst::run, runNumber_, runPath_, runPathLastCollect_, runPathMTime_, streamLabel_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by reset(), and update_state().

168  {
169  // search filesystem to find available lumi section files
170  // or the end of run files
171 
173  auto last_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
175 
176  // don't refresh if it's too soon
177  if ((!ignoreTimers) && (last_ms >= 0) && (last_ms < 100)) {
178  return;
179  }
180 
181  // check if directory changed
182  std::time_t mtime_now = boost::filesystem::last_write_time(runPath_);
183 
184  if ((!ignoreTimers) && (last_ms < forceFileCheckTimeoutMillis_) && (mtime_now == runPathMTime_)) {
185  //logFileAction("Directory hasn't changed.");
186  return;
187  } else {
188  //logFileAction("Directory changed, updating.");
189  }
190 
191  runPathMTime_ = mtime_now;
193 
194  using boost::filesystem::directory_iterator;
195  using boost::filesystem::directory_entry;
196 
197  std::string fn_eor;
198 
199  directory_iterator dend;
200  for (directory_iterator di(runPath_); di != dend; ++di) {
201  const boost::regex fn_re("run(\\d+)_ls(\\d+)_([a-zA-Z0-9]+)(_.*)?\\.jsn");
202 
203  const std::string filename = di->path().filename().string();
204  const std::string fn = di->path().string();
205 
206  if (filesSeen_.find(filename) != filesSeen_.end()) {
207  continue;
208  }
209 
210  boost::smatch result;
211  if (boost::regex_match(filename, result, fn_re)) {
212  unsigned int run = std::stoi(result[1]);
213  unsigned int lumi = std::stoi(result[2]);
214  std::string label = result[3];
215 
216  filesSeen_.insert(filename);
217 
218  if (run != runNumber_) continue;
219 
220  // check if this is EoR
221  // for various reasons we have to load it after all other files
222  if ((lumi == 0) && (label == "EoR") && (!eor_.loaded)) {
223  fn_eor = fn;
224  continue;
225  }
226 
227  // check if lumi is loaded
228  if (lumiSeen_.find(lumi) != lumiSeen_.end()) {
229  continue; // already loaded
230  }
231 
232  // check if this belongs to us
233  if (label != streamLabel_) {
234  std::string msg("Found and skipped json file (stream label mismatch, ");
235  msg += label + " [files] != " + streamLabel_ + " [config]";
236  msg += "): ";
237  logFileAction(msg, fn);
238  continue;
239  }
240 
241  try {
242  LumiEntry lumi_jsn = LumiEntry::load_json(fn, lumi, datafnPosition_);
243  lumiSeen_.emplace(lumi, lumi_jsn);
244  logFileAction("Found and loaded json file: ", fn);
245 
246  monUpdateLumi(lumi_jsn);
247  } catch (const std::exception& e) {
248  // don't reset the mtime, keep it waiting
249  filesSeen_.erase(filename);
250 
251  std::string msg("Found, tried to load the json, but failed (");
252  msg += e.what();
253  msg += "): ";
254  logFileAction(msg, fn);
255  }
256  }
257  }
258 
259  if (!fn_eor.empty()) {
260  logFileAction("EoR file found: ", fn_eor);
261 
262  // @TODO load EoR files correctly
263  // eor_ = EorEntry::load_json(fn_eor);
264  // logFileAction("Loaded eor file: ", fn_eor);
265 
266  // for now , set n_lumi to the highest _found_ lumi
267  eor_.loaded = true;
268 
269  if (lumiSeen_.empty()) {
270  eor_.n_lumi = 0;
271  } else {
272  eor_.n_lumi = lumiSeen_.rbegin()->first;
273  }
274  }
275 }
tuple lumi
Definition: fjr2json.py:35
std::map< unsigned int, LumiEntry > lumiSeen_
tuple result
Definition: query.py:137
void logFileAction(const std::string &msg, const std::string &fileName="") const
static LumiEntry load_json(const std::string &filename, int lumiNumber, unsigned int datafn_position)
tuple filename
Definition: lut2db_cfg.py:20
void monUpdateLumi(const LumiEntry &lumi)
std::chrono::high_resolution_clock::time_point runPathLastCollect_
std::unordered_set< std::string > filesSeen_
void dqmservices::DQMFileIterator::delay ( )

Definition at line 353 of file DQMFileIterator.cc.

References delayMillis_, and mon_.

Referenced by dqmservices::DQMProtobufReader::getNextItemType(), dqmservices::DQMStreamerReader::prepareNextEvent(), and dqmservices::DQMStreamerReader::reset_().

353  {
354  if (mon_.isAvailable())
355  mon_->keepAlive();
356 
357  usleep(delayMillis_ * 1000);
358 }
edm::Service< DQMMonitoringService > mon_
void dqmservices::DQMFileIterator::fillDescription ( edm::ParameterSetDescription d)
static

Definition at line 360 of file DQMFileIterator.cc.

References edm::ParameterSetDescription::addUntracked(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by dqmservices::DQMProtobufReader::fillDescriptions(), and dqmservices::DQMStreamerReader::fillDescriptions().

360  {
361 
362  desc.addUntracked<unsigned int>("runNumber")
363  ->setComment("Run number passed via configuration file.");
364 
365  desc.addUntracked<unsigned int>("datafnPosition", 3)
366  ->setComment("Data filename position in the positional arguments array 'data' in json file.");
367 
368  desc.addUntracked<std::string>("streamLabel")
369  ->setComment("Stream label used in json discovery.");
370 
371  desc.addUntracked<uint32_t>("delayMillis")
372  ->setComment("Number of milliseconds to wait between file checks.");
373 
374  desc.addUntracked<int32_t>("nextLumiTimeoutMillis", -1)->setComment(
375  "Number of milliseconds to wait before switching to the next lumi "
376  "section if the current is missing, -1 to disable.");
377 
378  desc.addUntracked<std::string>("runInputDir")
379  ->setComment("Directory where the DQM files will appear.");
380 }
void dqmservices::DQMFileIterator::initialise ( int  run,
const std::string &  ,
const std::string &   
)
unsigned int dqmservices::DQMFileIterator::lastLumiFound ( )

Definition at line 117 of file DQMFileIterator.cc.

References lumiSeen_.

Referenced by dqmservices::DQMStreamerReader::reset_().

117  {
118  if (!lumiSeen_.empty()) {
119  return lumiSeen_.rbegin()->first;
120  }
121 
122  return 1;
123 }
std::map< unsigned int, LumiEntry > lumiSeen_
void dqmservices::DQMFileIterator::logFileAction ( const std::string &  msg,
const std::string &  fileName = "" 
) const
void dqmservices::DQMFileIterator::logLumiState ( const LumiEntry lumi,
const std::string &  msg 
)

Definition at line 343 of file DQMFileIterator.cc.

References dqmservices::DQMFileIterator::LumiEntry::file_ls, logFileAction(), lumiSeen_, monUpdateLumi(), and visualization-live-secondInstance_cfg::msg.

Referenced by dqmservices::DQMStreamerReader::closeFile_(), dqmservices::DQMStreamerReader::openNextFile_(), and dqmservices::DQMProtobufReader::readLuminosityBlock_().

343  {
344  if (lumiSeen_.find(lumi.file_ls) != lumiSeen_.end()) {
345  lumiSeen_[lumi.file_ls].state = msg;
346 
347  monUpdateLumi(lumiSeen_[lumi.file_ls]);
348  } else {
349  logFileAction("Internal error: referenced lumi is not the map.");
350  }
351 }
tuple lumi
Definition: fjr2json.py:35
std::map< unsigned int, LumiEntry > lumiSeen_
void logFileAction(const std::string &msg, const std::string &fileName="") const
void monUpdateLumi(const LumiEntry &lumi)
bool dqmservices::DQMFileIterator::lumiReady ( )

Definition at line 107 of file DQMFileIterator.cc.

References lumiSeen_, and nextLumiNumber_.

Referenced by dqmservices::DQMProtobufReader::getNextItemType(), and dqmservices::DQMStreamerReader::prepareNextFile().

107  {
108  if (lumiSeen_.find(nextLumiNumber_) != lumiSeen_.end()) {
109  return true;
110  }
111 
112  return false;
113 }
std::map< unsigned int, LumiEntry > lumiSeen_
std::string dqmservices::DQMFileIterator::make_path ( const std::string &  fn)

Definition at line 160 of file DQMFileIterator.cc.

References personalPlayback::fn, AlCaHLTBitMon_ParallelJobs::p, cmsHarvester::path, and runPath_.

Referenced by dqmservices::DQMStreamerReader::openFile_(), dqmservices::DQMStreamerReader::openNextFile_(), and dqmservices::DQMProtobufReader::readLuminosityBlock_().

160  {
161  if (boost::starts_with(fn, "/")) return fn;
162 
164  p /= fn;
165  return p.string();
166 }
tuple path
else: Piece not in the list, fine.
void dqmservices::DQMFileIterator::monUpdateLumi ( const LumiEntry lumi)
private

Definition at line 151 of file DQMFileIterator.cc.

References asciidump::doc, dqmservices::DQMFileIterator::LumiEntry::file_ls, cmsPerfStripChart::format, mon_, and dqmservices::DQMFileIterator::LumiEntry::state.

Referenced by advanceToLumi(), collect(), and logLumiState().

151  {
152  if (! mon_.isAvailable())
153  return;
154 
155  ptree doc;
156  doc.put(str(boost::format("extra.lumi_seen.lumi%06d") % lumi.file_ls), lumi.state);
157  mon_->outputUpdate(doc);
158 }
edm::Service< DQMMonitoringService > mon_
tuple lumi
Definition: fjr2json.py:35
string format
Some error handling for the usage.
tuple doc
Definition: asciidump.py:381
DQMFileIterator::LumiEntry dqmservices::DQMFileIterator::open ( )
void dqmservices::DQMFileIterator::pop ( )
void dqmservices::DQMFileIterator::reset ( void  )

Definition at line 75 of file DQMFileIterator.cc.

References collect(), asciidump::doc, eor_, filesSeen_, cmsPerfStripChart::format, lastLumiLoad_, dqmservices::DQMFileIterator::EorEntry::loaded, lumiSeen_, mon_, nextLumiNumber_, fileCollector::now, runInputDir_, runNumber_, runPath_, state_, cond::to_string(), and update_state().

Referenced by DQMFileIterator().

75  {
76  runPath_ = str(boost::format("%s/run%06d") % runInputDir_ % runNumber_);
77 
78  eor_.loaded = false;
79  state_ = State::OPEN;
80  nextLumiNumber_ = 1;
81  lumiSeen_.clear();
82  filesSeen_.clear();
83 
85 
86  collect(true);
87  update_state();
88 
89  if (mon_.isAvailable()) {
90  ptree doc;
91  doc.put("run", runNumber_);
92  doc.put("next_lumi", nextLumiNumber_);
93  doc.put("fi_state", std::to_string(state_));
94  mon_->outputUpdate(doc);
95  }
96 
97 }
edm::Service< DQMMonitoringService > mon_
std::map< unsigned int, LumiEntry > lumiSeen_
string format
Some error handling for the usage.
std::string to_string(const T &t)
Definition: Logger.cc:26
tuple doc
Definition: asciidump.py:381
std::chrono::high_resolution_clock::time_point lastLumiLoad_
std::unordered_set< std::string > filesSeen_
void collect(bool ignoreTimers)
unsigned int dqmservices::DQMFileIterator::runNumber ( )
DQMFileIterator::State dqmservices::DQMFileIterator::state ( )
void dqmservices::DQMFileIterator::update_state ( )

Definition at line 277 of file DQMFileIterator.cc.

References advanceToLumi(), collect(), prof2calltree::count, asciidump::doc, eor_, getDQMSummary::iter, lastLumiLoad_, dqmservices::DQMFileIterator::EorEntry::loaded, logFileAction(), lumiSeen_, mon_, visualization-live-secondInstance_cfg::msg, dqmservices::DQMFileIterator::EorEntry::n_lumi, nextLumiNumber_, nextLumiTimeoutMillis_, fileCollector::now, state_, AlCaHLTBitMon_QueryRunRegistry::string, and cond::to_string().

Referenced by dqmservices::DQMProtobufReader::getNextItemType(), dqmservices::DQMStreamerReader::prepareNextFile(), reset(), and dqmservices::DQMStreamerReader::reset_().

277  {
278  using std::chrono::high_resolution_clock;
279  using std::chrono::duration_cast;
280  using std::chrono::milliseconds;
281 
282  collect(false);
283 
284  // now update the state
285  State old_state = state_;
286 
287  if ((state_ == State::OPEN) && (eor_.loaded)) {
288  state_ = State::EOR_CLOSING;
289  }
290 
291  // special case for missing lumi files
292  // skip to the next available, but after the timeout
293  if ((state_ != State::EOR) && (nextLumiTimeoutMillis_ >= 0)) {
294  auto iter = lumiSeen_.lower_bound(nextLumiNumber_);
295  if ((iter != lumiSeen_.end()) && iter->first != nextLumiNumber_) {
296 
297  auto elapsed = high_resolution_clock::now() - lastLumiLoad_;
298  auto elapsed_ms = duration_cast<milliseconds>(elapsed).count();
299 
300  if (elapsed_ms >= nextLumiTimeoutMillis_) {
301  std::string msg("Timeout reached, skipping lumisection(s) ");
302  msg += std::to_string(nextLumiNumber_) + " .. " +
303  std::to_string(iter->first - 1);
304  msg += ", nextLumiNumber_ is now " + std::to_string(iter->first);
306 
307  advanceToLumi(iter->first, "skipped: timeout");
308  }
309  }
310  }
311 
312  if (state_ == State::EOR_CLOSING) {
313  // check if we parsed all lumis
314  // n_lumi is both last lumi and the number of lumi
315  // since lumis are indexed from 1
316 
317  // after all lumi have been pop()'ed
318  // current lumi will become larger than the last lumi
319  if (nextLumiNumber_ > eor_.n_lumi) {
320  state_ = State::EOR;
321  }
322  }
323 
324  if (state_ != old_state) {
325  logFileAction("Streamer state changed: ",
326  std::to_string(old_state) + "->" + std::to_string(state_));
327 
328  if (mon_) {
329  ptree doc;
330  doc.put("fi_state", std::to_string(state_));
331  mon_->outputUpdate(doc);
332  }
333  }
334 }
edm::Service< DQMMonitoringService > mon_
std::map< unsigned int, LumiEntry > lumiSeen_
std::string to_string(const T &t)
Definition: Logger.cc:26
void logFileAction(const std::string &msg, const std::string &fileName="") const
tuple doc
Definition: asciidump.py:381
std::chrono::high_resolution_clock::time_point lastLumiLoad_
State
Definition: hltDiff.cc:314
void advanceToLumi(unsigned int lumi, std::string reason)
void collect(bool ignoreTimers)

Member Data Documentation

unsigned int dqmservices::DQMFileIterator::datafnPosition_
private

Definition at line 96 of file DQMFileIterator.h.

Referenced by collect(), and DQMFileIterator().

unsigned long dqmservices::DQMFileIterator::delayMillis_
private

Definition at line 91 of file DQMFileIterator.h.

Referenced by delay(), and DQMFileIterator().

EorEntry dqmservices::DQMFileIterator::eor_
private

Definition at line 99 of file DQMFileIterator.h.

Referenced by collect(), reset(), and update_state().

std::unordered_set<std::string> dqmservices::DQMFileIterator::filesSeen_
private

Definition at line 104 of file DQMFileIterator.h.

Referenced by collect(), and reset().

long dqmservices::DQMFileIterator::forceFileCheckTimeoutMillis_
private

Definition at line 93 of file DQMFileIterator.h.

Referenced by collect(), and DQMFileIterator().

std::chrono::high_resolution_clock::time_point dqmservices::DQMFileIterator::lastLumiLoad_
private

Definition at line 112 of file DQMFileIterator.h.

Referenced by advanceToLumi(), reset(), and update_state().

std::map<unsigned int, LumiEntry> dqmservices::DQMFileIterator::lumiSeen_
private
edm::Service<DQMMonitoringService> dqmservices::DQMFileIterator::mon_
private

Definition at line 118 of file DQMFileIterator.h.

Referenced by advanceToLumi(), delay(), monUpdateLumi(), reset(), and update_state().

unsigned int dqmservices::DQMFileIterator::nextLumiNumber_
private

Definition at line 102 of file DQMFileIterator.h.

Referenced by advanceToLumi(), lumiReady(), open(), reset(), and update_state().

long dqmservices::DQMFileIterator::nextLumiTimeoutMillis_
private

Definition at line 92 of file DQMFileIterator.h.

Referenced by DQMFileIterator(), and update_state().

std::string dqmservices::DQMFileIterator::runInputDir_
private

Definition at line 89 of file DQMFileIterator.h.

Referenced by DQMFileIterator(), and reset().

unsigned int dqmservices::DQMFileIterator::runNumber_
private

Definition at line 88 of file DQMFileIterator.h.

Referenced by collect(), DQMFileIterator(), reset(), and runNumber().

std::string dqmservices::DQMFileIterator::runPath_
private

Definition at line 97 of file DQMFileIterator.h.

Referenced by collect(), make_path(), and reset().

std::chrono::high_resolution_clock::time_point dqmservices::DQMFileIterator::runPathLastCollect_
private

Definition at line 109 of file DQMFileIterator.h.

Referenced by collect().

std::time_t dqmservices::DQMFileIterator::runPathMTime_
private

Definition at line 108 of file DQMFileIterator.h.

Referenced by collect().

State dqmservices::DQMFileIterator::state_
private

Definition at line 100 of file DQMFileIterator.h.

Referenced by reset(), state(), and update_state().

std::string dqmservices::DQMFileIterator::streamLabel_
private

Definition at line 90 of file DQMFileIterator.h.

Referenced by collect(), and DQMFileIterator().