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)
 
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_data (const LumiEntry &lumi)
 
const LumiEntry open ()
 
void pop ()
 
void reset ()
 
unsigned int runNumber ()
 
State state ()
 
void update_state ()
 
void updateMonitoring ()
 
 ~DQMFileIterator ()
 

Static Public Member Functions

static void fillDescription (edm::ParameterSetDescription &d)
 

Private Member Functions

void collect (bool ignoreTimers)
 

Private Attributes

unsigned int datafnPosition_
 
unsigned long delayMillis_
 
EorEntry eor_
 
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 44 of file DQMFileIterator.h.

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

Constructor & Destructor Documentation

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

Definition at line 60 of file DQMFileIterator.cc.

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

61  : state_(EOR) {
62 
63  runNumber_ = pset.getUntrackedParameter<unsigned int>("runNumber");
64  datafnPosition_ = pset.getUntrackedParameter<unsigned int>("datafnPosition");
65  runInputDir_ = pset.getUntrackedParameter<std::string>("runInputDir");
66  streamLabel_ = pset.getUntrackedParameter<std::string>("streamLabel");
67  delayMillis_ = pset.getUntrackedParameter<uint32_t>("delayMillis");
69  pset.getUntrackedParameter<int32_t>("nextLumiTimeoutMillis");
70 
72  reset();
73 
74  if (mon_.isAvailable()) {
75  ptree doc;
76  doc.put("run", runNumber_);
77  mon_->outputUpdate(doc);
79  }
80 }
edm::Service< DQMMonitoringService > mon_
tuple doc
Definition: asciidump.py:381
dqmservices::DQMFileIterator::~DQMFileIterator ( )

Definition at line 82 of file DQMFileIterator.cc.

82 {}

Member Function Documentation

void dqmservices::DQMFileIterator::advanceToLumi ( unsigned int  lumi)

Definition at line 126 of file DQMFileIterator.cc.

References asciidump::doc, lastLumiLoad_, fjr2json::lumi, mon_, nextLumiNumber_, fileCollector::now, and updateMonitoring().

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

126  {
127  using boost::property_tree::ptree;
128  using boost::str;
129 
130  unsigned int currentLumi = nextLumiNumber_;
131 
134 
135  if (mon_.isAvailable()) {
136  // report the successful lumi file open
137  ptree doc;
138  doc.put("lumi", currentLumi);
139  mon_->outputUpdate(doc);
141  }
142 }
edm::Service< DQMMonitoringService > mon_
tuple lumi
Definition: fjr2json.py:35
tuple doc
Definition: asciidump.py:381
std::chrono::high_resolution_clock::time_point lastLumiLoad_
void dqmservices::DQMFileIterator::collect ( bool  ignoreTimers)
private

Definition at line 172 of file DQMFileIterator.cc.

References prof2calltree::count, datafnPosition_, alignCSCRings::e, eor_, cppFunctionSkipper::exception, lut2db_cfg::filename, forceFileCheckTimeoutMillis_, diffTwoXMLs::label, dqmservices::DQMFileIterator::LumiEntry::load_json(), dqmservices::DQMFileIterator::EorEntry::loaded, logFileAction(), fjr2json::lumi, lumiSeen_, producerFileCleanner::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().

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

Definition at line 342 of file DQMFileIterator.cc.

References delayMillis_, and mon_.

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

342  {
343  //logFileAction("Streamer waiting for the next LS.");
344 
345  if (mon_.isAvailable())
346  mon_->keepAlive();
347 
348  usleep(delayMillis_ * 1000);
349 
350  if (mon_.isAvailable())
351  mon_->keepAlive();
352 }
edm::Service< DQMMonitoringService > mon_
void dqmservices::DQMFileIterator::fillDescription ( edm::ParameterSetDescription d)
static

Definition at line 354 of file DQMFileIterator.cc.

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

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

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

Definition at line 118 of file DQMFileIterator.cc.

References lumiSeen_.

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

118  {
119  if (!lumiSeen_.empty()) {
120  return lumiSeen_.rbegin()->first;
121  }
122 
123  return 1;
124 }
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 334 of file DQMFileIterator.cc.

References dqmservices::DQMFileIterator::LumiEntry::file_ls, logFileAction(), lumiSeen_, and producerFileCleanner::msg.

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

334  {
335  if (lumiSeen_.find(lumi.file_ls) != lumiSeen_.end()) {
336  lumiSeen_[lumi.file_ls].state = msg;
337  } else {
338  logFileAction("Internal error: referenced lumi is not the map.");
339  }
340 }
tuple lumi
Definition: fjr2json.py:35
std::map< unsigned int, LumiEntry > lumiSeen_
void logFileAction(const std::string &msg, const std::string &fileName="") const
bool dqmservices::DQMFileIterator::lumiReady ( )

Definition at line 108 of file DQMFileIterator.cc.

References lumiSeen_, and nextLumiNumber_.

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

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

Definition at line 164 of file DQMFileIterator.cc.

References dqmservices::DQMFileIterator::LumiEntry::datafilename, AlCaHLTBitMon_ParallelJobs::p, cmsHarvester::path, and runPath_.

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

164  {
165  if (boost::starts_with(lumi.datafilename, "/")) return lumi.datafilename;
166 
168  p /= lumi.datafilename;
169  return p.string();
170 }
tuple lumi
Definition: fjr2json.py:35
tuple path
else: Piece not in the list, fine.
const DQMFileIterator::LumiEntry dqmservices::DQMFileIterator::open ( )
void dqmservices::DQMFileIterator::pop ( )
void dqmservices::DQMFileIterator::reset ( void  )

Definition at line 84 of file DQMFileIterator.cc.

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

Referenced by DQMFileIterator().

84  {
85  runPath_ = str(boost::format("%s/run%06d") % runInputDir_ % runNumber_);
86 
87  eor_.loaded = false;
88  state_ = State::OPEN;
89  nextLumiNumber_ = 1;
90  lumiSeen_.clear();
91 
93 
94  collect(true);
95  update_state();
96 }
std::map< unsigned int, LumiEntry > lumiSeen_
string format
Some error handling for the usage.
std::chrono::high_resolution_clock::time_point lastLumiLoad_
void collect(bool ignoreTimers)
unsigned int dqmservices::DQMFileIterator::runNumber ( )
DQMFileIterator::State dqmservices::DQMFileIterator::state ( )
void dqmservices::DQMFileIterator::update_state ( )

Definition at line 271 of file DQMFileIterator.cc.

References collect(), prof2calltree::count, eor_, getDQMSummary::iter, lastLumiLoad_, dqmservices::DQMFileIterator::EorEntry::loaded, logFileAction(), lumiSeen_, producerFileCleanner::msg, dqmservices::DQMFileIterator::EorEntry::n_lumi, nextLumiNumber_, nextLumiTimeoutMillis_, fileCollector::now, state_, AlCaHLTBitMon_QueryRunRegistry::string, cond::to_string(), and updateMonitoring().

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

271  {
272  using std::chrono::high_resolution_clock;
273  using std::chrono::duration_cast;
274  using std::chrono::milliseconds;
275 
276  collect(false);
277 
278  // now update the state
279  State old_state = state_;
280 
281  if ((state_ == State::OPEN) && (eor_.loaded)) {
282  state_ = State::EOR_CLOSING;
283  }
284 
285  // special case for missing lumi files
286  // skip to the next available, but after the timeout
287  if ((state_ != State::EOR) && (nextLumiTimeoutMillis_ >= 0)) {
288  auto iter = lumiSeen_.lower_bound(nextLumiNumber_);
289  if ((iter != lumiSeen_.end()) && iter->first != nextLumiNumber_) {
290 
291  auto elapsed = high_resolution_clock::now() - lastLumiLoad_;
292  auto elapsed_ms = duration_cast<milliseconds>(elapsed).count();
293 
294  if (elapsed_ms >= nextLumiTimeoutMillis_) {
295  std::string msg("Timeout reached, skipping lumisection(s) ");
296  msg += std::to_string(nextLumiNumber_) + " .. " +
297  std::to_string(iter->first - 1);
298  msg += ", nextLumiNumber_ is now " + std::to_string(iter->first);
299 
301 
302  nextLumiNumber_ = iter->first;
303  }
304  }
305  }
306 
307  if (state_ == State::EOR_CLOSING) {
308  // check if we parsed all lumis
309  // n_lumi is both last lumi and the number of lumi
310  // since lumis are indexed from 1
311 
312  // after all lumi have been pop()'ed
313  // current lumi will become larger than the last lumi
314  if (nextLumiNumber_ > eor_.n_lumi) {
315  state_ = State::EOR;
316  }
317  }
318 
319  if (state_ != old_state) {
320  logFileAction("Streamer state changed: ",
321  std::to_string(old_state) + "->" + std::to_string(state_));
322 
324  }
325 }
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
std::chrono::high_resolution_clock::time_point lastLumiLoad_
void collect(bool ignoreTimers)
void dqmservices::DQMFileIterator::updateMonitoring ( )

Definition at line 144 of file DQMFileIterator.cc.

References asciidump::doc, getDQMSummary::iter, fjr2json::lumi, lumiSeen_, mon_, and cond::to_string().

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

144  {
145  if (! mon_.isAvailable())
146  return;
147 
148  ptree children;
149  auto iter = lumiSeen_.begin();
150  for (; iter != lumiSeen_.end(); ++iter) {
151  ptree lumi;
152  lumi.put("filename", iter->second.filename);
153  lumi.put("file_ls", iter->second.file_ls);
154  lumi.put("state", iter->second.state);
155 
156  children.add_child(std::to_string(iter->first), lumi);
157  }
158 
159  ptree doc;
160  doc.add_child("lumiSeen", children);
161  mon_->outputUpdate(doc);
162 }
edm::Service< DQMMonitoringService > mon_
tuple lumi
Definition: fjr2json.py:35
std::map< unsigned int, LumiEntry > lumiSeen_
std::string to_string(const T &t)
Definition: Logger.cc:26
tuple doc
Definition: asciidump.py:381

Member Data Documentation

unsigned int dqmservices::DQMFileIterator::datafnPosition_
private

Definition at line 99 of file DQMFileIterator.h.

Referenced by collect(), and DQMFileIterator().

unsigned long dqmservices::DQMFileIterator::delayMillis_
private

Definition at line 94 of file DQMFileIterator.h.

Referenced by delay(), and DQMFileIterator().

EorEntry dqmservices::DQMFileIterator::eor_
private

Definition at line 102 of file DQMFileIterator.h.

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

long dqmservices::DQMFileIterator::forceFileCheckTimeoutMillis_
private

Definition at line 96 of file DQMFileIterator.h.

Referenced by collect(), and DQMFileIterator().

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

Definition at line 114 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 119 of file DQMFileIterator.h.

Referenced by advanceToLumi(), delay(), DQMFileIterator(), and updateMonitoring().

unsigned int dqmservices::DQMFileIterator::nextLumiNumber_
private

Definition at line 105 of file DQMFileIterator.h.

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

long dqmservices::DQMFileIterator::nextLumiTimeoutMillis_
private

Definition at line 95 of file DQMFileIterator.h.

Referenced by DQMFileIterator(), and update_state().

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

Definition at line 92 of file DQMFileIterator.h.

Referenced by DQMFileIterator(), and reset().

unsigned int dqmservices::DQMFileIterator::runNumber_
private

Definition at line 91 of file DQMFileIterator.h.

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

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

Definition at line 100 of file DQMFileIterator.h.

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

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

Definition at line 111 of file DQMFileIterator.h.

Referenced by collect().

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

Definition at line 110 of file DQMFileIterator.h.

Referenced by collect().

State dqmservices::DQMFileIterator::state_
private

Definition at line 103 of file DQMFileIterator.h.

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

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

Definition at line 93 of file DQMFileIterator.h.

Referenced by collect(), and DQMFileIterator().