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