129 std::string parentFileReplacement;
130 if (ctx.
options().
isSet(
"aod-parent-base-path-replacement")) {
131 parentFileReplacement = ctx.
options().
get<std::string>(
"aod-parent-base-path-replacement");
133 int parentAccessLevel = 0;
135 parentAccessLevel = ctx.
options().
get<
int>(
"aod-parent-access-level");
150 if (!options.
isSet(
"aod-file-private")) {
151 LOGP(fatal,
"No input file defined!");
152 throw std::runtime_error(
"Processing is stopped!");
155 auto filename = options.
get<std::string>(
"aod-file-private");
157 auto maxRate = options.
get<
float>(
"aod-max-io-rate");
160 auto didir = std::make_shared<DataInputDirector>(
filename, &monitoring, parentAccessLevel, parentFileReplacement);
161 if (options.
isSet(
"aod-reader-json")) {
162 auto jsonFile = options.
get<std::string>(
"aod-reader-json");
163 if (!didir->readJson(jsonFile)) {
164 LOGP(error,
"Check the JSON document! Can not be properly parsed!");
173 bool reportTFN =
false;
174 bool reportTFFileName =
false;
177 std::vector<OutputRoute> requestedTables;
179 for (
auto route :
routes) {
182 TFNumberHeader =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
186 TFFileNameHeader =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
187 reportTFFileName =
true;
189 requestedTables.emplace_back(route);
193 auto fileCounter = std::make_shared<int>(0);
194 auto numTF = std::make_shared<int>(-1);
207 int ntf = *numTF + 1;
208 static int currentFileCounter = -1;
209 static int filesProcessed = 0;
210 if (currentFileCounter != *fileCounter) {
211 currentFileCounter = *fileCounter;
212 monitoring.send(
Metric{(uint64_t)++filesProcessed,
"files-opened"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
217 static size_t totalSizeUncompressed = 0;
218 static size_t totalSizeCompressed = 0;
219 static uint64_t totalDFSent = 0;
222 if (!watchdog->update()) {
223 LOGP(info,
"Run time exceeds run time limit of {} seconds. Exiting gracefully...", watchdog->runTimeLimit);
224 LOGP(info,
"Stopping reader {} after time frame {}.", device.
inputTimesliceId, watchdog->numberTimeFrames - 1);
225 didir->closeInputFiles();
226 monitoring.flushBuffer();
232 int64_t startTime = uv_hrtime();
233 int64_t startSize = totalSizeCompressed;
234 for (
auto& route : requestedTables) {
241 auto dh =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
243 if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed)) {
247 if (didir->atEnd(fcnt)) {
248 LOGP(info,
"No input files left to read for reader {}!", device.
inputTimesliceId);
249 didir->closeInputFiles();
250 monitoring.flushBuffer();
257 if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed)) {
258 LOGP(fatal,
"Can not retrieve tree for table {}: fileCounter {}, timeFrame {}", concrete.origin.as<std::string>(), fcnt, ntf);
259 throw std::runtime_error(
"Processing is stopped!");
262 LOGP(fatal,
"Can not retrieve tree for table {}: fileCounter {}, timeFrame {}", concrete.origin.as<std::string>(), fcnt, ntf);
263 throw std::runtime_error(
"Processing is stopped!");
270 auto timeFrameNumber = didir->getTimeFrameNumber(dh, fcnt, ntf);
271 auto o =
Output(TFNumberHeader);
272 outputs.
make<uint64_t>(o) = timeFrameNumber;
275 if (reportTFFileName) {
278 auto fileAndFolder = didir->getFileFolder(dh, fcnt, ntf);
279 auto rootFS = std::dynamic_pointer_cast<TFileFileSystem>(fileAndFolder.filesystem());
280 auto*
f =
dynamic_cast<TFile*
>(rootFS->GetFile());
281 std::string currentFilename(
f->GetFile()->GetName());
282 if (strcmp(
f->GetEndpointUrl()->GetProtocol(),
"file") == 0 &&
f->GetEndpointUrl()->GetFile()[0] !=
'/') {
284 static std::string pwd = gSystem->pwd() + std::string(
"/");
285 currentFilename = pwd + std::string(
f->GetName());
287 outputs.
make<std::string>(
o2) = currentFilename;
292 int64_t stopSize = totalSizeCompressed;
293 int64_t bytesDelta = stopSize - startSize;
294 int64_t stopTime = uv_hrtime();
295 float currentDelta = float(stopTime - startTime) / 1000000000;
296 if (ceil(maxRate) > 0.) {
297 float extraTime = (bytesDelta / 1000000 - currentDelta * maxRate) / maxRate;
299 if (extraTime > 0.) {
300 LOGP(info,
"Read {} MB in {} s. Sleeping for {} seconds to stay within {} MB/s limit.", bytesDelta / 1000000, currentDelta, extraTime, maxRate);
301 uv_sleep(extraTime * 1000);
305 monitoring.send(
Metric{(uint64_t)totalDFSent,
"df-sent"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
306 monitoring.send(
Metric{(uint64_t)totalSizeUncompressed / 1000,
"aod-bytes-read-uncompressed"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
307 monitoring.send(
Metric{(uint64_t)totalSizeCompressed / 1000,
"aod-bytes-read-compressed"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
317 auto& firstRoute = requestedTables.front();
319 auto dh =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
320 auto fileAndFolder = didir->getFileFolder(dh, fcnt, ntf);
323 if (fileAndFolder.path().empty()) {
326 if (didir->atEnd(fcnt)) {
327 LOGP(info,
"No input files left to read for reader {}!", device.
inputTimesliceId);
328 didir->closeInputFiles();
329 monitoring.flushBuffer();