ATLAS Offline Software
Loading...
Searching...
No Matches
xAOD::TFileAccessTracer Class Reference

Helper class keeping track of the files that got accessed. More...

#include <TFileAccessTracer.h>

Collaboration diagram for xAOD::TFileAccessTracer:

Classes

struct  Impl

Public Member Functions

 ~TFileAccessTracer ()
 Destructor.
void add (std::string_view fileName)
 Add information about a new file that got accessed.
const std::string & serverAddress () const
 The address of the server that information is sent to.
void setServerAddress (const std::string &addr)
 Set the address of the server that information is sent to.
double monitoredFraction () const
 Fraction of jobs that should send monitoring information.
void setMonitoredFraction (double value)
 Set the fraction of jobs that should send monitoring information.
void enableDataSubmission (bool value)
 Function for turning data submission on/off.

Static Public Member Functions

static TFileAccessTracerinstance ()
 Access the singleton instance of this class.

Private Member Functions

 TFileAccessTracer ()
 Default constructor.

Private Attributes

std::unique_ptr< Implm_impl
 Pointer to the implementation of the class.

Detailed Description

Helper class keeping track of the files that got accessed.

This class helps in keeping track of which files get accessed during a job. To be able to report about them to the DDM (Rucio) system in a way that doesn't rely on the grid middleware. (So backdoor access to files stored at data centres becomes visible to the DDM system.)

The class can also send information about which branches/variables got accessed in the job. This it simply gets from the xAODCore code.

xAOD::TEvent and xAOD::REvent use this class to send information about xAOD access to the central Rucio monitoring infrastructure. This default behaviour can be influenced in two ways:

  • Using the the public functions on the singleton instance of this class;
  • Setting the following environment variables before running a job:
    • "XAOD_ACCESSTRACER_FRACTION": This is a floating point value, which is the fraction of jobs that should be monitored within that session.
    • "XAOD_ACCESSTRACER_SERVER": This is the address of the server to which the monitoring information should be sent.

Definition at line 37 of file TFileAccessTracer.h.

Constructor & Destructor Documentation

◆ ~TFileAccessTracer()

xAOD::TFileAccessTracer::~TFileAccessTracer ( )

Destructor.

The destructor of the class is the one doing most of the heavy lifting.

If the $SEND_XAOD_FILE_ACCESS_STAT environment variable is set when the object gets deleted, it posts all the information it collected, to the address defined by SERVER_ADDRESS. By constructing an HTTP message from scratch.

Definition at line 81 of file TFileAccessTracer.cxx.

81 {
82
83 // If the user turned off the data submission, then stop already here...
84 if (m_impl->m_enableDataSumbission == false) {
85 return;
86 }
87
88 // Decide what monitoring fraction to take. To make it possible for Panda
89 // to override it with larger/smaller values if needed.
90 double monitoredFraction = m_impl->m_monitoredFraction;
91 const char* fractionString = gSystem->Getenv("XAOD_ACCESSTRACER_FRACTION");
92 if (fractionString) {
93 char* endptr = 0;
94 const double fraction = strtod(fractionString, &endptr);
95 if (endptr != fractionString) {
96 monitoredFraction = fraction;
97 }
98 }
99
100 // Decide randomly whether to send the monitoring data or not. While
101 // TRandom is not good enough for statistical purposes, it's fast, and is
102 // perfectly good to make this decision...
103 ::TRandom rng(::TTimeStamp().GetNanoSec());
104 if (rng.Rndm() > monitoredFraction) {
105 return;
106 }
107
108 // Decide what server to send the information to. To make it possible for
109 // Panda to override it if needed.
110 std::string serverAddress = m_impl->m_serverAddress;
111 const char* serverAddressString = gSystem->Getenv("XAOD_ACCESSTRACER_SERVER");
112 if (serverAddressString) {
113 serverAddress = serverAddressString;
114 }
115
116 // Construct the "technical address" of the host:
117 const ::TUrl url(serverAddress.c_str());
118 const ::TInetAddress serverInetAddress =
119 gSystem->GetHostByName(url.GetHost());
120
121 // Open a socket to the server:
122 TSocket socket;
123 if (socket.connect(serverInetAddress, url.GetPort()).isSuccess() == false) {
124 // Just exit silently. If we can't send the info, we can't send the
125 // info. It's not a problem.
126 return;
127 }
128
129 // Let the user know what's happening:
130 ::Info("xAOD::TFileAccessTracer", "Sending file access statistics to %s",
131 serverAddress.c_str());
132
133 // Start constructing the header of the message to send to the server:
134 ::TString hdr = "POST /";
135 hdr += url.GetFile();
136 hdr += " HTTP/1.0";
137 hdr += "\r\n";
138 hdr += "From: ";
139 hdr += gSystem->HostName();
140 hdr += "\r\n";
141 hdr += "User-Agent: xAODRootAccess\r\n";
142 hdr += "Content-Type: application/json\r\n";
143 hdr += "Content-Length: ";
144
145 //
146 // Now construct the message payload:
147 //
148 ::TString pld = "{";
149
150 //
151 // Collect the names of all the accessed files:
152 //
153 pld += "\"accessedFiles\": [";
154 bool first = true;
155 for (const Impl::AccessedFile& info : m_impl->m_accessedFiles) {
156 if (!first) {
157 pld += ", ";
158 }
159 pld += "\"";
160 pld += info.fullFilePath();
161 pld += "\"";
162 first = false;
163 }
164 pld += "], ";
165 //
166 // Collect the names of all the containers that were accessed:
167 //
168 pld += "\"accessedContainers\": [";
169 first = true;
170 for (const auto& bs : m_impl->m_readStats.containers()) {
171 if (!bs.second.readEntries()) {
172 continue;
173 }
174 if (!first) {
175 pld += ", ";
176 }
177 pld += "{\"";
178 pld += bs.second.GetName();
179 pld += "\": ";
180 pld += bs.second.readEntries();
181 pld += "}";
182 first = false;
183 }
184 pld += "], ";
185 //
186 // Collect the names of all the branches that were accessed:
187 //
188 pld += "\"accessedBranches\": [";
189 first = true;
190 for (const auto& branch : m_impl->m_readStats.branches()) {
191 for (const xAOD::BranchStats* bs : branch.second) {
192 if ((!bs) || (!bs->readEntries())) {
193 continue;
194 }
195 if (!first) {
196 pld += ", ";
197 }
198 pld += "{\"";
199 pld += bs->GetName();
200 pld += "\": ";
201 pld += bs->readEntries();
202 pld += "}";
203 first = false;
204 }
205 }
206 pld += "]";
207 //
208 // Collect some possible Panda information in case the job is running
209 // on the grid:
210 //
211 const char* pandaID = gSystem->Getenv("PandaID");
212 if (pandaID) {
213 pld += ", \"PandaID\": ";
214 pld += pandaID;
215 pld += "";
216 }
217 const char* taskID = gSystem->Getenv("PanDA_TaskID");
218 if (taskID) {
219 pld += ", \"PanDA_TaskID\": ";
220 pld += taskID;
221 pld += "";
222 }
223 //
224 // Add some simple information about the host:
225 //
226 pld += ", \"ROOT_RELEASE\": \"";
227 pld += ROOT_RELEASE;
228 pld += "\"";
229 pld += ", \"ReportRate\": ";
230 pld += monitoredFraction;
231 //
232 // Add some information about the file access pattern:
233 //
234 pld += ", \"ReadCalls\": ";
235 pld += m_impl->m_readStats.fileReads();
236 pld += ", \"ReadSize\": ";
237 pld +=
238 (m_impl->m_readStats.fileReads() != 0
239 ? m_impl->m_readStats.bytesRead() / m_impl->m_readStats.fileReads()
240 : 0);
241 pld += ", \"CacheSize\": ";
242 pld += m_impl->m_readStats.cacheSize();
243 pld += "}";
244
245 // Now finish constructing the header, and merge the two into a single
246 // message:
247 hdr += TString::Format("%i", pld.Length());
248 hdr += "\r\n\r\n";
249 const ::TString msg = hdr + pld;
250
251 // Finally, send the message:
252 socket.send(msg).ignore();
253}
::Long64_t readEntries() const
Get how many entries were read from this branch.
double monitoredFraction() const
Fraction of jobs that should send monitoring information.
const std::string & serverAddress() const
The address of the server that information is sent to.
std::unique_ptr< Impl > m_impl
Pointer to the implementation of the class.
uint32_t rng()
Definition FillerAlg.cxx:40
bool first
Definition DeMoScan.py:534
Helper struct storing information about the accessed files.
MsgStream & msg
Definition testRead.cxx:32

◆ TFileAccessTracer()

xAOD::TFileAccessTracer::TFileAccessTracer ( )
private

Default constructor.

Definition at line 319 of file TFileAccessTracer.cxx.

319: m_impl(std::make_unique<Impl>()) {}

Member Function Documentation

◆ add()

void xAOD::TFileAccessTracer::add ( std::string_view fileName)

Add information about a new file that got accessed.

This function is called by TEvent to record which files were read from during the job.

Parameters
fileNameThe name of the file that is being read from

Definition at line 266 of file TFileAccessTracer.cxx.

266 {
267
268 // Protect this call:
269 std::lock_guard<std::mutex> lock(m_impl->m_mutex);
270
271 // Remember this file:
272 m_impl->m_accessedFiles.insert(
273 {gSystem->DirName(fileName.data()), gSystem->BaseName(fileName.data())});
274}

◆ enableDataSubmission()

void xAOD::TFileAccessTracer::enableDataSubmission ( bool value)

Function for turning data submission on/off.

This function can be used by concerned users to turn off data collection and submission for their jobs completely.

Parameters
valueSetting whether data submission should be enabled or not

Definition at line 314 of file TFileAccessTracer.cxx.

314 {
315
316 m_impl->m_enableDataSumbission = value;
317}

◆ instance()

TFileAccessTracer & xAOD::TFileAccessTracer::instance ( )
static

Access the singleton instance of this class.

Definition at line 255 of file TFileAccessTracer.cxx.

255 {
256
258 return instance;
259}
TFileAccessTracer()
Default constructor.
static TFileAccessTracer & instance()
Access the singleton instance of this class.

◆ monitoredFraction()

double xAOD::TFileAccessTracer::monitoredFraction ( ) const

Fraction of jobs that should send monitoring information.

Definition at line 293 of file TFileAccessTracer.cxx.

293 {
294
295 // Protect this call:
296 std::lock_guard<std::mutex> lock(m_impl->m_mutex);
297
298 return m_impl->m_monitoredFraction;
299}

◆ serverAddress()

const std::string & xAOD::TFileAccessTracer::serverAddress ( ) const

The address of the server that information is sent to.

Definition at line 276 of file TFileAccessTracer.cxx.

276 {
277
278 // Protect this call:
279 std::lock_guard<std::mutex> lock(m_impl->m_mutex);
280
281 return m_impl->m_serverAddress;
282}

◆ setMonitoredFraction()

void xAOD::TFileAccessTracer::setMonitoredFraction ( double value)

Set the fraction of jobs that should send monitoring information.

Definition at line 301 of file TFileAccessTracer.cxx.

301 {
302
303 // Protect this call:
304 std::lock_guard<std::mutex> lock(m_impl->m_mutex);
305
306 m_impl->m_monitoredFraction = value;
307}

◆ setServerAddress()

void xAOD::TFileAccessTracer::setServerAddress ( const std::string & addr)

Set the address of the server that information is sent to.

Definition at line 284 of file TFileAccessTracer.cxx.

284 {
285
286 // Protect this call:
287 std::lock_guard<std::mutex> lock(m_impl->m_mutex);
288
289 // Set the address itself:
290 m_impl->m_serverAddress = addr;
291}

Member Data Documentation

◆ m_impl

std::unique_ptr<Impl> xAOD::TFileAccessTracer::m_impl
private

Pointer to the implementation of the class.

Definition at line 69 of file TFileAccessTracer.h.


The documentation for this class was generated from the following files: