-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_root_files.C
More file actions
49 lines (34 loc) · 1.46 KB
/
merge_root_files.C
File metadata and controls
49 lines (34 loc) · 1.46 KB
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
////////////////////////////////////////////////////////////////////////////////////////////////////
// File: merge_root_files.C
// Script to merge .root-files in 'txt_files/root_path_file.root'.
// It takes
// * 'txt_files/root_path_file.txt'
// * 'root_files/file_*.root'
// as inputs to create a new .root-file called 'merged_file.root' in the 'root_files/' directory.
// After starting root, this script can be run by typing: .x merge_root_files.C()
// Author: Lars Bathe-Peters <lars.bathe-peters@cern.ch>
// CERN Summer Student Programme 2019
////////////////////////////////////////////////////////////////////////////////////////////////////
void merge_root_files() {
TChain chain("data");
TChain chain2("corrections");
std::ifstream input_root_files("txt_files/root_path_file.txt");
if (input_root_files.is_open()) {
cout << "File" << " has been opened" << endl;
}
else {
cout << "NO FILE HAS BEEN OPENED" << endl;
exit(0);
}
std::string line;
while ( std::getline( input_root_files, line ) ) {
chain.Add( line.c_str() );
chain2.Add( line.c_str() );
cout << "line " << line << endl;
}
TFile* f = new TFile( "root_files/merged_file.root", "RECREATE" );
chain.CloneTree( -1, "fast" );
chain2.CloneTree( -1, "fast" );
f->Write();
return 0;
}