Skip to content

Commit 47ac293

Browse files
authored
Merge pull request AliceO2Group#8809 from jmyrcha/dev1
o2-eve-workflow: fixed json files ordering problem
1 parent 674c589 commit 47ac293

7 files changed

Lines changed: 83 additions & 43 deletions

File tree

EventVisualisation/Base/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ o2_add_library(EventVisualisationBase
1515
src/DataSourceOffline.cxx
1616
src/GeometryManager.cxx
1717
src/FileWatcher.cxx
18-
PUBLIC_LINK_LIBRARIES ROOT::Eve
18+
src/DirectoryLoader.cxx
19+
20+
PUBLIC_LINK_LIBRARIES ROOT::Eve
1921
O2::CCDB
2022
O2::EventVisualisationDataConverter
2123
O2::DetectorsBase
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file FileWatcher.h
13+
/// \brief Observing folder for created and removed files - preserving current
14+
/// \author julian.myrcha@cern.ch
15+
16+
#ifndef O2EVE_DIRECTORYLOADER_H
17+
#define O2EVE_DIRECTORYLOADER_H
18+
19+
#include <string>
20+
#include <deque>
21+
22+
namespace o2
23+
{
24+
namespace event_visualisation
25+
{
26+
27+
class DirectoryLoader
28+
{
29+
public:
30+
static std::deque<std::string> load(const std::string& path, const std::string& marker);
31+
};
32+
33+
} // namespace event_visualisation
34+
} // namespace o2
35+
36+
#endif // O2EVE_DIRECTORYLOADER_H

EventVisualisation/Base/include/EventVisualisationBase/FileWatcher.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class FileWatcher
3131
std::deque<std::string> mFiles; ///< sorted file list with guards at the beginning and end
3232
std::string nextItem(const std::string& item) const;
3333
std::string prevItem(const std::string& item) const;
34-
static std::deque<std::string> load(const std::string path);
3534
std::string mDataFolder; ///< folder being observed
3635
std::string mCurrentFile; ///< "current" file name
3736
bool currentFileExist();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file DirectoryLoader.h
13+
/// \brief Loading content of the Folder and returning sorted
14+
/// \author julian.myrcha@cern.ch
15+
16+
#include "EventVisualisationBase/DirectoryLoader.h"
17+
#include <filesystem>
18+
#include <algorithm>
19+
20+
using namespace std;
21+
using namespace o2::event_visualisation;
22+
23+
deque<string> DirectoryLoader::load(const std::string& path, const std::string& marker)
24+
{
25+
deque<string> result;
26+
for (const auto& entry : std::filesystem::directory_iterator(path)) {
27+
if (entry.path().extension() == ".json") {
28+
result.push_back(entry.path().filename());
29+
}
30+
}
31+
// comparison with safety if marker not in the filename (-1+1 gives 0)
32+
std::sort(result.begin(), result.end(),
33+
[marker](std::string a, std::string b) {
34+
return a.substr(a.find_last_of(marker) + 1) < b.substr(b.find_last_of(marker) + 1);
35+
});
36+
37+
return result;
38+
}

EventVisualisation/Base/src/FileWatcher.cxx

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,20 @@
1414
/// \author julian.myrcha@cern.ch
1515

1616
#include "EventVisualisationBase/FileWatcher.h"
17+
#include "EventVisualisationBase/DirectoryLoader.h"
1718
#include "FairLogger.h"
1819

1920
#include <list>
2021
#include <filesystem>
2122
#include <algorithm>
2223
#include <sys/stat.h>
23-
using namespace std;
2424

25-
namespace o2
26-
{
27-
namespace event_visualisation
28-
{
25+
using namespace std;
26+
using namespace o2::event_visualisation;
2927

3028
const char* FileWatcher::mLowGuard = " 0"; /// start guard
3129
const char* FileWatcher::mEndGuard = "~0"; /// stop guard
3230

33-
deque<string> FileWatcher::load(string path)
34-
{
35-
//LOG(info) << "FileWatcher::load(" << path << ")";
36-
deque<string> result;
37-
for (const auto& entry : std::filesystem::directory_iterator(path)) {
38-
if (entry.path().extension() == ".json") {
39-
result.push_back(entry.path().filename());
40-
}
41-
}
42-
//LOG(info) << result.size();
43-
return result;
44-
}
45-
4631
FileWatcher::FileWatcher(const string& path)
4732
{
4833
//LOG(info) << "FileWatcher::FileWatcher(" << path << ")";
@@ -134,8 +119,7 @@ bool FileWatcher::refresh()
134119
LOG(info) << "previous:" << previous;
135120
LOG(info) << "currentFile:" << this->mCurrentFile;
136121

137-
this->mFiles = load(this->mDataFolder);
138-
std::sort(this->mFiles.begin(), this->mFiles.end());
122+
this->mFiles = DirectoryLoader::load(this->mDataFolder, "_"); // already sorted according part staring with marker
139123
if (this->mCurrentFile != mEndGuard) {
140124
if (this->mFiles.empty()) {
141125
this->mCurrentFile = mEndGuard; // list empty - stick to last element
@@ -193,6 +177,3 @@ void FileWatcher::saveCurrentFileToFolder(const string& destinationFolder)
193177
std::filesystem::copy_file(source, destination);
194178
}
195179
}
196-
197-
} // namespace event_visualisation
198-
} // namespace o2

EventVisualisation/Workflow/include/EveWorkflow/FileProducer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ namespace event_visualisation
2626
class FileProducer
2727
{
2828
private:
29-
static std::deque<std::string> load(const std::string& path);
30-
3129
size_t mFilesInFolder;
3230
std::string mPath;
3331
std::string mName;

EventVisualisation/Workflow/src/FileProducer.cxx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/// \file FileProducer.cxx
1414
/// \author julian.myrcha@cern.ch
1515

16+
#include "EventVisualisationBase/DirectoryLoader.h"
1617
#include "EveWorkflow/FileProducer.h"
1718
#include "CommonUtils/FileSystemUtils.h"
1819

@@ -29,18 +30,6 @@ using std::chrono::duration_cast;
2930
using std::chrono::milliseconds;
3031
using std::chrono::system_clock;
3132

32-
std::deque<std::string> FileProducer::load(const std::string& path)
33-
{
34-
std::deque<std::string> result;
35-
36-
for (const auto& entry : std::filesystem::directory_iterator(path)) {
37-
if (entry.path().extension() == ".json") {
38-
result.push_back(entry.path().filename());
39-
}
40-
}
41-
return result;
42-
}
43-
4433
FileProducer::FileProducer(const std::string& path, int filesInFolder, const std::string& name)
4534
{
4635
this->mFilesInFolder = filesInFolder;
@@ -57,11 +46,8 @@ std::string FileProducer::newFileName() const
5746
gethostname(hostname, _POSIX_HOST_NAME_MAX);
5847

5948
auto pid = getpid();
60-
6149
auto result = fmt::format(this->mName, fmt::arg("hostname", hostname), fmt::arg("pid", pid), fmt::arg("timestamp", millisec_since_epoch));
62-
63-
auto files = this->load(this->mPath);
64-
std::sort(files.begin(), files.end());
50+
auto files = DirectoryLoader::load(this->mPath, "_"); // already sorted starting by part of name at pos
6551

6652
while (files.size() >= this->mFilesInFolder) {
6753
auto front = files.front();

0 commit comments

Comments
 (0)