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)
 
const LumiEntryfront ()
 
void initialise (int run, const std::string &, const std::string &)
 
unsigned int lastLumiFound ()
 
void logFileAction (const std::string &msg, const std::string &fileName="") const
 
bool lumiReady ()
 
std::string make_path_data (const LumiEntry &lumi)
 
void pop ()
 
void reset ()
 
unsigned int runNumber ()
 
State state ()
 
void update_state ()
 
void updateWatchdog ()
 
 ~DQMFileIterator ()
 

Static Public Member Functions

static void fillDescription (edm::ParameterSetDescription &d)
 

Private Member Functions

void collect (bool ignoreTimers)
 

Private Attributes

unsigned int currentLumi_
 
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_
 
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 61 of file DQMFileIterator.cc.

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

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

Definition at line 76 of file DQMFileIterator.cc.

76 {}

Member Function Documentation

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

Definition at line 120 of file DQMFileIterator.cc.

References currentLumi_, getDQMSummary::iter, lastLumiLoad_, fjr2json::lumi, lumiSeen_, mon_, fileCollector::now, runNumber_, and cond::to_string().

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

120  {
121  using boost::property_tree::ptree;
122  using boost::str;
123 
124  unsigned int prev_lumi = currentLumi_;
125 
126  currentLumi_ = lumi;
128 
129  // report the successful lumi file open
130  if (mon_.isAvailable()) {
131  ptree children;
132 
133  auto iter = lumiSeen_.begin();
134  for (; iter != lumiSeen_.end(); ++iter) {
135  children.put(std::to_string(iter->first), iter->second.filename);
136  }
137 
138  mon_->registerExtra("lumiSeen", children);
139  mon_->reportLumiSection(runNumber_, prev_lumi);
140  }
141 }
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
std::chrono::high_resolution_clock::time_point lastLumiLoad_
void dqmservices::DQMFileIterator::collect ( bool  ignoreTimers)
private

Definition at line 151 of file DQMFileIterator.cc.

References prof2calltree::count, datafnPosition_, eor_, lut2db_cfg::filename, forceFileCheckTimeoutMillis_, diffTwoXMLs::label, dqmservices::DQMFileIterator::LumiEntry::load_json(), dqmservices::DQMFileIterator::EorEntry::loaded, logFileAction(), fjr2json::lumi, lumiSeen_, dqmservices::DQMFileIterator::EorEntry::n_lumi, fileCollector::now, query::result, DTTTrigCorrFirst::run, runNumber_, runPath_, runPathLastCollect_, runPathMTime_, streamLabel_, AlCaHLTBitMon_QueryRunRegistry::string, and edmStreamStallGrapher::t.

Referenced by reset(), and update_state().

151  {
152  // search filesystem to find available lumi section files
153  // or the end of run files
154 
156  auto last_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
158 
159  // don't refresh if it's too soon
160  if ((!ignoreTimers) && (last_ms < 100)) {
161  return;
162  }
163 
164  // check if directory changed
165  std::time_t t = boost::filesystem::last_write_time(runPath_);
166 
167  if ((!ignoreTimers) && (last_ms < forceFileCheckTimeoutMillis_) && (t == runPathMTime_)) {
168  //logFileAction("Directory hasn't changed.");
169  return;
170  } else {
171  //logFileAction("Directory changed, updating.");
172  }
173 
174  runPathMTime_ = t;
176 
177  using boost::filesystem::directory_iterator;
178  using boost::filesystem::directory_entry;
179 
180  std::string fn_eor;
181 
182  directory_iterator dend;
183  for (directory_iterator di(runPath_); di != dend; ++di) {
184  const boost::regex fn_re("run(\\d+)_ls(\\d+)(_.*).jsn");
185 
186  const std::string filename = di->path().filename().string();
187  const std::string fn = di->path().string();
188 
189  boost::smatch result;
190  if (boost::regex_match(filename, result, fn_re)) {
191  unsigned int run = std::stoi(result[1]);
192  unsigned int lumi = std::stoi(result[2]);
193  std::string label = result[3];
194 
195  if (run != runNumber_) continue;
196 
197  // check if this is EoR
198  // for various reasons we have to load it after all other files
199  if ((lumi == 0) && (label == "_EoR") && (!eor_.loaded)) {
200  fn_eor = fn;
201  continue;
202  }
203 
204  // check if lumi is loaded
205  if (lumiSeen_.find(lumi) != lumiSeen_.end()) {
206  continue; // already loaded
207  }
208 
209  // check if this belongs to us
210  if (label != streamLabel_) {
211  logFileAction("Found and skipped json file (stream label mismatch): ",
212  fn);
213  continue;
214  }
215 
216  LumiEntry lumi_jsn = LumiEntry::load_json(fn, lumi, datafnPosition_);
217  lumiSeen_.emplace(lumi, lumi_jsn);
218  logFileAction("Found and loaded json file: ", fn);
219  }
220  }
221 
222  if (!fn_eor.empty()) {
223  logFileAction("EoR file found: ", fn_eor);
224 
225  // @TODO load EoR files correctly
226  // eor_ = EorEntry::load_json(fn_eor);
227  // logFileAction("Loaded eor file: ", fn_eor);
228 
229  // for now , set n_lumi to the highest _found_ lumi
230  eor_.loaded = true;
231 
232  if (lumiSeen_.empty()) {
233  eor_.n_lumi = 0;
234  } else {
235  eor_.n_lumi = lumiSeen_.rbegin()->first;
236  }
237  }
238 }
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 309 of file DQMFileIterator.cc.

References delayMillis_, and updateWatchdog().

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

309  {
310  //logFileAction("Streamer waiting for the next LS.");
311 
312  updateWatchdog();
313  usleep(delayMillis_ * 1000);
314  updateWatchdog();
315 }
void dqmservices::DQMFileIterator::fillDescription ( edm::ParameterSetDescription d)
static

Definition at line 317 of file DQMFileIterator.cc.

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

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

317  {
318 
319  desc.addUntracked<unsigned int>("runNumber")
320  ->setComment("Run number passed via configuration file.");
321 
322  desc.addUntracked<unsigned int>("datafnPosition", 3)
323  ->setComment("Data filename position in the positional arguments array 'data' in json file.");
324 
325  desc.addUntracked<std::string>("streamLabel")
326  ->setComment("Stream label used in json discovery.");
327 
328  desc.addUntracked<uint32_t>("delayMillis")
329  ->setComment("Number of milliseconds to wait between file checks.");
330 
331  desc.addUntracked<int32_t>("nextLumiTimeoutMillis", -1)->setComment(
332  "Number of milliseconds to wait before switching to the next lumi "
333  "section if the current is missing, -1 to disable.");
334 
335  desc.addUntracked<std::string>("runInputDir")
336  ->setComment("Directory where the DQM files will appear.");
337 }
const DQMFileIterator::LumiEntry & dqmservices::DQMFileIterator::front ( )
void dqmservices::DQMFileIterator::initialise ( int  run,
const std::string &  ,
const std::string &   
)
unsigned int dqmservices::DQMFileIterator::lastLumiFound ( )

Definition at line 112 of file DQMFileIterator.cc.

References lumiSeen_.

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

112  {
113  if (!lumiSeen_.empty()) {
114  return lumiSeen_.rbegin()->first;
115  }
116 
117  return 1;
118 }
std::map< unsigned int, LumiEntry > lumiSeen_
void dqmservices::DQMFileIterator::logFileAction ( const std::string &  msg,
const std::string &  fileName = "" 
) const
bool dqmservices::DQMFileIterator::lumiReady ( )

Definition at line 102 of file DQMFileIterator.cc.

References currentLumi_, and lumiSeen_.

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

102  {
103  if (lumiSeen_.find(currentLumi_) != lumiSeen_.end()) {
104  return true;
105  }
106 
107  return false;
108 }
std::map< unsigned int, LumiEntry > lumiSeen_
std::string dqmservices::DQMFileIterator::make_path_data ( const LumiEntry lumi)

Definition at line 143 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_().

143  {
144  if (boost::starts_with(lumi.datafilename, "/")) return lumi.datafilename;
145 
147  p /= lumi.datafilename;
148  return p.string();
149 }
tuple lumi
Definition: fjr2json.py:35
tuple path
else: Piece not in the list, fine.
void dqmservices::DQMFileIterator::pop ( )
void dqmservices::DQMFileIterator::reset ( void  )

Definition at line 78 of file DQMFileIterator.cc.

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

Referenced by DQMFileIterator().

78  {
79  runPath_ = str(boost::format("%s/run%06d") % runInputDir_ % runNumber_);
80 
81  eor_.loaded = false;
82  state_ = State::OPEN;
83  currentLumi_ = 1;
84  lumiSeen_.clear();
85 
87 
88  collect(true);
89  update_state();
90 }
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 240 of file DQMFileIterator.cc.

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

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

240  {
241  using std::chrono::high_resolution_clock;
242  using std::chrono::duration_cast;
243  using std::chrono::milliseconds;
244 
245  collect(false);
246 
247  // now update the state
248  State old_state = state_;
249 
250  if ((state_ == State::OPEN) && (eor_.loaded)) {
251  state_ = State::EOR_CLOSING;
252  }
253 
254  // special case for missing lumi files
255  // skip to the next available, but after the timeout
256  if ((state_ != State::EOR) && (nextLumiTimeoutMillis_ >= 0)) {
257  auto iter = lumiSeen_.lower_bound(currentLumi_);
258  if ((iter != lumiSeen_.end()) && iter->first != currentLumi_) {
259 
260  auto elapsed = high_resolution_clock::now() - lastLumiLoad_;
261  auto elapsed_ms = duration_cast<milliseconds>(elapsed).count();
262 
263  if (elapsed_ms >= nextLumiTimeoutMillis_) {
264  std::string msg("Timeout reached, skipping lumisection(s) ");
265  msg += std::to_string(currentLumi_) + " .. " +
266  std::to_string(iter->first - 1);
267  msg += ", currentLumi_ is now " + std::to_string(iter->first);
268 
270 
271  currentLumi_ = iter->first;
272  }
273  }
274  }
275 
276  if (state_ == State::EOR_CLOSING) {
277  // check if we parsed all lumis
278  // n_lumi is both last lumi and the number of lumi
279  // since lumis are indexed from 1
280 
281  // after all lumi have been pop()'ed
282  // current lumi will become larger than the last lumi
283  if (currentLumi_ > eor_.n_lumi) {
284  state_ = State::EOR;
285  }
286  }
287 
288  if (state_ != old_state) {
289  logFileAction("Streamer state changed: ",
290  std::to_string(old_state) + "->" + std::to_string(state_));
291  }
292 }
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::updateWatchdog ( )

Definition at line 301 of file DQMFileIterator.cc.

References TablePrint::write, and x.

Referenced by delay(), and dqmservices::DQMStreamerReader::prepareNextEvent().

301  {
302  const char* x = getenv("WATCHDOG_FD");
303  if (x) {
304  int fd = atoi(x);
305  write(fd, ".\n", 2);
306  }
307 }
Definition: DDAxes.h:10

Member Data Documentation

unsigned int dqmservices::DQMFileIterator::currentLumi_
private

Definition at line 99 of file DQMFileIterator.h.

Referenced by advanceToLumi(), front(), lumiReady(), pop(), reset(), and update_state().

unsigned int dqmservices::DQMFileIterator::datafnPosition_
private

Definition at line 92 of file DQMFileIterator.h.

Referenced by collect(), and DQMFileIterator().

unsigned long dqmservices::DQMFileIterator::delayMillis_
private

Definition at line 87 of file DQMFileIterator.h.

Referenced by delay(), and DQMFileIterator().

EorEntry dqmservices::DQMFileIterator::eor_
private

Definition at line 96 of file DQMFileIterator.h.

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

long dqmservices::DQMFileIterator::forceFileCheckTimeoutMillis_
private

Definition at line 89 of file DQMFileIterator.h.

Referenced by collect(), and DQMFileIterator().

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

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

Referenced by advanceToLumi().

long dqmservices::DQMFileIterator::nextLumiTimeoutMillis_
private

Definition at line 88 of file DQMFileIterator.h.

Referenced by DQMFileIterator(), and update_state().

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

Definition at line 85 of file DQMFileIterator.h.

Referenced by DQMFileIterator(), and reset().

unsigned int dqmservices::DQMFileIterator::runNumber_
private

Definition at line 84 of file DQMFileIterator.h.

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

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

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

Referenced by collect().

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

Definition at line 104 of file DQMFileIterator.h.

Referenced by collect().

State dqmservices::DQMFileIterator::state_
private

Definition at line 97 of file DQMFileIterator.h.

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

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

Definition at line 86 of file DQMFileIterator.h.

Referenced by collect(), and DQMFileIterator().