File indexing completed on 2025-08-06 08:12:31
0001 #include <TFile.h>
0002 #include <TTree.h>
0003 #include <TBranch.h>
0004
0005 void AddBranchFromFileAToFileB(const char* fileAName, const char* fileBName) {
0006
0007 TFile* fileB = TFile::Open(fileBName, "UPDATE");
0008 if (!fileB || fileB->IsZombie()) {
0009 std::cerr << "Error: Could not open fileB.root" << std::endl;
0010 return;
0011 }
0012
0013
0014 TFile* fileA = TFile::Open(fileAName, "READ");
0015 if (!fileA || fileA->IsZombie()) {
0016 std::cerr << "Error: Could not open fileA.root" << std::endl;
0017 fileB->Close();
0018 return;
0019 }
0020
0021
0022 TTree* treeB = dynamic_cast<TTree*>(fileB->Get("EventTree"));
0023 if (!treeB) {
0024 std::cerr << "Error: Could not retrieve TTree from fileB.root" << std::endl;
0025 fileA->Close();
0026 fileB->Close();
0027 return;
0028 }
0029
0030
0031 TTree* treeA = dynamic_cast<TTree*>(fileA->Get("EventTree"));
0032 if (!treeA) {
0033 std::cerr << "Error: Could not retrieve TTree from fileA.root" << std::endl;
0034 fileA->Close();
0035 fileB->Close();
0036 return;
0037 }
0038
0039 TBranch* branchA = treeA->GetBranch("clk");
0040 if (!branchA) {
0041 std::cerr << "Error: Could not retrieve TBranch from fileA.root" << std::endl;
0042 fileA->Close();
0043 fileB->Close();
0044 return;
0045 }
0046
0047
0048
0049 treeB -> Branch(branchA)
0050
0051
0052
0053
0054 Long64_t numEntries = treeA->GetEntries();
0055 for (Long64_t i = 0; i < 2; ++i) {
0056 treeA->GetEntry(i);
0057 newBranch->Fill();
0058 }
0059
0060
0061 fileB->Write("", TObject::kOverwrite);
0062
0063
0064 fileA->Close();
0065 fileB->Close();
0066 }
0067
0068
0069 int event_combiner_test3() {
0070 const char* file1Name = "/sphenix/user/ChengWei/INTT/INTT_commissioning/ZeroField/20869/folder_INTTMBD_EventCombiner/intt_run20869_test.root";
0071 const char* file2Name = "/sphenix/user/ChengWei/INTT/INTT_commissioning/ZeroField/20869/folder_INTTMBD_EventCombiner/centrality_run20869_test.root";
0072
0073 AddBranchFromFileAToFileB(file2Name, file1Name);
0074
0075 return 0;
0076 }
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093