14#include <TTimeStamp.h>
84 std::lock_guard<std::mutex> lock(
m_impl->m_mutex);
87 if (
m_impl->m_enableDataSumbission ==
false) {
94 const char* fractionString = gSystem->Getenv(
"XAOD_ACCESSTRACER_FRACTION");
97 const double fraction = strtod(fractionString, &endptr);
98 if (endptr != fractionString) {
106 ::TRandom rng(::TTimeStamp().GetNanoSec());
114 const char* serverAddressString = gSystem->Getenv(
"XAOD_ACCESSTRACER_SERVER");
115 if (serverAddressString) {
121 const ::TInetAddress serverInetAddress =
122 gSystem->GetHostByName(url.GetHost());
126 if (socket.
connect(serverInetAddress, url.GetPort()).isSuccess() ==
false) {
133 ::Info(
"xAOD::TFileAccessTracer",
"Sending file access statistics to %s",
137 ::TString hdr =
"POST /";
138 hdr += url.GetFile();
139 hdr +=
" HTTP/1.1\r\n";
141 hdr += gSystem->HostName();
144 hdr += url.GetHost();
146 hdr +=
"User-Agent: xAODRootAccess\r\n";
147 hdr +=
"Content-Type: application/json\r\n";
148 hdr +=
"Connection: close\r\n";
149 hdr +=
"Content-Length: ";
159 pld +=
"\"accessedFiles\": [";
166 pld += info.fullFilePath();
174 pld +=
"\"accessedContainers\": [";
176 for (
const auto& bs :
m_impl->m_readStats.containers()) {
177 if (!bs.second.readEntries()) {
184 pld += bs.second.GetName();
186 pld += bs.second.readEntries();
194 pld +=
"\"accessedBranches\": [";
196 for (
const auto& branch :
m_impl->m_readStats.branches()) {
205 pld += bs->GetName();
217 const char* pandaID = gSystem->Getenv(
"PandaID");
219 pld +=
", \"PandaID\": ";
223 const char* taskID = gSystem->Getenv(
"PanDA_TaskID");
225 pld +=
", \"PanDA_TaskID\": ";
232 pld +=
", \"ROOT_RELEASE\": \"";
235 pld +=
", \"ReportRate\": ";
240 pld +=
", \"ReadCalls\": ";
241 pld +=
m_impl->m_readStats.fileReads();
242 pld +=
", \"ReadSize\": ";
244 (
m_impl->m_readStats.fileReads() != 0
245 ?
m_impl->m_readStats.bytesRead() /
m_impl->m_readStats.fileReads()
247 pld +=
", \"CacheSize\": ";
248 pld +=
m_impl->m_readStats.cacheSize();
253 hdr += TString::Format(
"%i", pld.Length());
255 const ::TString
msg = hdr + pld;
277 std::lock_guard<std::mutex> lock(
m_impl->m_mutex);
280 m_impl->m_accessedFiles.insert(
281 {gSystem->DirName(fileName.data()), gSystem->BaseName(fileName.data())});
287 std::lock_guard<std::mutex> lock(
m_impl->m_mutex);
289 return m_impl->m_serverAddress;
295 std::lock_guard<std::mutex> lock(
m_impl->m_mutex);
298 m_impl->m_serverAddress = addr;
304 std::lock_guard<std::mutex> lock(
m_impl->m_mutex);
306 return m_impl->m_monitoredFraction;
312 std::lock_guard<std::mutex> lock(
m_impl->m_mutex);
314 m_impl->m_monitoredFraction = value;
324 m_impl->m_enableDataSumbission = value;
Class describing the access statistics of one (sub-)branch.
::Long64_t readEntries() const
Get how many entries were read from this branch.
ReadStats & stats()
Access the object belonging to the current thread.
static IOStats & instance()
Singleton object accessor.
Class describing the access statistics of a collection of branches.
double monitoredFraction() const
Fraction of jobs that should send monitoring information.
void enableDataSubmission(bool value)
Function for turning data submission on/off.
void setMonitoredFraction(double value)
Set the fraction of jobs that should send monitoring information.
const std::string & serverAddress() const
The address of the server that information is sent to.
void add(std::string_view fileName)
Add information about a new file that got accessed.
~TFileAccessTracer()
Destructor.
TFileAccessTracer()
Default constructor.
void setServerAddress(const std::string &addr)
Set the address of the server that information is sent to.
static TFileAccessTracer & instance()
Access the singleton instance of this class.
std::unique_ptr< Impl > m_impl
Pointer to the implementation of the class.
Very simple wrapper around POSIX sockets.
StatusCode send(const TString &payload)
Function sending a message to the connected address.
StatusCode connect(const TInetAddress &address, int port)
Function connecting to the specified address.
StatusCode receive(std::size_t maxSize, TString &response)
Function receiving a message from the connected address.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Helper struct storing information about the accessed files.
std::string m_filePath
The full path to the file.
bool operator<(const AccessedFile &rhs) const
Operator to be able to put this into an std::set.
std::string fullFilePath() const
Function returning the full file path.
std::string m_fileName
The name of the file.
std::atomic_bool m_enableDataSumbission
Overall flag for enabling/disabling the data submission.
std::set< AccessedFile > m_accessedFiles
List of all the input files that were accessed in the job.
const ReadStats & m_readStats
Permanent reference to the job's ReadStats object.
std::string m_serverAddress
Address of the server to send monitoring information to.
double m_monitoredFraction
Fraction of jobs that should send monitoring information.
std::mutex m_mutex
Mutex for modifying the object.