Skip to content

Commit 1f2ebd1

Browse files
authored
speed optimizations (#2266)
1 parent 8de76aa commit 1f2ebd1

1 file changed

Lines changed: 33 additions & 20 deletions

File tree

Common/Core/aodMerger.cxx

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,10 @@ int main(int argc, char* argv[])
243243
foundTrees.push_back(treeName);
244244

245245
auto inputTree = (TTree*)inputFile->Get(Form("%s/%s", dfName, treeName));
246-
printf(" Tree %s has %lld entries\n", treeName, inputTree->GetEntries());
246+
bool fastCopy = (inputTree->GetTotBytes() > 10000000); // Only do this for large enough trees to avoid that baskets are too small
247+
printf(" Tree %s has %lld entries with total size %lld (fast copy: %d)\n", treeName, inputTree->GetEntries(), inputTree->GetTotBytes(), fastCopy);
247248

249+
bool alreadyCopied = false;
248250
if (trees.count(treeName) == 0) {
249251
if (mergedDFs > 1) {
250252
printf(" *** FATAL ***: The tree %s was not in the previous dataframe(s)\n", treeName);
@@ -259,7 +261,9 @@ int main(int argc, char* argv[])
259261
printf("Writing to output folder %s\n", dfName);
260262
}
261263
outputDir->cd();
262-
auto outputTree = inputTree->CloneTree(0);
264+
auto outputTree = inputTree->CloneTree(-1, (fastCopy) ? "fast" : "");
265+
currentDirSize += outputTree->GetTotBytes();
266+
alreadyCopied = true;
263267
outputTree->SetAutoFlush(0);
264268
trees[treeName] = outputTree;
265269
} else {
@@ -321,30 +325,39 @@ int main(int argc, char* argv[])
321325
}
322326
}
323327

324-
auto entries = inputTree->GetEntries();
325-
int minIndexOffset = unassignedIndexOffset[treeName];
326-
auto newMinIndexOffset = minIndexOffset;
327-
for (int i = 0; i < entries; i++) {
328-
for (auto& index : indexList) {
329-
*(index.first) = 0; // Any positive number will do, in any case it will not be filled in the output. Otherwise the previous entry is used and manipulated in the following.
330-
}
331-
inputTree->GetEntry(i);
332-
// shift index columns by offset
333-
for (const auto& idx : indexList) {
334-
// if negative, the index is unassigned. In this case, the different unassigned blocks have to get unique negative IDs
335-
if (*(idx.first) < 0) {
336-
*(idx.first) += minIndexOffset;
337-
newMinIndexOffset = std::min(newMinIndexOffset, *(idx.first));
338-
} else {
339-
*(idx.first) += idx.second;
328+
if (indexList.size() > 0) {
329+
auto entries = inputTree->GetEntries();
330+
int minIndexOffset = unassignedIndexOffset[treeName];
331+
auto newMinIndexOffset = minIndexOffset;
332+
for (int i = 0; i < entries; i++) {
333+
for (auto& index : indexList) {
334+
*(index.first) = 0; // Any positive number will do, in any case it will not be filled in the output. Otherwise the previous entry is used and manipulated in the following.
335+
}
336+
inputTree->GetEntry(i);
337+
// shift index columns by offset
338+
for (const auto& idx : indexList) {
339+
// if negative, the index is unassigned. In this case, the different unassigned blocks have to get unique negative IDs
340+
if (*(idx.first) < 0) {
341+
*(idx.first) += minIndexOffset;
342+
newMinIndexOffset = std::min(newMinIndexOffset, *(idx.first));
343+
} else {
344+
*(idx.first) += idx.second;
345+
}
346+
}
347+
if (!alreadyCopied) {
348+
int nbytes = outputTree->Fill();
349+
if (nbytes > 0) {
350+
currentDirSize += nbytes;
351+
}
340352
}
341353
}
342-
int nbytes = outputTree->Fill();
354+
unassignedIndexOffset[treeName] = newMinIndexOffset;
355+
} else if (!alreadyCopied) {
356+
auto nbytes = outputTree->CopyEntries(inputTree, -1, (fastCopy) ? "fast" : "");
343357
if (nbytes > 0) {
344358
currentDirSize += nbytes;
345359
}
346360
}
347-
unassignedIndexOffset[treeName] = newMinIndexOffset;
348361

349362
delete inputTree;
350363

0 commit comments

Comments
 (0)