25 struct flock make_flock(short
type, short whence, off_t
start, off_t len, pid_t
pid)
37 testModeNoBuilderUnit_(
38 pset.getUntrackedParameter<bool> (
"testModeNoBuilderUnit",
42 pset.getUntrackedParameter<std::
string> (
"baseDir",
"/data")
45 pset.getUntrackedParameter<std::
string> (
"buBaseDir",
"/data")
48 pset.getUntrackedParameter<bool> (
"directorIsBu",
false)
50 run_(pset.getUntrackedParameter<unsigned int> (
"runNumber",0)),
54 fu_readwritelock_fd_(-1),
55 data_readwrite_fd_(-1),
56 fulocal_rwlock_fd_(-1),
57 fulocal_rwlock_fd2_(-1),
66 dirManager_(base_dir_),
72 bu_w_flk( make_flock( F_WRLCK, SEEK_SET, 0, 0, 0 )),
73 bu_r_flk( make_flock( F_RDLCK, SEEK_SET, 0, 0, 0 )),
74 bu_w_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, 0 )),
75 bu_r_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, 0 )),
76 fu_rw_flk( make_flock ( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
77 fu_rw_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() )),
78 data_rw_flk( make_flock ( F_WRLCK, SEEK_SET, 0, 0, getpid() )),
79 data_rw_fulk( make_flock( F_UNLCK, SEEK_SET, 0, 0, getpid() ))
93 ss <<
"run" << std::setfill(
'0') << std::setw(6) <<
run_;
99 gethostname(hostname,32);
102 int retval = mkdir(
base_dir_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
103 if (retval != 0 && errno != EEXIST) {
104 throw cms::Exception(
"DaqDirector") <<
" Error checking for base dir -: "
105 <<
base_dir_ <<
" mkdir error:" << strerror(errno);
111 S_IRWXU | S_IRWXG | S_IROTH | S_IRWXO | S_IXOTH);
112 if (retval != 0 && errno != EEXIST) {
113 throw cms::Exception(
"DaqDirector") <<
" Error creating run dir -: "
114 <<
run_dir_ <<
" mkdir error:" << strerror(errno);
122 fulocal_rwlock_fd_ = open(fulocal_lock_.c_str(), O_RDWR | O_CREAT, S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
124 throw cms::Exception(
"DaqDirector") <<
" Error creating/opening a local lock file -: " << fulocal_lock_.c_str() <<
" : " << strerror(errno);
125 chmod(fulocal_lock_.c_str(),0777);
128 fulocal_rwlock_fd2_ = open(fulocal_lock_.c_str(), O_RDWR, S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
130 throw cms::Exception(
"DaqDirector") <<
" Error opening a local lock file -: " << fulocal_lock_.c_str() <<
" : " << strerror(errno);
143 S_IRWXU | S_IRWXG | S_IRWXO);
144 if (retval != 0 && errno != EEXIST) {
147 <<
" mkdir error:" << strerror(errno) <<
"\n";
151 S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
152 if (retval != 0 && errno != EEXIST) {
153 throw cms::Exception(
"DaqDirector") <<
" Error creating bu run open dir -: "
160 O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
162 edm::LogWarning(
"EvFDaqDirector") <<
"problem with creating filedesc for buwritelock -: "
165 edm::LogInfo(
"EvFDaqDirector") <<
"creating filedesc for buwritelock -: "
169 edm::LogWarning(
"EvFDaqDirector")<<
"Error creating write lock stream -: " << strerror(errno);
182 retval = mkdir(
bu_base_dir_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
183 if (retval != 0 && errno != EEXIST) {
184 throw cms::Exception(
"DaqDirector") <<
" Error checking for bu base dir -: "
185 <<
bu_base_dir_ <<
" mkdir error:" << strerror(errno) <<
"\n";
236 <<
run_dir_ <<
". This is not the highest run "
246 edm::LogWarning(
"EvFDaqDirector") <<
" Handles to check for files to delete were not set by the input source...";
253 if (it->second->lumi_ == ls) {
255 LogDebug(
"EvFDaqDirector") <<
"Deleting input file -:" << it->second->fileName_;
260 catch (
const boost::filesystem::filesystem_error& ex)
262 edm::LogError(
"EvFDaqDirector") <<
" - deleteFile BOOST FILESYSTEM ERROR CAUGHT -: " << ex.what() <<
". Trying again.";
271 edm::LogError(
"EvFDaqDirector") <<
" - deleteFile std::exception CAUGHT -: " << ex.what() <<
". Trying again.";
370 int retval =
remove(filename.c_str());
372 edm::LogError(
"EvFDaqDirector") <<
"Could not remove used file -: " << filename <<
". error = "
386 if (retval==-1) usleep(50000);
388 if(retval!=0)
return fileStatus;
392 gettimeofday(&ts_lockend,0);
397 unsigned int readLs,
readIndex, jumpLs, jumpIndex;
406 &jumpLs, &jumpIndex);
411 bool bumpedOk =
bumpFile(readLs, readIndex, nextFile, fsize);
421 edm::LogError(
"EvFDaqDirector") <<
"seek on fu read/write lock for updating failed with error "
429 readIndex + 1, readLs + 2, readIndex + 1);
442 edm::LogInfo(
"EvFDaqDirector") <<
"Written to file -: " << readLs <<
":"
443 << readIndex + 1 <<
" --> " << readLs + 2
444 <<
":" << readIndex + 1;
446 LogDebug(
"EvFDaqDirector") <<
"Written to file -: " << readLs <<
":"
450 edm::LogError(
"EvFDaqDirector") <<
"seek on fu read/write lock for updating failed with error "
454 edm::LogError(
"EvFDaqDirector") <<
"seek on fu read/write lock for reading failed with error "
457 edm::LogError(
"EvFDaqDirector") <<
"fu read/write lock stream is invalid " << strerror(errno);
460 timeval ts_preunlock;
461 gettimeofday(&ts_preunlock,0);
462 int locked_period_int = ts_preunlock.tv_sec - ts_lockend.tv_sec;
463 double locked_period=locked_period_int+double(ts_preunlock.tv_usec - ts_lockend.tv_usec)/1000000;
472 if (retvalu==-1)
edm::LogError(
"EvFDaqDirector") <<
"Error unlocking the fu.lock " << strerror(errno);
475 edm::LogDebug(
"EvFDaqDirector") <<
"Waited during lock -: " << locked_period <<
" seconds";
478 if ( fileStatus ==
noFile ) {
495 edm::LogError(
"EvFDaqDirector") <<
" FastMonitoringService not found";
503 std::stringstream ss;
504 unsigned int nextIndex =
index;
509 if (stat(nextFile.c_str(), &buf) == 0) {
518 unsigned int startingLumi =
ls;
533 if (stat(nextFile.c_str(), &buf) == 0) {
545 std::string cpCmd =
"cp " + sourceEol +
" " + destEol;
546 edm::LogInfo(
"EvFDaqDirector") <<
" testmode: Running copy cmd -: " << cpCmd;
547 int rc = system(cpCmd.c_str());
549 edm::LogError(
"EvFDaqDirector") <<
" testmode: COPY EOL FAILED!!!!! -: " << cpCmd;
564 edm::LogError(
"EvFDaqDirector") <<
"Error creating fu read/write lock stream "
567 edm::LogInfo(
"EvFDaqDirector") <<
"Initializing FU LOCK FILE";
568 unsigned int readLs = 1,
readIndex = 0, jumpLs = 3, jumpIndex = 0;
580 S_IRWXU | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
581 chmod(fulockfile.c_str(),0766);
586 edm::LogError(
"EvFDaqDirector") <<
"problem with creating filedesc for fuwritelock -: " << fulockfile.c_str()
587 <<
" create:" << create <<
" error:" << strerror(errno);
589 LogDebug(
"EvFDaqDirector") <<
"creating filedesc for fureadwritelock -: "
600 edm::LogError(
"EvFDaqDirector") <<
"problem with creating filedesc for datamerge "
603 LogDebug(
"EvFDaqDirector") <<
"creating filedesc for datamerge -: "
650 if (!boost::filesystem::is_directory(openPath)) {
651 LogDebug(
"EvFDaqDirector") <<
"<open> FU dir not found. Creating... -:" << openPath.string();
652 boost::filesystem::create_directories(openPath);
unsigned int maxNumberOfThreads() const
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.
std::string getMergedProtocolBufferHistogramFilePath(const unsigned int ls, std::string const &stream) const
void watchPreallocate(Preallocate::slot_type const &iSlot)
std::vector< int > streamFileTracker_
std::list< std::pair< int, InputFile * > > * filesToDeletePtr_
void openFULockfileStream(std::string &fuLockFilePath, bool create)
void accumulateFileSize(unsigned int lumi, unsigned long fileSize)
void watchPreGlobalEndLumi(PreGlobalEndLumi::slot_type const &iSlot)
std::string getInitFilePath(std::string const &stream) const
std::string getMergedRootHistogramFilePath(const unsigned int ls, std::string const &stream) const
std::string inputRawFileName(const unsigned int run, const unsigned int ls, const unsigned int index)
pthread_mutex_t init_lock_
LuminosityBlockID const & luminosityBlockID() const
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
std::string getEoLSFilePathOnBU(const unsigned int ls) const
std::string getEoRFilePath() const
unsigned long previousFileSize_
void createRunOpendirMaybe()
FileStatus updateFuLock(unsigned int &ls, std::string &nextFile, uint32_t &fsize)
unsigned int maxNumberOfStreams() const
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)
EvFDaqDirector(const edm::ParameterSet &pset, edm::ActivityRegistry ®)
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)
void unlockAndCloseMergeStream()
void tryInitializeFuLockFile()
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)
bool testModeNoBuilderUnit_
void watchPostGlobalEndRun(PostGlobalEndRun::slot_type const &iSlot)
LuminosityBlockNumber_t luminosityBlock() const
evf::FastMonitoringService * fms_
std::string rootHistogramFileNameWithInstance(const unsigned int run, const unsigned int ls, std::string const &stream, std::string const &instance)
std::string findHighestRunDir()
void postEndRun(edm::GlobalContext const &globalContext)
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)
std::string eolsFileName(const unsigned int run, const unsigned int ls)
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_