test
CMS 3D CMS Logo

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

#include <EvFDaqDirector.h>

Public Types

enum  FileStatus {
  noFile, sameFile, newFile, newLumi,
  runEnded, runAbort
}
 

Public Member Functions

std::string & baseRunDir ()
 
std::string & buBaseRunDir ()
 
std::string & buBaseRunOpenDir ()
 
void checkMergeTypePSet (edm::ProcessContext const &pc)
 
void checkTransferSystemPSet (edm::ProcessContext const &pc)
 
void createProcessingNotificationMaybe () const
 
void createRunOpendirMaybe ()
 
bool emptyLumisectionMode () const
 
 EvFDaqDirector (const edm::ParameterSet &pset, edm::ActivityRegistry &reg)
 
std::string findCurrentRunDir ()
 
std::string getBoLSFilePathOnFU (const unsigned int ls) const
 
std::string getDatFilePath (const unsigned int ls, std::string const &stream) const
 
std::string getEoLSFilePathOnBU (const unsigned int ls) const
 
std::string getEoLSFilePathOnFU (const unsigned int ls) const
 
std::string getEoRFilePath () const
 
std::string getEoRFilePathOnFU () const
 
std::string getInitFilePath (std::string const &stream) const
 
std::string getInputJsonFilePath (const unsigned int ls, const unsigned int index) const
 
std::string getMergedDatChecksumFilePath (const unsigned int ls, std::string const &stream) const
 
std::string getMergedDatFilePath (const unsigned int ls, std::string const &stream) const
 
std::string getMergedProtocolBufferHistogramFilePath (const unsigned int ls, std::string const &stream) const
 
std::string getMergedRootHistogramFilePath (const unsigned int ls, std::string const &stream) const
 
std::string getOpenDatFilePath (const unsigned int ls, std::string const &stream) const
 
std::string getOpenInitFilePath (std::string const &stream) const
 
std::string getOpenInputJsonFilePath (const unsigned int ls, const unsigned int index) const
 
std::string getOpenOutputJsonFilePath (const unsigned int ls, std::string const &stream) const
 
std::string getOpenProtocolBufferHistogramFilePath (const unsigned int ls, std::string const &stream) const
 
std::string getOpenRawFilePath (const unsigned int ls, const unsigned int index) const
 
std::string getOpenRootHistogramFilePath (const unsigned int ls, std::string const &stream) const
 
std::string getOutputJsonFilePath (const unsigned int ls, std::string const &stream) const
 
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 getRootHistogramFilePath (const unsigned int ls, std::string const &stream) const
 
unsigned int getRunNumber () const
 
std::string getRunOpenDirPath () const
 
std::string getStreamDestinations (std::string const &stream) const
 
std::vector< int > * getStreamFileTracker ()
 
std::string getStreamMergeType (std::string const &stream, MergeType defaultType)
 
void initRun ()
 
bool isSingleStreamThread ()
 
void lockFULocal ()
 
void lockFULocal2 ()
 
void lockInitLock ()
 
FILE * maybeCreateAndLockFileHeadForStream (unsigned int ls, std::string &stream)
 
bool microMergeDisabled () const
 
bool outputAdler32Recheck () const
 
void overrideRunNumber (unsigned int run)
 
void postEndRun (edm::GlobalContext const &globalContext)
 
void preallocate (edm::service::SystemBounds const &bounds)
 
void preBeginJob (edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &)
 
void preBeginRun (edm::GlobalContext const &globalContext)
 
void preGlobalEndLumi (edm::GlobalContext const &globalContext)
 
void preSourceEvent (edm::StreamID const &streamID)
 
int readLastLSEntry (std::string const &file)
 
void removeFile (unsigned int ls, unsigned int index)
 
void removeFile (std::string)
 
void setDeleteTracking (std::mutex *fileDeleteLock, std::list< std::pair< int, InputFile * >> *filesToDelete)
 
void setFMS (evf::FastMonitoringService *fms)
 
void tryInitializeFuLockFile ()
 
void unlockAndCloseMergeStream ()
 
void unlockFULocal ()
 
void unlockFULocal2 ()
 
void unlockInitLock ()
 
void updateFileIndex (int const &fileIndex)
 
FileStatus updateFuLock (unsigned int &ls, std::string &nextFile, uint32_t &fsize, uint64_t &lockWaitTime)
 
 ~EvFDaqDirector ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

bool bumpFile (unsigned int &ls, unsigned int &index, std::string &nextFile, uint32_t &fsize, int maxLS)
 
std::string eolsFileName (const unsigned int ls) const
 
std::string eorFileName () const
 
int getNFilesFromEoLS (std::string BUEoLSFile)
 
std::string initFileName (std::string const &stream) const
 
std::string inputFileNameStem (const unsigned int ls, const unsigned int index) const
 
std::string mergedFileNameStem (const unsigned int ls, std::string const &stream) const
 
void openFULockfileStream (std::string &fuLockFilePath, bool create)
 
std::string outputFileNameStem (const unsigned int ls, std::string const &stream) const
 

Private Attributes

std::string base_dir_
 
std::string bu_base_dir_
 
struct flock bu_r_flk
 
struct flock bu_r_fulk
 
FILE * bu_r_lock_stream
 
int bu_readlock_fd_
 
std::string bu_run_dir_
 
std::string bu_run_open_dir_
 
FILE * bu_t_monitor_stream
 
struct flock bu_w_flk
 
struct flock bu_w_fulk
 
FILE * bu_w_lock_stream
 
FILE * bu_w_monitor_stream
 
int bu_writelock_fd_
 
int currentFileIndex_ = -1
 
int data_readwrite_fd_
 
struct flock data_rw_flk
 
struct flock data_rw_fulk
 
FILE * data_rw_stream
 
bool directorBu_
 
DirManager dirManager_
 
bool emptyLumisectionMode_
 
unsigned int eolsNFilesIndex_ = 1
 
std::mutexfileDeleteLockPtr_ = nullptr
 
std::list< std::pair< int,
InputFile * > > * 
filesToDeletePtr_ = nullptr
 
evf::FastMonitoringServicefms_ = nullptr
 
int fu_readwritelock_fd_
 
struct flock fu_rw_flk
 
struct flock fu_rw_fulk
 
FILE * fu_rw_lock_stream
 
int fulocal_rwlock_fd2_
 
int fulocal_rwlock_fd_
 
unsigned int fuLockPollInterval_
 
std::string hltSourceDirectory_
 
std::string hostname_
 
pthread_mutex_t init_lock_ = PTHREAD_MUTEX_INITIALIZER
 
std::map< std::string,
std::string > 
mergeTypeMap_
 
std::string mergeTypePset_
 
bool microMergeDisabled_
 
unsigned int nStreams_ =0
 
unsigned int nThreads_ =0
 
bool outputAdler32Recheck_
 
unsigned long previousFileSize_
 
bool readEolsDefinition_ = true
 
bool requireTSPSet_
 
unsigned int run_
 
std::string run_dir_
 
std::string run_string_
 
std::string selectedTransferMode_
 
unsigned int stop_ls_override_ = 0
 
std::string stopFilePath_
 
std::string stopFilePathPid_
 
std::vector< int > streamFileTracker_
 
std::shared_ptr< Json::ValuetransferSystemJson_
 

Static Private Attributes

static const std::vector
< std::string > 
MergeTypeNames_ = {"","DAT","PB","JSNDATA"}
 

Detailed Description

Definition at line 54 of file EvFDaqDirector.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

evf::EvFDaqDirector::EvFDaqDirector ( const edm::ParameterSet pset,
edm::ActivityRegistry reg 
)
explicit

Definition at line 47 of file EvFDaqDirector.cc.

References emptyLumisectionMode_, fuLockPollInterval_, hostname_, microMergeDisabled_, postEndRun(), preallocate(), preBeginJob(), preBeginRun(), preGlobalEndLumi(), preSourceEvent(), AlCaHLTBitMon_QueryRunRegistry::string, edm::ActivityRegistry::watchPostGlobalEndRun(), edm::ActivityRegistry::watchPreallocate(), edm::ActivityRegistry::watchPreBeginJob(), edm::ActivityRegistry::watchPreGlobalBeginRun(), edm::ActivityRegistry::watchPreGlobalEndLumi(), and edm::ActivityRegistry::watchPreSourceEvent().

48  :
49  base_dir_(pset.getUntrackedParameter<std::string> ("baseDir", ".")),
50  bu_base_dir_(pset.getUntrackedParameter<std::string> ("buBaseDir", ".")),
51  directorBu_(pset.getUntrackedParameter<bool> ("directorIsBu", false)),
52  run_(pset.getUntrackedParameter<unsigned int> ("runNumber",0)),
53  outputAdler32Recheck_(pset.getUntrackedParameter<bool>("outputAdler32Recheck",false)),
54  requireTSPSet_(pset.getUntrackedParameter<bool>("requireTransfersPSet",false)),
55  selectedTransferMode_(pset.getUntrackedParameter<std::string>("selectedTransferMode","")),
56  hltSourceDirectory_(pset.getUntrackedParameter<std::string>("hltSourceDirectory","")),
57  fuLockPollInterval_(pset.getUntrackedParameter<unsigned int>("fuLockPollInterval",2000)),
58  emptyLumisectionMode_(pset.getUntrackedParameter<bool>("emptyLumisectionMode",true)),
59  microMergeDisabled_(pset.getUntrackedParameter<bool>("microMergeDisabled",true)),
60  mergeTypePset_(pset.getUntrackedParameter<std::string>("mergeTypePset","")),
61  hostname_(""),
62  bu_readlock_fd_(-1),
63  bu_writelock_fd_(-1),
68 
72  //bu_w_monitor_stream(0),
73  //bu_t_monitor_stream(0),
74  data_rw_stream(0),
75 
77 
79 
80  bu_w_flk( make_flock( F_WRLCK, SEEK_SET, 0, 0, 0 )),
81  bu_r_flk( make_flock( F_RDLCK, SEEK_SET, 0, 0, 0 )),
82  bu_w_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, 0 )),
83  bu_r_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, 0 )),
84  fu_rw_flk( make_flock ( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
85  fu_rw_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() )),
86  data_rw_flk( make_flock ( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
87  data_rw_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() ))
88  //fulocal_rw_flk( make_flock( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
89  //fulocal_rw_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() )),
90  //fulocal_rw_flk2( make_flock( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
91  //fulocal_rw_fulk2( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() ))
92  {
93 
100 
101  //save hostname for later
102  char hostname[33];
103  gethostname(hostname,32);
104  hostname_ = hostname;
105 
106  char * fuLockPollIntervalPtr = getenv("FFF_LOCKPOLLINTERVAL");
107  if (fuLockPollIntervalPtr) {
108  try {
109  fuLockPollInterval_=boost::lexical_cast<unsigned int>(std::string(fuLockPollIntervalPtr));
110  edm::LogInfo("EvFDaqDirector") << "Setting fu lock poll interval by environment string: " << fuLockPollInterval_ << " us";
111  }
112  catch( boost::bad_lexical_cast const& ) {
113  edm::LogWarning("EvFDaqDirector") << "Bad lexical cast in parsing: " << std::string(fuLockPollIntervalPtr);
114  }
115  }
116 
117  char * emptyLumiModePtr = getenv("FFF_EMPTYLSMODE");
118  if (emptyLumiModePtr) {
119  emptyLumisectionMode_ = true;
120  edm::LogInfo("EvFDaqDirector") << "Setting empty lumisection mode";
121  }
122 
123  char * microMergeDisabledPtr = getenv("FFF_MICROMERGEDISABLED");
124  if (microMergeDisabledPtr) {
125  microMergeDisabled_ = true;
126  edm::LogInfo("EvFDaqDirector") << "Disabling dat file micro-merge by the HLT process (delegated to the hlt daemon)";
127  }
128  }
struct flock bu_w_fulk
T getUntrackedParameter(std::string const &, T const &) const
struct flock fu_rw_flk
void watchPreallocate(Preallocate::slot_type const &iSlot)
void watchPreGlobalEndLumi(PreGlobalEndLumi::slot_type const &iSlot)
struct flock bu_r_fulk
struct flock data_rw_flk
unsigned long previousFileSize_
struct flock fu_rw_fulk
std::string hltSourceDirectory_
std::string mergeTypePset_
std::string bu_base_dir_
std::string selectedTransferMode_
void preBeginJob(edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &)
void watchPreGlobalBeginRun(PreGlobalBeginRun::slot_type const &iSlot)
struct flock bu_w_flk
void preBeginRun(edm::GlobalContext const &globalContext)
void preSourceEvent(edm::StreamID const &streamID)
void preGlobalEndLumi(edm::GlobalContext const &globalContext)
void watchPostGlobalEndRun(PostGlobalEndRun::slot_type const &iSlot)
void watchPreBeginJob(PreBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
void postEndRun(edm::GlobalContext const &globalContext)
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
void preallocate(edm::service::SystemBounds const &bounds)
struct flock data_rw_fulk
unsigned int fuLockPollInterval_
struct flock bu_r_flk
evf::EvFDaqDirector::~EvFDaqDirector ( )

Definition at line 260 of file EvFDaqDirector.cc.

References fulocal_rwlock_fd2_, fulocal_rwlock_fd_, unlockFULocal(), and unlockFULocal2().

261  {
262  if (fulocal_rwlock_fd_!=-1) {
263  unlockFULocal();
264  close(fulocal_rwlock_fd_);
265  }
266 
267  if (fulocal_rwlock_fd2_!=-1) {
268  unlockFULocal2();
269  close(fulocal_rwlock_fd2_);
270  }
271 
272  }

Member Function Documentation

std::string& evf::EvFDaqDirector::baseRunDir ( )
inline

Definition at line 72 of file EvFDaqDirector.h.

References run_dir_.

72 {return run_dir_;}
std::string& evf::EvFDaqDirector::buBaseRunDir ( )
inline

Definition at line 73 of file EvFDaqDirector.h.

References bu_run_dir_.

73 {return bu_run_dir_;}
std::string bu_run_dir_
std::string& evf::EvFDaqDirector::buBaseRunOpenDir ( )
inline

Definition at line 74 of file EvFDaqDirector.h.

References bu_run_open_dir_.

74 {return bu_run_open_dir_;}
std::string bu_run_open_dir_
bool evf::EvFDaqDirector::bumpFile ( unsigned int &  ls,
unsigned int &  index,
std::string &  nextFile,
uint32_t &  fsize,
int  maxLS 
)
private

Definition at line 726 of file EvFDaqDirector.cc.

References evf::FastMonitoringService::accumulateFileSize(), fms_, getEoLSFilePathOnBU(), getInputJsonFilePath(), getNFilesFromEoLS(), cmsHarvester::index, eostools::ls(), previousFileSize_, contentValuesCheck::ss, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by updateFuLock().

726  {
727 
728  if (previousFileSize_ != 0) {
729  if (!fms_) {
730  fms_ = (FastMonitoringService *) (edm::Service<evf::MicroStateService>().operator->());
731  }
733  previousFileSize_ = 0;
734  }
735 
736  //reached limit
737  if (maxLS>=0 && ls > (unsigned int)maxLS) return false;
738 
739  struct stat buf;
740  std::stringstream ss;
741  unsigned int nextIndex = index;
742  nextIndex++;
743 
744  // 1. Check suggested file
745  nextFile = getInputJsonFilePath(ls,index);
746  if (stat(nextFile.c_str(), &buf) == 0) {
747 
748  previousFileSize_ = buf.st_size;
749  fsize = buf.st_size;
750  return true;
751  }
752  // 2. No file -> lumi ended? (and how many?)
753  else {
754  std::string BUEoLSFile = getEoLSFilePathOnBU(ls);
755  bool eolFound = (stat(BUEoLSFile.c_str(), &buf) == 0);
756  while (eolFound) {
757 
758  // recheck that no raw file appeared in the meantime
759  if (stat(nextFile.c_str(), &buf) == 0) {
760  previousFileSize_ = buf.st_size;
761  fsize = buf.st_size;
762  return true;
763  }
764 
765  int indexFilesInLS = getNFilesFromEoLS(BUEoLSFile);
766  if (indexFilesInLS < 0)
767  //parsing failed
768  return false;
769  else {
770  //check index
771  if ((int)index<indexFilesInLS) {
772  //we have 2 files, and check for 1 failed... retry (2 will never be here)
773  edm::LogError("EvFDaqDirector") << "Potential miss of index file in LS -: " << ls << ". Missing "
774  << nextFile << " because " << indexFilesInLS-1 << " is the highest index expected. Will not update fu.lock file";
775  return false;
776  }
777  }
778  // this lumi ended, check for files
779  ++ls;
780  index = 0;
781 
782  //reached limit
783  if (maxLS>=0 && ls > (unsigned int)maxLS) return false;
784 
785  nextFile = getInputJsonFilePath(ls,0);
786  if (stat(nextFile.c_str(), &buf) == 0) {
787  // a new file was found at new lumisection, index 0
788  previousFileSize_ = buf.st_size;
789  fsize = buf.st_size;
790  return true;
791  }
792  else {
793  //change of policy: we need to cycle through each LS
794  return false;
795  }
796  BUEoLSFile = getEoLSFilePathOnBU(ls);
797  eolFound = (stat(BUEoLSFile.c_str(), &buf) == 0);
798  }
799  }
800  // no new file found
801  return false;
802  }
void accumulateFileSize(unsigned int lumi, unsigned long fileSize)
def ls
Definition: eostools.py:348
std::string getEoLSFilePathOnBU(const unsigned int ls) const
unsigned long previousFileSize_
int getNFilesFromEoLS(std::string BUEoLSFile)
evf::FastMonitoringService * fms_
std::string getInputJsonFilePath(const unsigned int ls, const unsigned int index) const
void evf::EvFDaqDirector::checkMergeTypePSet ( edm::ProcessContext const &  pc)

Definition at line 1015 of file EvFDaqDirector.cc.

References edm::ParameterSet::existsAs(), edm::ParameterSet::getParameterSet(), edm::getParameterSet(), mergeTypeMap_, mergeTypePset_, edm::ProcessContext::parameterSetID(), unpackData-CaloStage2::pname, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by preBeginJob().

1016  {
1017  if (mergeTypePset_.empty()) return;
1018  if(mergeTypeMap_.size()) return;
1019  edm::ParameterSet const& topPset = edm::getParameterSet(pc.parameterSetID());
1020  if (topPset.existsAs<edm::ParameterSet>(mergeTypePset_,true))
1021  {
1022  const edm::ParameterSet& tsPset(topPset.getParameterSet(mergeTypePset_));
1023  for (std::string pname : tsPset.getParameterNames()) {
1024  std::string streamType = tsPset.getParameter<std::string>(pname);
1025  mergeTypeMap_[pname]=streamType;
1026  }
1027  }
1028  }
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
ParameterSet const & getParameterSet(ParameterSetID const &id)
std::map< std::string, std::string > mergeTypeMap_
std::string mergeTypePset_
ParameterSet const & getParameterSet(std::string const &) const
void evf::EvFDaqDirector::checkTransferSystemPSet ( edm::ProcessContext const &  pc)

Definition at line 912 of file EvFDaqDirector.cc.

References Json::Value::append(), Json::arrayValue, alignCSCRings::dest, myMessageLogger_cff::destinations, Exception, edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterSet(), edm::getParameterSet(), universalConfigTemplate::mode, edm::ProcessContext::parameterSetID(), requireTSPSet_, and transferSystemJson_.

Referenced by preBeginJob().

913  {
914  if(transferSystemJson_) return;
915 
916  transferSystemJson_.reset(new Json::Value);
917  edm::ParameterSet const& topPset = edm::getParameterSet(pc.parameterSetID());
918  if (topPset.existsAs<edm::ParameterSet>("transferSystem",true))
919  {
920  const edm::ParameterSet& tsPset(topPset.getParameterSet("transferSystem"));
921 
922  Json::Value destinationsVal(Json::arrayValue);
923  std::vector<std::string> destinations = tsPset.getParameter<std::vector<std::string>>("destinations");
924  for (auto & dest: destinations) destinationsVal.append(dest);
925  (*transferSystemJson_)["destinations"]=destinationsVal;
926 
927  Json::Value modesVal(Json::arrayValue);
928  std::vector<std::string> modes = tsPset.getParameter< std::vector<std::string> >("transferModes");
929  for (auto & mode: modes) modesVal.append(mode);
930  (*transferSystemJson_)["transferModes"]=modesVal;
931 
932  for (auto psKeyItr =tsPset.psetTable().begin();psKeyItr!=tsPset.psetTable().end(); ++ psKeyItr) {
933  if (psKeyItr->first!="destinations" && psKeyItr->first!="transferModes") {
934  const edm::ParameterSet & streamDef = tsPset.getParameterSet(psKeyItr->first);
935  Json::Value streamVal;
936  for (auto & mode : modes) {
937  //validation
938  if (!streamDef.existsAs<std::vector<std::string>>(mode,true))
939  throw cms::Exception("EvFDaqDirector") << " Missing transfer system specification for -:" << psKeyItr->first << " (transferMode " << mode << ")";
940  std::vector<std::string> streamDestinations = streamDef.getParameter<std::vector<std::string>>(mode);
941 
942  Json::Value sDestsValue(Json::arrayValue);
943 
944  if (!streamDestinations.size())
945  throw cms::Exception("EvFDaqDirector") << " Missing transter system destination(s) for -: "<< psKeyItr->first << ", mode:" << mode;
946 
947  for (auto & sdest:streamDestinations) {
948  bool sDestValid=false;
949  sDestsValue.append(sdest);
950  for (auto & dest: destinations) {
951  if (dest==sdest) sDestValid=true;
952  }
953  if (!sDestValid)
954  throw cms::Exception("EvFDaqDirector") << " Invalid transter system destination specified for -: "<< psKeyItr->first << ", mode:" << mode << ", dest:"<<sdest;
955  }
956  streamVal[mode]=sDestsValue;
957  }
958  (*transferSystemJson_)[psKeyItr->first] = streamVal;
959  }
960  }
961  }
962  else {
963  if (requireTSPSet_)
964  throw cms::Exception("EvFDaqDirector") << "transferSystem PSet not found";
965  }
966  }
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
std::shared_ptr< Json::Value > transferSystemJson_
ParameterSet const & getParameterSet(ParameterSetID const &id)
Represents a JSON value.
Definition: value.h:111
ParameterSet const & getParameterSet(std::string const &) const
array value (ordered list)
Definition: value.h:31
void evf::EvFDaqDirector::createProcessingNotificationMaybe ( ) const

Definition at line 1043 of file EvFDaqDirector.cc.

References run_dir_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by FedRawDataInputSource::checkNextEvent().

1043  {
1044  std::string proc_flag = run_dir_ + "/processing";
1045  int proc_flag_fd = open(proc_flag.c_str(), O_RDWR | O_CREAT, S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
1046  close(proc_flag_fd);
1047  }
void evf::EvFDaqDirector::createRunOpendirMaybe ( )

Definition at line 884 of file EvFDaqDirector.cc.

References getRunOpenDirPath(), LogDebug, and fed_dqm_sourceclient-live_cfg::path.

Referenced by initRun().

884  {
885  // create open dir if not already there
886 
888  if (!boost::filesystem::is_directory(openPath)) {
889  LogDebug("EvFDaqDirector") << "<open> FU dir not found. Creating... -:" << openPath.string();
890  boost::filesystem::create_directories(openPath);
891  }
892  }
#define LogDebug(id)
std::string getRunOpenDirPath() const
bool evf::EvFDaqDirector::emptyLumisectionMode ( ) const
inline

Definition at line 131 of file EvFDaqDirector.h.

References emptyLumisectionMode_.

Referenced by FedRawDataInputSource::checkNextEvent().

131 {return emptyLumisectionMode_;}
std::string evf::EvFDaqDirector::eolsFileName ( const unsigned int  ls) const
private
std::string evf::EvFDaqDirector::eorFileName ( ) const
private
void evf::EvFDaqDirector::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 286 of file EvFDaqDirector.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::addUntracked(), edm::ParameterSetDescription::setAllowAnything(), edm::ParameterSetDescription::setComment(), and AlCaHLTBitMon_QueryRunRegistry::string.

287  {
289  desc.setComment("Service used for file locking arbitration and for propagating information between other EvF components");
290  desc.addUntracked<std::string> ("baseDir", ".")->setComment("Local base directory for run output");
291  desc.addUntracked<std::string> ("buBaseDir", ".")->setComment("BU base ramdisk directory ");
292  desc.addUntracked<unsigned int> ("runNumber",0)->setComment("Run Number in ramdisk to open");
293  desc.addUntracked<bool>("outputAdler32Recheck",false)->setComment("Check Adler32 of per-process output files while micro-merging");
294  desc.addUntracked<bool>("requireTransfersPSet",false)->setComment("Require complete transferSystem PSet in the process configuration");
295  desc.addUntracked<std::string>("selectedTransferMode","")->setComment("Selected transfer mode (choice in Lvl0 propagated as Python parameter");
296  desc.addUntracked<unsigned int>("fuLockPollInterval",2000)->setComment("Lock polling interval in microseconds for the input directory file lock");
297  desc.addUntracked<bool>("emptyLumisectionMode",true)->setComment("Enables writing stream output metadata even when no events are processed in a lumisection");
298  desc.addUntracked<bool>("microMergeDisabled",true)->setComment("Disabled micro-merging by the Output Module, so it is later done by hltd service");
299  desc.addUntracked<std::string>("mergingPset","")->setComment("Name of merging PSet to look for merging type definitions for streams");
300  desc.setAllowAnything();
301  descriptions.add("EvFDaqDirector", desc);
302  }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void setAllowAnything()
allow any parameter label/value pairs
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::string evf::EvFDaqDirector::findCurrentRunDir ( )
inline

Definition at line 76 of file EvFDaqDirector.h.

References dirManager_, evf::DirManager::findRunDir(), and run_.

76 { return dirManager_.findRunDir(run_);}
std::string findRunDir(unsigned int)
Definition: DirManager.cc:37
std::string evf::EvFDaqDirector::getBoLSFilePathOnFU ( const unsigned int  ls) const

Definition at line 461 of file EvFDaqDirector.cc.

References fffnaming::bolsFileName(), run_, and run_dir_.

Referenced by FedRawDataInputSource::createBoLSFile().

461  {
462  return run_dir_ + "/" + fffnaming::bolsFileName(run_,ls);
463  }
std::string bolsFileName(const unsigned int run, const unsigned int ls)
def ls
Definition: eostools.py:348
std::string evf::EvFDaqDirector::getDatFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 397 of file EvFDaqDirector.cc.

References run_, run_dir_, and fffnaming::streamerDataFileNameWithPid().

397  {
399  }
def ls
Definition: eostools.py:348
std::string streamerDataFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
std::string evf::EvFDaqDirector::getEoLSFilePathOnBU ( const unsigned int  ls) const

Definition at line 453 of file EvFDaqDirector.cc.

References bu_run_dir_, fffnaming::eolsFileName(), and run_.

Referenced by bumpFile(), and FedRawDataInputSource::checkNextEvent().

453  {
454  return bu_run_dir_ + "/" + fffnaming::eolsFileName(run_,ls);
455  }
def ls
Definition: eostools.py:348
std::string bu_run_dir_
std::string eolsFileName(const unsigned int run, const unsigned int ls)
std::string evf::EvFDaqDirector::getEoLSFilePathOnFU ( const unsigned int  ls) const

Definition at line 457 of file EvFDaqDirector.cc.

References fffnaming::eolsFileName(), run_, and run_dir_.

Referenced by FedRawDataInputSource::checkNextEvent(), FedRawDataInputSource::maybeOpenNewLumiSection(), and updateFuLock().

457  {
458  return run_dir_ + "/" + fffnaming::eolsFileName(run_,ls);
459  }
def ls
Definition: eostools.py:348
std::string eolsFileName(const unsigned int run, const unsigned int ls)
std::string evf::EvFDaqDirector::getEoRFilePath ( ) const

Definition at line 465 of file EvFDaqDirector.cc.

References bu_run_dir_, fffnaming::eorFileName(), and run_.

Referenced by updateFuLock().

465  {
466  return bu_run_dir_ + "/" + fffnaming::eorFileName(run_);
467  }
std::string eorFileName(const unsigned int run)
std::string bu_run_dir_
std::string evf::EvFDaqDirector::getEoRFilePathOnFU ( ) const

Definition at line 470 of file EvFDaqDirector.cc.

References fffnaming::eorFileName(), run_, and run_dir_.

Referenced by FedRawDataInputSource::checkNextEvent().

470  {
471  return run_dir_ + "/" + fffnaming::eorFileName(run_);
472  }
std::string eorFileName(const unsigned int run)
std::string evf::EvFDaqDirector::getInitFilePath ( std::string const &  stream) const

Definition at line 425 of file EvFDaqDirector.cc.

References fffnaming::initFileNameWithPid(), run_, and run_dir_.

Referenced by DQMFileSaver::globalBeginRun().

425  {
426  return run_dir_ + "/" + fffnaming::initFileNameWithPid(run_,0,stream);
427  }
std::string initFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
std::string evf::EvFDaqDirector::getInputJsonFilePath ( const unsigned int  ls,
const unsigned int  index 
) const

Definition at line 380 of file EvFDaqDirector.cc.

References bu_run_dir_, fffnaming::inputJsonFileName(), and run_.

Referenced by bumpFile().

380  {
382  }
def ls
Definition: eostools.py:348
std::string inputJsonFileName(const unsigned int run, const unsigned int ls, const unsigned int index)
std::string bu_run_dir_
std::string evf::EvFDaqDirector::getMergedDatChecksumFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 417 of file EvFDaqDirector.cc.

References hostname_, run_, run_dir_, and fffnaming::streamerDataChecksumFileNameWithInstance().

417  {
419  }
std::string streamerDataChecksumFileNameWithInstance(const unsigned int run, const unsigned int ls, std::string const &stream, std::string const &instance)
def ls
Definition: eostools.py:348
std::string evf::EvFDaqDirector::getMergedDatFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 413 of file EvFDaqDirector.cc.

References hostname_, run_, run_dir_, and fffnaming::streamerDataFileNameWithInstance().

Referenced by maybeCreateAndLockFileHeadForStream().

413  {
415  }
def ls
Definition: eostools.py:348
std::string streamerDataFileNameWithInstance(const unsigned int run, const unsigned int ls, std::string const &stream, std::string const &instance)
std::string evf::EvFDaqDirector::getMergedProtocolBufferHistogramFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 437 of file EvFDaqDirector.cc.

References hostname_, fffnaming::protocolBufferHistogramFileNameWithInstance(), run_, and run_dir_.

437  {
439  }
std::string protocolBufferHistogramFileNameWithInstance(const unsigned int run, const unsigned int ls, std::string const &stream, std::string const &instance)
def ls
Definition: eostools.py:348
std::string evf::EvFDaqDirector::getMergedRootHistogramFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 449 of file EvFDaqDirector.cc.

References hostname_, fffnaming::rootHistogramFileNameWithInstance(), run_, and run_dir_.

449  {
451  }
def ls
Definition: eostools.py:348
std::string rootHistogramFileNameWithInstance(const unsigned int run, const unsigned int ls, std::string const &stream, std::string const &instance)
int evf::EvFDaqDirector::getNFilesFromEoLS ( std::string  BUEoLSFile)
private

Definition at line 665 of file EvFDaqDirector.cc.

References bu_run_dir_, data, def, jsoncollector::DataPoint::deserialize(), reco::dp, eolsNFilesIndex_, jsoncollector::DataPoint::getData(), jsoncollector::DataPoint::getDefinition(), jsoncollector::DataPointDefinition::getNames(), i, Json::Reader::parse(), readEolsDefinition_, matplotRender::reader, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by bumpFile().

665  {
666 
667  boost::filesystem::ifstream ij(BUEoLSFile);
668  Json::Value deserializeRoot;
670 
671  if (!reader.parse(ij, deserializeRoot)) {
672  edm::LogError("EvFDaqDirector") << "Cannot deserialize input JSON file -:" << BUEoLSFile;
673  return -1;
674  }
675 
677  DataPoint dp;
678  dp.deserialize(deserializeRoot);
679 
680  //read definition
681  if (readEolsDefinition_) {
682  //std::string def = boost::algorithm::trim(dp.getDefinition());
684  if (!def.size()) readEolsDefinition_=false;
685  while (def.size()) {
686  std::string fullpath;
687  if (def.find('/')==0)
688  fullpath = def;
689  else
690  fullpath = bu_run_dir_+'/'+def;
691  struct stat buf;
692  if (stat(fullpath.c_str(), &buf) == 0) {
693  DataPointDefinition eolsDpd;
694  std::string defLabel = "legend";
695  DataPointDefinition::getDataPointDefinitionFor(fullpath, &eolsDpd,&defLabel);
696  if (eolsDpd.getNames().size()==0) {
697  //try with "data" label if "legend" format is not used
698  eolsDpd = DataPointDefinition();
699  defLabel="data";
700  DataPointDefinition::getDataPointDefinitionFor(fullpath, &eolsDpd,&defLabel);
701  }
702  for (unsigned int i=0;i<eolsDpd.getNames().size();i++)
703  if (eolsDpd.getNames().at(i)=="NFiles")
705  readEolsDefinition_=false;
706  break;
707  }
708  //check if we can still find definition
709  if (def.size()<=1 || def.find('/')==std::string::npos) {
710  readEolsDefinition_=false;
711  break;
712  }
713  def = def.substr(def.find('/')+1);
714  }
715  }
716 
717  if (dp.getData().size()>eolsNFilesIndex_)
718  data = dp.getData()[eolsNFilesIndex_];
719  else {
720  edm::LogError("EvFDaqDirector") << " error reading number of files from BU JSON -: " << BUEoLSFile;
721  return -1;
722  }
723  return boost::lexical_cast<int>(data);
724  }
std::vector< std::string > & getData()
Definition: DataPoint.h:58
int i
Definition: DBlmapReader.cc:9
bool parse(const std::string &document, Value &root, bool collectComments=true)
Read a Value from a JSON document.
Represents a JSON value.
Definition: value.h:111
virtual void deserialize(Json::Value &root)
Definition: DataPoint.cc:56
unsigned int eolsNFilesIndex_
auto dp
Definition: deltaR.h:22
std::string & getDefinition()
Definition: DataPoint.h:59
std::string bu_run_dir_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
Unserialize a JSON document into a Value.
Definition: reader.h:16
std::vector< std::string > const & getNames()
JetCorrectorParameters::Definitions def
Definition: classes.h:6
std::string evf::EvFDaqDirector::getOpenDatFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 401 of file EvFDaqDirector.cc.

References run_, run_dir_, and fffnaming::streamerDataFileNameWithPid().

401  {
402  return run_dir_ + "/open/" + fffnaming::streamerDataFileNameWithPid(run_,ls,stream);
403  }
def ls
Definition: eostools.py:348
std::string streamerDataFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
std::string evf::EvFDaqDirector::getOpenInitFilePath ( std::string const &  stream) const

Definition at line 421 of file EvFDaqDirector.cc.

References fffnaming::initFileNameWithPid(), run_, and run_dir_.

421  {
422  return run_dir_ + "/open/" + fffnaming::initFileNameWithPid(run_,0,stream);
423  }
std::string initFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
std::string evf::EvFDaqDirector::getOpenInputJsonFilePath ( const unsigned int  ls,
const unsigned int  index 
) const

Definition at line 393 of file EvFDaqDirector.cc.

References bu_run_dir_, fffnaming::inputJsonFileName(), and run_.

393  {
395  }
def ls
Definition: eostools.py:348
std::string inputJsonFileName(const unsigned int run, const unsigned int ls, const unsigned int index)
std::string bu_run_dir_
std::string evf::EvFDaqDirector::getOpenOutputJsonFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 405 of file EvFDaqDirector.cc.

References run_, run_dir_, and fffnaming::streamerJsonFileNameWithPid().

405  {
406  return run_dir_ + "/open/" + fffnaming::streamerJsonFileNameWithPid(run_,ls,stream);
407  }
def ls
Definition: eostools.py:348
std::string streamerJsonFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
std::string evf::EvFDaqDirector::getOpenProtocolBufferHistogramFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 429 of file EvFDaqDirector.cc.

References fffnaming::protocolBufferHistogramFileNameWithPid(), run_, and run_dir_.

429  {
431  }
def ls
Definition: eostools.py:348
std::string protocolBufferHistogramFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
std::string evf::EvFDaqDirector::getOpenRawFilePath ( const unsigned int  ls,
const unsigned int  index 
) const

Definition at line 389 of file EvFDaqDirector.cc.

References bu_run_dir_, fffnaming::inputRawFileName(), and run_.

389  {
390  return bu_run_dir_ + "/open/" + fffnaming::inputRawFileName(run_,ls,index);
391  }
std::string inputRawFileName(const unsigned int run, const unsigned int ls, const unsigned int index)
def ls
Definition: eostools.py:348
std::string bu_run_dir_
std::string evf::EvFDaqDirector::getOpenRootHistogramFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 441 of file EvFDaqDirector.cc.

References fffnaming::rootHistogramFileNameWithPid(), run_, and run_dir_.

441  {
442  return run_dir_ + "/open/" + fffnaming::rootHistogramFileNameWithPid(run_,ls,stream);
443  }
def ls
Definition: eostools.py:348
std::string rootHistogramFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
std::string evf::EvFDaqDirector::getOutputJsonFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 409 of file EvFDaqDirector.cc.

References run_, run_dir_, and fffnaming::streamerJsonFileNameWithPid().

409  {
411  }
def ls
Definition: eostools.py:348
std::string streamerJsonFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
std::string evf::EvFDaqDirector::getProtocolBufferHistogramFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 433 of file EvFDaqDirector.cc.

References fffnaming::protocolBufferHistogramFileNameWithPid(), run_, and run_dir_.

433  {
435  }
def ls
Definition: eostools.py:348
std::string protocolBufferHistogramFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
std::string evf::EvFDaqDirector::getRawFilePath ( const unsigned int  ls,
const unsigned int  index 
) const

Definition at line 385 of file EvFDaqDirector.cc.

References bu_run_dir_, fffnaming::inputRawFileName(), and run_.

Referenced by removeFile().

385  {
387  }
std::string inputRawFileName(const unsigned int run, const unsigned int ls, const unsigned int index)
def ls
Definition: eostools.py:348
std::string bu_run_dir_
std::string evf::EvFDaqDirector::getRootHistogramFilePath ( const unsigned int  ls,
std::string const &  stream 
) const

Definition at line 445 of file EvFDaqDirector.cc.

References fffnaming::rootHistogramFileNameWithPid(), run_, and run_dir_.

445  {
447  }
def ls
Definition: eostools.py:348
std::string rootHistogramFileNameWithPid(const unsigned int run, const unsigned int ls, std::string const &stream)
unsigned int evf::EvFDaqDirector::getRunNumber ( ) const
inline

Definition at line 107 of file EvFDaqDirector.h.

References run_.

107 { return run_; }
std::string evf::EvFDaqDirector::getRunOpenDirPath ( ) const
inline

Definition at line 100 of file EvFDaqDirector.h.

References run_dir_.

Referenced by createRunOpendirMaybe(), and initRun().

100 {return run_dir_ +"/open";}
std::string evf::EvFDaqDirector::getStreamDestinations ( std::string const &  stream) const

Definition at line 968 of file EvFDaqDirector.cc.

References Json::Value::begin(), Json::Value::end(), Exception, visualization-live-secondInstance_cfg::msg, requireTSPSet_, runTheMatrix::ret, selectedTransferMode_, AlCaHLTBitMon_QueryRunRegistry::string, and transferSystemJson_.

969  {
970  std::string streamRequestName;
971  if (transferSystemJson_->isMember(stream.c_str()))
972  streamRequestName = stream;
973  else {
974  std::stringstream msg;
975  msg << "Transfer system mode definitions missing for -: " << stream;
976  if (requireTSPSet_)
977  throw cms::Exception("EvFDaqDirector") << msg.str();
978  else {
979  edm::LogWarning("EvFDaqDirector") << msg.str() << " (permissive mode)";
980  return std::string("Failsafe");
981  }
982  }
983  //return empty if strict check parameter is not on
985  edm::LogWarning("EvFDaqDirector") << "Selected mode string is not provided as DaqDirector parameter."
986  << "Switch on requireTSPSet parameter to enforce this requirement. Setting mode to empty string.";
987  return std::string("Failsafe");
988  }
990  throw cms::Exception("EvFDaqDirector") << "Selected mode string is not provided as DaqDirector parameter.";
991  }
992  //check if stream has properly listed transfer stream
993  if (!transferSystemJson_->get(streamRequestName, "").isMember(selectedTransferMode_.c_str()))
994  {
995  std::stringstream msg;
996  msg << "Selected transfer mode " << selectedTransferMode_ << " is not specified for stream " << streamRequestName;
997  if (requireTSPSet_)
998  throw cms::Exception("EvFDaqDirector") << msg.str();
999  else
1000  edm::LogWarning("EvFDaqDirector") << msg.str() << " (permissive mode)";
1001  return std::string("Failsafe");
1002  }
1003  Json::Value destsVec = transferSystemJson_->get(streamRequestName, "").get(selectedTransferMode_,"");
1004 
1005  //flatten string json::Array into CSV std::string
1006  std::string ret;
1007  for (Json::Value::iterator it = destsVec.begin(); it!=destsVec.end(); it++)
1008  {
1009  if (ret!="") ret +=",";
1010  ret+=(*it).asString();
1011  }
1012  return ret;
1013  }
tuple ret
prodAgent to be discontinued
const_iterator begin() const
std::shared_ptr< Json::Value > transferSystemJson_
Represents a JSON value.
Definition: value.h:111
std::string selectedTransferMode_
const_iterator end() const
Iterator for object and array value.
Definition: value.h:1007
std::vector<int>* evf::EvFDaqDirector::getStreamFileTracker ( )
inline

Definition at line 114 of file EvFDaqDirector.h.

References streamFileTracker_.

Referenced by FedRawDataInputSource::getNextEvent().

114 {return &streamFileTracker_;}
std::vector< int > streamFileTracker_
std::string evf::EvFDaqDirector::getStreamMergeType ( std::string const &  stream,
MergeType  defaultType 
)

Definition at line 1030 of file EvFDaqDirector.cc.

References assert(), mergeTypeMap_, MergeTypeNames_, and AlCaHLTBitMon_QueryRunRegistry::string.

1031  {
1032  auto mergeTypeItr = mergeTypeMap_.find(stream.c_str());
1033  if (mergeTypeItr == mergeTypeMap_.end()) {
1034  edm::LogInfo("EvFDaqDirector") << " No merging type specified for stream " << stream << ". Using default value";
1035  assert(defaultType<MergeTypeNames_.size());
1036  std::string defaultName = MergeTypeNames_[defaultType];
1037  mergeTypeMap_[stream] = defaultName;
1038  return defaultName;
1039  }
1040  return mergeTypeItr->second;
1041  }
assert(m_qm.get())
std::map< std::string, std::string > mergeTypeMap_
static const std::vector< std::string > MergeTypeNames_
std::string evf::EvFDaqDirector::initFileName ( std::string const &  stream) const
private
void evf::EvFDaqDirector::initRun ( void  )

Definition at line 130 of file EvFDaqDirector.cc.

References base_dir_, bu_base_dir_, bu_run_dir_, bu_run_open_dir_, bu_w_lock_stream, bu_writelock_fd_, eostools::chmod(), createRunOpendirMaybe(), directorBu_, Exception, fu_readwritelock_fd_, fu_rw_lock_stream, fulocal_rwlock_fd2_, fulocal_rwlock_fd_, getRunOpenDirPath(), hltSourceDirectory_, init_lock_, eostools::mkdir(), NULL, openFULockfileStream(), run_, run_dir_, run_string_, contentValuesCheck::ss, stopFilePath_, stopFilePathPid_, AlCaHLTBitMon_QueryRunRegistry::string, and tryInitializeFuLockFile().

Referenced by preallocate().

131  {
132  std::stringstream ss;
133  ss << "run" << std::setfill('0') << std::setw(6) << run_;
134  run_string_ = ss.str();
136 
137  // check if base dir exists or create it accordingly
138  int retval = mkdir(base_dir_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
139  if (retval != 0 && errno != EEXIST) {
140  throw cms::Exception("DaqDirector") << " Error checking for base dir -: "
141  << base_dir_ << " mkdir error:" << strerror(errno);
142  }
143 
144  //create run dir in base dir
145  umask(0);
146  retval = mkdir(run_dir_.c_str(),
147  S_IRWXU | S_IRWXG | S_IROTH | S_IRWXO | S_IXOTH);
148  if (retval != 0 && errno != EEXIST) {
149  throw cms::Exception("DaqDirector") << " Error creating run dir -: "
150  << run_dir_ << " mkdir error:" << strerror(errno);
151  }
152 
153  //create fu-local.lock in run open dir
154  if (!directorBu_) {
155 
157  std::string fulocal_lock_ = getRunOpenDirPath() +"/fu-local.lock";
158  fulocal_rwlock_fd_ = open(fulocal_lock_.c_str(), O_RDWR | O_CREAT, S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);//O_RDWR?
159  if (fulocal_rwlock_fd_==-1)
160  throw cms::Exception("DaqDirector") << " Error creating/opening a local lock file -: " << fulocal_lock_.c_str() << " : " << strerror(errno);
161  chmod(fulocal_lock_.c_str(),0777);
162  fsync(fulocal_rwlock_fd_);
163  //open second fd for another input source thread
164  fulocal_rwlock_fd2_ = open(fulocal_lock_.c_str(), O_RDWR, S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);//O_RDWR?
165  if (fulocal_rwlock_fd2_==-1)
166  throw cms::Exception("DaqDirector") << " Error opening a local lock file -: " << fulocal_lock_.c_str() << " : " << strerror(errno);
167  }
168 
169  //bu_run_dir: for FU, for which the base dir is local and the BU is remote, it is expected to be there
170  //for BU, it is created at this point
171  if (directorBu_)
172  {
174  std::string bulockfile = bu_run_dir_ + "/bu.lock";
175  std::string fulockfile = bu_run_dir_ + "/fu.lock";
176 
177  //make or find bu run dir
178  retval = mkdir(bu_run_dir_.c_str(),
179  S_IRWXU | S_IRWXG | S_IRWXO);
180  if (retval != 0 && errno != EEXIST) {
181  throw cms::Exception("DaqDirector")
182  << " Error creating bu run dir -: " << bu_run_dir_
183  << " mkdir error:" << strerror(errno) << "\n";
184  }
185  bu_run_open_dir_ = bu_run_dir_ + "/open";
186  retval = mkdir(bu_run_open_dir_.c_str(),
187  S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
188  if (retval != 0 && errno != EEXIST) {
189  throw cms::Exception("DaqDirector") << " Error creating bu run open dir -: "
190  << bu_run_open_dir_ << " mkdir error:" << strerror(errno)
191  << "\n";
192  }
193 
194  // the BU director does not need to know about the fu lock
195  bu_writelock_fd_ = open(bulockfile.c_str(),
196  O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
197  if (bu_writelock_fd_ == -1)
198  edm::LogWarning("EvFDaqDirector") << "problem with creating filedesc for buwritelock -: "
199  << strerror(errno);
200  else
201  edm::LogInfo("EvFDaqDirector") << "creating filedesc for buwritelock -: "
202  << bu_writelock_fd_;
203  bu_w_lock_stream = fdopen(bu_writelock_fd_, "w");
204  if (bu_w_lock_stream == 0)
205  edm::LogWarning("EvFDaqDirector")<< "Error creating write lock stream -: " << strerror(errno);
206 
207  // BU INITIALIZES LOCK FILE
208  // FU LOCK FILE OPEN
209  openFULockfileStream(fulockfile, true);
211  fflush(fu_rw_lock_stream);
212  close(fu_readwritelock_fd_);
213 
214  if (hltSourceDirectory_.size())
215  {
216  struct stat buf;
217  if (stat(hltSourceDirectory_.c_str(),&buf)==0) {
218  std::string hltdir=bu_run_dir_+"/hlt";
219  std::string tmphltdir=bu_run_open_dir_+"/hlt";
220  retval = mkdir(tmphltdir.c_str(),S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
221  if (retval != 0 && errno != EEXIST)
222  throw cms::Exception("DaqDirector")
223  << " Error creating bu run dir -: " << hltdir
224  << " mkdir error:" << strerror(errno) << "\n";
225 
226  boost::filesystem::copy_file(hltSourceDirectory_+"/HltConfig.py",tmphltdir+"/HltConfig.py");
227 
228  boost::filesystem::copy_file(hltSourceDirectory_+"/fffParameters.jsn",tmphltdir+"/fffParameters.jsn");
229 
230  boost::filesystem::rename(tmphltdir,hltdir);
231  }
232  else
233  throw cms::Exception("DaqDirector") << " Error looking for HLT configuration -: " << hltSourceDirectory_;
234  }
235  //else{}//no configuration specified
236  }
237  else
238  {
239  // for FU, check if bu base dir exists
240 
241  retval = mkdir(bu_base_dir_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
242  if (retval != 0 && errno != EEXIST) {
243  throw cms::Exception("DaqDirector") << " Error checking for bu base dir -: "
244  << bu_base_dir_ << " mkdir error:" << strerror(errno) << "\n";
245  }
246 
248  std::string fulockfile = bu_run_dir_ + "/fu.lock";
249  openFULockfileStream(fulockfile, false);
250  }
251 
252  pthread_mutex_init(&init_lock_,NULL);
253 
254  stopFilePath_ = run_dir_+"/CMSSW_STOP";
255  std::stringstream sstp;
256  sstp << stopFilePath_ << "_pid" << getpid();
257  stopFilePathPid_ = sstp.str();
258  }
std::string run_string_
void openFULockfileStream(std::string &fuLockFilePath, bool create)
pthread_mutex_t init_lock_
#define NULL
Definition: scimark2.h:8
def chmod
Definition: eostools.py:293
std::string hltSourceDirectory_
std::string stopFilePath_
std::string bu_base_dir_
std::string stopFilePathPid_
std::string bu_run_dir_
def mkdir
Definition: eostools.py:250
std::string getRunOpenDirPath() const
std::string bu_run_open_dir_
std::string evf::EvFDaqDirector::inputFileNameStem ( const unsigned int  ls,
const unsigned int  index 
) const
private
bool evf::EvFDaqDirector::isSingleStreamThread ( )
inline

Definition at line 115 of file EvFDaqDirector.h.

References nStreams_, and nThreads_.

Referenced by FedRawDataInputSource::getNextEvent().

115 {return nStreams_==1 && nThreads_==1;}
unsigned int nThreads_
unsigned int nStreams_
void evf::EvFDaqDirector::lockFULocal ( )

Definition at line 862 of file EvFDaqDirector.cc.

References fulocal_rwlock_fd_.

Referenced by updateFuLock().

862  {
863  //fcntl(fulocal_rwlock_fd_, F_SETLKW, &fulocal_rw_flk);
864  flock(fulocal_rwlock_fd_,LOCK_SH);
865  }
void evf::EvFDaqDirector::lockFULocal2 ( )

Definition at line 873 of file EvFDaqDirector.cc.

References fulocal_rwlock_fd2_.

Referenced by FedRawDataInputSource::checkNextEvent(), and FedRawDataInputSource::maybeOpenNewLumiSection().

873  {
874  //fcntl(fulocal_rwlock_fd2_, F_SETLKW, &fulocal_rw_flk2);
875  flock(fulocal_rwlock_fd2_,LOCK_EX);
876  }
void evf::EvFDaqDirector::lockInitLock ( )

Definition at line 854 of file EvFDaqDirector.cc.

References init_lock_.

854  {
855  pthread_mutex_lock(&init_lock_);
856  }
pthread_mutex_t init_lock_
FILE * evf::EvFDaqDirector::maybeCreateAndLockFileHeadForStream ( unsigned int  ls,
std::string &  stream 
)

Definition at line 834 of file EvFDaqDirector.cc.

References data_readwrite_fd_, data_rw_flk, data_rw_stream, getMergedDatFilePath(), and LogDebug.

834  {
835  data_rw_stream = fopen(getMergedDatFilePath(ls,stream).c_str(), "a"); //open stream for appending
837  if (data_readwrite_fd_ == -1)
838  edm::LogError("EvFDaqDirector") << "problem with creating filedesc for datamerge "
839  << strerror(errno);
840  else
841  LogDebug("EvFDaqDirector") << "creating filedesc for datamerge -: "
843  fcntl(data_readwrite_fd_, F_SETLKW, &data_rw_flk);
844 
845  return data_rw_stream;
846  }
#define LogDebug(id)
def ls
Definition: eostools.py:348
struct flock data_rw_flk
std::string getMergedDatFilePath(const unsigned int ls, std::string const &stream) const
std::string evf::EvFDaqDirector::mergedFileNameStem ( const unsigned int  ls,
std::string const &  stream 
) const
private
bool evf::EvFDaqDirector::microMergeDisabled ( ) const
inline

Definition at line 132 of file EvFDaqDirector.h.

References microMergeDisabled_.

132 {return microMergeDisabled_;}
void evf::EvFDaqDirector::openFULockfileStream ( std::string &  fuLockFilePath,
bool  create 
)
private

Definition at line 815 of file EvFDaqDirector.cc.

References eostools::chmod(), fu_readwritelock_fd_, fu_rw_lock_stream, and LogDebug.

Referenced by initRun().

815  {
816  if (create) {
817  fu_readwritelock_fd_ = open(fulockfile.c_str(), O_RDWR | O_CREAT,
818  S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
819  chmod(fulockfile.c_str(),0766);
820  } else {
821  fu_readwritelock_fd_ = open(fulockfile.c_str(), O_RDWR, S_IRWXU);
822  }
823  if (fu_readwritelock_fd_ == -1)
824  edm::LogError("EvFDaqDirector") << "problem with creating filedesc for fuwritelock -: " << fulockfile.c_str()
825  << " create:" << create << " error:" << strerror(errno);
826  else
827  LogDebug("EvFDaqDirector") << "creating filedesc for fureadwritelock -: "
829 
830  fu_rw_lock_stream = fdopen(fu_readwritelock_fd_, "r+");
831  }
#define LogDebug(id)
def chmod
Definition: eostools.py:293
bool evf::EvFDaqDirector::outputAdler32Recheck ( ) const
inline

Definition at line 101 of file EvFDaqDirector.h.

References outputAdler32Recheck_.

101 {return outputAdler32Recheck_;}
std::string evf::EvFDaqDirector::outputFileNameStem ( const unsigned int  ls,
std::string const &  stream 
) const
private
void evf::EvFDaqDirector::overrideRunNumber ( unsigned int  run)
inline

Definition at line 71 of file EvFDaqDirector.h.

References DTTTrigCorrFirst::run, and run_.

void evf::EvFDaqDirector::postEndRun ( edm::GlobalContext const &  globalContext)

Definition at line 322 of file EvFDaqDirector.cc.

References bu_readlock_fd_, bu_run_dir_, bu_writelock_fd_, directorBu_, lut2db_cfg::filename, removeFile(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by EvFDaqDirector().

322  {
323  close(bu_readlock_fd_);
324  close(bu_writelock_fd_);
325  if (directorBu_) {
326  std::string filename = bu_run_dir_ + "/bu.lock";
327  removeFile(filename);
328  }
329  }
void removeFile(unsigned int ls, unsigned int index)
std::string bu_run_dir_
tuple filename
Definition: lut2db_cfg.py:20
void evf::EvFDaqDirector::preallocate ( edm::service::SystemBounds const &  bounds)

Definition at line 275 of file EvFDaqDirector.cc.

References i, initRun(), edm::service::SystemBounds::maxNumberOfStreams(), edm::service::SystemBounds::maxNumberOfThreads(), nStreams_, nThreads_, and streamFileTracker_.

Referenced by EvFDaqDirector().

275  {
276 
277  initRun();
278 
279  for (unsigned int i=0;i<bounds.maxNumberOfStreams();i++){
280  streamFileTracker_.push_back(-1);
281  }
282  nThreads_=bounds.maxNumberOfStreams();
283  nStreams_=bounds.maxNumberOfThreads();
284  }
unsigned int nThreads_
int i
Definition: DBlmapReader.cc:9
std::vector< int > streamFileTracker_
unsigned int nStreams_
void evf::EvFDaqDirector::preBeginJob ( edm::PathsAndConsumesOfModulesBase const &  ,
edm::ProcessContext const &  pc 
)

Definition at line 304 of file EvFDaqDirector.cc.

References checkMergeTypePSet(), and checkTransferSystemPSet().

Referenced by EvFDaqDirector().

305  {
307  checkMergeTypePSet(pc);
308  }
void checkMergeTypePSet(edm::ProcessContext const &pc)
void checkTransferSystemPSet(edm::ProcessContext const &pc)
void evf::EvFDaqDirector::preBeginRun ( edm::GlobalContext const &  globalContext)

Definition at line 310 of file EvFDaqDirector.cc.

References dirManager_, evf::DirManager::findHighestRunDir(), and run_dir_.

Referenced by EvFDaqDirector().

310  {
311 
312  //assert(run_ == id.run());
313 
314  // check if the requested run is the latest one - issue a warning if it isn't
316  edm::LogWarning("EvFDaqDirector") << "WARNING - checking run dir -: "
317  << run_dir_ << ". This is not the highest run "
319  }
320  }
std::string findHighestRunDir()
Definition: DirManager.cc:20
void evf::EvFDaqDirector::preGlobalEndLumi ( edm::GlobalContext const &  globalContext)

Definition at line 331 of file EvFDaqDirector.cc.

References cppFunctionSkipper::exception, fileDeleteLockPtr_, filesToDeletePtr_, LogDebug, eostools::ls(), edm::LuminosityBlockID::luminosityBlock(), edm::GlobalContext::luminosityBlockID(), fed_dqm_sourceclient-live_cfg::path, and MatrixUtil::remove().

Referenced by EvFDaqDirector().

332  {
333  //delete all files belonging to just closed lumi
334  unsigned int ls = globalContext.luminosityBlockID().luminosityBlock();
336  edm::LogWarning("EvFDaqDirector") << " Handles to check for files to delete were not set by the input source...";
337  return;
338  }
339 
340  std::unique_lock<std::mutex> lkw(*fileDeleteLockPtr_);
341  auto it = filesToDeletePtr_->begin();
342  while (it!=filesToDeletePtr_->end()) {
343  if (it->second->lumi_ == ls) {
344  const boost::filesystem::path filePath(it->second->fileName_);
345  LogDebug("EvFDaqDirector") << "Deleting input file -:" << it->second->fileName_;
346  try {
347  //rarely this fails but file gets deleted
348  boost::filesystem::remove(filePath);
349  }
350  catch (const boost::filesystem::filesystem_error& ex)
351  {
352  edm::LogError("EvFDaqDirector") << " - deleteFile BOOST FILESYSTEM ERROR CAUGHT -: " << ex.what() << ". Trying again.";
353  usleep(10000);
354  try {
355  boost::filesystem::remove(filePath);
356  }
357  catch (const boost::filesystem::filesystem_error&) {/*file gets deleted first time but exception is still thrown*/}
358  }
359  catch (std::exception& ex)
360  {
361  edm::LogError("EvFDaqDirector") << " - deleteFile std::exception CAUGHT -: " << ex.what() << ". Trying again.";
362  usleep(10000);
363  try {
364  boost::filesystem::remove(filePath);
365  } catch (std::exception&) {/*file gets deleted first time but exception is still thrown*/}
366  }
367 
368  delete it->second;
369  it = filesToDeletePtr_->erase(it);
370  }
371  else it++;
372  }
373  }
#define LogDebug(id)
std::list< std::pair< int, InputFile * > > * filesToDeletePtr_
def ls
Definition: eostools.py:348
std::mutex * fileDeleteLockPtr_
void evf::EvFDaqDirector::preSourceEvent ( edm::StreamID const &  streamID)
inline

Definition at line 375 of file EvFDaqDirector.cc.

References currentFileIndex_, and streamFileTracker_.

Referenced by EvFDaqDirector().

375  {
377  }
std::vector< int > streamFileTracker_
int evf::EvFDaqDirector::readLastLSEntry ( std::string const &  file)

Definition at line 895 of file EvFDaqDirector.cc.

References Json::Value::asInt(), mergeVDriftHistosByStation::file, Json::Value::get(), Json::Reader::parse(), matplotRender::reader, and runTheMatrix::ret.

Referenced by updateFuLock().

895  {
896 
897  boost::filesystem::ifstream ij(file);
898  Json::Value deserializeRoot;
900 
901  if (!reader.parse(ij, deserializeRoot)) {
902  edm::LogError("EvFDaqDirector") << "Cannot deserialize input JSON file -:" << file;
903  return -1;
904  }
905 
906  int ret = deserializeRoot.get("lastLS","").asInt();
907  return ret;
908 
909  }
Value get(UInt index, const Value &defaultValue) const
tuple ret
prodAgent to be discontinued
bool parse(const std::string &document, Value &root, bool collectComments=true)
Read a Value from a JSON document.
Represents a JSON value.
Definition: value.h:111
Int asInt() const
Unserialize a JSON document into a Value.
Definition: reader.h:16
void evf::EvFDaqDirector::removeFile ( unsigned int  ls,
unsigned int  index 
)

Definition at line 481 of file EvFDaqDirector.cc.

References getRawFilePath().

Referenced by postEndRun().

481  {
483  }
def ls
Definition: eostools.py:348
std::string getRawFilePath(const unsigned int ls, const unsigned int index) const
void removeFile(unsigned int ls, unsigned int index)
void evf::EvFDaqDirector::removeFile ( std::string  filename)

Definition at line 474 of file EvFDaqDirector.cc.

474  {
475  int retval = remove(filename.c_str());
476  if (retval != 0)
477  edm::LogError("EvFDaqDirector") << "Could not remove used file -: " << filename << ". error = "
478  << strerror(errno);
479  }
tuple filename
Definition: lut2db_cfg.py:20
void evf::EvFDaqDirector::setDeleteTracking ( std::mutex fileDeleteLock,
std::list< std::pair< int, InputFile * >> *  filesToDelete 
)
inline

Definition at line 123 of file EvFDaqDirector.h.

References fileDeleteLockPtr_, and filesToDeletePtr_.

Referenced by FedRawDataInputSource::FedRawDataInputSource().

123  {
124  fileDeleteLockPtr_=fileDeleteLock;
125  filesToDeletePtr_ = filesToDelete;
126  }
std::list< std::pair< int, InputFile * > > * filesToDeletePtr_
std::mutex * fileDeleteLockPtr_
void evf::EvFDaqDirector::setFMS ( evf::FastMonitoringService fms)
inline

Definition at line 112 of file EvFDaqDirector.h.

References fms_.

Referenced by FedRawDataInputSource::FedRawDataInputSource().

112 {fms_=fms;}
evf::FastMonitoringService * fms_
void evf::EvFDaqDirector::tryInitializeFuLockFile ( )

Definition at line 804 of file EvFDaqDirector.cc.

References fu_rw_lock_stream, and getHLTprescales::readIndex().

Referenced by initRun().

804  {
805  if (fu_rw_lock_stream == 0)
806  edm::LogError("EvFDaqDirector") << "Error creating fu read/write lock stream "
807  << strerror(errno);
808  else {
809  edm::LogInfo("EvFDaqDirector") << "Initializing FU LOCK FILE";
810  unsigned int readLs = 1, readIndex = 0;
811  fprintf(fu_rw_lock_stream, "%u %u", readLs, readIndex);
812  }
813  }
void evf::EvFDaqDirector::unlockAndCloseMergeStream ( )

Definition at line 848 of file EvFDaqDirector.cc.

References data_readwrite_fd_, data_rw_fulk, and data_rw_stream.

848  {
849  fflush(data_rw_stream);
850  fcntl(data_readwrite_fd_, F_SETLKW, &data_rw_fulk);
851  fclose(data_rw_stream);
852  }
struct flock data_rw_fulk
void evf::EvFDaqDirector::unlockFULocal ( )

Definition at line 867 of file EvFDaqDirector.cc.

References fulocal_rwlock_fd_.

Referenced by FedRawDataInputSource::grabNextJsonFile(), and ~EvFDaqDirector().

867  {
868  //fcntl(fulocal_rwlock_fd_, F_SETLKW, &fulocal_rw_fulk);
869  flock(fulocal_rwlock_fd_,LOCK_UN);
870  }
void evf::EvFDaqDirector::unlockFULocal2 ( )

Definition at line 878 of file EvFDaqDirector.cc.

References fulocal_rwlock_fd2_.

Referenced by FedRawDataInputSource::checkNextEvent(), FedRawDataInputSource::maybeOpenNewLumiSection(), and ~EvFDaqDirector().

878  {
879  //fcntl(fulocal_rwlock_fd2_, F_SETLKW, &fulocal_rw_fulk2);
880  flock(fulocal_rwlock_fd2_,LOCK_UN);
881  }
void evf::EvFDaqDirector::unlockInitLock ( )

Definition at line 858 of file EvFDaqDirector.cc.

References init_lock_.

858  {
859  pthread_mutex_unlock(&init_lock_);
860  }
pthread_mutex_t init_lock_
void evf::EvFDaqDirector::updateFileIndex ( int const &  fileIndex)
inline

Definition at line 113 of file EvFDaqDirector.h.

References currentFileIndex_.

Referenced by FedRawDataInputSource::getNextEvent().

113 {currentFileIndex_=fileIndex;}
EvFDaqDirector::FileStatus evf::EvFDaqDirector::updateFuLock ( unsigned int &  ls,
std::string &  nextFile,
uint32_t &  fsize,
uint64_t &  lockWaitTime 
)

Definition at line 485 of file EvFDaqDirector.cc.

References bu_run_dir_, bumpFile(), trackerTree::check(), Exception, fu_readwritelock_fd_, fu_rw_flk, fu_rw_fulk, fu_rw_lock_stream, fuLockPollInterval_, getEoLSFilePathOnFU(), getEoRFilePath(), lockFULocal(), LogDebug, eostools::ls(), newFile, noFile, getHLTprescales::readIndex(), readLastLSEntry(), runEnded, stop_ls_override_, stopFilePath_, and stopFilePathPid_.

Referenced by FedRawDataInputSource::readSupervisor().

485  {
486  EvFDaqDirector::FileStatus fileStatus = noFile;
487 
488  int retval = -1;
489  int lock_attempts = 0;
490 
491  struct stat buf;
492  int stopFileLS = -1;
493  int stopFileCheck = stat(stopFilePath_.c_str(),&buf);
494  int stopFilePidCheck = stat(stopFilePathPid_.c_str(),&buf);
495  if (stopFileCheck==0 || stopFilePidCheck==0) {
496  if (stopFileCheck==0)
497  stopFileLS = readLastLSEntry(stopFilePath_);
498  else
499  stopFileLS = 1;//stop without drain if only pid is stopped
500  if (!stop_ls_override_) {
501  //if lumisection is higher than in stop file, should quit at next from current
502  if (stopFileLS>=0 && (int)ls>=stopFileLS) stopFileLS = stop_ls_override_ = ls;
503  }
504  else stopFileLS = stop_ls_override_;
505  edm::LogWarning("EvFDaqDirector") << "Detected stop request from hltd. Ending run for this process after LS -: " << stopFileLS;
506  //return runEnded;
507  }
508  else //if file was removed before reaching stop condition, reset this
509  stop_ls_override_ = 0;
510 
511  timeval ts_lockbegin;
512  gettimeofday(&ts_lockbegin,0);
513 
514  while (retval==-1) {
515  retval = fcntl(fu_readwritelock_fd_, F_SETLK, &fu_rw_flk);
516  if (retval==-1) usleep(fuLockPollInterval_);
517  else continue;
518 
519  lock_attempts+=fuLockPollInterval_;
520  if (lock_attempts>5000000 || errno==116) {
521  if (errno==116)
522  edm::LogWarning("EvFDaqDirector") << "Stale lock file handle. Checking if run directory and fu.lock file are present" << std::endl;
523  else
524  edm::LogWarning("EvFDaqDirector") << "Unable to obtain a lock for 5 seconds. Checking if run directory and fu.lock file are present -: errno "
525  << errno <<":"<< strerror(errno) << std::endl;
526 
527 
528  if (stat(getEoLSFilePathOnFU(ls).c_str(),&buf)==0) {
529  edm::LogWarning("EvFDaqDirector") << "Detected local EoLS for lumisection "<< ls ;
530  ls++;
531  return noFile;
532  }
533 
534  if (stat(bu_run_dir_.c_str(), &buf)!=0) return runEnded;
535  if (stat((bu_run_dir_+"/fu.lock").c_str(), &buf)!=0) return runEnded;
536  lock_attempts=0;
537  }
538  }
539 
540  timeval ts_lockend;
541  gettimeofday(&ts_lockend,0);
542  long deltat = (ts_lockend.tv_usec-ts_lockbegin.tv_usec) + (ts_lockend.tv_sec-ts_lockbegin.tv_sec)*1000000;
543  if (deltat>0.) lockWaitTime=deltat;
544 
545 
546 
547  if(retval!=0) return fileStatus;
548 
549 #ifdef DEBUG
550  timeval ts_lockend;
551  gettimeofday(&ts_lockend,0);
552 #endif
553 
554  // if the stream is readable
555  if (fu_rw_lock_stream != 0) {
556  unsigned int readLs, readIndex;
557  int check = 0;
558  // rewind the stream
559  check = fseek(fu_rw_lock_stream, 0, SEEK_SET);
560  // if rewinded ok
561  if (check == 0) {
562  // read its' values
563  fscanf(fu_rw_lock_stream, "%u %u", &readLs, &readIndex);
564  edm::LogInfo("EvFDaqDirector") << "Read fu.lock file file -: " << readLs << ":" << readIndex;
565 
566  unsigned int currentLs = readLs;
567  bool bumpedOk = false;
568  //if next lumisection in a lock file is not +1 wrt. source, cycle through the next empty one, unless initial lumi not yet set
569  //no lock file write in this case
570  if (ls && ls+1 < currentLs) ls++;
571  else {
572  // try to bump (look for new index or EoLS file)
573  bumpedOk = bumpFile(readLs, readIndex, nextFile, fsize, stopFileLS);
574  //avoid 2 lumisections jump
575  if (ls && readLs>currentLs && currentLs > ls) {
576  ls++;
577  readLs=currentLs=ls;
578  readIndex=0;
579  bumpedOk=false;
580  //no write to lock file
581  }
582  else {
583  if (ls==0 && readLs>currentLs) {
584  //make sure to intialize always with LS found in the lock file, with possibility of grabbing index file immediately
585  //in this case there is no new file in the same LS
586  readLs=currentLs;
587  readIndex=0;
588  bumpedOk=false;
589  //no write to lock file
590  }
591  //update return LS value
592  ls = readLs;
593  }
594  }
595  if (bumpedOk) {
596  // there is a new index file to grab, lock file needs to be updated
597  check = fseek(fu_rw_lock_stream, 0, SEEK_SET);
598  if (check == 0) {
599  ftruncate(fu_readwritelock_fd_, 0);
600  // write next index in the file, which is the file the next process should take
601  fprintf(fu_rw_lock_stream, "%u %u", readLs, readIndex + 1);
602  fflush(fu_rw_lock_stream);
603  fsync(fu_readwritelock_fd_);
604  fileStatus = newFile;
605  LogDebug("EvFDaqDirector") << "Written to file -: " << readLs << ":" << readIndex + 1;
606  }
607  else {
608  throw cms::Exception("EvFDaqDirector") << "seek on fu read/write lock for updating failed with error " << strerror(errno);
609  }
610  }
611  else if (currentLs < readLs) {
612  //there is no new file in next LS (yet), but lock file can be updated to the next LS
613  check = fseek(fu_rw_lock_stream, 0, SEEK_SET);
614  if (check == 0) {
615  ftruncate(fu_readwritelock_fd_, 0);
616  // in this case LS was bumped, but no new file. Thus readIndex is 0 (set by bumpFile)
617  fprintf(fu_rw_lock_stream, "%u %u", readLs, readIndex);
618  fflush(fu_rw_lock_stream);
619  fsync(fu_readwritelock_fd_);
620  LogDebug("EvFDaqDirector") << "Written to file -: " << readLs << ":" << readIndex;
621  }
622  else {
623  throw cms::Exception("EvFDaqDirector") << "seek on fu read/write lock for updating failed with error " << strerror(errno);
624  }
625  }
626  } else {
627  edm::LogError("EvFDaqDirector") << "seek on fu read/write lock for reading failed with error " << strerror(errno);
628  }
629  } else {
630  edm::LogError("EvFDaqDirector") << "fu read/write lock stream is invalid " << strerror(errno);
631  }
632 
633 #ifdef DEBUG
634  timeval ts_preunlock;
635  gettimeofday(&ts_preunlock,0);
636  int locked_period_int = ts_preunlock.tv_sec - ts_lockend.tv_sec;
637  double locked_period=locked_period_int+double(ts_preunlock.tv_usec - ts_lockend.tv_usec)/1000000;
638 #endif
639 
640  //if new json is present, lock file which FedRawDataInputSource will later unlock
641  if (fileStatus==newFile) lockFULocal();
642 
643  //release lock at this point
644  int retvalu=-1;
645  retvalu=fcntl(fu_readwritelock_fd_, F_SETLKW, &fu_rw_fulk);
646  if (retvalu==-1) edm::LogError("EvFDaqDirector") << "Error unlocking the fu.lock " << strerror(errno);
647 
648 #ifdef DEBUG
649  edm::LogDebug("EvFDaqDirector") << "Waited during lock -: " << locked_period << " seconds";
650 #endif
651 
652  if ( fileStatus == noFile ) {
653  struct stat buf;
654  //edm::LogInfo("EvFDaqDirector") << " looking for EoR file: " << getEoRFilePath().c_str();
655  if ( stat(getEoRFilePath().c_str(), &buf) == 0 || stat(bu_run_dir_.c_str(), &buf)!=0)
656  fileStatus = runEnded;
657  if (stopFileLS>=0 && (int)ls > stopFileLS) {
658  edm::LogInfo("EvFDaqDirector") << "Reached maximum lumisection set by hltd";
659  fileStatus = runEnded;
660  }
661  }
662  return fileStatus;
663  }
#define LogDebug(id)
struct flock fu_rw_flk
def ls
Definition: eostools.py:348
std::string getEoRFilePath() const
struct flock fu_rw_fulk
std::string stopFilePath_
unsigned int stop_ls_override_
int readLastLSEntry(std::string const &file)
std::string stopFilePathPid_
std::string bu_run_dir_
std::string getEoLSFilePathOnFU(const unsigned int ls) const
bool bumpFile(unsigned int &ls, unsigned int &index, std::string &nextFile, uint32_t &fsize, int maxLS)
unsigned int fuLockPollInterval_

Member Data Documentation

std::string evf::EvFDaqDirector::base_dir_
private

Definition at line 148 of file EvFDaqDirector.h.

Referenced by initRun().

std::string evf::EvFDaqDirector::bu_base_dir_
private

Definition at line 149 of file EvFDaqDirector.h.

Referenced by initRun().

struct flock evf::EvFDaqDirector::bu_r_flk
private

Definition at line 186 of file EvFDaqDirector.h.

struct flock evf::EvFDaqDirector::bu_r_fulk
private

Definition at line 188 of file EvFDaqDirector.h.

FILE* evf::EvFDaqDirector::bu_r_lock_stream
private

Definition at line 175 of file EvFDaqDirector.h.

int evf::EvFDaqDirector::bu_readlock_fd_
private

Definition at line 167 of file EvFDaqDirector.h.

Referenced by postEndRun().

std::string evf::EvFDaqDirector::bu_run_dir_
private
std::string evf::EvFDaqDirector::bu_run_open_dir_
private

Definition at line 165 of file EvFDaqDirector.h.

Referenced by buBaseRunOpenDir(), and initRun().

FILE* evf::EvFDaqDirector::bu_t_monitor_stream
private

Definition at line 178 of file EvFDaqDirector.h.

struct flock evf::EvFDaqDirector::bu_w_flk
private

Definition at line 185 of file EvFDaqDirector.h.

struct flock evf::EvFDaqDirector::bu_w_fulk
private

Definition at line 187 of file EvFDaqDirector.h.

FILE* evf::EvFDaqDirector::bu_w_lock_stream
private

Definition at line 174 of file EvFDaqDirector.h.

Referenced by initRun().

FILE* evf::EvFDaqDirector::bu_w_monitor_stream
private

Definition at line 177 of file EvFDaqDirector.h.

int evf::EvFDaqDirector::bu_writelock_fd_
private

Definition at line 168 of file EvFDaqDirector.h.

Referenced by initRun(), and postEndRun().

int evf::EvFDaqDirector::currentFileIndex_ = -1
private

Definition at line 200 of file EvFDaqDirector.h.

Referenced by preSourceEvent(), and updateFileIndex().

int evf::EvFDaqDirector::data_readwrite_fd_
private
struct flock evf::EvFDaqDirector::data_rw_flk
private

Definition at line 191 of file EvFDaqDirector.h.

Referenced by maybeCreateAndLockFileHeadForStream().

struct flock evf::EvFDaqDirector::data_rw_fulk
private

Definition at line 192 of file EvFDaqDirector.h.

Referenced by unlockAndCloseMergeStream().

FILE* evf::EvFDaqDirector::data_rw_stream
private
bool evf::EvFDaqDirector::directorBu_
private

Definition at line 150 of file EvFDaqDirector.h.

Referenced by initRun(), and postEndRun().

DirManager evf::EvFDaqDirector::dirManager_
private

Definition at line 181 of file EvFDaqDirector.h.

Referenced by findCurrentRunDir(), and preBeginRun().

bool evf::EvFDaqDirector::emptyLumisectionMode_
private

Definition at line 157 of file EvFDaqDirector.h.

Referenced by emptyLumisectionMode(), and EvFDaqDirector().

unsigned int evf::EvFDaqDirector::eolsNFilesIndex_ = 1
private

Definition at line 211 of file EvFDaqDirector.h.

Referenced by getNFilesFromEoLS().

std::mutex* evf::EvFDaqDirector::fileDeleteLockPtr_ = nullptr
private

Definition at line 202 of file EvFDaqDirector.h.

Referenced by preGlobalEndLumi(), and setDeleteTracking().

std::list<std::pair<int,InputFile*> >* evf::EvFDaqDirector::filesToDeletePtr_ = nullptr
private

Definition at line 203 of file EvFDaqDirector.h.

Referenced by preGlobalEndLumi(), and setDeleteTracking().

evf::FastMonitoringService* evf::EvFDaqDirector::fms_ = nullptr
private

Definition at line 198 of file EvFDaqDirector.h.

Referenced by bumpFile(), and setFMS().

int evf::EvFDaqDirector::fu_readwritelock_fd_
private

Definition at line 169 of file EvFDaqDirector.h.

Referenced by initRun(), openFULockfileStream(), and updateFuLock().

struct flock evf::EvFDaqDirector::fu_rw_flk
private

Definition at line 189 of file EvFDaqDirector.h.

Referenced by updateFuLock().

struct flock evf::EvFDaqDirector::fu_rw_fulk
private

Definition at line 190 of file EvFDaqDirector.h.

Referenced by updateFuLock().

FILE* evf::EvFDaqDirector::fu_rw_lock_stream
private
int evf::EvFDaqDirector::fulocal_rwlock_fd2_
private

Definition at line 172 of file EvFDaqDirector.h.

Referenced by initRun(), lockFULocal2(), unlockFULocal2(), and ~EvFDaqDirector().

int evf::EvFDaqDirector::fulocal_rwlock_fd_
private

Definition at line 171 of file EvFDaqDirector.h.

Referenced by initRun(), lockFULocal(), unlockFULocal(), and ~EvFDaqDirector().

unsigned int evf::EvFDaqDirector::fuLockPollInterval_
private

Definition at line 156 of file EvFDaqDirector.h.

Referenced by EvFDaqDirector(), and updateFuLock().

std::string evf::EvFDaqDirector::hltSourceDirectory_
private

Definition at line 155 of file EvFDaqDirector.h.

Referenced by initRun().

std::string evf::EvFDaqDirector::hostname_
private
pthread_mutex_t evf::EvFDaqDirector::init_lock_ = PTHREAD_MUTEX_INITIALIZER
private

Definition at line 205 of file EvFDaqDirector.h.

Referenced by initRun(), lockInitLock(), and unlockInitLock().

std::map<std::string,std::string> evf::EvFDaqDirector::mergeTypeMap_
private

Definition at line 217 of file EvFDaqDirector.h.

Referenced by checkMergeTypePSet(), and getStreamMergeType().

const std::vector< std::string > evf::EvFDaqDirector::MergeTypeNames_ = {"","DAT","PB","JSNDATA"}
staticprivate

Definition at line 220 of file EvFDaqDirector.h.

Referenced by getStreamMergeType().

std::string evf::EvFDaqDirector::mergeTypePset_
private

Definition at line 159 of file EvFDaqDirector.h.

Referenced by checkMergeTypePSet().

bool evf::EvFDaqDirector::microMergeDisabled_
private

Definition at line 158 of file EvFDaqDirector.h.

Referenced by EvFDaqDirector(), and microMergeDisabled().

unsigned int evf::EvFDaqDirector::nStreams_ =0
private

Definition at line 207 of file EvFDaqDirector.h.

Referenced by isSingleStreamThread(), and preallocate().

unsigned int evf::EvFDaqDirector::nThreads_ =0
private

Definition at line 208 of file EvFDaqDirector.h.

Referenced by isSingleStreamThread(), and preallocate().

bool evf::EvFDaqDirector::outputAdler32Recheck_
private

Definition at line 152 of file EvFDaqDirector.h.

Referenced by outputAdler32Recheck().

unsigned long evf::EvFDaqDirector::previousFileSize_
private

Definition at line 183 of file EvFDaqDirector.h.

Referenced by bumpFile().

bool evf::EvFDaqDirector::readEolsDefinition_ = true
private

Definition at line 210 of file EvFDaqDirector.h.

Referenced by getNFilesFromEoLS().

bool evf::EvFDaqDirector::requireTSPSet_
private

Definition at line 153 of file EvFDaqDirector.h.

Referenced by checkTransferSystemPSet(), and getStreamDestinations().

unsigned int evf::EvFDaqDirector::run_
private
std::string evf::EvFDaqDirector::run_dir_
private
std::string evf::EvFDaqDirector::run_string_
private

Definition at line 162 of file EvFDaqDirector.h.

Referenced by initRun().

std::string evf::EvFDaqDirector::selectedTransferMode_
private

Definition at line 154 of file EvFDaqDirector.h.

Referenced by getStreamDestinations().

unsigned int evf::EvFDaqDirector::stop_ls_override_ = 0
private

Definition at line 214 of file EvFDaqDirector.h.

Referenced by updateFuLock().

std::string evf::EvFDaqDirector::stopFilePath_
private

Definition at line 212 of file EvFDaqDirector.h.

Referenced by initRun(), and updateFuLock().

std::string evf::EvFDaqDirector::stopFilePathPid_
private

Definition at line 213 of file EvFDaqDirector.h.

Referenced by initRun(), and updateFuLock().

std::vector<int> evf::EvFDaqDirector::streamFileTracker_
private

Definition at line 199 of file EvFDaqDirector.h.

Referenced by getStreamFileTracker(), preallocate(), and preSourceEvent().

std::shared_ptr<Json::Value> evf::EvFDaqDirector::transferSystemJson_
private

Definition at line 216 of file EvFDaqDirector.h.

Referenced by checkTransferSystemPSet(), and getStreamDestinations().