106 std::string parentFileReplacement;
107 if (ctx.
options().
isSet(
"aod-parent-base-path-replacement")) {
108 parentFileReplacement = ctx.
options().
get<std::string>(
"aod-parent-base-path-replacement");
110 int parentAccessLevel = 0;
112 parentAccessLevel = ctx.
options().
get<
int>(
"aod-parent-access-level");
127 if (!options.
isSet(
"aod-file-private")) {
128 LOGP(fatal,
"No input file defined!");
129 throw std::runtime_error(
"Processing is stopped!");
132 auto filename = options.
get<std::string>(
"aod-file-private");
134 auto maxRate = options.
get<
float>(
"aod-max-io-rate");
137 auto didir = std::make_shared<DataInputDirector>(
filename, &monitoring, parentAccessLevel, parentFileReplacement);
138 if (options.
isSet(
"aod-reader-json")) {
139 auto jsonFile = options.
get<std::string>(
"aod-reader-json");
140 if (!didir->readJson(jsonFile)) {
141 LOGP(error,
"Check the JSON document! Can not be properly parsed!");
150 bool reportTFN =
false;
151 bool reportTFFileName =
false;
154 std::vector<OutputRoute> requestedTables;
156 for (
auto route :
routes) {
159 TFNumberHeader =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
163 TFFileNameHeader =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
164 reportTFFileName =
true;
166 requestedTables.emplace_back(route);
170 auto fileCounter = std::make_shared<int>(0);
171 auto numTF = std::make_shared<int>(-1);
184 int ntf = *numTF + 1;
185 static int currentFileCounter = -1;
186 static int filesProcessed = 0;
187 if (currentFileCounter != *fileCounter) {
188 currentFileCounter = *fileCounter;
189 monitoring.send(
Metric{(uint64_t)++filesProcessed,
"files-opened"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
194 static size_t totalSizeUncompressed = 0;
195 static size_t totalSizeCompressed = 0;
196 static uint64_t totalDFSent = 0;
199 if (!watchdog->update()) {
200 LOGP(info,
"Run time exceeds run time limit of {} seconds. Exiting gracefully...", watchdog->runTimeLimit);
201 LOGP(info,
"Stopping reader {} after time frame {}.", device.
inputTimesliceId, watchdog->numberTimeFrames - 1);
202 didir->closeInputFiles();
203 monitoring.flushBuffer();
209 int64_t startTime = uv_hrtime();
210 int64_t startSize = totalSizeCompressed;
211 for (
auto& route : requestedTables) {
218 auto dh =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
220 if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed)) {
224 if (didir->atEnd(fcnt)) {
225 LOGP(info,
"No input files left to read for reader {}!", device.
inputTimesliceId);
226 didir->closeInputFiles();
227 monitoring.flushBuffer();
234 if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed)) {
235 LOGP(fatal,
"Can not retrieve tree for table {}: fileCounter {}, timeFrame {}", concrete.origin.as<std::string>(), fcnt, ntf);
236 throw std::runtime_error(
"Processing is stopped!");
239 LOGP(fatal,
"Can not retrieve tree for table {}: fileCounter {}, timeFrame {}", concrete.origin.as<std::string>(), fcnt, ntf);
240 throw std::runtime_error(
"Processing is stopped!");
247 auto timeFrameNumber = didir->getTimeFrameNumber(dh, fcnt, ntf);
248 auto o =
Output(TFNumberHeader);
249 outputs.
make<uint64_t>(o) = timeFrameNumber;
252 if (reportTFFileName) {
255 auto fileAndFolder = didir->getFileFolder(dh, fcnt, ntf);
256 auto rootFS = std::dynamic_pointer_cast<TFileFileSystem>(fileAndFolder.filesystem());
257 auto*
f =
dynamic_cast<TFile*
>(rootFS->GetFile());
258 std::string currentFilename(
f->GetFile()->GetName());
259 if (strcmp(
f->GetEndpointUrl()->GetProtocol(),
"file") == 0 &&
f->GetEndpointUrl()->GetFile()[0] !=
'/') {
261 static std::string pwd = gSystem->pwd() + std::string(
"/");
262 currentFilename = pwd + std::string(
f->GetName());
264 outputs.
make<std::string>(
o2) = currentFilename;
269 int64_t stopSize = totalSizeCompressed;
270 int64_t bytesDelta = stopSize - startSize;
271 int64_t stopTime = uv_hrtime();
272 float currentDelta = float(stopTime - startTime) / 1000000000;
273 if (ceil(maxRate) > 0.) {
274 float extraTime = (bytesDelta / 1000000 - currentDelta * maxRate) / maxRate;
276 if (extraTime > 0.) {
277 LOGP(info,
"Read {} MB in {} s. Sleeping for {} seconds to stay within {} MB/s limit.", bytesDelta / 1000000, currentDelta, extraTime, maxRate);
278 uv_sleep(extraTime * 1000);
286 monitoring.send(
Metric{(uint64_t)totalDFSent,
"df-sent"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
287 monitoring.send(
Metric{(uint64_t)totalSizeUncompressed / 1000,
"aod-bytes-read-uncompressed"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
288 monitoring.send(
Metric{(uint64_t)totalSizeCompressed / 1000,
"aod-bytes-read-compressed"}.addTag(Key::Subsystem, monitoring::tags::Value::DPL));
298 auto& firstRoute = requestedTables.front();
300 auto dh =
header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
301 auto fileAndFolder = didir->getFileFolder(dh, fcnt, ntf);
304 if (fileAndFolder.path().empty()) {
307 if (didir->atEnd(fcnt)) {
308 LOGP(info,
"No input files left to read for reader {}!", device.
inputTimesliceId);
309 didir->closeInputFiles();
310 monitoring.flushBuffer();