ATLAS Offline Software
Classes | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
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. More...
 
 ~TFileAccessTracer ()
 Destructor. More...
 
void add (const ::TFile &file)
 Add information about a new file that got accessed. More...
 
const std::string & serverAddress () const
 The address of the server that information is sent to. More...
 
void setServerAddress (const std::string &addr)
 Set the address of the server that information is sent to. More...
 
::Double_t monitoredFraction () const
 Fraction of jobs that should send monitoring information. More...
 
void setMonitoredFraction (::Double_t value)
 Set the fraction of jobs that should send monitoring information. More...
 

Static Public Member Functions

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

Private Attributes

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

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:

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.

31  : m_accessedFiles(),
32  m_serverAddress( "http://rucio-lb-prod.cern.ch:18762/traces/" ),
34  m_monitoredFraction( 1.0 ),
35  m_readStats( &( IOStats::instance().stats() ) ) {
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  }

◆ ~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...
51  if( ! s_enableDataSumbission ) {
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 ?
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  }

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  }

◆ 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 
283  s_enableDataSumbission = value;
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:
grepfile.info
info
Definition: grepfile.py:38
xAOD::ReadStats::fileReads
::Int_t fileReads() const
Get the total number of file read calls.
xAOD::ReadStats::bytesRead
::Long64_t bytesRead() const
Get how many bytes were read in total during the analysis.
xAOD::ReadStats::cacheSize
::Int_t cacheSize() const
Get the TTreeCache size used.
xAOD::TFileAccessTracer::m_serverAddress
std::string m_serverAddress
Address of the server to send monitoring information to.
Definition: TFileAccessTracer.h:88
StateLessPT_NewConfig.Format
Format
Definition: StateLessPT_NewConfig.py:146
athena.value
value
Definition: athena.py:122
xAOD::TFileAccessTracer::monitoredFraction
::Double_t monitoredFraction() const
Fraction of jobs that should send monitoring information.
Definition: TFileAccessTracer.cxx:259
xAOD::TFileAccessTracer::m_mutex
std::mutex m_mutex
Mutex for modifying the object.
Definition: TFileAccessTracer.h:99
D3PDTest::rng
uint32_t rng()
Definition: FillerAlg.cxx:40
trigbs_dumpHLTContentInBS.stats
stats
Definition: trigbs_dumpHLTContentInBS.py:91
physics_parameters.url
string url
Definition: physics_parameters.py:27
xAOD::ReadStats::containers
const MapC_t & containers() const
Get information about all the containers.
file
TFile * file
Definition: tile_monitor.h:29
xAOD::BranchStats
Class describing the access statistics of one (sub-)branch.
Definition: ReadStats.h:43
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
xAOD::TFileAccessTracer::m_serverInetAddress
::TInetAddress m_serverInetAddress
Technical address of the server.
Definition: TFileAccessTracer.h:90
xAOD::TFileAccessTracer::m_monitoredFraction
::Double_t m_monitoredFraction
Fraction of jobs that should send monitoring information.
Definition: TFileAccessTracer.h:93
xAOD::TFileAccessTracer::m_accessedFiles
std::set< AccessedFile > m_accessedFiles
List of all the input files that were accessed in the job.
Definition: TFileAccessTracer.h:85
RTTAlgmain.branch
branch
Definition: RTTAlgmain.py:61
DeMoScan.first
bool first
Definition: DeMoScan.py:534
python.test_cfgItemList.msg
msg
Definition: test_cfgItemList.py:7
beamspotCoolDiff.bs
bs
Definition: beamspotCoolDiff.py:148
xAOD::ReadStats::branches
const Map_t & branches() const
Get all variable information.
xAOD::TFileAccessTracer::m_readStats
ReadStats * m_readStats
Object describing the job's xAOD access statistics.
Definition: TFileAccessTracer.h:96