ATLAS Offline Software
TFileMerger.h
Go to the documentation of this file.
1 // Dear emacs, this is -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // $Id: TFileMerger.h 784654 2016-11-16 17:17:32Z krasznaa $
8 #ifndef XAODROOTACCESS_TOOLS_TFILEMERGER_H
9 #define XAODROOTACCESS_TOOLS_TFILEMERGER_H
10 
11 // System include(s):
12 #include <string>
13 #include <vector>
14 #include <map>
15 #include <set>
16 #include <memory>
17 
18 // ROOT include(s):
19 #include <TObject.h>
20 
21 // Local include(s):
22 #include "xAODRootAccess/TEvent.h"
25 
26 // Forward declaration(s):
27 class TFile;
28 class TDirectory;
29 class TTree;
30 class TBranch;
31 
32 namespace xAOD {
33 
47  class TFileMerger : public ::TObject {
48 
49  public:
54 
56  StatusCode setOutputFileName( const std::string& name,
57  const std::string& mode = "RECREATE" );
58 
60  StatusCode addFile( const std::string& name,
61  bool copyLocally = false );
62 
64  StatusCode addMetaDataTool( const std::string& typeName );
65 
71  enum EMergeMode {
72  kSlowMerge = 0,
73  kFastMerge = 1
74  };
75 
77  static const ::Long64_t kBigNumber = 1234567890;
78 
81  ::Long64_t entries = kBigNumber );
82 
87 
89  int verbosity() const;
91  void setVerbosity( int value );
92 
94  const std::set< std::string >& treesSkipped() const;
96  void addTreeToSkip( const std::string& name );
97 
98  private:
102  StatusCode mergeDirectory( ::TDirectory& input, ::TDirectory& output,
103  EMergeMode mode, bool topLevelDir );
105  StatusCode mergeObject( ::TObject& input, ::TObject& output );
109  std::vector< ::TBranch* > getMissingBranches( ::TTree* first,
110  ::TTree* second ) const;
112  std::vector< ::TBranch* > getSkippedBranches( ::TTree* tree ) const;
114  StatusCode addAuxBranch( ::TTree* otree, ::TBranch* ibranch ) const;
115 
117  std::vector< ::TFile* > m_input;
119  std::vector< bool > m_copiedInput;
121  ::TFile* m_output;
122 
124  std::set< std::string > m_treesToSkip;
125 
127  std::map< std::string, std::unique_ptr< TEvent > > m_events;
129  std::vector< ::TFile* > m_helperFiles;
130 
132  std::set< std::string > m_metaDataToolNames;
134  std::map< std::string, THolder > m_metaDataTools;
135 
138 
140  ::Long64_t m_entriesToMerge;
141 
144 
146  ClassDef( xAOD::TFileMerger, 0 )
147 
148  }; // class TFileMerger
149 
150 } // namespace xAOD
151 
152 #endif // XAODROOTACCESS_TOOLS_TFILEMERGER_H
xAOD::TFileMerger::m_verbosity
int m_verbosity
Verbosity level.
Definition: TFileMerger.h:143
xAOD::TFileMerger::merge
StatusCode merge(EMergeMode mode=kFastMerge, ::Long64_t entries=kBigNumber)
Execute the file merge itself.
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
xAOD::TFileMerger::verbosity
int verbosity() const
The current verbosity level.
xAOD::TFileMerger::m_helperFiles
std::vector< ::TFile * > m_helperFiles
Helper in-memory files used during fast merging.
Definition: TFileMerger.h:129
xAOD::name
name
Definition: TriggerMenuJson_v1.cxx:29
tree
TChain * tree
Definition: tile_monitor.h:30
xAOD::TFileMerger::setVerbosity
void setVerbosity(int value)
Set verbosity level (meant for debugging mainly)
xAOD::TFileMerger::addFile
StatusCode addFile(const std::string &name, bool copyLocally=false)
Add a file to the list to be merged, by name.
xAOD::TFileMerger::m_mode
TEvent::EAuxMode m_mode
Access mode for the created TEvent objects.
Definition: TFileMerger.h:137
athena.value
value
Definition: athena.py:124
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::TFileMerger::closeFiles
StatusCode closeFiles()
Close all the open files.
xAOD::TFileMerger::createMetaDataTools
StatusCode createMetaDataTools()
Instantiate the metadata handling tools.
xAOD::TFileMerger::m_copiedInput
std::vector< bool > m_copiedInput
Whether the files were copied locally before being merged.
Definition: TFileMerger.h:119
xAOD::TFileMerger::addAuxBranch
StatusCode addAuxBranch(::TTree *otree, ::TBranch *ibranch) const
Duplicate an auxiliary branch from the input into the output.
xAOD::TFileMerger::kSlowMerge
@ kSlowMerge
Merging is done using TEvent.
Definition: TFileMerger.h:72
xAOD::TFileMerger::addMetaDataTool
StatusCode addMetaDataTool(const std::string &typeName)
Add a metadata tool to be used during the merging.
xAOD::TFileMerger::m_metaDataTools
std::map< std::string, THolder > m_metaDataTools
Metadata tools instantiated for the file merging.
Definition: TFileMerger.h:134
xAOD::TFileMerger::m_treesToSkip
std::set< std::string > m_treesToSkip
Names of the TTrees to skip from the merge.
Definition: TFileMerger.h:124
xAOD::TFileMerger::getSkippedBranches
std::vector< ::TBranch * > getSkippedBranches(::TTree *tree) const
Get the branches that should be skipped from merging.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TFileMerger::~TFileMerger
~TFileMerger()
Destructor.
xAOD::TFileMerger::TFileMerger
TFileMerger()
Default constructor.
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
xAOD::TFileMerger::accessMode
TEvent::EAuxMode accessMode() const
The access mode used for slow and metadata merging.
TEvent.h
Preparation.mode
mode
Definition: Preparation.py:94
StatusCode.h
merge.output
output
Definition: merge.py:17
xAOD::TFileMerger::m_output
::TFile * m_output
The output file to write to.
Definition: TFileMerger.h:121
xAOD::TFileMerger::m_metaDataToolNames
std::set< std::string > m_metaDataToolNames
Names of the metadata handling tools.
Definition: TFileMerger.h:132
xAOD::TFileMerger::setOutputFileName
StatusCode setOutputFileName(const std::string &name, const std::string &mode="RECREATE")
Set the name of the output file that should be created.
xAOD::TFileMerger
Helper class for merging xAOD files.
Definition: TFileMerger.h:47
xAOD::TFileMerger::kFastMerge
@ kFastMerge
Merging is done using fast TTree merge.
Definition: TFileMerger.h:73
xAOD::TFileMerger::treesSkipped
const std::set< std::string > & treesSkipped() const
Get the names of the trees that will be skipped from the merge.
xAOD::TEvent::EAuxMode
EAuxMode
Auxiliary store "mode".
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:98
xAOD::TFileMerger::m_input
std::vector< ::TFile * > m_input
The list of input files to be merged.
Definition: TFileMerger.h:117
xAOD::TFileMerger::setAccessMode
void setAccessMode(TEvent::EAuxMode mode)
Set the access mode used for slow and metadata merging.
DeMoScan.first
bool first
Definition: DeMoScan.py:536
THolder.h
xAOD::TFileMerger::EMergeMode
EMergeMode
Types of merging that can be done.
Definition: TFileMerger.h:71
entries
double entries
Definition: listroot.cxx:49
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
xAOD::TFileMerger::m_entriesToMerge
::Long64_t m_entriesToMerge
Events to merge into the output.
Definition: TFileMerger.h:140
xAOD::TFileMerger::kBigNumber
static const ::Long64_t kBigNumber
Number of entries that are assumed to be never exceeded in a file.
Definition: TFileMerger.h:77
xAOD::TFileMerger::mergeDirectory
StatusCode mergeDirectory(::TDirectory &input, ::TDirectory &output, EMergeMode mode, bool topLevelDir)
Merge the contents of one directory from the input files.
xAOD::TFileMerger::addTreeToSkip
void addTreeToSkip(const std::string &name)
Add a tree name that should be skipped during the merging.
xAOD::TFileMerger::mergeObject
StatusCode mergeObject(::TObject &input, ::TObject &output)
Merge two top level objects that were found in the inputs.
xAOD::TFileMerger::m_events
std::map< std::string, std::unique_ptr< TEvent > > m_events
Helper objects for merging the xAOD Tree(s) from the input file(s)
Definition: TFileMerger.h:127
xAOD::TFileMerger::getMissingBranches
std::vector< ::TBranch * > getMissingBranches(::TTree *first, ::TTree *second) const
Get the auxiliary branches missing in one of the trees.