126 std::string parentFileReplacement;
127 if (ctx.
options().
isSet(
"aod-parent-base-path-replacement")) {
128 parentFileReplacement = ctx.
options().
get<std::string>(
"aod-parent-base-path-replacement");
130 int parentAccessLevel = 0;
132 parentAccessLevel = ctx.
options().
get<
int>(
"aod-parent-access-level");
146 if (!options.
isSet(
"aod-file-private")) {
147 LOGP(fatal,
"No input file defined!");
148 throw std::runtime_error(
"Processing is stopped!");
151 auto filename = options.
get<std::string>(
"aod-file-private");
153 auto maxRate = options.
get<
float>(
"aod-max-io-rate");
156 auto didir = std::make_shared<DataInputDirector>(
filename, &monitoring, parentAccessLevel, parentFileReplacement);
157 if (options.
isSet(
"aod-reader-json")) {
158 auto jsonFile = options.
get<std::string>(
"aod-reader-json");
159 if (!didir->readJson(jsonFile)) {
160 LOGP(error,
"Check the JSON document! Can not be properly parsed!");
169 bool reportTFN =
false;
170 bool reportTFFileName =
false;
173 std::vector<OutputRoute> requestedTables;
174 std::vector<OutputRoute> routes(spec.
outputs);
175 for (
auto route : routes) {
178 TFNumberHeader =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
182 TFFileNameHeader =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
183 reportTFFileName =
true;
185 requestedTables.emplace_back(route);
189 auto fileCounter = std::make_shared<int>(0);
190 auto numTF = std::make_shared<int>(-1);
203 int ntf = *numTF + 1;
204 static int currentFileCounter = -1;
205 static int filesProcessed = 0;
206 if (currentFileCounter != *fileCounter) {
207 currentFileCounter = *fileCounter;
208 monitoring.send(
Metric{(uint64_t)++filesProcessed,
"files-opened"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
213 static size_t totalSizeUncompressed = 0;
214 static size_t totalSizeCompressed = 0;
215 static uint64_t totalDFSent = 0;
218 if (!watchdog->update()) {
219 LOGP(info,
"Run time exceeds run time limit of {} seconds. Exiting gracefully...", watchdog->runTimeLimit);
220 LOGP(info,
"Stopping reader {} after time frame {}.", device.
inputTimesliceId, watchdog->numberTimeFrames - 1);
221 didir->closeInputFiles();
222 monitoring.flushBuffer();
228 int64_t startTime = uv_hrtime();
229 int64_t startSize = totalSizeCompressed;
230 for (
auto& route : requestedTables) {
237 auto dh =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
239 if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed)) {
243 if (didir->atEnd(fcnt)) {
244 LOGP(info,
"No input files left to read for reader {}!", device.
inputTimesliceId);
245 didir->closeInputFiles();
246 monitoring.flushBuffer();
253 if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed)) {
254 LOGP(fatal,
"Can not retrieve tree for table {}: fileCounter {}, timeFrame {}", concrete.origin.as<std::string>(), fcnt, ntf);
255 throw std::runtime_error(
"Processing is stopped!");
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!");
266 auto timeFrameNumber = didir->getTimeFrameNumber(dh, fcnt, ntf);
267 auto o =
Output(TFNumberHeader);
268 outputs.
make<uint64_t>(
o) = timeFrameNumber;
271 if (reportTFFileName) {
274 auto fileAndFolder = didir->getFileFolder(dh, fcnt, ntf);
275 std::string currentFilename(fileAndFolder.file->GetName());
276 if (strcmp(fileAndFolder.file->GetEndpointUrl()->GetProtocol(),
"file") == 0 && fileAndFolder.file->GetEndpointUrl()->GetFile()[0] !=
'/') {
278 static std::string pwd = gSystem->pwd() + std::string(
"/");
279 currentFilename = pwd + std::string(fileAndFolder.file->GetName());
281 outputs.
make<std::string>(
o2) = currentFilename;
286 int64_t stopSize = totalSizeCompressed;
287 int64_t bytesDelta = stopSize - startSize;
288 int64_t stopTime = uv_hrtime();
289 float currentDelta = float(stopTime - startTime) / 1000000000;
290 if (ceil(maxRate) > 0.) {
291 float extraTime = (bytesDelta / 1000000 - currentDelta * maxRate) / maxRate;
293 if (extraTime > 0.) {
294 LOGP(info,
"Read {} MB in {} s. Sleeping for {} seconds to stay within {} MB/s limit.", bytesDelta / 1000000, currentDelta, extraTime, maxRate);
295 uv_sleep(extraTime * 1000);
299 monitoring.send(
Metric{(uint64_t)totalDFSent,
"df-sent"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
300 monitoring.send(
Metric{(uint64_t)totalSizeUncompressed / 1000,
"aod-bytes-read-uncompressed"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
301 monitoring.send(
Metric{(uint64_t)totalSizeCompressed / 1000,
"aod-bytes-read-compressed"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
311 auto& firstRoute = requestedTables.front();
313 auto dh =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
314 auto fileAndFolder = didir->getFileFolder(dh, fcnt, ntf);
315 if (!fileAndFolder.file) {
318 if (didir->atEnd(fcnt)) {
319 LOGP(info,
"No input files left to read for reader {}!", device.
inputTimesliceId);
320 didir->closeInputFiles();
321 monitoring.flushBuffer();