ATLAS Offline Software
DataAccess.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: DataAccess.cxx 339267 2011-01-07 16:30:10Z krasznaa $
6 
7 // ROOT include(s):
8 #include <TTree.h>
9 #include <TChain.h>
10 #include <TBranch.h>
11 
12 // Local include(s):
13 #include "DataAccess.h"
14 
16 
17 namespace D3PD {
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 
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,
313  m_tree->SetBranchAddress( m_prefix + "EF_resurrected", &m_ef_resurrected,
315  m_tree->SetBranchAddress( m_prefix + "L2_passedThrough", &m_l2_passedThrough,
317  m_tree->SetBranchAddress( m_prefix + "EF_passedThrough", &m_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 
354 
355  m_b_l2_resurrected = 0;
356  m_b_ef_resurrected = 0;
357 
360 
363 
364  return;
365  }
366 
367  } // namespace Trig
368 
369 } // namespace D3PD
D3PD::Trig::DataAccess::m_l2_resurrected
std::vector< short > * m_l2_resurrected
Definition: DataAccess.h:128
D3PD::Trig::DataAccess::GetSMK
virtual Int_t GetSMK() const
Get the Super Master Key of the current event.
D3PD::Trig::DataAccess::m_initialized
Bool_t m_initialized
Flag for knowing if the branches have been connected.
Definition: DataAccess.h:96
D3PD::Trig::DataAccess::m_b_l2_raw
TBranch * m_b_l2_raw
Definition: DataAccess.h:125
D3PD::Trig::DataAccess::m_b_l2_physics
TBranch * m_b_l2_physics
Definition: DataAccess.h:115
D3PD::Trig::DataAccess::m_b_hltpsk
TBranch * m_b_hltpsk
Definition: DataAccess.h:108
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
D3PD::Trig::DataAccess::m_detailLevel
Int_t m_detailLevel
The detail level guessed from the available branches.
Definition: DataAccess.h:97
D3PD::Trig::IDataAccess::Resurrected
@ Resurrected
Definition: IDataAccess.h:60
D3PD::Trig::DataAccess::m_tree
TTree * m_tree
The event-wise TTree.
Definition: DataAccess.h:94
Trig
The common trigger namespace for trigger analysis tools.
Definition: CaloTowerVecMon.h:44
D3PD::Trig::DataAccess::Initialize
Bool_t Initialize()
Initialize the object from the specified TTree.
D3PD::Trig::DataAccess::m_l2_passedThrough
std::vector< short > * m_l2_passedThrough
Definition: DataAccess.h:134
D3PD::Trig::DataAccess::m_l1_tbp
std::vector< unsigned int > * m_l1_tbp
Definition: DataAccess.h:118
D3PD::Trig::DataAccess::m_l1_tav
std::vector< unsigned int > * m_l1_tav
Definition: DataAccess.h:110
D3PD::Trig::DataAccess::m_b_l1psk
TBranch * m_b_l1psk
Definition: DataAccess.h:107
D3PD::Trig::DataAccess::m_smk
UInt_t m_smk
Definition: DataAccess.h:102
D3PD::Trig::DataAccess::Reset
void Reset()
Reset the object.
D3PD::Trig::IDataAccess::TAV
@ TAV
Definition: IDataAccess.h:54
D3PD::Trig::DataAccess::m_b_l1_tbp
TBranch * m_b_l1_tbp
Definition: DataAccess.h:123
ClassImp
ClassImp(D3PD::Trig::DataAccess) namespace D3PD
Definition: DataAccess.cxx:15
D3PD::Trig::DataAccess::m_b_l1_tap
TBranch * m_b_l1_tap
Definition: DataAccess.h:124
D3PD::Trig::DataAccess::GetL1PSK
virtual Int_t GetL1PSK() const
Get the LVL1 prescale key of the current event.
D3PD
Block filler tool for noisy FEB information.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:21
D3PD::Trig::IDataAccess::TAP
@ TAP
Definition: IDataAccess.h:53
D3PD::Trig::DataAccess::GetDetailLevel
virtual Int_t GetDetailLevel() const
Get the detail level that the D3PD was produced with.
D3PD::Trig::DataAccess::m_b_l2_passedThrough
TBranch * m_b_l2_passedThrough
Definition: DataAccess.h:137
D3PD::Trig::DataAccess::m_l1_tap
std::vector< unsigned int > * m_l1_tap
Definition: DataAccess.h:119
D3PD::Trig::IDataAccess::PassedThrough
@ PassedThrough
Definition: IDataAccess.h:61
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
D3PD::Trig::IDataAccess::Physics
@ Physics
Definition: IDataAccess.h:58
D3PD::Trig::DataAccess::m_b_smk
TBranch * m_b_smk
Definition: DataAccess.h:106
D3PD::Trig::DataAccess::m_l2_raw
std::vector< short > * m_l2_raw
Definition: DataAccess.h:120
D3PD::Trig::DataAccess::~DataAccess
~DataAccess()
Destructor.
D3PD::Trig::DataAccess::GetHLTPSK
virtual Int_t GetHLTPSK() const
Get the HLT prescale key of the current event.
D3PD::Trig::DataAccess::m_ef_passedThrough
std::vector< short > * m_ef_passedThrough
Definition: DataAccess.h:135
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
D3PD::Trig::DataAccess::m_l2_physics
std::vector< short > * m_l2_physics
Definition: DataAccess.h:111
D3PD::Trig::DataAccess::m_b_l2_resurrected
TBranch * m_b_l2_resurrected
Definition: DataAccess.h:131
DataAccess.h
D3PD::Trig::DataAccess::m_l1psk
UInt_t m_l1psk
Definition: DataAccess.h:103
D3PD::Trig::DataAccess::GetL2Result
virtual const std::vector< short > * GetL2Result(HLTResultType type) const
Function for retrieving the encoded LVL2 result.
jobOptions.Initialize
Initialize
Definition: jobOptions.pA.py:28
D3PD::Trig::DataAccess::m_b_ef_passedThrough
TBranch * m_b_ef_passedThrough
Definition: DataAccess.h:138
D3PD::Trig::DataAccess::GetEventTree
TTree * GetEventTree() const
Get the pointer to the event-wise treee currently being used.
D3PD::Trig::DataAccess::m_b_ef_resurrected
TBranch * m_b_ef_resurrected
Definition: DataAccess.h:132
D3PD::Trig::DataAccess::GetEntry
Int_t GetEntry(Long64_t entry, Int_t getall=0)
Load a new entry (new event)
D3PD::Trig::DataAccess::m_ef_physics
std::vector< short > * m_ef_physics
Definition: DataAccess.h:112
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
D3PD::Trig::DataAccess::GetL1Result
virtual const std::vector< unsigned int > * GetL1Result(L1ResultType type) const
Function for retrieving the encoded LVL1 result.
D3PD::Trig::DataAccess::m_b_ef_physics
TBranch * m_b_ef_physics
Definition: DataAccess.h:116
D3PD::Trig::DataAccess::SetEventTree
Bool_t SetEventTree(TTree *eventTree)
Set the pointer to the event-wise treee.
D3PD::Trig::DataAccess::GetEFResult
virtual const std::vector< short > * GetEFResult(HLTResultType type) const
Function for retrieving the encoded EF result.
D3PD::Trig::DataAccess::m_b_l1_tav
TBranch * m_b_l1_tav
Definition: DataAccess.h:114
D3PD::Trig::DataAccess::m_ef_raw
std::vector< short > * m_ef_raw
Definition: DataAccess.h:121
D3PD::Trig::DataAccess::m_b_ef_raw
TBranch * m_b_ef_raw
Definition: DataAccess.h:126
D3PD::Trig::DataAccess::m_hltpsk
UInt_t m_hltpsk
Definition: DataAccess.h:104
D3PD::Trig::DataAccess::m_prefix
const TString m_prefix
Prefix for the trigger branch names.
Definition: DataAccess.h:95
D3PD::Trig::DataAccess::DataAccess
DataAccess(TTree *eventTree=0, const TString &prefix="trig_")
Constructor specifying the event-wise tree.
D3PD::Trig::IDataAccess::Raw
@ Raw
Definition: IDataAccess.h:59
D3PD::Trig::DataAccess::m_ef_resurrected
std::vector< short > * m_ef_resurrected
Definition: DataAccess.h:129
D3PD::Trig::DataAccess
Class handling the access to the trigger data in the events.
Definition: DataAccess.h:54
D3PD::Trig::IDataAccess::TBP
@ TBP
Definition: IDataAccess.h:52