ATLAS Offline Software
NTupleSvc.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef EVENT_LOOP_ALGS__NTUPLE_SVC_H
6 #define EVENT_LOOP_ALGS__NTUPLE_SVC_H
7 
8 //
9 // Distributed under the Boost Software License, Version 1.0.
10 // (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12 
13 // Please feel free to contact me (krumnack@iastate.edu) for bug
14 // reports, feature suggestions, praise and complaints.
15 
16 
21 
22 
23 
24 #include <EventLoopAlgs/Global.h>
25 
26 #include <set>
27 #include <EventLoop/Algorithm.h>
28 
29 class TBranch;
30 class TFile;
31 class TTree;
32 
33 namespace EL
34 {
43  const std::string& outputStream,
44  const std::string& treeName = "");
45 
46 
47 
48  class NTupleSvc : public EL::Algorithm
49  {
50  //
51  // public interface
52  //
53 
56  public:
57  void testInvariant () const;
58 
59 
64  public:
65  NTupleSvc (const std::string& val_outputName = "output");
66 
67 
70  public:
72 
73 
78  public:
79  void copyBranch (const std::string& name);
80 
81 
89  public:
90  void copyBranchList (const std::string& fileName);
91 
92 
96  public:
97  void addWhiteFloat (const std::string& varName);
98 
99 
103  public:
104  void addWhiteArray (const std::string& varName);
105 
106 
111  public:
112  TTree *tree () const;
113 
114 
117  public:
118  bool getFilterPassed () const;
119 
120 
124  public:
125  void setFilterPassed (bool passed = true);
126 
127 
132  public:
133  const std::string& treeName () const;
134  void treeName (const std::string& val_treeName);
135 
136 
137  //
138  // interface inherited from Algorithm
139  //
140 
143  public:
144  virtual const char *GetName () const;
145 
146 
155  private:
157 
158 
164  private:
165  virtual StatusCode changeInput (bool firstFile);
166 
167 
178  private:
179  virtual StatusCode initialize ();
180 
181 
186  private:
187  virtual StatusCode execute ();
188 
189 
197  private:
199 
200 
207  private:
208  virtual bool hasName (const std::string& name) const;
209 
210 
211 
212  //
213  // private interface
214  //
215 
217  private:
218  std::string m_outputName;
219 
221  private:
222  std::string m_treeName;
223 
225  private:
226  std::string m_tree_title;
227 
229  private:
230  std::set<std::string> m_copyBranches;
232 
234  private:
235  std::set<std::string> m_whiteFloat;
237 
239  private:
240  std::set<std::string> m_whiteArray;
242 
244  private:
245  TFile *m_file;
246 
248  private:
249  TTree *m_tree;
250 
252  private:
254 
256  private:
257  bool m_taken;
258 
261  private:
262  bool m_connected;
263 
265  private:
267 
269  private:
270  struct CopyInfo
271  {
273  public:
274  std::string name;
275 
277  public:
278  TBranch *source;
279 
281  public:
282  TBranch *target;
283 
285  public:
286  std::vector<char> buffer;
287  };
288  std::vector<CopyInfo> m_copyInfo;
290 
292  private:
293  struct WhiteInfo
294  {
296  public:
297  std::string name;
298 
300  public:
301  bool array;
302 
304  public:
305  std::vector<float> buffer;
306 
309  public:
310  std::vector<float> *pointer;
311  };
312  std::vector<WhiteInfo> m_whiteInfo;
314 
315 
320  private:
321  void initBranches ();
322 
323 
328  private:
329  void findBranches (std::set<std::string>& branchList);
330 
331 
340  private:
341  void initOutput (const std::string& branchName);
342 
343 
349  private:
350  void initOutput (const std::set<std::string>& branchList);
351 
352 
356  private:
357  void copyInput ();
358 
359 
361  };
362 }
363 
364 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
EL::NTupleSvc::m_initialized
bool m_initialized
description: whether we initialized the tree we are writing out
Definition: NTupleSvc.h:253
EL::NTupleSvc::addWhiteArray
void addWhiteArray(const std::string &varName)
effects: add an array from the whiteboard guarantee: strong failures: out of memory II
EL::NTupleSvc::copyInfoMIter
std::vector< CopyInfo >::iterator copyInfoMIter
Definition: NTupleSvc.h:289
EL::NTupleSvc::m_treeName
std::string m_treeName
description: the name of the output tree
Definition: NTupleSvc.h:222
EL::NTupleSvc::m_whiteFloat
std::set< std::string > m_whiteFloat
description: the list of whiteboard floats we copy
Definition: NTupleSvc.h:235
EL::NTupleSvc::WhiteInfo::pointer
std::vector< float > * pointer
description: a pointer to the buffer rationale: this is used when writing arrays
Definition: NTupleSvc.h:310
EL::NTupleSvc::addWhiteFloat
void addWhiteFloat(const std::string &varName)
effects: add a float from the whiteboard guarantee: strong failures: out of memory II
EL::NTupleSvc::m_whiteInfo
std::vector< WhiteInfo > m_whiteInfo
Definition: NTupleSvc.h:312
TrigCompositeUtils::passed
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
Definition: TrigCompositeUtilsRoot.cxx:117
EL::NTupleSvc::testInvariant
void testInvariant() const
effects: test the invariant of this object guarantee: no-fail
EL::NTupleSvc::m_file
TFile * m_file
description: the file we are writing out
Definition: NTupleSvc.h:245
EL::NTupleSvc::treeName
const std::string & treeName() const
description: the name of the tree, or the empty string to use the name of the input tree guarantee: n...
RunGeantinoStepRecordingITk.outputStream
outputStream
Definition: RunGeantinoStepRecordingITk.py:126
EL::NTupleSvc::CopyInfo::buffer
std::vector< char > buffer
description: the buffer used if none is set
Definition: NTupleSvc.h:286
EL::NTupleSvc::treeName
void treeName(const std::string &val_treeName)
Global.h
EL::NTupleSvc::tree
TTree * tree() const
returns: the tree we are writing out guarantee: no-fail requires(soft): initialize() has been called ...
EL::NTupleSvc::m_whiteFloatIter
std::set< std::string >::iterator m_whiteFloatIter
Definition: NTupleSvc.h:236
EL::NTupleSvc::initBranches
void initBranches()
effects: create all the branches when called for the first time guarantee: basic, may create some fai...
EL::NTupleSvc::m_copyBranchesIter
std::set< std::string >::iterator m_copyBranchesIter
Definition: NTupleSvc.h:231
EL::NTupleSvc::copyBranchList
void copyBranchList(const std::string &fileName)
effects: read a list of branches to copy from a file.
EL::NTupleSvc
Definition: NTupleSvc.h:49
EL::NTupleSvc::m_outputName
std::string m_outputName
description: the name of the output stream
Definition: NTupleSvc.h:218
EL::NTupleSvc::changeInput
virtual StatusCode changeInput(bool firstFile)
effects: do all changes to work with a new input file, e.g.
EL::NTupleSvc::execute
virtual StatusCode execute()
effects: process the next event guarantee: basic failures: algorithm dependent rationale: the virtual...
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
EL::Algorithm
Definition: Algorithm.h:22
EL::NTupleSvc::ClassDef
ClassDef(NTupleSvc, 1)
PixelAthClusterMonAlgCfg.varName
string varName
end cluster ToT and charge
Definition: PixelAthClusterMonAlgCfg.py:125
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Algorithm.h
EL::NTupleSvc::m_taken
bool m_taken
description: whether we take the current event
Definition: NTupleSvc.h:257
EL::IWorker
the interface for algorithms to access IWorker
Definition: IWorker.h:40
EL::NTupleSvc::GetName
virtual const char * GetName() const
effects: return the name of this algorithm guarantee: no-fail
dumpFileToPlots.treeName
string treeName
Definition: dumpFileToPlots.py:20
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
EL::NTupleSvc::NTupleSvc
NTupleSvc(const std::string &val_outputName="output")
effects: standard constructor guarantee: strong failures: out of memory I requires: !...
EL::NTupleSvc::WhiteInfo::name
std::string name
description: the name of the branch
Definition: NTupleSvc.h:297
EL::NTupleSvc::whiteInfoMIter
std::vector< WhiteInfo >::iterator whiteInfoMIter
Definition: NTupleSvc.h:313
EL::Algorithm::name
virtual const std::string & name() const
EL::NTupleSvc::m_copyBranches
std::set< std::string > m_copyBranches
description: the list of branches we copy
Definition: NTupleSvc.h:230
EL::NTupleSvc::copyBranch
void copyBranch(const std::string &name)
effects: add another branch to copy.
EL::NTupleSvc::~NTupleSvc
~NTupleSvc()
effects: standard destructor guarantee: no-fail
EL::NTupleSvc::WhiteInfo::buffer
std::vector< float > buffer
description: the buffer we are writing
Definition: NTupleSvc.h:305
EL::NTupleSvc::WhiteInfo
description: the information we need for whiteboard variables
Definition: NTupleSvc.h:294
EL::NTupleSvc::setupJob
virtual StatusCode setupJob(Job &job)
effects: give the algorithm a chance to intialize the job with anything this algorithm needs.
EL::NTupleSvc::findBranches
void findBranches(std::set< std::string > &branchList)
effects: find the branches in the input tree guarantee: basic, may create some failures: out of memor...
EL::NTupleSvc::getFilterPassed
bool getFilterPassed() const
returns: whether the current event will be taken guarantee: no-fail
EL::NTupleSvc::initOutput
void initOutput(const std::string &branchName)
effects: create the branch in the output tree guarantee: basic, may create some failures: out of memo...
EL::NTupleSvc::m_tree
TTree * m_tree
description: the tree we are writing out
Definition: NTupleSvc.h:249
EL::NTupleSvc::postExecute
virtual StatusCode postExecute()
effects: do the post-processing for the event guarantee: basic failures: algorithm dependent rational...
EL::NTupleSvc::CopyInfo
description: the information we need for copying branches
Definition: NTupleSvc.h:271
EL::NTupleSvc::m_connected
bool m_connected
description: whether our output branches are properly connected to the input tree
Definition: NTupleSvc.h:262
EL::NTupleSvc::m_whiteArrayIter
std::set< std::string >::iterator m_whiteArrayIter
Definition: NTupleSvc.h:241
EL::NTupleSvc::hasName
virtual bool hasName(const std::string &name) const
returns: whether this algorithm has the given name guarantee: basic failures: algorithm dependent rat...
EL::NTupleSvc::initOutput
void initOutput(const std::set< std::string > &branchList)
effects: create the branches in the output tree guarantee: basic, may create some failures: out of me...
EL::NTupleSvc::m_whiteArray
std::set< std::string > m_whiteArray
description: the list of whiteboard arrays we copy
Definition: NTupleSvc.h:240
EL::NTupleSvc::initialize
virtual StatusCode initialize()
effects: do everything that needs to be done before running the algorithm, e.g.
EL::NTupleSvc::CopyInfo::name
std::string name
description: the name of the branch
Definition: NTupleSvc.h:274
EL::NTupleSvc::m_copyInfo
std::vector< CopyInfo > m_copyInfo
Definition: NTupleSvc.h:288
EL::WhiteBoardSvc
Definition: WhiteBoardSvc.h:41
EL::NTupleSvc::setFilterPassed
void setFilterPassed(bool passed=true)
effects: take the current event if passed is set, otherwise perform a no-op guarantee: no-fail
EL::NTupleSvc::CopyInfo::target
TBranch * target
description: the branch in the output tree
Definition: NTupleSvc.h:282
EL::NTupleSvc::copyInput
void copyInput()
effects: copy the input branches to the output branches guarantee: basic, may copy some failures: out...
EL::Job
Definition: Job.h:51
test_interactive_athena.job
job
Definition: test_interactive_athena.py:6
EL::NTupleSvc::m_tree_title
std::string m_tree_title
description: the title of the output tree
Definition: NTupleSvc.h:226
EL::NTupleSvc::WhiteInfo::array
bool array
description: whether this is an array branch
Definition: NTupleSvc.h:301
EL::NTupleSvc::m_whiteboard
WhiteBoardSvc * m_whiteboard
description: the white board service, if we are using it
Definition: NTupleSvc.h:266
EL::getNTupleSvc
NTupleSvc * getNTupleSvc(IWorker *worker, const std::string &outputStream, const std::string &treeName="")
effects: get the skimming algorithm for the given output for this worker guarantee: strong failures: ...
EL::NTupleSvc::CopyInfo::source
TBranch * source
description: the branch in the source tree
Definition: NTupleSvc.h:278