2525#include " Framework/ChannelInfo.h"
2626#include " Framework/Logger.h"
2727
28- #include < Monitoring/Monitoring.h>
29-
3028#include < ROOT/RDataFrame.hxx>
3129#if __has_include(<TJAlienFile.h>)
3230#include < TJAlienFile.h>
@@ -147,6 +145,18 @@ static inline auto extractOriginalsTuple(framework::pack<Os...>, ProcessingConte
147145 return std::make_tuple (extractTypedOriginal<Os>(pc)...);
148146}
149147
148+ void AODJAlienReaderHelpers::dumpFileMetrics (Monitoring& monitoring, TFile* currentFile, int tfPerFile, int tfRead)
149+ {
150+ std::string monitoringInfo (fmt::format (" lfn={},size={},total_tf={},read_tf={},read_bytes={},read_calls={}" , currentFile->GetPath (), currentFile->GetSize (), tfPerFile, tfRead, currentFile->GetBytesRead (), currentFile->GetReadCalls ()));
151+ #if __has_include(<TJAlienFile.h>)
152+ auto alienFile = dynamic_cast <TJAlienFile*>(currentFile);
153+ if (alienFile) {
154+ monitoringInfo += fmt::format (" ,se={}" , alienFile->GetSE ());
155+ }
156+ #endif
157+ monitoring.send (Metric{monitoringInfo, " aod-file-read-info" }.addTag (Key::Subsystem, monitoring::tags::Value::DPL ));
158+ }
159+
150160AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback ()
151161{
152162 auto callback = AlgorithmSpec{adaptStateful ([](ConfigParamRegistry const & options,
@@ -159,7 +169,7 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback()
159169 monitoring.flushBuffer ();
160170
161171 if (!options.isSet (" aod-file" )) {
162- LOGP (ERROR , " No input file defined!" );
172+ LOGP (FATAL , " No input file defined!" );
163173 throw std::runtime_error (" Processing is stopped!" );
164174 }
165175
@@ -199,24 +209,12 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback()
199209 numTF,
200210 watchdog,
201211 didir](Monitoring& monitoring, DataAllocator& outputs, ControlService& control, DeviceSpec const & device) {
202- // check if RuntimeLimit is reached
203- if (!watchdog->update ()) {
204- LOGP (INFO , " Run time exceeds run time limit of {} seconds!" , watchdog->runTimeLimit );
205- LOGP (INFO , " Stopping reader {} after time frame {}." , device.inputTimesliceId , watchdog->numberTimeFrames - 1 );
206- monitoring.flushBuffer ();
207- didir->closeInputFiles ();
208- control.endOfStream ();
209- control.readyToQuit (QuitRequest::Me);
210- return ;
211- }
212-
213212 // Each parallel reader device.inputTimesliceId reads the files fileCounter*device.maxInputTimeslices+device.inputTimesliceId
214213 // the TF to read is numTF
215214 assert (device.inputTimesliceId < device.maxInputTimeslices );
216215 uint64_t timeFrameNumber = 0 ;
217216 int fcnt = (*fileCounter * device.maxInputTimeslices ) + device.inputTimesliceId ;
218217 int ntf = *numTF + 1 ;
219- monitoring.send (Metric{(uint64_t )ntf, " tf-sent" }.addTag (Key::Subsystem, monitoring::tags::Value::DPL ));
220218 static int currentFileCounter = -1 ;
221219 static int filesProcessed = 0 ;
222220 if (currentFileCounter != *fileCounter) {
@@ -225,11 +223,25 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback()
225223 }
226224
227225 // loop over requested tables
228- TTree* tr = nullptr ;
229226 bool first = true ;
230227 static size_t totalSizeUncompressed = 0 ;
231228 static size_t totalSizeCompressed = 0 ;
232- static size_t totalReadCalls = 0 ;
229+ static TFile* currentFile = nullptr ;
230+ static int tfCurrentFile = -1 ;
231+
232+ // check if RuntimeLimit is reached
233+ if (!watchdog->update ()) {
234+ LOGP (INFO , " Run time exceeds run time limit of {} seconds!" , watchdog->runTimeLimit );
235+ LOGP (INFO , " Stopping reader {} after time frame {}." , device.inputTimesliceId , watchdog->numberTimeFrames - 1 );
236+ if (currentFile) {
237+ dumpFileMetrics (monitoring, currentFile, tfCurrentFile, ntf);
238+ }
239+ monitoring.flushBuffer ();
240+ didir->closeInputFiles ();
241+ control.endOfStream ();
242+ control.readyToQuit (QuitRequest::Me);
243+ return ;
244+ }
233245
234246 for (auto route : requestedTables) {
235247
@@ -238,11 +250,12 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback()
238250 auto dh = header::DataHeader (concrete.description , concrete.origin , concrete.subSpec );
239251
240252 // create a TreeToTable object
241- auto info = didir->getFileFolder (dh, fcnt, ntf);
242- size_t before = 0 ;
243- tr = didir->getDataTree (dh, fcnt, ntf);
253+ TTree* tr = didir->getDataTree (dh, fcnt, ntf);
244254 if (!tr) {
245255 if (first) {
256+ // dump metrics of file which is done for reading
257+ dumpFileMetrics (monitoring, currentFile, tfCurrentFile, ntf);
258+
246259 // check if there is a next file to read
247260 fcnt += device.maxInputTimeslices ;
248261 if (didir->atEnd (fcnt)) {
@@ -278,7 +291,6 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback()
278291
279292 // add branches to read
280293 // fill the table
281-
282294 auto colnames = getColumnNames (dh);
283295 if (colnames.size () == 0 ) {
284296 totalSizeCompressed += tr->GetZipBytes ();
@@ -293,35 +305,19 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback()
293305 }
294306 }
295307 t2t.fill (tr);
296- if (info.file ) {
297- totalReadCalls += info.file ->GetReadCalls () - before;
298- static std::string currentFileRead = " " ;
299- std::string nextFileRead = info.file ->GetPath ();
300- if (currentFileRead != nextFileRead) {
301- currentFileRead = nextFileRead;
302- std::string monitoringInfo (currentFileRead);
303- monitoringInfo += " ," ;
304- monitoringInfo += std::to_string (info.file ->GetSize ());
305- #if __has_include(<TJAlienFile.h>)
306- auto alienFile = dynamic_cast <TJAlienFile*>(info.file );
307- if (alienFile) {
308- monitoringInfo += " ," ;
309- monitoringInfo += alienFile->GetSE ();
310- }
311- #endif
312- monitoring.send (Metric{monitoringInfo, " aod-file-read-info" }.addTag (Key::Subsystem, monitoring::tags::Value::DPL ));
313- LOGP (INFO , " File read info: {}" , monitoringInfo);
314- // TODO extend to publish at the end of the file (or on each TF?) the sizes read *per file*
315- }
316- }
317308 monitoring.send (Metric{(double )ps.GetReadCalls (), " aod-tree-read-calls" }.addTag (Key::Subsystem, monitoring::tags::Value::DPL ));
318309 delete tr;
319310
311+ // needed for metrics dumping (upon next file read, or terminate due to watchdog)
312+ auto info = didir->getFileFolder (dh, fcnt, ntf);
313+ currentFile = info.file ;
314+ tfCurrentFile = didir->getTimeFramesInFile (dh, fcnt);
315+
320316 first = false ;
321317 }
318+ monitoring.send (Metric{(uint64_t )ntf, " tf-sent" }.addTag (Key::Subsystem, monitoring::tags::Value::DPL ));
322319 monitoring.send (Metric{(uint64_t )totalSizeUncompressed / 1000 , " aod-bytes-read-uncompressed" }.addTag (Key::Subsystem, monitoring::tags::Value::DPL ));
323320 monitoring.send (Metric{(uint64_t )totalSizeCompressed / 1000 , " aod-bytes-read-compressed" }.addTag (Key::Subsystem, monitoring::tags::Value::DPL ));
324- monitoring.send (Metric{(uint64_t )totalReadCalls, " aod-total-read-calls" }.addTag (Key::Subsystem, monitoring::tags::Value::DPL ));
325321
326322 // save file number and time frame
327323 *fileCounter = (fcnt - device.inputTimesliceId ) / device.maxInputTimeslices ;
0 commit comments