Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace boost filesystem in EventFilter/Utilities #30602

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DQMServices/FileIO/plugins/DQMFileSaverBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const std::string DQMFileSaverBase::filename(const FileParameters &fp, bool useL
}
buf[255] = 0;

namespace fs = boost::filesystem;
namespace fs = std::filesystem;
fs::path path(fp.path_);
fs::path file(buf);

Expand Down
1 change: 1 addition & 0 deletions EventFilter/Utilities/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<use name="DataFormats/TCDS"/>
<use name="IOPool/Streamer"/>
<use name="curl"/>
<use name="stdcxx-fs"/>
<export>
<lib name="1"/>
</export>
12 changes: 6 additions & 6 deletions EventFilter/Utilities/interface/EvFDaqDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#include "EventFilter/Utilities/interface/DirManager.h"

//std headers
#include <string>
#include <sstream>
#include <filesystem>
#include <iomanip>
#include <vector>
#include <map>
#include <list>
#include <map>
#include <mutex>
#include <sstream>
#include <string>
#include <vector>

//system headers
#include <sys/stat.h>
Expand All @@ -26,7 +27,6 @@
#include <cstdio>

#include <tbb/concurrent_hash_map.h>
#include <boost/filesystem.hpp>
#include <boost/asio.hpp>

class SystemBounds;
Expand Down Expand Up @@ -149,7 +149,7 @@ namespace evf {
std::string const& rawSourcePath,
int64_t& fileSizeFromJson,
bool& fileFound);
int grabNextJsonFileAndUnlock(boost::filesystem::path const& jsonSourcePath);
int grabNextJsonFileAndUnlock(std::filesystem::path const& jsonSourcePath);

EvFDaqDirector::FileStatus contactFileBroker(unsigned int& serverHttpStatus,
bool& serverState,
Expand Down
6 changes: 4 additions & 2 deletions EventFilter/Utilities/interface/FastMonitoringService.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "DataFormats/Provenance/interface/ParameterSetID.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "boost/filesystem.hpp"
#include <filesystem>

#include <boost/thread.hpp>

#include "EventFilter/Utilities/interface/MicroStateService.h"
#include "EventFilter/Utilities/interface/FastMonitoringThread.h"
Expand Down Expand Up @@ -281,7 +283,7 @@ namespace evf {
std::vector<ContainableAtomic<unsigned int>> eventCountForPathInit_;
std::vector<bool> pathNamesReady_;

boost::filesystem::path workingDirectory_, runDirectory_;
std::filesystem::path workingDirectory_, runDirectory_;

bool threadIDAvailable_ = false;

Expand Down
8 changes: 4 additions & 4 deletions EventFilter/Utilities/interface/FedRawDataInputSource.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef EventFilter_Utilities_FedRawDataInputSource_h
#define EventFilter_Utilities_FedRawDataInputSource_h

#include <memory>
#include <condition_variable>
#include <cstdio>
#include <filesystem>
#include <memory>
#include <mutex>
#include <condition_variable>
#include <thread>

#include "tbb/concurrent_queue.h"
#include "tbb/concurrent_vector.h"

#include "boost/filesystem.hpp"

#include "DataFormats/Provenance/interface/ProcessHistoryID.h"
#include "DataFormats/Provenance/interface/Timestamp.h"
#include "EventFilter/Utilities/interface/EvFDaqDirector.h"
Expand Down
1 change: 1 addition & 0 deletions EventFilter/Utilities/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<use name="CLHEP"/>
<use name="boost"/>
<use name="root"/>
<use name="stdcxx-fs"/>
<flags EDM_PLUGIN="1"/>
</library>
2 changes: 1 addition & 1 deletion EventFilter/Utilities/plugins/RawEventFileWriterForBU.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void RawEventFileWriterForBU::finishFileWrite(int ls) {
rename(fileName_.c_str(), (destinationDir_ + fileName_.substr(fileName_.rfind("/"))).c_str());
//create equivalent JSON file
//TODO:fix this to use DaqDirector convention and better extension replace
boost::filesystem::path source(fileName_);
std::filesystem::path source(fileName_);
std::string path = source.replace_extension(".jsn").string();

fileMon_->snap(ls);
Expand Down
20 changes: 10 additions & 10 deletions EventFilter/Utilities/plugins/RecoEventOutputModuleForFU.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
#include "FWCore/Framework/interface/LuminosityBlockForOutput.h"
#include "FWCore/ServiceRegistry/interface/Service.h"

#include <sstream>
#include <filesystem>
#include <iomanip>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <sstream>

#include <zlib.h>
#include <boost/algorithm/string.hpp>

#include "EventFilter/Utilities/interface/EvFDaqDirector.h"
#include "EventFilter/Utilities/interface/JsonMonitorable.h"
Expand Down Expand Up @@ -50,8 +51,8 @@ namespace evf {
private:
std::unique_ptr<Consumer> c_;
std::string streamLabel_;
boost::filesystem::path openDatFilePath_;
boost::filesystem::path openDatChecksumFilePath_;
std::filesystem::path openDatFilePath_;
std::filesystem::path openDatChecksumFilePath_;
jsoncollector::IntJ processed_;
mutable jsoncollector::IntJ accepted_;
jsoncollector::IntJ errorEvents_;
Expand Down Expand Up @@ -157,7 +158,7 @@ namespace evf {
std::string content;
jsoncollector::JSONSerializer::serialize(&outJsonDef_, content);
jsoncollector::FileIO::writeStringToFile(outTmpJsonDefName, content);
boost::filesystem::rename(outTmpJsonDefName, outJsonDefName);
std::filesystem::rename(outTmpJsonDefName, outJsonDefName);
}
edm::Service<evf::EvFDaqDirector>()->unlockInitLock();

Expand Down Expand Up @@ -224,7 +225,7 @@ namespace evf {
<< " obtained:" << adler32c;
} else {
LogDebug("RecoEventOutputModuleForFU") << "Ini file checksum -: " << streamLabel_ << " " << adler32c;
boost::filesystem::rename(openIniFileName, edm::Service<evf::EvFDaqDirector>()->getInitFilePath(streamLabel_));
std::filesystem::rename(openIniFileName, edm::Service<evf::EvFDaqDirector>()->getInitFilePath(streamLabel_));
}
}

Expand Down Expand Up @@ -289,9 +290,8 @@ namespace evf {
struct stat istat;
stat(openDatFilePath_.string().c_str(), &istat);
filesize = istat.st_size;
boost::filesystem::rename(
openDatFilePath_.string().c_str(),
edm::Service<evf::EvFDaqDirector>()->getDatFilePath(ls.luminosityBlock(), streamLabel_));
std::filesystem::rename(openDatFilePath_.string().c_str(),
edm::Service<evf::EvFDaqDirector>()->getDatFilePath(ls.luminosityBlock(), streamLabel_));
} else {
filelist_ = "";
fileAdler32_.value() = -1;
Expand Down
42 changes: 21 additions & 21 deletions EventFilter/Utilities/src/EvFDaqDirector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ namespace evf {
throw cms::Exception("DaqDirector")
<< " Error creating bu run dir -: " << hltdir << " mkdir error:" << strerror(errno) << "\n";

boost::filesystem::copy_file(hltSourceDirectory_ + "/HltConfig.py", tmphltdir + "/HltConfig.py");
std::filesystem::copy_file(hltSourceDirectory_ + "/HltConfig.py", tmphltdir + "/HltConfig.py");

boost::filesystem::copy_file(hltSourceDirectory_ + "/fffParameters.jsn", tmphltdir + "/fffParameters.jsn");
std::filesystem::copy_file(hltSourceDirectory_ + "/fffParameters.jsn", tmphltdir + "/fffParameters.jsn");

boost::filesystem::rename(tmphltdir, hltdir);
std::filesystem::rename(tmphltdir, hltdir);
} else
throw cms::Exception("DaqDirector") << " Error looking for HLT configuration -: " << hltSourceDirectory_;
}
Expand Down Expand Up @@ -710,7 +710,7 @@ namespace evf {
}

int EvFDaqDirector::getNFilesFromEoLS(std::string BUEoLSFile) {
boost::filesystem::ifstream ij(BUEoLSFile);
std::ifstream ij(BUEoLSFile);
Json::Value deserializeRoot;
Json::Reader reader;

Expand Down Expand Up @@ -1097,7 +1097,7 @@ namespace evf {
fileFound = true;

//take only first three tokens delimited by "_" in the renamed raw file name
std::string jsonStem = boost::filesystem::path(rawSourcePath).stem().string();
std::string jsonStem = std::filesystem::path(rawSourcePath).stem().string();
size_t pos = 0, n_tokens = 0;
while (n_tokens++ < 3 && (pos = jsonStem.find("_", pos + 1)) != std::string::npos) {
}
Expand Down Expand Up @@ -1177,7 +1177,7 @@ namespace evf {

//should be ported to use fffnaming
std::ostringstream fileNameWithPID;
fileNameWithPID << boost::filesystem::path(rawSourcePath).stem().string() << "_pid" << std::setfill('0')
fileNameWithPID << std::filesystem::path(rawSourcePath).stem().string() << "_pid" << std::setfill('0')
<< std::setw(5) << pid_ << ".jsn";

// assemble json destination path
Expand Down Expand Up @@ -1273,9 +1273,9 @@ namespace evf {
} else {
//json will normally not be bigger than buf_sz bytes
try {
boost::filesystem::ifstream ij(jsonDestPath);
std::ifstream ij(jsonDestPath);
ss << ij.rdbuf();
} catch (boost::filesystem::filesystem_error const& ex) {
} catch (std::filesystem::filesystem_error const& ex) {
edm::LogError("EvFDaqDirector") << "grabNextJsonFile - BOOST FILESYSTEM ERROR CAUGHT -: " << ex.what();
return -1;
}
Expand Down Expand Up @@ -1349,11 +1349,11 @@ namespace evf {
return -1;
}

int EvFDaqDirector::grabNextJsonFileAndUnlock(boost::filesystem::path const& jsonSourcePath) {
int EvFDaqDirector::grabNextJsonFileAndUnlock(std::filesystem::path const& jsonSourcePath) {
std::string data;
try {
// assemble json destination path
boost::filesystem::path jsonDestPath(baseRunDir());
std::filesystem::path jsonDestPath(baseRunDir());

//should be ported to use fffnaming
std::ostringstream fileNameWithPID;
Expand All @@ -1363,28 +1363,28 @@ namespace evf {

LogDebug("EvFDaqDirector") << "JSON rename -: " << jsonSourcePath << " to " << jsonDestPath;
try {
boost::filesystem::copy(jsonSourcePath, jsonDestPath);
} catch (boost::filesystem::filesystem_error const& ex) {
std::filesystem::copy(jsonSourcePath, jsonDestPath);
} catch (std::filesystem::filesystem_error const& ex) {
// Input dir gone?
edm::LogError("EvFDaqDirector") << "grabNextFile BOOST FILESYSTEM ERROR CAUGHT -: " << ex.what();
// << " Maybe the file is not yet visible by FU. Trying again in one second";
sleep(1);
boost::filesystem::copy(jsonSourcePath, jsonDestPath);
std::filesystem::copy(jsonSourcePath, jsonDestPath);
}
unlockFULocal();

try {
//sometimes this fails but file gets deleted
boost::filesystem::remove(jsonSourcePath);
} catch (boost::filesystem::filesystem_error const& ex) {
std::filesystem::remove(jsonSourcePath);
} catch (std::filesystem::filesystem_error const& ex) {
// Input dir gone?
edm::LogError("EvFDaqDirector") << "grabNextFile BOOST FILESYSTEM ERROR CAUGHT -: " << ex.what();
} catch (std::exception const& ex) {
// Input dir gone?
edm::LogError("EvFDaqDirector") << "grabNextFile std::exception CAUGHT -: " << ex.what();
}

boost::filesystem::ifstream ij(jsonDestPath);
std::ifstream ij(jsonDestPath);
Json::Value deserializeRoot;
Json::Reader reader;

Expand Down Expand Up @@ -1418,7 +1418,7 @@ namespace evf {
<< " error reading number of events from BU JSON -: No input value " << data;
}
return boost::lexical_cast<int>(data);
} catch (boost::filesystem::filesystem_error const& ex) {
} catch (std::filesystem::filesystem_error const& ex) {
// Input dir gone?
unlockFULocal();
edm::LogError("EvFDaqDirector") << "grabNextFile BOOST FILESYSTEM ERROR CAUGHT -: " << ex.what();
Expand Down Expand Up @@ -1832,15 +1832,15 @@ namespace evf {
void EvFDaqDirector::createRunOpendirMaybe() {
// create open dir if not already there

boost::filesystem::path openPath = getRunOpenDirPath();
if (!boost::filesystem::is_directory(openPath)) {
std::filesystem::path openPath = getRunOpenDirPath();
if (!std::filesystem::is_directory(openPath)) {
LogDebug("EvFDaqDirector") << "<open> FU dir not found. Creating... -:" << openPath.string();
boost::filesystem::create_directories(openPath);
std::filesystem::create_directories(openPath);
}
}

int EvFDaqDirector::readLastLSEntry(std::string const& file) {
boost::filesystem::ifstream ij(file);
std::ifstream ij(file);
Json::Value deserializeRoot;
Json::Reader reader;

Expand Down
13 changes: 6 additions & 7 deletions EventFilter/Utilities/src/EvFOutputModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "IOPool/Streamer/interface/EventMsgBuilder.h"

#include <sys/stat.h>
#include <boost/filesystem.hpp>
#include <filesystem>
#include <boost/algorithm/string.hpp>

namespace evf {
Expand Down Expand Up @@ -84,7 +84,7 @@ namespace evf {
std::string content;
jsoncollector::JSONSerializer::serialize(&outJsonDef_, content);
jsoncollector::FileIO::writeStringToFile(outTmpJsonDefName, content);
boost::filesystem::rename(outTmpJsonDefName, outJsonDefName);
std::filesystem::rename(outTmpJsonDefName, outJsonDefName);
}
edm::Service<evf::EvFDaqDirector>()->unlockInitLock();

Expand Down Expand Up @@ -206,7 +206,7 @@ namespace evf {
<< " expected:" << preamble_adler32 << " obtained:" << adler32c;
} else {
LogDebug("EvFOutputModule") << "Ini file checksum -: " << streamLabel_ << " " << adler32c;
boost::filesystem::rename(openIniFileName, edm::Service<evf::EvFDaqDirector>()->getInitFilePath(streamLabel_));
std::filesystem::rename(openIniFileName, edm::Service<evf::EvFDaqDirector>()->getInitFilePath(streamLabel_));
}
}

Expand Down Expand Up @@ -252,12 +252,11 @@ namespace evf {

if (jsonWriter_->processed_.value() != 0) {
struct stat istat;
boost::filesystem::path openDatFilePath = lumiWriter->getFilePath();
std::filesystem::path openDatFilePath = lumiWriter->getFilePath();
stat(openDatFilePath.string().c_str(), &istat);
jsonWriter_->filesize_ = istat.st_size;
boost::filesystem::rename(
openDatFilePath.string().c_str(),
edm::Service<evf::EvFDaqDirector>()->getDatFilePath(iLB.luminosityBlock(), streamLabel_));
std::filesystem::rename(openDatFilePath.string().c_str(),
edm::Service<evf::EvFDaqDirector>()->getDatFilePath(iLB.luminosityBlock(), streamLabel_));
jsonWriter_->filelist_ = openDatFilePath.filename().string();
} else {
//remove empty file when no event processing has occurred
Expand Down
16 changes: 8 additions & 8 deletions EventFilter/Utilities/src/FastMonitoringService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,30 +237,30 @@ namespace evf {
if (edm::Service<evf::EvFDaqDirector>().operator->() == nullptr) {
throw cms::Exception("FastMonitoringService") << "EvFDaqDirector is not present";
}
boost::filesystem::path runDirectory{edm::Service<evf::EvFDaqDirector>()->baseRunDir()};
std::filesystem::path runDirectory{edm::Service<evf::EvFDaqDirector>()->baseRunDir()};
workingDirectory_ = runDirectory_ = runDirectory;
workingDirectory_ /= "mon";

if (!boost::filesystem::is_directory(workingDirectory_)) {
if (!std::filesystem::is_directory(workingDirectory_)) {
LogDebug("FastMonitoringService") << "<MON> DIR NOT FOUND! Trying to create -: " << workingDirectory_.string();
boost::filesystem::create_directories(workingDirectory_);
if (!boost::filesystem::is_directory(workingDirectory_))
std::filesystem::create_directories(workingDirectory_);
if (!std::filesystem::is_directory(workingDirectory_))
edm::LogWarning("FastMonitoringService") << "Unable to create <MON> DIR -: " << workingDirectory_.string()
<< ". No monitoring data will be written.";
}

std::ostringstream fastFileName;

fastFileName << fastName_ << "_pid" << std::setfill('0') << std::setw(5) << getpid() << ".fast";
boost::filesystem::path fast = workingDirectory_;
std::filesystem::path fast = workingDirectory_;
fast /= fastFileName.str();
fastPath_ = fast.string();
if (filePerFwkStream_)
for (unsigned int i = 0; i < nStreams_; i++) {
std::ostringstream fastFileNameTid;
fastFileNameTid << fastName_ << "_pid" << std::setfill('0') << std::setw(5) << getpid() << "_tid" << i
<< ".fast";
boost::filesystem::path fastTid = workingDirectory_;
std::filesystem::path fastTid = workingDirectory_;
fastTid /= fastFileNameTid.str();
fastPathList_.push_back(fastTid.string());
}
Expand Down Expand Up @@ -515,14 +515,14 @@ namespace evf {
std::stringstream slowFileNameStem;
slowFileNameStem << slowName_ << "_ls" << std::setfill('0') << std::setw(4) << lumi << "_pid" << std::setfill('0')
<< std::setw(5) << getpid();
boost::filesystem::path slow = workingDirectory_;
std::filesystem::path slow = workingDirectory_;
slow /= slowFileNameStem.str();
fmt_.jsonMonitor_->outputFullJSONs(slow.string(), ".jsn", lumi);
} else {
std::stringstream slowFileName;
slowFileName << slowName_ << "_ls" << std::setfill('0') << std::setw(4) << lumi << "_pid" << std::setfill('0')
<< std::setw(5) << getpid() << ".jsn";
boost::filesystem::path slow = workingDirectory_;
std::filesystem::path slow = workingDirectory_;
slow /= slowFileName.str();
fmt_.jsonMonitor_->outputFullJSON(slow.string(),
lumi); //full global and stream merge and JSON write for this lumi
Expand Down
Loading