ATLAS Offline Software
Loading...
Searching...
No Matches
ParallelFileMerger Struct Reference
Inheritance diagram for ParallelFileMerger:
Collaboration diagram for ParallelFileMerger:

Public Member Functions

 ParallelFileMerger (const char *filename, std::unordered_map< TClass *, void * > *cache, int compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault)
 ~ParallelFileMerger ()
ULong_t Hash () const
const char * GetName () const
bool syncBranches (TTree *fromTree, TTree *toTree)
Bool_t MergeTrees (TFile *input)

Public Attributes

TString fFilename
TFileMerger fMerger
std::unordered_map< TClass *, void * > * m_cache

Detailed Description

Definition at line 45 of file AthenaRootSharedWriterSvc.cxx.

Constructor & Destructor Documentation

◆ ParallelFileMerger()

ParallelFileMerger::ParallelFileMerger ( const char * filename,
std::unordered_map< TClass *, void * > * cache,
int compress = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault )
inline

Definition at line 51 of file AthenaRootSharedWriterSvc.cxx.

52 : fFilename(filename), fMerger(kFALSE, kTRUE), m_cache(cache)
53 {
54 fMerger.OutputFile(filename, "RECREATE", compress);
55 }
std::unordered_map< TClass *, void * > * m_cache

◆ ~ParallelFileMerger()

ParallelFileMerger::~ParallelFileMerger ( )
inline

Definition at line 57 of file AthenaRootSharedWriterSvc.cxx.

58 {
59 }

Member Function Documentation

◆ GetName()

const char * ParallelFileMerger::GetName ( ) const
inline

Definition at line 66 of file AthenaRootSharedWriterSvc.cxx.

67 {
68 return fFilename;
69 }

◆ Hash()

ULong_t ParallelFileMerger::Hash ( ) const
inline

Definition at line 61 of file AthenaRootSharedWriterSvc.cxx.

62 {
63 return fFilename.Hash();
64 }

◆ MergeTrees()

Bool_t ParallelFileMerger::MergeTrees ( TFile * input)
inline

Definition at line 118 of file AthenaRootSharedWriterSvc.cxx.

119 {
120 fMerger.AddFile(input);
121 TIter nextKey(input->GetListOfKeys());
122 while (TKey* key = static_cast<TKey*>(nextKey())) {
123 TClass* cl = TClass::GetClass(key->GetClassName());
124 if (cl != nullptr && cl->InheritsFrom("TTree")) {
125 TTree* outCollTree = static_cast<TTree*>(fMerger.GetOutputFile()->Get(key->GetName()));
126 TTree* inCollTree = static_cast<TTree*>(input->Get(key->GetName()));
127 if (inCollTree != nullptr && outCollTree != nullptr) {
128 if (syncBranches(outCollTree, inCollTree)) {
129 input->Write();
130 }
131 syncBranches(inCollTree, outCollTree);
132 }
133 }
134 }
135
136 Bool_t result = fMerger.PartialMerge(TFileMerger::kIncremental | TFileMerger::kResetable | TFileMerger::kKeepCompression);
137 nextKey = input->GetListOfKeys();
138 while (TKey* key = static_cast<TKey*>(nextKey())) {
139 TClass* cl = TClass::GetClass(key->GetClassName());
140 if (cl != nullptr && 0 != cl->GetResetAfterMerge()) {
141 key->Delete();
142 input->GetListOfKeys()->Remove(key);
143 delete key;
144 }
145 }
146 return result;
147 }
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
bool syncBranches(TTree *fromTree, TTree *toTree)

◆ syncBranches()

bool ParallelFileMerger::syncBranches ( TTree * fromTree,
TTree * toTree )
inline

Definition at line 72 of file AthenaRootSharedWriterSvc.cxx.

73 {
74 bool updated = false;
75 const TObjArray* fromBranches = fromTree->GetListOfBranches();
76 const TObjArray* toBranches = toTree->GetListOfBranches();
77 int nBranches = fromBranches->GetEntriesFast();
78 int nEntries = toTree->GetEntries();
79 for (int k = 0; k < nBranches; ++k) {
80 TBranch* branch = static_cast<TBranch*>(fromBranches->UncheckedAt(k));
81 if (toBranches->FindObject(branch->GetName()) == nullptr) {
82 TBranch* newBranch = nullptr;
83 TClass* cl = TClass::GetClass(branch->GetClassName());
84 if (cl != nullptr) {
85 newBranch = toTree->Branch(branch->GetName(), branch->GetClassName(), nullptr, branch->GetBasketSize(), branch->GetSplitLevel());
86 void* objectAddress = getCachedObjectAddress(cl, *m_cache);
87 newBranch->SetAddress(objectAddress);
88 } else {
89 TObjArray* outLeaves = branch->GetListOfLeaves();
90 TLeaf* leaf = static_cast<TLeaf*>(outLeaves->UncheckedAt(0));
91 std::string_view attr = leaf->GetName();
92 std::string_view type = leaf->GetTypeName();
93 std::string branchSpec(attr);
94 branchSpec += '/';
95 if (type == "Int_t") branchSpec += 'I';
96 else if (type == "Short_t") branchSpec += 'S';
97 else if (type == "Long_t") branchSpec += 'L';
98 else if (type == "UInt_t") branchSpec +='i';
99 else if (type == "UShort_t") branchSpec+='s';
100 else if (type == "ULong_t") branchSpec +='l';
101 else if (type == "Float_t") branchSpec +='F';
102 else if (type == "Double_t") branchSpec+='D';
103 else if (type == "Char_t") branchSpec +='B';
104 else if (type == "UChar_t") branchSpec +='b';
105 else if (type == "Bool_t") branchSpec +='O';
106 else { branchSpec += type; }// fallback
107 newBranch = toTree->Branch(branch->GetName(), static_cast<void*>(nullptr), branchSpec.c_str(), 2048);
108 }
109 for (int m = 0; m < nEntries; ++m) {
110 newBranch->BackFill();
111 }
112 updated = true;
113 }
114 }
115 return updated;
116 }
void * getCachedObjectAddress(TClass *cl, std::unordered_map< TClass *, void * > &cache)

Member Data Documentation

◆ fFilename

TString ParallelFileMerger::fFilename

Definition at line 47 of file AthenaRootSharedWriterSvc.cxx.

◆ fMerger

TFileMerger ParallelFileMerger::fMerger

Definition at line 48 of file AthenaRootSharedWriterSvc.cxx.

◆ m_cache

std::unordered_map<TClass*, void*>* ParallelFileMerger::m_cache

Definition at line 49 of file AthenaRootSharedWriterSvc.cxx.


The documentation for this struct was generated from the following file: