Project
Loading...
Searching...
No Matches
FileWatcher.cxx
Go to the documentation of this file.
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
15
18#include <fairlogger/Logger.h>
19
20#include <list>
21#include <filesystem>
22#include <algorithm>
23#include <sys/stat.h>
24
25using namespace std;
26using namespace o2::event_visualisation;
27
28const char* FileWatcher::mLowGuard = " 0";
29const char* FileWatcher::mEndGuard = "~0";
30
31FileWatcher::FileWatcher(const std::vector<string>& path, const std::vector<std::string>& ext) : mExt(ext)
32{
33 //LOG(info) << "FileWatcher::FileWatcher(" << path << ")";
34 this->mDataFolders = path;
35 this->mCurrentFile = mEndGuard;
36 this->mFiles.clear();
37 this->mFiles.push_front(mLowGuard);
38 this->mFiles.push_back(mEndGuard);
39}
40
42{
43 if (this->mDataFolders.size() == 1 && this->mDataFolders[0] == path) {
44 return; // the same folder - no action
45 }
46 this->mDataFolders.clear();
47 this->mDataFolders.push_back(path);
48 this->mCurrentFile = mEndGuard;
49 this->mFiles.clear();
50 this->mFiles.push_front(mLowGuard);
51 this->mFiles.push_back(mEndGuard);
52 this->refresh();
53 // LOG(info) << "FileWatcher" << this->getSize();
54}
55
56void FileWatcher::changeFolder(const std::vector<string>& paths)
57{
58 if (this->mDataFolders == paths) {
59 return; // the same folders - no action
60 }
61 this->mDataFolders.clear();
62 this->mDataFolders = paths;
63 this->mCurrentFile = mEndGuard;
64 this->mFiles.clear();
65 this->mFiles.push_front(mLowGuard);
66 this->mFiles.push_back(mEndGuard);
67 this->refresh();
68 //LOG(info) << "FileWatcher" << this->getSize();
69}
70
71string FileWatcher::nextItem(const string& item) const
72{
73 if (item == mEndGuard) {
74 return mEndGuard;
75 }
76 return *(std::find(this->mFiles.begin(), this->mFiles.end(), item) + 1);
77}
78
79string FileWatcher::prevItem(const string& item) const
80{
81 if (item == mLowGuard) {
82 return mLowGuard;
83 }
84 return *(std::find(mFiles.begin(), mFiles.end(), item) - 1);
85}
86
88{
89 if (this->mFiles.size() == 2) { // only guards on the list
90 return "";
91 }
92 if (this->mCurrentFile == mLowGuard) {
93 return *(this->mFiles.begin() + 1);
94 }
95 if (this->mCurrentFile == mEndGuard) {
96 return *(this->mFiles.end() - 2);
97 }
98 return this->mCurrentFile;
99}
100
102{
103 if (this->mFiles.size() == 2) { // only guards on the list
104 return; // nothing to do
105 }
106 this->setNext();
107 if (this->mCurrentFile == mEndGuard) {
108 this->setFirst();
109 this->setNext();
110 }
111}
112
114{
115 this->mCurrentFile = mLowGuard;
116}
117
119{
120 this->mCurrentFile = mEndGuard;
121}
122
124{
125 this->mCurrentFile = nextItem(this->mCurrentFile);
126}
127
129{
130 this->mCurrentFile = prevItem(this->mCurrentFile);
131}
132
134{
135 return this->mFiles.size(); // guards
136}
137
139{
140 return std::distance(mFiles.begin(), std::find(mFiles.begin(), mFiles.end(), this->mCurrentFile));
141}
142
144{
145 string previous = this->currentItem();
146 LOGF(info, "previous:", previous);
147 LOGF(info, "currentFile:", this->mCurrentFile);
148
149 this->mFiles = DirectoryLoader::load(this->mDataFolders, "_", this->mExt); // already sorted according part staring with marker
150 if (this->mCurrentFile != mEndGuard) {
151 if (this->mFiles.empty()) {
152 this->mCurrentFile = mEndGuard; // list empty - stick to last element
153 } else if (this->mCurrentFile < *(this->mFiles.begin())) {
154 this->mCurrentFile = mLowGuard; // lower then first => go to first
155 } else {
156 auto it = std::find(mFiles.begin(), mFiles.end(), this->mCurrentFile);
157 if (it == this->mFiles.end()) {
158 this->mCurrentFile = mEndGuard; // not on the list -> go to last element
159 }
160 }
161 }
162 //for (auto it = this->mFiles.begin(); it != this->mFiles.end(); ++it) {
163 // LOG(info) << *it;
164 //}
165 this->mFiles.push_front(mLowGuard);
166 this->mFiles.push_back(mEndGuard);
167
168 LOGF(info, "this->mFiles.size() = ", this->mFiles.size());
169 LOGF(info, "this->mCurrentFile = ", this->mCurrentFile);
170 LOGF(info, "current:", this->currentItem());
171 return previous != this->currentItem();
172}
173
175{
176 this->mCurrentFile = this->mFiles[no];
177 LOGF(info, "this->setCurrentItem(", no, ")");
178 LOGF(info, "this->mCurrentFile = ", this->mCurrentFile);
179}
180
182{
183 if (this->mDataFolders.size() > 1) {
184 for (std::string dataFolder : mDataFolders) {
185 struct stat buffer;
186 std::string path = dataFolder + "/" + this->currentItem();
187 if (stat(path.c_str(), &buffer) == 0) {
188 return dataFolder + "/" + this->currentItem();
189 }
190 }
191 }
192 return this->mDataFolders[0] + "/" + this->currentItem();
193}
194
195bool FileWatcher::currentFileExist()
196{
197 struct stat buffer;
198 return (stat(this->currentFilePath().c_str(), &buffer) == 0);
199}
200
201void FileWatcher::saveCurrentFileToFolder(const string& destinationFolder)
202{
203 if (!std::filesystem::exists(destinationFolder)) {
204 return; // do not specified, where to save
205 }
206 for (const auto& folder : this->mDataFolders) {
207 if (folder == destinationFolder) {
208 return; // could not save to yourself
209 }
210 }
211 if (this->currentFileExist()) {
212 std::filesystem::path source = this->currentFilePath();
213 std::filesystem::path destination = destinationFolder;
214 destination /= source.filename();
215 std::filesystem::copy_file(source, destination);
216 }
217}
Loading content of the Folder and returning sorted.
Observing folder for created and removed files - preserving current.
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder Print launch bounds used for RTC code as debugging for exit after Allow RTC with slave GPUReconstruction instances with optConstexpr and optSpecialcode Maximum number of RTC cache files per backend in the cache folder
static std::deque< std::string > load(const std::string &path, const std::string &marker, const std::vector< std::string > &ext)
std::string currentFilePath() const
name of the file (with path) but guards replaced with file names
void saveCurrentFileToFolder(const std::string &destinationFolder)
copies
FileWatcher(const std::vector< std::string > &path, const std::vector< std::string > &ext)
stop guard
int getPos() const
include guards -> 0 points to mLowGuard
void setCurrentItem(int no)
sets using index
void rollToNext()
round robin next item
std::string currentItem() const
name of the file (without path) but guards replaced with file names
bool refresh()
reads folder content, updates current if points to not existing file
int getSize() const
include guards (so >=2 )
void changeFolder(const std::string &path)
switch to observe other folder
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
GLsizei const GLuint * paths
Definition glcorearb.h:5475
GLsizei const GLchar *const * path
Definition glcorearb.h:3591