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

class  AccessedFile
 Helper class storing information about the accessed files. More...

Public Member Functions

 TFileAccessTracer ()
 Default constructor.
 ~TFileAccessTracer ()
 Destructor.
void add (const ::TFile &file)
 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_t monitoredFraction () const
 Fraction of jobs that should send monitoring information.
void setMonitoredFraction (::Double_t value)
 Set the fraction of jobs that should send monitoring information.

Static Public Member Functions

static void enableDataSubmission (::Bool_t value)
 Function for turning data submission on/off.

Private Attributes

std::set< AccessedFilem_accessedFiles
 List of all the input files that were accessed in the job.
std::string m_serverAddress
 Address of the server to send monitoring information to.
::TInetAddress m_serverInetAddress
 Technical address of the server.
::Double_t m_monitoredFraction
 Fraction of jobs that should send monitoring information.
ReadStatsm_readStats
 Object describing the job's xAOD access statistics.
std::mutex m_mutex
 Mutex for modifying the object.

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 uses this class to send information about xAOD access to the central Rucio monitoring infrastructure. This default behaviour can be influenced in two ways:

  • Use the TFileAccessTrancer::enableDataSubmission function to disable data submission from a particular application;
  • Set the environment variable "XAOD_ACCESSTRACER_FRACTION" to a floating point value, which is the fraction of jobs that should be monitored within that session. This is mostly for grid purposes...
Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h

Definition at line 46 of file TFileAccessTracer.h.

Constructor & Destructor Documentation

◆ TFileAccessTracer()

xAOD::TFileAccessTracer::TFileAccessTracer ( )

Default constructor.

Definition at line 30 of file TFileAccessTracer.cxx.

32 m_serverAddress( "http://rucio-lb-prod.cern.ch:18762/traces/" ),
36
37 // Construct the "technical address" of the host:
38 const ::TUrl url( m_serverAddress.c_str() );
39 m_serverInetAddress = gSystem->GetHostByName( url.GetHost() );
40 }
static IOStats & instance()
Singleton object accessor.
Definition IOStats.cxx:11
::Double_t m_monitoredFraction
Fraction of jobs that should send monitoring information.
ReadStats * m_readStats
Object describing the job's xAOD access statistics.
::TInetAddress m_serverInetAddress
Technical address of the server.
std::set< AccessedFile > m_accessedFiles
List of all the input files that were accessed in the job.
std::string m_serverAddress
Address of the server to send monitoring information to.

◆ ~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 48 of file TFileAccessTracer.cxx.

48 {
49
50 // If the user turned off the data submission, then stop already here...
52 return;
53 }
54
55 // Decide what monitoring fraction to take. To make it possible for Panda
56 // to override it with larger/smaller values if needed.
58 const char* fractionString =
59 gSystem->Getenv( "XAOD_ACCESSTRACER_FRACTION" );
60 if( fractionString ) {
61 char* endptr = 0;
62 const Double_t fraction = strtod( fractionString, &endptr );
63 if( endptr != fractionString ) {
64 monitoredFraction = fraction;
65 }
66 }
67
68 // Decide randomly whether to send the monitoring data or not. While
69 // TRandom is not good enough for statistical purposes, it's fast, and is
70 // perfectly good to make this decision...
71 ::TRandom rng( ::TTimeStamp().GetNanoSec() );
72 if( rng.Rndm() > monitoredFraction ) {
73 return;
74 }
75
76 // Open a socket to the server:
77 const ::TUrl url( m_serverAddress.c_str() );
78 TSocket socket;
79 if( ! socket.connect( m_serverInetAddress, url.GetPort() ).isSuccess() ) {
80 // Just exit silently. If we can't send the info, we can't send the
81 // info. It's not a problem.
82 return;
83 }
84
85 // Let the user know what's happening:
86 ::Info( "xAOD::TFileAccessTracer",
87 "Sending file access statistics to %s", m_serverAddress.c_str() );
88
89 // Start constructing the header of the message to send to the server:
90 ::TString hdr = "POST /";
91 hdr += url.GetFile();
92 hdr += " HTTP/1.0";
93 hdr += "\r\n";
94 hdr += "From: ";
95 hdr += gSystem->HostName();
96 hdr += "\r\n";
97 hdr += "User-Agent: xAODRootAccess\r\n";
98 hdr += "Content-Type: application/json\r\n";
99 hdr += "Content-Length: ";
100
101 //
102 // Now construct the message payload:
103 //
104 ::TString pld = "{";
105
106 //
107 // Collect the names of all the accessed files:
108 //
109 pld += "\"accessedFiles\": [";
110 bool first = true;
111 for( auto& info : m_accessedFiles ) {
112 if( ! first ) {
113 pld += ", ";
114 }
115 pld += "\"";
116 pld += info.fullFilePath();
117 pld += "\"";
118 first = false;
119 }
120 pld += "], ";
121 //
122 // Collect the names of all the containers that were accessed:
123 //
124 pld += "\"accessedContainers\": [";
125 first = true;
126 for( const auto& bs : m_readStats->containers() ) {
127 if( ! bs.second.readEntries() ) {
128 continue;
129 }
130 if( ! first ) {
131 pld += ", ";
132 }
133 pld += "{\"";
134 pld += bs.second.GetName();
135 pld += "\": ";
136 pld += bs.second.readEntries();
137 pld += "}";
138 first = false;
139 }
140 pld += "], ";
141 //
142 // Collect the names of all the branches that were accessed:
143 //
144 pld += "\"accessedBranches\": [";
145 first = true;
146 for( const auto& branch : m_readStats->branches() ) {
147 for( const xAOD::BranchStats* bs : branch.second ) {
148 if( ( ! bs ) || ( ! bs->readEntries() ) ) {
149 continue;
150 }
151 if( ! first ) {
152 pld += ", ";
153 }
154 pld += "{\"";
155 pld += bs->GetName();
156 pld += "\": ";
157 pld += bs->readEntries();
158 pld += "}";
159 first = false;
160 }
161 }
162 pld += "]";
163 //
164 // Collect some possible Panda information in case the job is running
165 // on the grid:
166 //
167 const char* pandaID = gSystem->Getenv( "PandaID" );
168 if( pandaID ) {
169 pld += ", \"PandaID\": ";
170 pld += pandaID;
171 pld += "";
172 }
173 const char* taskID = gSystem->Getenv( "PanDA_TaskID" );
174 if( taskID ) {
175 pld += ", \"PanDA_TaskID\": ";
176 pld += taskID;
177 pld += "";
178 }
179 //
180 // Add some simple information about the host:
181 //
182 pld += ", \"ROOT_RELEASE\": \"";
183 pld += ROOT_RELEASE;
184 pld += "\"";
185 pld += ", \"ReportRate\": ";
186 pld += monitoredFraction;
187 //
188 // Add some information about the file access pattern:
189 //
190 pld += ", \"ReadCalls\": ";
191 pld += m_readStats->fileReads();
192 pld += ", \"ReadSize\": ";
193 pld += ( m_readStats->fileReads() != 0 ?
194 m_readStats->bytesRead() / m_readStats->fileReads() : 0 );
195 pld += ", \"CacheSize\": ";
196 pld += m_readStats->cacheSize();
197 pld += "}";
198
199 // Now finish constructing the header, and merge the two into a single
200 // message:
201 hdr += TString::Format( "%i", pld.Length() );
202 hdr += "\r\n\r\n";
203 const ::TString msg = hdr + pld;
204
205 // A debug message for the time being:
206 /*
207 Info( "xAOD::TFileAccessTracer::~TFileAccessTracer",
208 "Sending message:\n\n%s", msg.Data() );
209 */
210
211 // Finally, send the message:
212 if( ! socket.send( msg ).isSuccess() ) {
213 // Don't be vocal about the issue...
214 return;
215 }
216 }
::Long64_t readEntries() const
Get how many entries were read from this branch.
::Double_t monitoredFraction() const
Fraction of jobs that should send monitoring information.
uint32_t rng()
Definition FillerAlg.cxx:40
bool first
Definition DeMoScan.py:534
static std::atomic_bool s_enableDataSumbission(true)
MsgStream & msg
Definition testRead.cxx:32

Member Function Documentation

◆ add()

void xAOD::TFileAccessTracer::add ( const ::TFile & file)

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
fileThe file object that is being read from

Definition at line 223 of file TFileAccessTracer.cxx.

223 {
224
225 // Protect this call:
226 std::lock_guard< std::mutex > lock( m_mutex );
227
228 // Remember this file:
229 m_accessedFiles.insert(
230 AccessedFile{ gSystem->DirName( file.GetName() ),
231 gSystem->BaseName( file.GetName() ) } );
232
233 // Return gracefully:
234 return;
235 }
Helper class storing information about the accessed files.
std::mutex m_mutex
Mutex for modifying the object.
TFile * file

◆ enableDataSubmission()

void xAOD::TFileAccessTracer::enableDataSubmission ( ::Bool_t value)
static

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 281 of file TFileAccessTracer.cxx.

281 {
282
284 return;
285 }

◆ monitoredFraction()

Double_t xAOD::TFileAccessTracer::monitoredFraction ( ) const

Fraction of jobs that should send monitoring information.

Definition at line 259 of file TFileAccessTracer.cxx.

259 {
260
261 // Protect this call:
262 std::lock_guard< std::mutex > lock( m_mutex );
263
264 return m_monitoredFraction;
265 }

◆ serverAddress()

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

The address of the server that information is sent to.

Definition at line 237 of file TFileAccessTracer.cxx.

237 {
238
239 // Protect this call:
240 std::lock_guard< std::mutex > lock( m_mutex );
241
242 return m_serverAddress;
243 }

◆ setMonitoredFraction()

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

Set the fraction of jobs that should send monitoring information.

Definition at line 267 of file TFileAccessTracer.cxx.

267 {
268
269 // Protect this call:
270 std::lock_guard< std::mutex > lock( m_mutex );
271
273 return;
274 }

◆ setServerAddress()

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

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

Definition at line 245 of file TFileAccessTracer.cxx.

245 {
246
247 // Protect this call:
248 std::lock_guard< std::mutex > lock( m_mutex );
249
250 // Set the address itself:
251 m_serverAddress = addr;
252
253 // Construct the "technical address" of the host:
254 ::TUrl url( m_serverAddress.c_str() );
255 m_serverInetAddress = gSystem->GetHostByName( url.GetHost() );
256 return;
257 }

Member Data Documentation

◆ m_accessedFiles

std::set< AccessedFile > xAOD::TFileAccessTracer::m_accessedFiles
private

List of all the input files that were accessed in the job.

Definition at line 85 of file TFileAccessTracer.h.

◆ m_monitoredFraction

::Double_t xAOD::TFileAccessTracer::m_monitoredFraction
private

Fraction of jobs that should send monitoring information.

Definition at line 93 of file TFileAccessTracer.h.

◆ m_mutex

std::mutex xAOD::TFileAccessTracer::m_mutex
mutableprivate

Mutex for modifying the object.

Definition at line 99 of file TFileAccessTracer.h.

◆ m_readStats

ReadStats* xAOD::TFileAccessTracer::m_readStats
private

Object describing the job's xAOD access statistics.

Definition at line 96 of file TFileAccessTracer.h.

◆ m_serverAddress

std::string xAOD::TFileAccessTracer::m_serverAddress
private

Address of the server to send monitoring information to.

Definition at line 88 of file TFileAccessTracer.h.

◆ m_serverInetAddress

::TInetAddress xAOD::TFileAccessTracer::m_serverInetAddress
private

Technical address of the server.

Definition at line 90 of file TFileAccessTracer.h.


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