CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EvFDaqDirector.cc
Go to the documentation of this file.
7 
11 
12 
13 #include <iostream>
14 #include <sstream>
15 #include <sys/time.h>
16 #include <unistd.h>
17 #include <stdio.h>
18 #include <sys/file.h>
19 
20 //#define DEBUG
21 
22 namespace evf {
23 
24  namespace {
25  struct flock make_flock(short type, short whence, off_t start, off_t len, pid_t pid)
26  {
27 #ifdef __APPLE__
28  return {start, len, pid, type, whence};
29 #else
30  return {type, whence, start, len, pid};
31 #endif
32  }
33  }
34 
36  edm::ActivityRegistry& reg) :
37  testModeNoBuilderUnit_(
38  pset.getUntrackedParameter<bool> ("testModeNoBuilderUnit",
39  false)
40  ),
41  base_dir_(
42  pset.getUntrackedParameter<std::string> ("baseDir", "/data")
43  ),
44  bu_base_dir_(
45  pset.getUntrackedParameter<std::string> ("buBaseDir", "/data")
46  ),
47  directorBu_(
48  pset.getUntrackedParameter<bool> ("directorIsBu", false)
49  ),
50  run_(pset.getUntrackedParameter<unsigned int> ("runNumber",0)),
51  hostname_(""),
52  bu_readlock_fd_(-1),
53  bu_writelock_fd_(-1),
54  fu_readwritelock_fd_(-1),
55  data_readwrite_fd_(-1),
56  fulocal_rwlock_fd_(-1),
57  fulocal_rwlock_fd2_(-1),
58 
59  bu_w_lock_stream(0),
60  bu_r_lock_stream(0),
61  fu_rw_lock_stream(0),
62  //bu_w_monitor_stream(0),
63  //bu_t_monitor_stream(0),
64  data_rw_stream(0),
65 
66  dirManager_(base_dir_),
67 
68  previousFileSize_(0),
69  jumpLS_(0),
70  jumpIndex_(0),
71 
72  bu_w_flk( make_flock( F_WRLCK, SEEK_SET, 0, 0, 0 )),
73  bu_r_flk( make_flock( F_RDLCK, SEEK_SET, 0, 0, 0 )),
74  bu_w_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, 0 )),
75  bu_r_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, 0 )),
76  fu_rw_flk( make_flock ( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
77  fu_rw_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() )),
78  data_rw_flk( make_flock ( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
79  data_rw_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() ))
80  //fulocal_rw_flk( make_flock( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
81  //fulocal_rw_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() )),
82  //fulocal_rw_flk2( make_flock( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
83  //fulocal_rw_fulk2( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() ))
84  {
85 
91 
92  std::stringstream ss;
93  ss << "run" << std::setfill('0') << std::setw(6) << run_;
94  run_string_ = ss.str();
96 
97  //save hostname for later
98  char hostname[33];
99  gethostname(hostname,32);
100  hostname_ = hostname;
101  // check if base dir exists or create it accordingly
102  int retval = mkdir(base_dir_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
103  if (retval != 0 && errno != EEXIST) {
104  throw cms::Exception("DaqDirector") << " Error checking for base dir -: "
105  << base_dir_ << " mkdir error:" << strerror(errno);
106  }
107 
108  //create run dir in base dir
109  umask(0);
110  retval = mkdir(run_dir_.c_str(),
111  S_IRWXU | S_IRWXG | S_IROTH | S_IRWXO | S_IXOTH);
112  if (retval != 0 && errno != EEXIST) {
113  throw cms::Exception("DaqDirector") << " Error creating run dir -: "
114  << run_dir_ << " mkdir error:" << strerror(errno);
115  }
116 
117  //create fu-local.lock in run open dir
118  if (!directorBu_) {
119 
121  std::string fulocal_lock_ = getRunOpenDirPath() +"/fu-local.lock";
122  fulocal_rwlock_fd_ = open(fulocal_lock_.c_str(), O_RDWR | O_CREAT, S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);//O_RDWR?
123  if (fulocal_rwlock_fd_==-1)
124  throw cms::Exception("DaqDirector") << " Error creating/opening a local lock file -: " << fulocal_lock_.c_str() << " : " << strerror(errno);
125  chmod(fulocal_lock_.c_str(),0777);
126  fsync(fulocal_rwlock_fd_);
127  //open second fd for another input source thread
128  fulocal_rwlock_fd2_ = open(fulocal_lock_.c_str(), O_RDWR, S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);//O_RDWR?
129  if (fulocal_rwlock_fd2_==-1)
130  throw cms::Exception("DaqDirector") << " Error opening a local lock file -: " << fulocal_lock_.c_str() << " : " << strerror(errno);
131  }
132 
133  //bu_run_dir: for FU, for which the base dir is local and the BU is remote, it is expected to be there
134  //for BU, it is created at this point
135  if (directorBu_)
136  {
138  std::string bulockfile = bu_run_dir_ + "/bu.lock";
139  std::string fulockfile = bu_run_dir_ + "/fu.lock";
140 
141  //make or find bu run dir
142  retval = mkdir(bu_run_dir_.c_str(),
143  S_IRWXU | S_IRWXG | S_IRWXO);
144  if (retval != 0 && errno != EEXIST) {
145  throw cms::Exception("DaqDirector")
146  << " Error creating bu run dir -: " << bu_run_dir_
147  << " mkdir error:" << strerror(errno) << "\n";
148  }
149  bu_run_open_dir_ = bu_run_dir_ + "/open";
150  retval = mkdir(bu_run_open_dir_.c_str(),
151  S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
152  if (retval != 0 && errno != EEXIST) {
153  throw cms::Exception("DaqDirector") << " Error creating bu run open dir -: "
154  << bu_run_open_dir_ << " mkdir error:" << strerror(errno)
155  << "\n";
156  }
157 
158  // the BU director does not need to know about the fu lock
159  bu_writelock_fd_ = open(bulockfile.c_str(),
160  O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
161  if (bu_writelock_fd_ == -1)
162  edm::LogWarning("EvFDaqDirector") << "problem with creating filedesc for buwritelock -: "
163  << strerror(errno);
164  else
165  edm::LogInfo("EvFDaqDirector") << "creating filedesc for buwritelock -: "
166  << bu_writelock_fd_;
167  bu_w_lock_stream = fdopen(bu_writelock_fd_, "w");
168  if (bu_w_lock_stream == 0)
169  edm::LogWarning("EvFDaqDirector")<< "Error creating write lock stream -: " << strerror(errno);
170 
171  // BU INITIALIZES LOCK FILE
172  // FU LOCK FILE OPEN
173  openFULockfileStream(fulockfile, true);
175  fflush(fu_rw_lock_stream);
176  close(fu_readwritelock_fd_);
177  }
178  else
179  {
180  // for FU, check if bu base dir exists
181 
182  retval = mkdir(bu_base_dir_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
183  if (retval != 0 && errno != EEXIST) {
184  throw cms::Exception("DaqDirector") << " Error checking for bu base dir -: "
185  << bu_base_dir_ << " mkdir error:" << strerror(errno) << "\n";
186  }
187 
189  std::string fulockfile = bu_run_dir_ + "/fu.lock";
190  openFULockfileStream(fulockfile, false);
191  }
192 
193  pthread_mutex_init(&init_lock_,NULL);
194 
195  }
196 
198  {
199  if (fulocal_rwlock_fd_!=-1) {
200  unlockFULocal();
201  close(fulocal_rwlock_fd_);
202  }
203 
204  if (fulocal_rwlock_fd2_!=-1) {
205  unlockFULocal2();
206  close(fulocal_rwlock_fd2_);
207  }
208 
209  }
210 
211  void EvFDaqDirector::postEndRun(edm::GlobalContext const& globalContext) {
212  close(bu_readlock_fd_);
213  close(bu_writelock_fd_);
214  if (directorBu_) {
215  std::string filename = base_dir_ + "/bu.lock";
216  removeFile(filename);
217  }
218  }
219 
221 
222  for (unsigned int i=0;i<bounds.maxNumberOfStreams();i++){
223  streamFileTracker_.push_back(-1);
224  }
225  nThreads_=bounds.maxNumberOfStreams();
226  nStreams_=bounds.maxNumberOfThreads();
227  }
228 
229  void EvFDaqDirector::preBeginRun(edm::GlobalContext const& globalContext) {
230 
231 // assert(run_ == id.run());
232 
233  // check if the requested run is the latest one - issue a warning if it isn't
235  edm::LogWarning("EvFDaqDirector") << "WARNING - checking run dir -: "
236  << run_dir_ << ". This is not the highest run "
238  }
239  }
240 
242  {
243  //delete all files belonging to just closed lumi
244  unsigned int ls = globalContext.luminosityBlockID().luminosityBlock();
246  edm::LogWarning("EvFDaqDirector") << " Handles to check for files to delete were not set by the input source...";
247  return;
248  }
249 
250  std::unique_lock<std::mutex> lkw(*fileDeleteLockPtr_);
251  auto it = filesToDeletePtr_->begin();
252  while (it!=filesToDeletePtr_->end()) {
253  if (it->second->lumi_ == ls) {
254  const boost::filesystem::path filePath(it->second->fileName_);
255  LogDebug("EvFDaqDirector") << "Deleting input file -:" << it->second->fileName_;
256  try {
257  //rarely this fails but file gets deleted
258  boost::filesystem::remove(filePath);
259  }
260  catch (const boost::filesystem::filesystem_error& ex)
261  {
262  edm::LogError("EvFDaqDirector") << " - deleteFile BOOST FILESYSTEM ERROR CAUGHT -: " << ex.what() << ". Trying again.";
263  usleep(10000);
264  try {
265  boost::filesystem::remove(filePath);
266  }
267  catch (...) {/*file gets deleted first time but exception is still thrown*/}
268  }
269  catch (std::exception& ex)
270  {
271  edm::LogError("EvFDaqDirector") << " - deleteFile std::exception CAUGHT -: " << ex.what() << ". Trying again.";
272  usleep(10000);
273  try {
274  boost::filesystem::remove(filePath);
275  } catch (...) {/*file gets deleted first time but exception is still thrown*/}
276  }
277 
278  delete it->second;
279  it = filesToDeletePtr_->erase(it);
280  }
281  else it++;
282  }
283  }
284 
285  inline void EvFDaqDirector::preSourceEvent(edm::StreamID const& streamID) {
287  }
288 
289 
290  std::string EvFDaqDirector::getInputJsonFilePath(const unsigned int ls, const unsigned int index) const {
291  return bu_run_dir_ + "/" + fffnaming::inputJsonFileName(run_,ls,index);
292  }
293 
294 
295  std::string EvFDaqDirector::getRawFilePath(const unsigned int ls, const unsigned int index) const {
296  return bu_run_dir_ + "/" + fffnaming::inputRawFileName(run_,ls,index);
297  }
298 
299  std::string EvFDaqDirector::getOpenRawFilePath(const unsigned int ls, const unsigned int index) const {
300  return bu_run_dir_ + "/open/" + fffnaming::inputRawFileName(run_,ls,index);
301  }
302 
303  std::string EvFDaqDirector::getOpenInputJsonFilePath(const unsigned int ls, const unsigned int index) const {
304  return bu_run_dir_ + "/open/" + fffnaming::inputJsonFileName(run_,ls,index);
305  }
306 
307 
309  return run_dir_ + "/open/" + fffnaming::streamerDataFileNameWithPid(run_,ls,stream);
310  }
311 
313  return run_dir_ + "/open/" + fffnaming::streamerJsonFileNameWithPid(run_,ls,stream);
314  }
315 
317  return run_dir_ + "/" + fffnaming::streamerJsonFileNameWithPid(run_,ls,stream);
318  }
319 
322  }
323 
325  return run_dir_ + "/" + fffnaming::initFileNameWithPid(run_,0,stream);
326  }
327 
329  return run_dir_ + "/open/" + fffnaming::protocolBufferHistogramFileNameWithPid(run_,ls,stream);
330  }
331 
334  }
335 
338  }
339 
341  return run_dir_ + "/open/" + fffnaming::rootHistogramFileNameWithPid(run_,ls,stream);
342  }
343 
345  return run_dir_ + "/" + fffnaming::rootHistogramFileNameWithPid(run_,ls,stream);
346  }
347 
350  }
351 
353  return bu_run_dir_ + "/" + fffnaming::eolsFileName(run_,ls);
354  }
355 
357  return run_dir_ + "/" + fffnaming::eolsFileName(run_,ls);
358  }
359 
361  return bu_run_dir_ + "/" + fffnaming::eorFileName(run_);
362  }
363 
364 
366  return run_dir_ + "/" + fffnaming::eorFileName(run_);
367  }
368 
370  int retval = remove(filename.c_str());
371  if (retval != 0)
372  edm::LogError("EvFDaqDirector") << "Could not remove used file -: " << filename << ". error = "
373  << strerror(errno);
374  }
375 
376  void EvFDaqDirector::removeFile(unsigned int ls, unsigned int index) {
377  removeFile(getRawFilePath(ls,index));
378  }
379 
380  EvFDaqDirector::FileStatus EvFDaqDirector::updateFuLock(unsigned int& ls, std::string& nextFile, uint32_t& fsize) {
381  EvFDaqDirector::FileStatus fileStatus = noFile;
382 
383  int retval = -1;
384  int lock_attempts = 0;
385 
386  while (retval==-1) {
387  retval = fcntl(fu_readwritelock_fd_, F_SETLK, &fu_rw_flk);
388  if (retval==-1) usleep(50000);
389  else continue;
390 
391  lock_attempts++;
392  if (lock_attempts>100 || errno==116) {
393  if (errno==116)
394  edm::LogWarning("EvFDaqDirector") << "Stale lock file handle. Checking if run directory and fu.lock file are present" << std::endl;
395  else
396  edm::LogWarning("EvFDaqDirector") << "Unable to obtain a lock for 5 seconds. Checking if run directory and fu.lock file are present -: errno "<< errno <<":"<< strerror(errno) << std::endl;
397 
398  struct stat buf;
399  if (stat(bu_run_dir_.c_str(), &buf)!=0) return runEnded;
400  if (stat((bu_run_dir_+"/fu.lock").c_str(), &buf)!=0) return runEnded;
401  lock_attempts=0;
402  }
403  }
404  if(retval!=0) return fileStatus;
405 
406 #ifdef DEBUG
407  timeval ts_lockend;
408  gettimeofday(&ts_lockend,0);
409 #endif
410 
411  // if the stream is readable
412  if (fu_rw_lock_stream != 0) {
413  unsigned int readLs, readIndex, jumpLs, jumpIndex;
414  int check = 0;
415  // rewind the stream
416  check = fseek(fu_rw_lock_stream, 0, SEEK_SET);
417  // if rewinded ok
418  if (check == 0) {
419  // read its' values
421  fscanf(fu_rw_lock_stream, "%u %u %u %u", &readLs, &readIndex,
422  &jumpLs, &jumpIndex);
423  else {
424  fscanf(fu_rw_lock_stream, "%u %u", &readLs, &readIndex);
425  edm::LogInfo("EvFDaqDirector") << "Read fu.lock file file -: " << readLs << ":" << readIndex;
426  }
427 
428  // try to bump
429  bool bumpedOk = bumpFile(readLs, readIndex, nextFile, fsize);
430  ls = readLs;
431  // there is a new file to grab or lumisection ended
432  if (bumpedOk) {
433  // rewind and clear
434  check = fseek(fu_rw_lock_stream, 0, SEEK_SET);
435  if (check == 0) {
436  ftruncate(fu_readwritelock_fd_, 0);
437  fflush(fu_rw_lock_stream); //this should not be needed ???
438  } else
439  edm::LogError("EvFDaqDirector") << "seek on fu read/write lock for updating failed with error "
440  << strerror(errno);
441  // write new data
442  check = fseek(fu_rw_lock_stream, 0, SEEK_SET);
443  if (check == 0) {
444  // write next index in the file, which is the file the next process should take
446  fprintf(fu_rw_lock_stream, "%u %u %u %u", readLs,
447  readIndex + 1, readLs + 2, readIndex + 1);
448  jumpLS_ = readLs + 2;
450  } else {
451  fprintf(fu_rw_lock_stream, "%u %u", readLs,
452  readIndex + 1);
453  }
454  fflush(fu_rw_lock_stream);
455  fsync(fu_readwritelock_fd_);
456 
457  fileStatus = newFile;
458 
460  edm::LogInfo("EvFDaqDirector") << "Written to file -: " << readLs << ":"
461  << readIndex + 1 << " --> " << readLs + 2
462  << ":" << readIndex + 1;
463  else
464  LogDebug("EvFDaqDirector") << "Written to file -: " << readLs << ":"
465  << readIndex + 1;
466 
467  } else
468  edm::LogError("EvFDaqDirector") << "seek on fu read/write lock for updating failed with error "
469  << strerror(errno);
470  }
471  } else
472  edm::LogError("EvFDaqDirector") << "seek on fu read/write lock for reading failed with error "
473  << strerror(errno);
474  } else
475  edm::LogError("EvFDaqDirector") << "fu read/write lock stream is invalid " << strerror(errno);
476 
477 #ifdef DEBUG
478  timeval ts_preunlock;
479  gettimeofday(&ts_preunlock,0);
480  int locked_period_int = ts_preunlock.tv_sec - ts_lockend.tv_sec;
481  double locked_period=locked_period_int+double(ts_preunlock.tv_usec - ts_lockend.tv_usec)/1000000;
482 #endif
483 
484  //if new json is present, lock file which FedRawDataInputSource will later unlock
485  if (fileStatus==newFile) lockFULocal();
486 
487  //release lock at this point
488  int retvalu=-1;
489  retvalu=fcntl(fu_readwritelock_fd_, F_SETLKW, &fu_rw_fulk);
490  if (retvalu==-1) edm::LogError("EvFDaqDirector") << "Error unlocking the fu.lock " << strerror(errno);
491 
492 #ifdef DEBUG
493  edm::LogDebug("EvFDaqDirector") << "Waited during lock -: " << locked_period << " seconds";
494 #endif
495 
496  if ( fileStatus == noFile ) {
497  struct stat buf;
498  //edm::LogInfo("EvFDaqDirector") << " looking for EoR file: " << getEoRFilePath().c_str();
499  if ( stat(getEoRFilePath().c_str(), &buf) == 0 || stat(bu_run_dir_.c_str(), &buf)!=0)
500  fileStatus = runEnded;
501  }
502  return fileStatus;
503  }
504 
505 
506  bool EvFDaqDirector::bumpFile(unsigned int& ls, unsigned int& index, std::string& nextFile, uint32_t& fsize) {
507 
508  if (previousFileSize_ != 0) {
509  if (!fms_) {
510  try {
512  } catch (...) {
513  edm::LogError("EvFDaqDirector") <<" FastMonitoringService not found";
514  }
515  }
517  previousFileSize_ = 0;
518  }
519 
520  struct stat buf;
521  std::stringstream ss;
522  unsigned int nextIndex = index;
523  nextIndex++;
524 
525  // 1. Check suggested file
526  nextFile = getInputJsonFilePath(ls,index);
527  if (stat(nextFile.c_str(), &buf) == 0) {
528 
529  previousFileSize_ = buf.st_size;
530  fsize = buf.st_size;
531  return true;
532  }
533  // 2. No file -> lumi ended? (and how many?)
534  else {
535  bool eolFound = (stat(getEoLSFilePathOnBU(ls).c_str(), &buf) == 0);
536  unsigned int startingLumi = ls;
537  while (eolFound) {
538 
539  // recheck that no raw file appeared in the meantime
540  if (stat(nextFile.c_str(), &buf) == 0) {
541  previousFileSize_ = buf.st_size;
542  fsize = buf.st_size;
543  return true;
544  }
545 
546  // this lumi ended, check for files
547  ++ls;
548  nextFile = getInputJsonFilePath(ls,0);
549  if (stat(nextFile.c_str(), &buf) == 0) {
550  // a new file was found at new lumisection, index 0
551  index = 0;
552  previousFileSize_ = buf.st_size;
553  fsize = buf.st_size;
554 
556  // rename ended lumi to + 2
557  std::string sourceEol = getEoLSFilePathOnBU(startingLumi);
558 
559  std::string destEol = getEoLSFilePathOnBU(startingLumi+2);
560 
561  std::string cpCmd = "cp " + sourceEol + " " + destEol;
562  edm::LogInfo("EvFDaqDirector") << " testmode: Running copy cmd -: " << cpCmd;
563  int rc = system(cpCmd.c_str());
564  if (rc != 0) {
565  edm::LogError("EvFDaqDirector") << " testmode: COPY EOL FAILED!!!!! -: " << cpCmd;
566  }
567  }
568 
569  return true;
570  }
571  eolFound = (stat(getEoLSFilePathOnBU(ls).c_str(), &buf) == 0);
572  }
573  }
574  // no new file found
575  return false;
576  }
577 
579  if (fu_rw_lock_stream == 0)
580  edm::LogError("EvFDaqDirector") << "Error creating fu read/write lock stream "
581  << strerror(errno);
582  else {
583  edm::LogInfo("EvFDaqDirector") << "Initializing FU LOCK FILE";
584  unsigned int readLs = 1, readIndex = 0, jumpLs = 3, jumpIndex = 0;
586  fprintf(fu_rw_lock_stream, "%u %u %u %u", readLs, readIndex,
587  jumpLs, jumpIndex);
588  else
589  fprintf(fu_rw_lock_stream, "%u %u", readLs, readIndex);
590  }
591  }
592 
594  if (create) {
595  fu_readwritelock_fd_ = open(fulockfile.c_str(), O_RDWR | O_CREAT,
596  S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
597  chmod(fulockfile.c_str(),0766);
598  } else {
599  fu_readwritelock_fd_ = open(fulockfile.c_str(), O_RDWR, S_IRWXU);
600  }
601  if (fu_readwritelock_fd_ == -1)
602  edm::LogError("EvFDaqDirector") << "problem with creating filedesc for fuwritelock -: " << fulockfile.c_str()
603  << " create:" << create << " error:" << strerror(errno);
604  else
605  LogDebug("EvFDaqDirector") << "creating filedesc for fureadwritelock -: "
607 
608  fu_rw_lock_stream = fdopen(fu_readwritelock_fd_, "r+");
609  }
610 
611  //create if does not exist then lock the merge destination file
613  data_rw_stream = fopen(getMergedDatFilePath(ls,stream).c_str(), "a"); //open stream for appending
615  if (data_readwrite_fd_ == -1)
616  edm::LogError("EvFDaqDirector") << "problem with creating filedesc for datamerge "
617  << strerror(errno);
618  else
619  LogDebug("EvFDaqDirector") << "creating filedesc for datamerge -: "
621  fcntl(data_readwrite_fd_, F_SETLKW, &data_rw_flk);
622 
623  return data_rw_stream;
624  }
625 
627  fflush(data_rw_stream);
628  fcntl(data_readwrite_fd_, F_SETLKW, &data_rw_fulk);
629  fclose(data_rw_stream);
630  }
631 
633  pthread_mutex_lock(&init_lock_);
634  }
635 
637  pthread_mutex_unlock(&init_lock_);
638  }
639 
641  //fcntl(fulocal_rwlock_fd_, F_SETLKW, &fulocal_rw_flk);
642  flock(fulocal_rwlock_fd_,LOCK_EX);
643  }
644 
646  //fcntl(fulocal_rwlock_fd_, F_SETLKW, &fulocal_rw_fulk);
647  flock(fulocal_rwlock_fd_,LOCK_UN);
648  }
649 
650 
652  //fcntl(fulocal_rwlock_fd2_, F_SETLKW, &fulocal_rw_flk2);
653  flock(fulocal_rwlock_fd2_,LOCK_EX);
654  }
655 
657  //fcntl(fulocal_rwlock_fd2_, F_SETLKW, &fulocal_rw_fulk2);
658  flock(fulocal_rwlock_fd2_,LOCK_UN);
659  }
660 
661 
663  // create open dir if not already there
664 
666  if (!boost::filesystem::is_directory(openPath)) {
667  LogDebug("EvFDaqDirector") << "<open> FU dir not found. Creating... -:" << openPath.string();
668  boost::filesystem::create_directories(openPath);
669  }
670  }
671 
672 }
#define LogDebug(id)
unsigned int nThreads_
type
Definition: HCALResponse.h:21
unsigned int maxNumberOfThreads() const
Definition: SystemBounds.h:46
int i
Definition: DBlmapReader.cc:9
struct flock fu_rw_flk
std::string run_string_
std::string protocolBufferHistogramFileNameWithInstance(const unsigned int run, const unsigned int ls, std::string const &stream, std::string const &instance)
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
std::string getMergedProtocolBufferHistogramFilePath(const unsigned int ls, std::string const &stream) const
void watchPreallocate(Preallocate::slot_type const &iSlot)
std::vector< int > streamFileTracker_
std::list< std::pair< int, InputFile * > > * filesToDeletePtr_
void openFULockfileStream(std::string &fuLockFilePath, bool create)
void accumulateFileSize(unsigned int lumi, unsigned long fileSize)
void watchPreGlobalEndLumi(PreGlobalEndLumi::slot_type const &iSlot)
std::string getInitFilePath(std::string const &stream) const
std::string getMergedRootHistogramFilePath(const unsigned int ls, std::string const &stream) const
std::string inputRawFileName(const unsigned int run, const unsigned int ls, const unsigned int index)
pthread_mutex_t init_lock_
LuminosityBlockID const & luminosityBlockID() const
Definition: GlobalContext.h:52
std::string getProtocolBufferHistogramFilePath(const unsigned int ls, std::string const &stream) const
std::string getRawFilePath(const unsigned int ls, const unsigned int index) const
std::string getOpenRawFilePath(const unsigned int ls, const unsigned int index) const
#define NULL
Definition: scimark2.h:8
struct flock data_rw_flk
std::string getEoLSFilePathOnBU(const unsigned int ls) const
std::string getEoRFilePath() const
unsigned long previousFileSize_
unsigned int jumpIndex_
FileStatus updateFuLock(unsigned int &ls, std::string &nextFile, uint32_t &fsize)
struct flock fu_rw_fulk
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:43
std::string getOpenProtocolBufferHistogramFilePath(const unsigned int ls, std::string const &stream) const
std::mutex * fileDeleteLockPtr_
std::string streamerDataFileNameWithInstance(const unsigned int run, const unsigned int ls, std::string const &stream, std::string const &instance)
tuple path
else: Piece not in the list, fine.
EvFDaqDirector(const edm::ParameterSet &pset, edm::ActivityRegistry &reg)
std::string getMergedDatFilePath(const unsigned int ls, std::string const &stream) const
std::string getOpenOutputJsonFilePath(const unsigned int ls, std::string const &stream) const
std::string getOpenRootHistogramFilePath(const unsigned int ls, std::string const &stream) const
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
std::string getRootHistogramFilePath(const unsigned int ls, std::string const &stream) const
std::string getOpenDatFilePath(const unsigned int ls, std::string const &stream) const
std::string inputJsonFileName(const unsigned int run, const unsigned int ls, const unsigned int index)
FILE * maybeCreateAndLockFileHeadForStream(unsigned int ls, std::string &stream)
std::string bu_base_dir_
void removeFile(unsigned int ls, unsigned int index)
std::string streamerJsonFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
std::string getOpenInputJsonFilePath(const unsigned int ls, const unsigned int index) const
std::string eorFileName(const unsigned int run)
void watchPreGlobalBeginRun(PreGlobalBeginRun::slot_type const &iSlot)
std::string getOutputJsonFilePath(const unsigned int ls, std::string const &stream) const
bool bumpFile(unsigned int &ls, unsigned int &index, std::string &nextFile, uint32_t &fsize)
void preBeginRun(edm::GlobalContext const &globalContext)
std::string rootHistogramFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
void preSourceEvent(edm::StreamID const &streamID)
std::string initFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
void preGlobalEndLumi(edm::GlobalContext const &globalContext)
tuple pid
Definition: sysUtil.py:22
void watchPostGlobalEndRun(PostGlobalEndRun::slot_type const &iSlot)
LuminosityBlockNumber_t luminosityBlock() const
evf::FastMonitoringService * fms_
std::string bu_run_dir_
std::string rootHistogramFileNameWithInstance(const unsigned int run, const unsigned int ls, std::string const &stream, std::string const &instance)
std::string findHighestRunDir()
Definition: DirManager.cc:20
void postEndRun(edm::GlobalContext const &globalContext)
tuple filename
Definition: lut2db_cfg.py:20
unsigned int jumpLS_
std::string getEoLSFilePathOnFU(const unsigned int ls) const
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
volatile std::atomic< bool > shutdown_flag false
void preallocate(edm::service::SystemBounds const &bounds)
struct flock data_rw_fulk
std::string getInputJsonFilePath(const unsigned int ls, const unsigned int index) const
std::string getRunOpenDirPath() const
std::string protocolBufferHistogramFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
SurfaceDeformation * create(int type, const std::vector< double > &params)
std::string eolsFileName(const unsigned int run, const unsigned int ls)
unsigned int nStreams_
std::string streamerDataFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
std::string getEoRFilePathOnFU() const
std::string bu_run_open_dir_