BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
insert_run_calib.cxx File Reference
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <TFile.h>
#include <TTree.h>
#include <TString.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

int const num_item = 9
 
TString str_name_list [num_item]
 
TTree * arr_tree [num_item]
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 25 of file insert_run_calib.cxx.

25 {
26 if(argc<2){
27 cout << "plase append the old calibration const root file, Ex. insert_run_calib.exe old.root [runlist.txt]" << endl;
28 return 0;
29 }
30 TString str_old = argv[1];
31 TString str_runlist = "runlist.txt";
32 if(argc>=3) str_runlist = argv[2];
33 cout << "old file: " << str_old << " runlist file: " << str_runlist << endl;
34 TFile f_old(str_old); //input
35 TFile f_new("new.root","recreate");
36 for(int i=0; i<num_item; i++) arr_tree[i] = ((TTree*)f_old.Get(str_name_list[i]))->CloneTree();
37 ifstream in(str_runlist);
38 if(!in){
39 cout << "cannot open runlist.txt" << endl;
40 return 0;
41 }
42 char str[255];
43 int in_runno(0);
44 int runno;
45 Double_t runmean, rungain, runresol;
46 while(in){
47 in.getline(str, 255);
48 sscanf(str ,"%d", &in_runno);
49 if(!in_runno) continue; // protect of read at the end
50 arr_tree[0]->SetBranchAddress("runno", &runno );
51 arr_tree[0]->SetBranchAddress("runmean", &runmean);
52 arr_tree[0]->SetBranchAddress("rungain", &rungain);
53 arr_tree[0]->SetBranchAddress("runresol", &runresol);
54 int min_diff(10000);
55 double temp_runmean(0), temp_rungain(0), temp_runresol(0);
56 for(Long64_t i=0; i<arr_tree[0]->GetEntries(); i++){
57 arr_tree[0]->GetEntry(i);
58 if(abs(runno-in_runno)<min_diff){
59 min_diff = abs(runno-in_runno);
60 temp_runmean = runmean;
61 temp_rungain = rungain;
62 temp_runresol = runresol;
63 }
64 }
65 runno = in_runno;
66 runmean = temp_runmean;
67 rungain = temp_rungain;
68 runresol = temp_runresol;
69 cout << "runno " << runno << endl;
70 arr_tree[0]->Fill();
71 in_runno = 0;
72 }
73
74 f_new.cd();
75 for(int j=0; j<num_item; j++) arr_tree[j]->Write(str_name_list[j]);
76 f_new.Close();
77 f_old.Close();
78}
TString str_name_list[num_item]
int const num_item
TTree * arr_tree[num_item]

Variable Documentation

◆ arr_tree

TTree* arr_tree[num_item]

Definition at line 22 of file insert_run_calib.cxx.

Referenced by main().

◆ num_item

int const num_item = 9

Definition at line 12 of file insert_run_calib.cxx.

Referenced by main().

◆ str_name_list

TString str_name_list[num_item]
Initial value:
={"runcalib",
"gaincalib",
"resolcalib",
"wiregcalib",
"ggscalib",
"ddgcalib",
"entracalib",
"zdepcalib",
"layergcalib"}

Definition at line 13 of file insert_run_calib.cxx.

Referenced by main().