]>
Commit | Line | Data |
---|---|---|
a65a7e70 | 1 | /******************************************************************** |
2 | ||
3 | Bad Chunks Checking code, 15th April 2013 | |
4 | ||
5 | --- This version is a bit more "automatized" in that you give it a | |
6 | dataset string as a parameter and it spits out appropriately named | |
7 | text files. Some small customization for each usage case (output | |
8 | directory, in the first lines of the function below) may still | |
9 | be needed when being used in general. | |
10 | ||
11 | --- Also note: the code expects to find an "output" directory to | |
12 | store text files with summaries. If it does not exist, please create | |
13 | it or also chang the path! | |
14 | ||
15 | ********************************************************************/ | |
16 | ||
17 | ||
18 | #include <iostream> | |
19 | #include <fstream> | |
20 | ||
21 | #include "TFile.h" | |
22 | #include "TTree.h" | |
23 | #include "TString.h" | |
24 | ||
25 | using namespace std; | |
26 | ||
27 | int ProcessBadChunks02(TString lDataset ){ | |
28 | ||
29 | //Path to output files: change as needed | |
30 | TString lFileName = "/Volumes/MyPassport/work/download/badchunk/"; | |
31 | lFileName.Append(lDataset.Data()); | |
32 | lFileName.Append(".root"); | |
33 | ||
34 | //Print out "I'm alive" | |
35 | cout<<"----------------------------------------------------"<<endl; | |
36 | cout<<" Bad Chunk Analysis Macro"<<endl; | |
37 | cout<<"----------------------------------------------------"<<endl; | |
38 | cout<<" Dataset identified as......: "<<lDataset<<endl; | |
39 | cout<<" Filename to open...........: "<<lFileName<<endl; | |
40 | ||
41 | //Open... | |
42 | // Open the file | |
43 | TFile* file = TFile::Open(lFileName, "READ"); | |
44 | if (!file || !file->IsOpen()) { | |
45 | cout<<"File not found!"<<endl; | |
46 | return 1; | |
47 | } | |
48 | // Get the tree | |
49 | TTree* ftree = (TTree*)file->FindObjectAny("fTree"); | |
50 | if (!ftree) { | |
51 | cout<<"File doesn't contain fTree!"<<endl; | |
52 | return 2; | |
53 | } | |
54 | ||
55 | cout<<" Entries in Event Tree......: "<<ftree->GetEntries()<<endl; | |
56 | cout<<"----------------------------------------------------"<<endl; | |
57 | //return 0; | |
58 | Int_t llRunNumber = 0; | |
59 | TString * llFileName = 0x0; | |
60 | Int_t llNTracks = 0; | |
61 | Int_t llNGlobalTracks = 0; | |
62 | ||
63 | ftree->SetBranchAddress("fRunNumber" ,&llRunNumber ); | |
64 | ftree->SetBranchAddress("fFileName" , &llFileName ); | |
65 | ftree->SetBranchAddress("fNTracks" ,&llNTracks ); | |
66 | ftree->SetBranchAddress("fNGlobalTracks" ,&llNGlobalTracks ); | |
67 | ||
68 | //Output ostreams: text files with chunk location, good and bad | |
69 | ||
70 | //Save by default to "output" directory | |
71 | TString lGoodName = "output/GoodChunks-"; | |
72 | lGoodName.Append(lDataset.Data()); | |
73 | lGoodName.Append(".txt"); | |
74 | TString lBadName = "output/BadChunks-"; | |
75 | lBadName.Append(lDataset.Data()); | |
76 | lBadName.Append(".txt"); | |
77 | ||
78 | TString lReport = "output/Datasetreport-"; | |
79 | lReport.Append(lDataset.Data()); | |
80 | lReport.Append(".txt"); | |
81 | ||
82 | filebuf fbgood; | |
83 | fbgood.open (lGoodName,ios::out); | |
84 | ostream osgood(&fbgood); | |
85 | ||
86 | filebuf fbbad; | |
87 | fbbad.open (lBadName,ios::out); | |
88 | ostream osbad(&fbbad); | |
89 | ||
90 | filebuf fbreport; | |
91 | fbreport.open (lReport,ios::out); | |
92 | ostream osreport(&fbreport); | |
93 | ||
94 | //Main Tree Loop | |
95 | Long_t lProcessedChunks = 0; | |
96 | Long_t lProcessedChunksGood = 0; | |
97 | Long_t lProcessedChunksBad = 0; | |
98 | Long_t lTracks = 0; | |
99 | Long_t lGlobalTracks = 0; | |
100 | TString *lChunkName = new TString(); | |
101 | ||
102 | //First Chunk entry | |
103 | ftree->GetEntry(0); | |
104 | *lChunkName = *llFileName; | |
105 | ||
106 | cout<<"TEST "<<lChunkName->Data() <<", track = "<<lTracks<<", globals = "<<lGlobalTracks<<" " << llFileName->Data() << endl; | |
107 | ||
108 | for(Long_t iEvent = 1; iEvent<ftree->GetEntries(); iEvent++){ | |
109 | ftree->GetEntry(iEvent); | |
110 | if( !llFileName->EqualTo(*lChunkName) ){ | |
111 | lProcessedChunks++; | |
112 | //Change Chunk | |
113 | if( lTracks > 0 && lGlobalTracks ==0){ | |
114 | //Candidate bad chunk found! | |
115 | cout<<"BAD CHUNK at "<<lChunkName->Data() <<", track = "<<lTracks<<", globals = "<<lGlobalTracks<< endl; | |
116 | osbad<<lChunkName->Data()<<endl; | |
117 | lProcessedChunksBad++; | |
118 | }else{ | |
119 | //This looks OK... | |
120 | //cout<<"GOOD CHUNK at "<<lChunkName<<endl; | |
121 | osgood<<lChunkName->Data()<<endl; | |
122 | lProcessedChunksGood++; | |
123 | } | |
124 | //Get ready to loop over new chunk | |
125 | *lChunkName = *llFileName; | |
126 | lTracks = llNTracks; | |
127 | lGlobalTracks = llNGlobalTracks; | |
128 | if(lProcessedChunks%5000==0) cout<<"---> Processed "<<lProcessedChunks<<"..."<<endl; | |
129 | }else{ | |
130 | lTracks += llNTracks; | |
131 | lGlobalTracks += llNGlobalTracks; | |
132 | } | |
133 | } | |
134 | //CLOSE the processing: one extra pass... | |
135 | lProcessedChunks++; | |
136 | if( lTracks > 0 && lGlobalTracks ==0){ | |
137 | //Candidate bad chunk found! | |
138 | cout<<"BAD CHUNK at "<<lChunkName->Data()<<endl; | |
139 | osbad<<lChunkName->Data() <<endl; | |
140 | lProcessedChunksBad++; | |
141 | }else{ | |
142 | //This looks OK... | |
143 | //cout<<"GOOD CHUNK at "<<lChunkName<<endl; | |
144 | osgood<<lChunkName->Data()<<endl; | |
145 | lProcessedChunksGood++; | |
146 | } | |
147 | fbgood.close(); | |
148 | fbbad.close(); | |
149 | ||
150 | cout<<"----------------------------------------------------"<<endl; | |
151 | cout<<"Processed chunks, total..: "<<lProcessedChunks<<endl; | |
152 | cout<<"Processed chunks, good...: "<<lProcessedChunksGood<<endl; | |
153 | cout<<"Processed chunks, bad....: "<<lProcessedChunksBad<<endl; | |
154 | cout<<"Corruption rate..........: "<<((double)lProcessedChunksBad)/((double)lProcessedChunks)<<endl; | |
155 | cout<<"Corruption rate, percent.: "<<100.*((double)lProcessedChunksBad)/((double)lProcessedChunks)<<" percent"<<endl; | |
156 | cout<<"----------------------------------------------------"<<endl; | |
157 | ||
158 | //Write report file | |
159 | osreport<<"----------------------------------------------------"<<endl; | |
160 | osreport<<" "<<lDataset<<" Processed chunks, total..: "<<lProcessedChunks<<endl; | |
161 | osreport<<" "<<lDataset<<" Processed chunks, good...: "<<lProcessedChunksGood<<endl; | |
162 | osreport<<" "<<lDataset<<" Processed chunks, bad....: "<<lProcessedChunksBad<<endl; | |
163 | osreport<<" "<<lDataset<<" Corruption rate..........: "<<((double)lProcessedChunksBad)/((double)lProcessedChunks)<<endl; | |
164 | osreport<<" "<<lDataset<<" Corruption rate, percent.: "<<100.*((double)lProcessedChunksBad)/((double)lProcessedChunks)<<" percent"<<endl; | |
165 | osreport<<"----------------------------------------------------"<<endl; | |
166 | ||
167 | ||
168 | fbreport.close(); | |
169 | cout<<endl; | |
170 | cout<<"---> Good chunks saved to \"goodguys.txt\""<<endl; | |
171 | cout<<"---> Bad chunks saved to \"badguys.txt\""<<endl; | |
172 | cout<<endl; | |
173 | cout<<"DONE!"<<endl; | |
174 | return 0; | |
175 | ||
176 | } |