@@ -38,6 +38,7 @@ int main(int argc, char* argv[])
3838 long maxDirSize = 100000000 ;
3939 bool skipNonExistingFiles = false ;
4040 bool skipParentFilesList = false ;
41+ bool mergeByName = false ;
4142 int verbosity = 2 ;
4243 int exitCode = 0 ; // 0: success, >0: failure
4344 int compression = 505 ;
@@ -50,6 +51,7 @@ int main(int argc, char* argv[])
5051 {" skip-non-existing-files" , no_argument, nullptr , 3 },
5152 {" skip-parent-files-list" , no_argument, nullptr , 4 },
5253 {" compression" , required_argument, nullptr , 5 },
54+ {" merge-by-name" , no_argument, nullptr , 6 },
5355 {" verbosity" , required_argument, nullptr , ' v' },
5456 {" help" , no_argument, nullptr , ' h' },
5557 {nullptr , 0 , nullptr , 0 }};
@@ -70,6 +72,8 @@ int main(int argc, char* argv[])
7072 skipParentFilesList = true ;
7173 } else if (c == 5 ) {
7274 compression = atoi (optarg);
75+ } else if (c == 6 ) {
76+ mergeByName = true ;
7377 } else if (c == ' v' ) {
7478 verbosity = atoi (optarg);
7579 } else if (c == ' h' ) {
@@ -80,6 +84,7 @@ int main(int argc, char* argv[])
8084 printf (" --skip-non-existing-files Flag to allow skipping of non-existing files in the input list.\n " );
8185 printf (" --skip-parent-files-list Flag to allow skipping the merging of the parent files list.\n " );
8286 printf (" --compression <root compression id> Compression algorithm / level to use (default: %d)\n " , compression);
87+ printf (" --merge-by-name Only merge TTrees from folders with the same name.\n " );
8388 printf (" --verbosity <flag> Verbosity of output (default: %d).\n " , verbosity);
8489 return -1 ;
8590 } else {
@@ -94,6 +99,9 @@ int main(int argc, char* argv[])
9499 if (skipNonExistingFiles) {
95100 printf (" WARNING: Skipping non-existing files.\n " );
96101 }
102+ if (mergeByName) {
103+ printf (" Merging only folders with the same name.\n " );
104+ }
97105
98106 std::map<std::string, TTree*> trees;
99107 std::map<std::string, uint64_t > sizeCompressed;
@@ -182,6 +190,24 @@ int main(int argc, char* argv[])
182190
183191 auto dfName = ((TObjString*)key1)->GetString ().Data ();
184192
193+ // If merge-by-name is active, flush accumulated trees when the folder name changes
194+ if (mergeByName && outputDir && std::string (outputDir->GetName ()) != std::string (dfName)) {
195+ if (verbosity > 0 ) {
196+ printf (" Folder name changed: closing folder %s.\n " , outputDir->GetName ());
197+ }
198+ for (auto const & tree : trees) {
199+ outputDir->cd ();
200+ tree.second ->Write ();
201+ sizeCompressed[tree.first ] += tree.second ->GetZipBytes ();
202+ sizeUncompressed[tree.first ] += tree.second ->GetTotBytes ();
203+ delete tree.second ;
204+ }
205+ outputDir = nullptr ;
206+ trees.clear ();
207+ offsets.clear ();
208+ mergedDFs = 0 ;
209+ }
210+
185211 if (verbosity > 0 ) {
186212 printf (" Processing folder %s\n " , dfName);
187213 }
@@ -462,4 +488,4 @@ int main(int argc, char* argv[])
462488 printf (" \n " );
463489
464490 return exitCode;
465- }
491+ }
0 commit comments