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  outputAdler32Recheck_(pset.getUntrackedParameter<bool>("outputAdler32Recheck",false)),
52  hostname_(""),
53  bu_readlock_fd_(-1),
54  bu_writelock_fd_(-1),
55  fu_readwritelock_fd_(-1),
56  data_readwrite_fd_(-1),
57  fulocal_rwlock_fd_(-1),
58  fulocal_rwlock_fd2_(-1),
59 
60  bu_w_lock_stream(0),
61  bu_r_lock_stream(0),
62  fu_rw_lock_stream(0),
63  //bu_w_monitor_stream(0),
64  //bu_t_monitor_stream(0),
65  data_rw_stream(0),
66 
67  dirManager_(base_dir_),
68 
69  previousFileSize_(0),
70  jumpLS_(0),
71  jumpIndex_(0),
72 
73  bu_w_flk( make_flock( F_WRLCK, SEEK_SET, 0, 0, 0 )),
74  bu_r_flk( make_flock( F_RDLCK, SEEK_SET, 0, 0, 0 )),
75  bu_w_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, 0 )),
76  bu_r_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, 0 )),
77  fu_rw_flk( make_flock ( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
78  fu_rw_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() )),
79  data_rw_flk( make_flock ( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
80  data_rw_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() ))
81  //fulocal_rw_flk( make_flock( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
82  //fulocal_rw_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() )),
83  //fulocal_rw_flk2( make_flock( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
84  //fulocal_rw_fulk2( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() ))
85  {
86 
92 
93  std::stringstream ss;
94  ss << "run" << std::setfill('0') << std::setw(6) << run_;
95  run_string_ = ss.str();
97 
98  //save hostname for later
99  char hostname[33];
100  gethostname(hostname,32);
101  hostname_ = hostname;
102  // check if base dir exists or create it accordingly
103  int retval = mkdir(base_dir_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
104  if (retval != 0 && errno != EEXIST) {
105  throw cms::Exception("DaqDirector") << " Error checking for base dir -: "
106  << base_dir_ << " mkdir error:" << strerror(errno);
107  }
108 
109  //create run dir in base dir
110  umask(0);
111  retval = mkdir(run_dir_.c_str(),
112  S_IRWXU | S_IRWXG | S_IROTH | S_IRWXO | S_IXOTH);
113  if (retval != 0 && errno != EEXIST) {
114  throw cms::Exception("DaqDirector") << " Error creating run dir -: "
115  << run_dir_ << " mkdir error:" << strerror(errno);
116  }
117 
118  //create fu-local.lock in run open dir
119  if (!directorBu_) {
120 
122  std::string fulocal_lock_ = getRunOpenDirPath() +"/fu-local.lock";
123  fulocal_rwlock_fd_ = open(fulocal_lock_.c_str(), O_RDWR | O_CREAT, S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);//O_RDWR?
124  if (fulocal_rwlock_fd_==-1)
125  throw cms::Exception("DaqDirector") << " Error creating/opening a local lock file -: " << fulocal_lock_.c_str() << " : " << strerror(errno);
126  chmod(fulocal_lock_.c_str(),0777);
127  fsync(fulocal_rwlock_fd_);
128  //open second fd for another input source thread
129  fulocal_rwlock_fd2_ = open(fulocal_lock_.c_str(), O_RDWR, S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);//O_RDWR?
130  if (fulocal_rwlock_fd2_==-1)
131  throw cms::Exception("DaqDirector") << " Error opening a local lock file -: " << fulocal_lock_.c_str() << " : " << strerror(errno);
132  }
133 
134  //bu_run_dir: for FU, for which the base dir is local and the BU is remote, it is expected to be there
135  //for BU, it is created at this point
136  if (directorBu_)
137  {
139  std::string bulockfile = bu_run_dir_ + "/bu.lock";
140  std::string fulockfile = bu_run_dir_ + "/fu.lock";
141 
142  //make or find bu run dir
143  retval = mkdir(bu_run_dir_.c_str(),
144  S_IRWXU | S_IRWXG | S_IRWXO);
145  if (retval != 0 && errno != EEXIST) {
146  throw cms::Exception("DaqDirector")
147  << " Error creating bu run dir -: " << bu_run_dir_
148  << " mkdir error:" << strerror(errno) << "\n";
149  }
150  bu_run_open_dir_ = bu_run_dir_ + "/open";
151  retval = mkdir(bu_run_open_dir_.c_str(),
152  S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
153  if (retval != 0 && errno != EEXIST) {
154  throw cms::Exception("DaqDirector") << " Error creating bu run open dir -: "
155  << bu_run_open_dir_ << " mkdir error:" << strerror(errno)
156  << "\n";
157  }
158 
159  // the BU director does not need to know about the fu lock
160  bu_writelock_fd_ = open(bulockfile.c_str(),
161  O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
162  if (bu_writelock_fd_ == -1)
163  edm::LogWarning("EvFDaqDirector") << "problem with creating filedesc for buwritelock -: "
164  << strerror(errno);
165  else
166  edm::LogInfo("EvFDaqDirector") << "creating filedesc for buwritelock -: "
167  << bu_writelock_fd_;
168  bu_w_lock_stream = fdopen(bu_writelock_fd_, "w");
169  if (bu_w_lock_stream == 0)
170  edm::LogWarning("EvFDaqDirector")<< "Error creating write lock stream -: " << strerror(errno);
171 
172  // BU INITIALIZES LOCK FILE
173  // FU LOCK FILE OPEN
174  openFULockfileStream(fulockfile, true);
176  fflush(fu_rw_lock_stream);
177  close(fu_readwritelock_fd_);
178  }
179  else
180  {
181  // for FU, check if bu base dir exists
182 
183  retval = mkdir(bu_base_dir_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
184  if (retval != 0 && errno != EEXIST) {
185  throw cms::Exception("DaqDirector") << " Error checking for bu base dir -: "
186  << bu_base_dir_ << " mkdir error:" << strerror(errno) << "\n";
187  }
188 
190  std::string fulockfile = bu_run_dir_ + "/fu.lock";
191  openFULockfileStream(fulockfile, false);
192  }
193 
194  pthread_mutex_init(&init_lock_,NULL);
195 
196  }
197 
199  {
200  if (fulocal_rwlock_fd_!=-1) {
201  unlockFULocal();
202  close(fulocal_rwlock_fd_);
203  }
204 
205  if (fulocal_rwlock_fd2_!=-1) {
206  unlockFULocal2();
207  close(fulocal_rwlock_fd2_);
208  }
209 
210  }
211 
212  void EvFDaqDirector::postEndRun(edm::GlobalContext const& globalContext) {
213  close(bu_readlock_fd_);
214  close(bu_writelock_fd_);
215  if (directorBu_) {
216  std::string filename = base_dir_ + "/bu.lock";
217  removeFile(filename);
218  }
219  }
220 
222 
223  for (unsigned int i=0;i<bounds.maxNumberOfStreams();i++){
224  streamFileTracker_.push_back(-1);
225  }
226  nThreads_=bounds.maxNumberOfStreams();
227  nStreams_=bounds.maxNumberOfThreads();
228  }
229 
230  void EvFDaqDirector::preBeginRun(edm::GlobalContext const& globalContext) {
231 
232 // assert(run_ == id.run());
233 
234  // check if the requested run is the latest one - issue a warning if it isn't
236  edm::LogWarning("EvFDaqDirector") << "WARNING - checking run dir -: "
237  << run_dir_ << ". This is not the highest run "
239  }
240  }
241 
243  {
244  //delete all files belonging to just closed lumi
245  unsigned int ls = globalContext.luminosityBlockID().luminosityBlock();
247  edm::LogWarning("EvFDaqDirector") << " Handles to check for files to delete were not set by the input source...";
248  return;
249  }
250 
251  std::unique_lock<std::mutex> lkw(*fileDeleteLockPtr_);
252  auto it = filesToDeletePtr_->begin();
253  while (it!=filesToDeletePtr_->end()) {
254  if (it->second->lumi_ == ls) {
255  const boost::filesystem::path filePath(it->second->fileName_);
256  LogDebug("EvFDaqDirector") << "Deleting input file -:" << it->second->fileName_;
257  try {
258  //rarely this fails but file gets deleted
259  boost::filesystem::remove(filePath);
260  }
261  catch (const boost::filesystem::filesystem_error& ex)
262  {
263  edm::LogError("EvFDaqDirector") << " - deleteFile BOOST FILESYSTEM ERROR CAUGHT -: " << ex.what() << ". Trying again.";
264  usleep(10000);
265  try {
266  boost::filesystem::remove(filePath);
267  }
268  catch (...) {/*file gets deleted first time but exception is still thrown*/}
269  }
270  catch (std::exception& ex)
271  {
272  edm::LogError("EvFDaqDirector") << " - deleteFile std::exception CAUGHT -: " << ex.what() << ". Trying again.";
273  usleep(10000);
274  try {
275  boost::filesystem::remove(filePath);
276  } catch (...) {/*file gets deleted first time but exception is still thrown*/}
277  }
278 
279  delete it->second;
280  it = filesToDeletePtr_->erase(it);
281  }
282  else it++;
283  }
284  }
285 
286  inline void EvFDaqDirector::preSourceEvent(edm::StreamID const& streamID) {
288  }
289 
290 
291  std::string EvFDaqDirector::getInputJsonFilePath(const unsigned int ls, const unsigned int index) const {
292  return bu_run_dir_ + "/" + fffnaming::inputJsonFileName(run_,ls,index);
293  }
294 
295 
296  std::string EvFDaqDirector::getRawFilePath(const unsigned int ls, const unsigned int index) const {
297  return bu_run_dir_ + "/" + fffnaming::inputRawFileName(run_,ls,index);
298  }
299 
300  std::string EvFDaqDirector::getOpenRawFilePath(const unsigned int ls, const unsigned int index) const {
301  return bu_run_dir_ + "/open/" + fffnaming::inputRawFileName(run_,ls,index);
302  }
303 
304  std::string EvFDaqDirector::getOpenInputJsonFilePath(const unsigned int ls, const unsigned int index) const {
305  return bu_run_dir_ + "/open/" + fffnaming::inputJsonFileName(run_,ls,index);
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 
326  }
327 
329  return run_dir_ + "/" + fffnaming::initFileNameWithPid(run_,0,stream);
330  }
331 
333  return run_dir_ + "/open/" + fffnaming::protocolBufferHistogramFileNameWithPid(run_,ls,stream);
334  }
335 
338  }
339 
342  }
343 
345  return run_dir_ + "/open/" + fffnaming::rootHistogramFileNameWithPid(run_,ls,stream);
346  }
347 
349  return run_dir_ + "/" + fffnaming::rootHistogramFileNameWithPid(run_,ls,stream);
350  }
351 
354  }
355 
357  return bu_run_dir_ + "/" + fffnaming::eolsFileName(run_,ls);
358  }
359 
361  return run_dir_ + "/" + fffnaming::eolsFileName(run_,ls);
362  }
363 
365  return bu_run_dir_ + "/" + fffnaming::eorFileName(run_);
366  }
367 
368 
370  return run_dir_ + "/" + fffnaming::eorFileName(run_);
371  }
372 
374  int retval = remove(filename.c_str());
375  if (retval != 0)
376  edm::LogError("EvFDaqDirector") << "Could not remove used file -: " << filename << ". error = "
377  << strerror(errno);
378  }
379 
380  void EvFDaqDirector::removeFile(unsigned int ls, unsigned int index) {
381  removeFile(getRawFilePath(ls,index));
382  }
383 
384  EvFDaqDirector::FileStatus EvFDaqDirector::updateFuLock(unsigned int& ls, std::string& nextFile, uint32_t& fsize) {
385  EvFDaqDirector::FileStatus fileStatus = noFile;
386 
387  int retval = -1;
388  int lock_attempts = 0;
389 
390  while (retval==-1) {
391  retval = fcntl(fu_readwritelock_fd_, F_SETLK, &fu_rw_flk);
392  if (retval==-1) usleep(50000);
393  else continue;
394 
395  lock_attempts++;
396  if (lock_attempts>100 || errno==116) {
397  if (errno==116)
398  edm::LogWarning("EvFDaqDirector") << "Stale lock file handle. Checking if run directory and fu.lock file are present" << std::endl;
399  else
400  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;
401 
402  struct stat buf;
403  if (stat(bu_run_dir_.c_str(), &buf)!=0) return runEnded;
404  if (stat((bu_run_dir_+"/fu.lock").c_str(), &buf)!=0) return runEnded;
405  lock_attempts=0;
406  }
407  }
408  if(retval!=0) return fileStatus;
409 
410 #ifdef DEBUG
411  timeval ts_lockend;
412  gettimeofday(&ts_lockend,0);
413 #endif
414 
415  // if the stream is readable
416  if (fu_rw_lock_stream != 0) {
417  unsigned int readLs, readIndex, jumpLs, jumpIndex;
418  int check = 0;
419  // rewind the stream
420  check = fseek(fu_rw_lock_stream, 0, SEEK_SET);
421  // if rewinded ok
422  if (check == 0) {
423  // read its' values
425  fscanf(fu_rw_lock_stream, "%u %u %u %u", &readLs, &readIndex,
426  &jumpLs, &jumpIndex);
427  else {
428  fscanf(fu_rw_lock_stream, "%u %u", &readLs, &readIndex);
429  edm::LogInfo("EvFDaqDirector") << "Read fu.lock file file -: " << readLs << ":" << readIndex;
430  }
431 
432  // try to bump
433  bool bumpedOk = bumpFile(readLs, readIndex, nextFile, fsize);
434  ls = readLs;
435  // there is a new file to grab or lumisection ended
436  if (bumpedOk) {
437  // rewind and clear
438  check = fseek(fu_rw_lock_stream, 0, SEEK_SET);
439  if (check == 0) {
440  ftruncate(fu_readwritelock_fd_, 0);
441  fflush(fu_rw_lock_stream); //this should not be needed ???
442  } else
443  edm::LogError("EvFDaqDirector") << "seek on fu read/write lock for updating failed with error "
444  << strerror(errno);
445  // write new data
446  check = fseek(fu_rw_lock_stream, 0, SEEK_SET);
447  if (check == 0) {
448  // write next index in the file, which is the file the next process should take
450  fprintf(fu_rw_lock_stream, "%u %u %u %u", readLs,
451  readIndex + 1, readLs + 2, readIndex + 1);
452  jumpLS_ = readLs + 2;
454  } else {
455  fprintf(fu_rw_lock_stream, "%u %u", readLs,
456  readIndex + 1);
457  }
458  fflush(fu_rw_lock_stream);
459  fsync(fu_readwritelock_fd_);
460 
461  fileStatus = newFile;
462 
464  edm::LogInfo("EvFDaqDirector") << "Written to file -: " << readLs << ":"
465  << readIndex + 1 << " --> " << readLs + 2
466  << ":" << readIndex + 1;
467  else
468  LogDebug("EvFDaqDirector") << "Written to file -: " << readLs << ":"
469  << readIndex + 1;
470 
471  } else
472  edm::LogError("EvFDaqDirector") << "seek on fu read/write lock for updating failed with error "
473  << strerror(errno);
474  }
475  } else
476  edm::LogError("EvFDaqDirector") << "seek on fu read/write lock for reading failed with error "
477  << strerror(errno);
478  } else
479  edm::LogError("EvFDaqDirector") << "fu read/write lock stream is invalid " << strerror(errno);
480 
481 #ifdef DEBUG
482  timeval ts_preunlock;
483  gettimeofday(&ts_preunlock,0);
484  int locked_period_int = ts_preunlock.tv_sec - ts_lockend.tv_sec;
485  double locked_period=locked_period_int+double(ts_preunlock.tv_usec - ts_lockend.tv_usec)/1000000;
486 #endif
487 
488  //if new json is present, lock file which FedRawDataInputSource will later unlock
489  if (fileStatus==newFile) lockFULocal();
490 
491  //release lock at this point
492  int retvalu=-1;
493  retvalu=fcntl(fu_readwritelock_fd_, F_SETLKW, &fu_rw_fulk);
494  if (retvalu==-1) edm::LogError("EvFDaqDirector") << "Error unlocking the fu.lock " << strerror(errno);
495 
496 #ifdef DEBUG
497  edm::LogDebug("EvFDaqDirector") << "Waited during lock -: " << locked_period << " seconds";
498 #endif
499 
500  if ( fileStatus == noFile ) {
501  struct stat buf;
502  //edm::LogInfo("EvFDaqDirector") << " looking for EoR file: " << getEoRFilePath().c_str();
503  if ( stat(getEoRFilePath().c_str(), &buf) == 0 || stat(bu_run_dir_.c_str(), &buf)!=0)
504  fileStatus = runEnded;
505  }
506  return fileStatus;
507  }
508 
509 
510  bool EvFDaqDirector::bumpFile(unsigned int& ls, unsigned int& index, std::string& nextFile, uint32_t& fsize) {
511 
512  if (previousFileSize_ != 0) {
513  if (!fms_) {
514  try {
516  } catch (...) {
517  edm::LogError("EvFDaqDirector") <<" FastMonitoringService not found";
518  }
519  }
521  previousFileSize_ = 0;
522  }
523 
524  struct stat buf;
525  std::stringstream ss;
526  unsigned int nextIndex = index;
527  nextIndex++;
528 
529  // 1. Check suggested file
530  nextFile = getInputJsonFilePath(ls,index);
531  if (stat(nextFile.c_str(), &buf) == 0) {
532 
533  previousFileSize_ = buf.st_size;
534  fsize = buf.st_size;
535  return true;
536  }
537  // 2. No file -> lumi ended? (and how many?)
538  else {
539  bool eolFound = (stat(getEoLSFilePathOnBU(ls).c_str(), &buf) == 0);
540  unsigned int startingLumi = ls;
541  while (eolFound) {
542 
543  // recheck that no raw file appeared in the meantime
544  if (stat(nextFile.c_str(), &buf) == 0) {
545  previousFileSize_ = buf.st_size;
546  fsize = buf.st_size;
547  return true;
548  }
549 
550  // this lumi ended, check for files
551  ++ls;
552  nextFile = getInputJsonFilePath(ls,0);
553  if (stat(nextFile.c_str(), &buf) == 0) {
554  // a new file was found at new lumisection, index 0
555  index = 0;
556  previousFileSize_ = buf.st_size;
557  fsize = buf.st_size;
558 
560  // rename ended lumi to + 2
561  std::string sourceEol = getEoLSFilePathOnBU(startingLumi);
562 
563  std::string destEol = getEoLSFilePathOnBU(startingLumi+2);
564 
565  std::string cpCmd = "cp " + sourceEol + " " + destEol;
566  edm::LogInfo("EvFDaqDirector") << " testmode: Running copy cmd -: " << cpCmd;
567  int rc = system(cpCmd.c_str());
568  if (rc != 0) {
569  edm::LogError("EvFDaqDirector") << " testmode: COPY EOL FAILED!!!!! -: " << cpCmd;
570  }
571  }
572 
573  return true;
574  }
575  eolFound = (stat(getEoLSFilePathOnBU(ls).c_str(), &buf) == 0);
576  }
577  }
578  // no new file found
579  return false;
580  }
581 
583  if (fu_rw_lock_stream == 0)
584  edm::LogError("EvFDaqDirector") << "Error creating fu read/write lock stream "
585  << strerror(errno);
586  else {
587  edm::LogInfo("EvFDaqDirector") << "Initializing FU LOCK FILE";
588  unsigned int readLs = 1, readIndex = 0, jumpLs = 3, jumpIndex = 0;
590  fprintf(fu_rw_lock_stream, "%u %u %u %u", readLs, readIndex,
591  jumpLs, jumpIndex);
592  else
593  fprintf(fu_rw_lock_stream, "%u %u", readLs, readIndex);
594  }
595  }
596 
598  if (create) {
599  fu_readwritelock_fd_ = open(fulockfile.c_str(), O_RDWR | O_CREAT,
600  S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
601  chmod(fulockfile.c_str(),0766);
602  } else {
603  fu_readwritelock_fd_ = open(fulockfile.c_str(), O_RDWR, S_IRWXU);
604  }
605  if (fu_readwritelock_fd_ == -1)
606  edm::LogError("EvFDaqDirector") << "problem with creating filedesc for fuwritelock -: " << fulockfile.c_str()
607  << " create:" << create << " error:" << strerror(errno);
608  else
609  LogDebug("EvFDaqDirector") << "creating filedesc for fureadwritelock -: "
611 
612  fu_rw_lock_stream = fdopen(fu_readwritelock_fd_, "r+");
613  }
614 
615  //create if does not exist then lock the merge destination file
617  data_rw_stream = fopen(getMergedDatFilePath(ls,stream).c_str(), "a"); //open stream for appending
619  if (data_readwrite_fd_ == -1)
620  edm::LogError("EvFDaqDirector") << "problem with creating filedesc for datamerge "
621  << strerror(errno);
622  else
623  LogDebug("EvFDaqDirector") << "creating filedesc for datamerge -: "
625  fcntl(data_readwrite_fd_, F_SETLKW, &data_rw_flk);
626 
627  return data_rw_stream;
628  }
629 
631  fflush(data_rw_stream);
632  fcntl(data_readwrite_fd_, F_SETLKW, &data_rw_fulk);
633  fclose(data_rw_stream);
634  }
635 
637  pthread_mutex_lock(&init_lock_);
638  }
639 
641  pthread_mutex_unlock(&init_lock_);
642  }
643 
645  //fcntl(fulocal_rwlock_fd_, F_SETLKW, &fulocal_rw_flk);
646  flock(fulocal_rwlock_fd_,LOCK_EX);
647  }
648 
650  //fcntl(fulocal_rwlock_fd_, F_SETLKW, &fulocal_rw_fulk);
651  flock(fulocal_rwlock_fd_,LOCK_UN);
652  }
653 
654 
656  //fcntl(fulocal_rwlock_fd2_, F_SETLKW, &fulocal_rw_flk2);
657  flock(fulocal_rwlock_fd2_,LOCK_EX);
658  }
659 
661  //fcntl(fulocal_rwlock_fd2_, F_SETLKW, &fulocal_rw_fulk2);
662  flock(fulocal_rwlock_fd2_,LOCK_UN);
663  }
664 
665 
667  // create open dir if not already there
668 
670  if (!boost::filesystem::is_directory(openPath)) {
671  LogDebug("EvFDaqDirector") << "<open> FU dir not found. Creating... -:" << openPath.string();
672  boost::filesystem::create_directories(openPath);
673  }
674  }
675 
676 }
#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 streamerDataChecksumFileNameWithInstance(const unsigned int run, const unsigned int ls, std::string const &stream, std::string const &instance)
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_
std::string getMergedDatChecksumFilePath(const unsigned int ls, std::string const &stream) const
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_