-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathprepare_cms.cxx
52 lines (45 loc) · 1.2 KB
/
prepare_cms.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <TFile.h>
#include <TTree.h>
#include <iostream>
#include <string>
#include <unistd.h>
void Usage(char *progname) {
std::cout << "Usage: " << progname << " -i <input file> -o <clustered output file>"
<< std::endl;
}
int main(int argc, char **argv) {
std::string inputPath;
std::string outputPath;
int c;
while ((c = getopt(argc, argv, "hvo:i:")) != -1) {
switch (c) {
case 'h':
case 'v':
Usage(argv[0]);
return 0;
case 'o':
outputPath = optarg;
break;
case 'i':
inputPath = optarg;
break;
default:
fprintf(stderr, "Unknown option: -%c\n", c);
Usage(argv[0]);
return 1;
}
}
if (inputPath.empty() || outputPath.empty()) {
Usage(argv[0]);
return 1;
}
std::cout << "Converting " << inputPath << " - [clustered] -> " << outputPath << std::endl;
auto inputFile = TFile::Open(inputPath.c_str());
auto inputTree = inputFile->Get<TTree>("Events");
inputTree->SetAutoFlush();
auto outputFile = new TFile(outputPath.c_str(), "RECREATE");
inputTree->CloneTree();
outputFile->Write();
outputFile->Close();
delete outputFile;
}