SimpleIterate.C
Go to the documentation of this file.
1 {
2 //////////////////////////////////////////////////////////
3 // Simple code for iterating over the FD MtericsTree
4 // and printing some DQ metics in the order they
5 // appear in the TTree
6 // Usage: root -b -l -q SimpleIterate.C
7 // And in the code below edit the std::vector printConditions
8 // to add what you want to print.
9 //////////////////////////////////////////////////////////
10 
11 
12 //Reset ROOT and connect tree file
13  gROOT->Reset();
14  TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("MetricsTree_All.root");
15  if (!f) {
16  f = new TFile("MetricsTree_All.root");
17  }
18  TTree * mytree;
19  f->GetObject("mytree",mytree);
20 
21 //Declaration of leaves types
22  Int_t run;
23  Int_t subrun;
24  Int_t par;
25  Int_t nevents;
26  Int_t firstsec;
27  Int_t lastsec;
28  Int_t ngoodpix;
29  Int_t ngoodfeb;
30  Int_t ngooddcm;
31  Int_t ngooddb;
32  Int_t ngoodmip;
33  Int_t ngoodcdb;
34  Int_t nactivefeb;
35  Int_t nactivedcm;
36  Int_t nactivedb;
37  Int_t pass_runlen;
38  Int_t pass_empty;
39  Int_t pass_hits;
40  Int_t pass_db;
41  Int_t pass_time;
42  Int_t pass_all;
43  Int_t setsize;
44  Double_t rectimesec;
45  Double_t setlivetime;
46  Double_t hitrate;
47  Double_t midhitrate;
48  Double_t miprate;
49  Double_t midmiprate;
50  Double_t mipratio;
51  Double_t mipasym;
52  Double_t nactivechannels;
53  Double_t emptypercentage;
54  Int_t dbencoded;
55  Int_t dbaencoded;
56  Int_t pass_reco;
57  Int_t pass_slc;
58  Int_t pass_trk;
59  Int_t corrupted;
60  Int_t procsec;
61  Double_t numslc;
62  Double_t trkfrac2D;
63  Int_t preliminary;
64 
65  // Set branch addresses.
66  mytree->SetBranchAddress("run",&run);
67  mytree->SetBranchAddress("subrun",&subrun);
68  mytree->SetBranchAddress("par",&par);
69  mytree->SetBranchAddress("nevents",&nevents);
70  mytree->SetBranchAddress("firstsec",&firstsec);
71  mytree->SetBranchAddress("lastsec",&lastsec);
72  mytree->SetBranchAddress("ngoodpix",&ngoodpix);
73  mytree->SetBranchAddress("ngoodfeb",&ngoodfeb);
74  mytree->SetBranchAddress("ngooddcm",&ngooddcm);
75  mytree->SetBranchAddress("ngooddb",&ngooddb);
76  mytree->SetBranchAddress("ngoodmip",&ngoodmip);
77  mytree->SetBranchAddress("ngoodcdb",&ngoodcdb);
78  mytree->SetBranchAddress("nactivefeb",&nactivefeb);
79  mytree->SetBranchAddress("nactivedcm",&nactivedcm);
80  mytree->SetBranchAddress("nactivedb",&nactivedb);
81  mytree->SetBranchAddress("pass_runlen",&pass_runlen);
82  mytree->SetBranchAddress("pass_empty",&pass_empty);
83  mytree->SetBranchAddress("pass_hits",&pass_hits);
84  mytree->SetBranchAddress("pass_db",&pass_db);
85  mytree->SetBranchAddress("pass_time",&pass_time);
86  mytree->SetBranchAddress("pass_all",&pass_all);
87  mytree->SetBranchAddress("setsize",&setsize);
88  mytree->SetBranchAddress("rectimesec",&rectimesec);
89  mytree->SetBranchAddress("setlivetime",&setlivetime);
90  mytree->SetBranchAddress("hitrate",&hitrate);
91  mytree->SetBranchAddress("midhitrate",&midhitrate);
92  mytree->SetBranchAddress("miprate",&miprate);
93  mytree->SetBranchAddress("midmiprate",&midmiprate);
94  mytree->SetBranchAddress("mipratio",&mipratio);
95  mytree->SetBranchAddress("mipasym",&mipasym);
96  mytree->SetBranchAddress("nactivechannels",&nactivechannels);
97  mytree->SetBranchAddress("emptypercentage",&emptypercentage);
98  mytree->SetBranchAddress("dbencoded",&dbencoded);
99  mytree->SetBranchAddress("dbaencoded",&dbaencoded);
100  mytree->SetBranchAddress("pass_reco",&pass_reco);
101  mytree->SetBranchAddress("pass_slc",&pass_slc);
102  mytree->SetBranchAddress("pass_trk",&pass_trk);
103  mytree->SetBranchAddress("corrupted",&corrupted);
104  mytree->SetBranchAddress("procsec",&procsec);
105  mytree->SetBranchAddress("numslc",&numslc);
106  mytree->SetBranchAddress("trkfrac2D",&trkfrac2D);
107  mytree->SetBranchAddress("preliminary",&preliminary);
108 
109 // This is the loop skeleton
110 // To read only selected branches, Insert statements like:
111 // mytree->SetBranchStatus("*",0); // disable all branches
112 // TTreePlayer->SetBranchStatus("branchname",1); // activate branchname
113 
114  Long64_t nentries = mytree->GetEntries();
115 
116  Long64_t nbytes = 0;
117  for (Long64_t i=0; i<nentries;i++) {
118  nbytes += mytree->GetEntry(i);
119 
120  //Define here conditions for printing output
121  std::vector<bool> printConditions;
122  printConditions.push_back( bool(i%10000==0) ); //Every 10K rows
123  //printConditions.push_back( bool(i>=1405900 && i<=1407000) ); //Range 1
124  //printConditions.push_back( bool(i>=1407450 && i<=1409000) ); //Range 2
125  printConditions.push_back( bool(i>=1350000 && i<=1360000) ); //Range 2
126 
127  //Compose (logical OR) all the conditions
128  bool jointPrintCondition = 0;
129  for(int k=0; k<printConditions.size();k++)
130  jointPrintCondition = jointPrintCondition || printConditions[k];
131 
132  //Actually print
133  if (jointPrintCondition){
134  std::cout
135  << "Row "
136  << std::setw(7) << i
137  << " : "
138  << std::setw(5) << run
139  << "/"
140  << std::setw(2) << subrun
141  << " GoodDB "
142  << std::setw(2) << ngooddb
143  << " PassAll "
144  << std::setw(1) << pass_all
145  << " Length "
146  << std::setw(4) << lastsec-firstsec
147  << " DBdecoded "
148  << std::setw(14) << std::bitset<14>(dbencoded)
149  << std::endl;
150  }
151 
152  }
153 
154  //Happy ending!
155  std::cout<<"Successfully completed the loop over ttree" << std::endl;
156 }
Int_t pass_trk
Definition: SimpleIterate.C:58
Int_t lastsec
Definition: SimpleIterate.C:27
Double_t numslc
Definition: SimpleIterate.C:61
Int_t ngooddcm
Definition: SimpleIterate.C:30
Int_t pass_all
Definition: SimpleIterate.C:42
Double_t trkfrac2D
Definition: SimpleIterate.C:62
Int_t ngooddb
Definition: SimpleIterate.C:31
Int_t par
Definition: SimpleIterate.C:24
Double_t nactivechannels
Definition: SimpleIterate.C:52
Int_t dbencoded
Definition: SimpleIterate.C:54
Double_t miprate
Definition: SimpleIterate.C:48
Double_t rectimesec
Definition: SimpleIterate.C:44
Int_t nevents
Definition: SimpleIterate.C:25
Int_t pass_empty
Definition: SimpleIterate.C:38
Int_t nactivefeb
Definition: SimpleIterate.C:34
TFile * f
Definition: SimpleIterate.C:14
Int_t dbaencoded
Definition: SimpleIterate.C:55
Long64_t nentries
Double_t midhitrate
Definition: SimpleIterate.C:47
Int_t nactivedcm
Definition: SimpleIterate.C:35
Int_t ngoodmip
Definition: SimpleIterate.C:32
Double_t emptypercentage
Definition: SimpleIterate.C:53
Int_t preliminary
Definition: SimpleIterate.C:63
Int_t subrun
Definition: SimpleIterate.C:23
Int_t ngoodcdb
Definition: SimpleIterate.C:33
TTree * mytree
Definition: SimpleIterate.C:18
Int_t run
Definition: SimpleIterate.C:22
Double_t midmiprate
Definition: SimpleIterate.C:49
Int_t nactivedb
Definition: SimpleIterate.C:36
OStream cout
Definition: OStream.cxx:6
Int_t procsec
Definition: SimpleIterate.C:60
Int_t ngoodpix
Definition: SimpleIterate.C:28
Int_t firstsec
Definition: SimpleIterate.C:26
Double_t mipratio
Definition: SimpleIterate.C:50
Int_t pass_db
Definition: SimpleIterate.C:40
Long64_t nbytes
Double_t hitrate
Definition: SimpleIterate.C:46
Int_t pass_slc
Definition: SimpleIterate.C:57
Int_t setsize
Definition: SimpleIterate.C:43
Double_t setlivetime
Definition: SimpleIterate.C:45
Int_t pass_reco
Definition: SimpleIterate.C:56
Double_t mipasym
Definition: SimpleIterate.C:51
Int_t ngoodfeb
Definition: SimpleIterate.C:29
Int_t pass_runlen
Definition: SimpleIterate.C:37
Int_t corrupted
Definition: SimpleIterate.C:59
Int_t pass_time
Definition: SimpleIterate.C:41
Int_t pass_hits
Definition: SimpleIterate.C:39