Skip to content
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
47 changes: 33 additions & 14 deletions EventVisualisation/Base/src/DirectoryLoader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ using namespace o2::event_visualisation;
deque<string> DirectoryLoader::load(const std::string& path, const std::string& marker, const std::vector<std::string>& ext)
{
deque<string> result;
for (const auto& entry : std::filesystem::directory_iterator(path)) {
if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) {
result.push_back(entry.path().filename());
try {
for (const auto& entry : std::filesystem::directory_iterator(path)) {
if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) {
result.push_back(entry.path().filename());
}
}
} catch (std::filesystem::filesystem_error const& ex) {
LOGF(error, "filesystem problem during DirectoryLoader::load: %s", ex.what());
return result;
}
// comparison with safety if marker not in the filename (-1+1 gives 0)
std::sort(result.begin(), result.end(),
Expand All @@ -56,7 +61,8 @@ bool DirectoryLoader::canCreateNextFile(const std::vector<std::string>& paths, c
}
}
} catch (std::filesystem::filesystem_error const& ex) {
LOGF(info, "filesystem problem: %s", ex.what());
LOGF(error, "filesystem problem during DirectoryLoader::canCreateNextFile: %s", ex.what());
return false;
}
}

Expand Down Expand Up @@ -87,12 +93,17 @@ bool DirectoryLoader::canCreateNextFile(const std::vector<std::string>& paths, c
deque<string> DirectoryLoader::load(const std::vector<std::string>& paths, const std::string& marker, const std::vector<std::string>& ext)
{
deque<string> result;
for (const auto& path : paths) {
for (const auto& entry : std::filesystem::directory_iterator(path)) {
if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) {
result.push_back(entry.path().filename());
try {
for (const auto& path : paths) {
for (const auto& entry : std::filesystem::directory_iterator(path)) {
if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) {
result.push_back(entry.path().filename());
}
}
}
} catch (std::filesystem::filesystem_error const& ex) {
LOGF(error, "filesystem problem during DirectoryLoader::load: %s", ex.what());
return result;
}
// comparison with safety if marker not in the filename (-1+1 gives 0)
std::sort(result.begin(), result.end(),
Expand Down Expand Up @@ -135,10 +146,14 @@ std::time_t to_time_t(TP tp)
int DirectoryLoader::getNumberOfFiles(const std::string& path, std::vector<std::string>& ext)
{
int res = 0;
for (const auto& entry : std::filesystem::directory_iterator(path)) {
if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) {
res++;
try {
for (const auto& entry : std::filesystem::directory_iterator(path)) {
if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) {
res++;
}
}
} catch (std::filesystem::filesystem_error const& ex) {
LOGF(error, "filesystem problem during DirectoryLoader::getNumberOfFiles: %s", ex.what());
}
return res;
}
Expand All @@ -160,8 +175,12 @@ std::string DirectoryLoader::getLatestFile(const std::string& path, std::vector<

void DirectoryLoader::removeOldestFiles(const std::string& path, std::vector<std::string>& ext, const int remaining)
{
while (getNumberOfFiles(path, ext) > remaining) {
LOGF(info, "removing oldest file in folder: %s : %s", path, getLatestFile(path, ext));
filesystem::remove(path + "/" + getLatestFile(path, ext));
try {
while (getNumberOfFiles(path, ext) > remaining) {
LOGF(info, "removing oldest file in folder: %s : %s", path, getLatestFile(path, ext));
filesystem::remove(path + "/" + getLatestFile(path, ext));
}
} catch (std::filesystem::filesystem_error const& ex) {
LOGF(error, "filesystem problem during DirectoryLoader::removeOldestFiles: %s", ex.what());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ void VisualisationEventROOTSerializer::toFile(const VisualisationEvent& event, L
{
std::string fileName = location.fileName();
TFile f(fileName.c_str(), "recreate");
if (f.IsZombie()) {
LOGF(error, "Could not create output file %s", fileName.c_str());
return;
}

saveInt("runNumber", event.mRunNumber);
saveInt("runType", event.mRunType);
Expand Down