ATLAS Offline Software
Functions
DataAccess.cxx File Reference
#include <TTree.h>
#include <TChain.h>
#include <TBranch.h>
#include "DataAccess.h"
Include dependency graph for DataAccess.cxx:

Go to the source code of this file.

Functions

 ClassImp (D3PD::Trig::DataAccess) namespace D3PD
 

Function Documentation

◆ ClassImp()

ClassImp ( D3PD::Trig::DataAccess  )

The constructor tries to initialize the object by connecting to all the available branches. However it's possible to create the object without an existing event-wise TTree as well.

Parameters
eventTreeThe event-wise D3PD TTree
prefixThe prefix used for the trigger branches (usually "trig_")

The destructor deletes all the allocated objects, and releases whatever resource it can.

This function can be used to instruct the object to start using a new event-wise TTree. This is very useful when processing multiple D3PD files.

Note that it is possible to provide a null pointer to the function. In this case the object will be reset, and the previous TTree will be released without connecting to a new one.

Also note that unfortunately we can't just check if the passed TTree pointer is the same as the cached one. ROOT has the habit of putting the same sort of TTree into the same memory space when the second file is opened for instance. I've seen some weird problems because of this.

Parameters
eventTreeThe event-wise D3PD TTree
Returns
kTRUE if the operation was successful, kFALSE otherwise

Unfortunately however I tried I didn't manage to figure out an elegant way of automatically figuring out which event the tool should be operating on. Of course if the user issues TTree::GetEntry(...) calls on the event-wise TTree himself/herself, then the tool gets the correct data automatically. But since this is usually a slow thing to do, the user can also explicitly request the tool to read a new event using this function.

Parameters
entryThe entry from the event-wise tree that should be loaded
getallFlag telling whether all the sub-branches should be read
Returns
The number of bytes read

Definition at line 15 of file DataAccess.cxx.

17  {
18 
19  namespace Trig {
20 
29  DataAccess::DataAccess( TTree* eventTree, const TString& prefix )
30  : TNamed( "DataAccess", "Sub-class accessing the data in the D3PD" ),
31  m_tree( eventTree ), m_prefix( prefix ), m_initialized( kFALSE ),
32  m_detailLevel( -1 ),
33  m_l1_tav( 0 ), m_l2_physics( 0 ), m_ef_physics( 0 ),
34  m_l1_tbp( 0 ), m_l1_tap( 0 ), m_l2_raw( 0 ), m_ef_raw( 0 ),
35  m_l2_resurrected( 0 ), m_ef_resurrected( 0 ),
36  m_l2_passedThrough( 0 ), m_ef_passedThrough( 0 ) {
37 
38  Reset();
39  Initialize();
40  }
41 
46  DataAccess::~DataAccess() {
47 
48  Reset();
49  }
50 
51  TTree* DataAccess::GetEventTree() const {
52 
53  return m_tree;
54  }
55 
73  Bool_t DataAccess::SetEventTree( TTree* eventTree ) {
74 
75  //
76  // If the user gave a null-pointer, reset the object and return gracefully:
77  //
78  if( ! eventTree ) {
79  Reset();
80  return kTRUE;
81  }
82 
83  //
84  // Reset the object and start using a new TTree:
85  //
86  Reset();
87  m_tree = eventTree;
88  return Initialize();
89  }
90 
103  Int_t DataAccess::GetEntry( Long64_t entry, Int_t getall ) {
104 
105  // The number of bytes read:
106  Int_t bytes = 0;
107 
108  // Figure out the correct entry if we've been given a TChain:
109  Long64_t centry = entry;
110  TChain* chain = dynamic_cast< TChain* >( m_tree );
111  if( chain ) {
112  centry = chain->LoadTree( entry );
113  }
114 
115  if( m_b_smk ) bytes += m_b_smk->GetEntry( centry, getall );
116  if( m_b_l1psk ) bytes += m_b_l1psk->GetEntry( centry, getall );
117  if( m_b_hltpsk ) bytes += m_b_hltpsk->GetEntry( centry, getall );
118 
119  if( m_b_l1_tav ) bytes += m_b_l1_tav->GetEntry( centry, getall );
120  if( m_b_l2_physics ) bytes += m_b_l2_physics->GetEntry( centry, getall );
121  if( m_b_ef_physics ) bytes += m_b_ef_physics->GetEntry( centry, getall );
122 
123  if( m_b_l1_tbp ) bytes += m_b_l1_tbp->GetEntry( centry, getall );
124  if( m_b_l1_tap ) bytes += m_b_l1_tap->GetEntry( centry, getall );
125  if( m_b_l2_raw ) bytes += m_b_l2_raw->GetEntry( centry, getall );
126  if( m_b_ef_raw ) bytes += m_b_ef_raw->GetEntry( centry, getall );
127 
128  if( m_b_l2_resurrected ) bytes += m_b_l2_resurrected->GetEntry( centry, getall );
129  if( m_b_ef_resurrected ) bytes += m_b_ef_resurrected->GetEntry( centry, getall );
130  if( m_b_l2_passedThrough ) bytes += m_b_l2_passedThrough->GetEntry( centry, getall );
131  if( m_b_ef_passedThrough ) bytes += m_b_ef_passedThrough->GetEntry( centry, getall );
132 
133  return bytes;
134  }
135 
136  Int_t DataAccess::GetDetailLevel() const {
137 
138  return m_detailLevel;
139  }
140 
141  Int_t DataAccess::GetSMK() const {
142 
143  return m_smk;
144  }
145 
146  Int_t DataAccess::GetL1PSK() const {
147 
148  return m_l1psk;
149  }
150 
151  Int_t DataAccess::GetHLTPSK() const {
152 
153  return m_hltpsk;
154  }
155 
156  const std::vector< unsigned int >* DataAccess::GetL1Result( L1ResultType type ) const {
157 
158  switch( type ) {
159 
160  case TBP:
161  return m_l1_tbp;
162  break;
163  case TAP:
164  return m_l1_tap;
165  break;
166  case TAV:
167  return m_l1_tav;
168  break;
169  default:
170  Error( "GetL1Result", "Unknown result type requested" );
171  return 0;
172  break;
173  }
174  }
175 
176  const std::vector< short >* DataAccess::GetL2Result( HLTResultType type ) const {
177 
178  switch( type ) {
179 
180  case Physics:
181  return m_l2_physics;
182  break;
183  case Raw:
184  return m_l2_raw;
185  break;
186  case Resurrected:
187  return m_l2_resurrected;
188  break;
189  case PassedThrough:
190  return m_l2_passedThrough;
191  break;
192  default:
193  Error( "GetL2Result", "Unknown result type requested" );
194  return 0;
195  break;
196  }
197  }
198 
199  const std::vector< short >* DataAccess::GetEFResult( HLTResultType type ) const {
200 
201  switch( type ) {
202 
203  case Physics:
204  return m_ef_physics;
205  break;
206  case Raw:
207  return m_ef_raw;
208  break;
209  case Resurrected:
210  return m_ef_resurrected;
211  break;
212  case PassedThrough:
213  return m_ef_passedThrough;
214  break;
215  default:
216  Error( "GetEFResult", "Unknown result type requested" );
217  return 0;
218  break;
219  }
220  }
221 
222  Bool_t DataAccess::Initialize() {
223 
224  // Return right away if there's nothing to do:
225  if( m_initialized ) return kTRUE;
226 
227  //
228  // Just a basic check:
229  //
230  if( ! m_tree ) {
231  Info( "Initialize", "Null pointer provided as event tree -> "
232  "Delaying initialization" );
233  return kFALSE;
234  }
235 
236  //
237  // Check if we're handling a TChain:
238  //
239  TChain* chain = dynamic_cast< TChain* >( m_tree );
240  if( chain ) {
241  // Make sure that a TTree is already loaded:
242  if( ! chain->GetTree() ) {
243  chain->LoadTree( 0 );
244  }
245  }
246 
247  //
248  // Try to initialize the DB key variables:
249  //
250  if( ( ! ( m_b_smk = m_tree->GetBranch( m_prefix + "DB_SMK" ) ) ) ||
251  ( ! ( m_b_l1psk = m_tree->GetBranch( m_prefix + "DB_L1PSK" ) ) ) ||
252  ( ! ( m_b_hltpsk = m_tree->GetBranch( m_prefix + "DB_HLTPSK" ) ) ) ) {
253  Error( "Initialize", "The supplied D3PD doesn't seem to hold trigger configuration "
254  "metadata" );
255  return kFALSE;
256  }
257 
258  m_tree->SetBranchAddress( m_prefix + "DB_SMK", &m_smk, &m_b_smk );
259  m_tree->SetBranchAddress( m_prefix + "DB_L1PSK", &m_l1psk, &m_b_l1psk );
260  m_tree->SetBranchAddress( m_prefix + "DB_HLTPSK", &m_hltpsk, &m_b_hltpsk );
261 
262  //
263  // Try to initialize the variables coming from detail level 0:
264  //
265  if( ( ! ( m_b_l1_tav = m_tree->GetBranch( m_prefix + "L1_TAV" ) ) ) ||
266  ( ! ( m_b_l2_physics = m_tree->GetBranch( m_prefix + "L2_passedPhysics" ) ) ) ||
267  ( ! ( m_b_ef_physics = m_tree->GetBranch( m_prefix + "EF_passedPhysics" ) ) ) ) {
268  Error( "Initialize", "The supplied TTree doesn't seem to hold trigger decision "
269  "information" );
270  return kFALSE;
271  }
272 
273  m_tree->SetBranchAddress( m_prefix + "L1_TAV", &m_l1_tav,
274  &m_b_l1_tav );
275  m_tree->SetBranchAddress( m_prefix + "L2_passedPhysics", &m_l2_physics,
276  &m_b_l2_physics );
277  m_tree->SetBranchAddress( m_prefix + "EF_passedPhysics", &m_ef_physics,
278  &m_b_ef_physics );
279 
280  m_detailLevel = 0;
281 
282  //
283  // Try to initialize the variables coming from detail level 1:
284  //
285  if( ( ! ( m_b_l1_tbp = m_tree->GetBranch( m_prefix + "L1_TBP" ) ) ) ||
286  ( ! ( m_b_l1_tap = m_tree->GetBranch( m_prefix + "L1_TAP" ) ) ) ||
287  ( ! ( m_b_l2_raw = m_tree->GetBranch( m_prefix + "L2_passedRaw" ) ) ) ||
288  ( ! ( m_b_ef_raw = m_tree->GetBranch( m_prefix + "EF_passedRaw" ) ) ) ) {
289  // Apparently the D3PD was created with detail level 0...
290  return kTRUE;
291  }
292 
293  m_tree->SetBranchAddress( m_prefix + "L1_TBP", &m_l1_tbp, &m_b_l1_tbp );
294  m_tree->SetBranchAddress( m_prefix + "L1_TAP", &m_l1_tap, &m_b_l1_tap );
295  m_tree->SetBranchAddress( m_prefix + "L2_passedRaw", &m_l2_raw, &m_b_l2_raw );
296  m_tree->SetBranchAddress( m_prefix + "EF_passedRaw", &m_ef_raw, &m_b_ef_raw );
297 
298  m_detailLevel = 1;
299 
300  //
301  // Try to initialize the variables coming from detail level 2:
302  //
303  if( ( ! ( m_b_l2_resurrected = m_tree->GetBranch( m_prefix + "L2_resurrected" ) ) ) ||
304  ( ! ( m_b_ef_resurrected = m_tree->GetBranch( m_prefix + "EF_resurrected" ) ) ) ||
305  ( ! ( m_b_l2_passedThrough = m_tree->GetBranch( m_prefix + "L2_passedThrough" ) ) ) ||
306  ( ! ( m_b_ef_passedThrough = m_tree->GetBranch( m_prefix + "EF_passedThrough" ) ) ) ) {
307  // Apparently the D3PD was created with detail level 1...
308  return kTRUE;
309  }
310 
311  m_tree->SetBranchAddress( m_prefix + "L2_resurrected", &m_l2_resurrected,
312  &m_b_l2_resurrected );
313  m_tree->SetBranchAddress( m_prefix + "EF_resurrected", &m_ef_resurrected,
314  &m_b_ef_resurrected );
315  m_tree->SetBranchAddress( m_prefix + "L2_passedThrough", &m_l2_passedThrough,
316  &m_b_l2_passedThrough );
317  m_tree->SetBranchAddress( m_prefix + "EF_passedThrough", &m_ef_passedThrough,
318  &m_b_ef_passedThrough );
319 
320  m_detailLevel = 2;
321 
322  return kTRUE;
323  }
324 
325  void DataAccess::Reset() {
326 
327  m_initialized = kFALSE;
328  m_detailLevel = -1;
329 
330  m_b_smk = 0;
331  m_b_l1psk = 0;
332  m_b_hltpsk = 0;
333 
334  if( m_l1_tav ) delete m_l1_tav; m_l1_tav = 0;
335  if( m_l2_physics ) delete m_l2_physics; m_l2_physics = 0;
336  if( m_ef_physics ) delete m_ef_physics; m_ef_physics = 0;
337 
338  m_b_l1_tav = 0;
339  m_b_l2_physics = 0;
340  m_b_ef_physics = 0;
341 
342  if( m_l1_tbp ) delete m_l1_tbp; m_l1_tbp = 0;
343  if( m_l1_tap ) delete m_l1_tap; m_l1_tap = 0;
344  if( m_l2_raw ) delete m_l2_raw; m_l2_raw = 0;
345  if( m_ef_raw ) delete m_ef_raw; m_ef_raw = 0;
346 
347  m_b_l1_tbp = 0;
348  m_b_l1_tap = 0;
349  m_b_l2_raw = 0;
350  m_b_ef_raw = 0;
351 
352  if( m_l2_resurrected ) delete m_l2_resurrected; m_l2_resurrected = 0;
353  if( m_ef_resurrected ) delete m_ef_resurrected; m_ef_resurrected = 0;
354 
355  m_b_l2_resurrected = 0;
356  m_b_ef_resurrected = 0;
357 
358  if( m_l2_passedThrough ) delete m_l2_passedThrough; m_l2_passedThrough = 0;
359  if( m_ef_passedThrough ) delete m_ef_passedThrough; m_ef_passedThrough = 0;
360 
361  m_b_l2_passedThrough = 0;
362  m_b_ef_passedThrough = 0;
363 
364  return;
365  }
366 
367  } // namespace Trig
368 
369 } // namespace D3PD
D3PD::TrigDefs::Physics
@ Physics
"The" physics decision
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/Conditions.h:48
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
Trig
The common trigger namespace for trigger analysis tools.
Definition: CaloTowerVecMon.h:44
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
jobOptions.Initialize
Initialize
Definition: jobOptions.pA.py:28
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16