Skip to content

Commit f98eb4a

Browse files
committed
aod-merger: add option to skip non-existing files
1 parent b422984 commit f98eb4a

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

Common/Core/aodMerger.cxx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ int main(int argc, char* argv[])
2828
std::string inputCollection("input.txt");
2929
std::string outputFileName("AO2D.root");
3030
long maxDirSize = 100000000;
31+
bool skipNonExistingFiles = false;
3132

3233
int option_index = 0;
3334
static struct option long_options[] = {
3435
{"input", required_argument, nullptr, 0},
3536
{"output", required_argument, nullptr, 1},
3637
{"max-size", required_argument, nullptr, 2},
37-
{"help", no_argument, nullptr, 3},
38+
{"skip-non-existing-files", required_argument, nullptr, 3},
39+
{"help", no_argument, nullptr, 4},
3840
{nullptr, 0, nullptr, 0}};
3941

4042
while (true) {
@@ -48,10 +50,13 @@ int main(int argc, char* argv[])
4850
} else if (c == 2) {
4951
maxDirSize = atol(optarg);
5052
} else if (c == 3) {
53+
skipNonExistingFiles = (strcmp(optarg, "true")) ? false : true;
54+
} else if (c == 4) {
5155
printf("AOD merging tool. Options: \n");
52-
printf(" --input <inputfile.txt> Contains path to files to be merged. Default: %s\n", inputCollection.c_str());
53-
printf(" --output <outputfile.root> Target output ROOT file. Default: %s\n", outputFileName.c_str());
54-
printf(" --max-size <size in Bytes> Target directory size: %ld \n", maxDirSize);
56+
printf(" --input <inputfile.txt> Contains path to files to be merged. Default: %s\n", inputCollection.c_str());
57+
printf(" --output <outputfile.root> Target output ROOT file. Default: %s\n", outputFileName.c_str());
58+
printf(" --max-size <size in Bytes> Target directory size. Default: %ld\n", maxDirSize);
59+
printf(" --skip-non-existing-files <true|false> Non-existing files are skipped. Default: %s\n", "false");
5560
return -1;
5661
} else {
5762
return -2;
@@ -62,6 +67,7 @@ int main(int argc, char* argv[])
6267
printf(" Input file: %s\n", inputCollection.c_str());
6368
printf(" Ouput file name: %s\n", outputFileName.c_str());
6469
printf(" Maximal folder size (uncompressed): %ld\n", maxDirSize);
70+
printf(" Skip non-existing files: %s\n", (skipNonExistingFiles) ? "true" : "false");
6571

6672
std::map<std::string, TTree*> trees;
6773
std::map<std::string, int> offsets;
@@ -93,6 +99,16 @@ int main(int argc, char* argv[])
9399
printf("Processing input file: %s\n", line.Data());
94100

95101
auto inputFile = TFile::Open(line);
102+
if (!inputFile) {
103+
printf("Could not open input file %s.\n", line.Data());
104+
if (skipNonExistingFiles) {
105+
continue;
106+
} else {
107+
printf("Aborting merge!\n");
108+
return 1;
109+
}
110+
}
111+
96112
TList* keyList = inputFile->GetListOfKeys();
97113
keyList->Sort();
98114

@@ -234,9 +250,9 @@ int main(int argc, char* argv[])
234250
}
235251

236252
if (currentDirSize > maxDirSize) {
237-
printf("Maximum size reached: %ld. Closing folder.\n", currentDirSize);
253+
printf("Maximum size reached: %ld. Closing folder %s.\n", currentDirSize, dfName);
238254
for (auto const& tree : trees) {
239-
//printf("Writing %s\n", tree.first.c_str());
255+
// printf("Writing %s\n", tree.first.c_str());
240256
outputDir->cd();
241257
tree.second->Write();
242258
delete tree.second;
@@ -249,6 +265,7 @@ int main(int argc, char* argv[])
249265
}
250266
inputFile->Close();
251267
}
268+
252269
outputFile->Write();
253270
outputFile->Close();
254271

0 commit comments

Comments
 (0)