1 /********************************************************************
3 Bad Chunks Checking code, 15th April 2013
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.
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!
15 ********************************************************************/
27 int ProcessBadChunks02(TString lDataset ){
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");
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;
43 TFile* file = TFile::Open(lFileName, "READ");
44 if (!file || !file->IsOpen()) {
45 cout<<"File not found!"<<endl;
49 TTree* ftree = (TTree*)file->FindObjectAny("fTree");
51 cout<<"File doesn't contain fTree!"<<endl;
55 cout<<" Entries in Event Tree......: "<<ftree->GetEntries()<<endl;
56 cout<<"----------------------------------------------------"<<endl;
58 Int_t llRunNumber = 0;
59 TString * llFileName = 0x0;
61 Int_t llNGlobalTracks = 0;
63 ftree->SetBranchAddress("fRunNumber" ,&llRunNumber );
64 ftree->SetBranchAddress("fFileName" , &llFileName );
65 ftree->SetBranchAddress("fNTracks" ,&llNTracks );
66 ftree->SetBranchAddress("fNGlobalTracks" ,&llNGlobalTracks );
68 //Output ostreams: text files with chunk location, good and bad
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");
78 TString lReport = "output/Datasetreport-";
79 lReport.Append(lDataset.Data());
80 lReport.Append(".txt");
83 fbgood.open (lGoodName,ios::out);
84 ostream osgood(&fbgood);
87 fbbad.open (lBadName,ios::out);
88 ostream osbad(&fbbad);
91 fbreport.open (lReport,ios::out);
92 ostream osreport(&fbreport);
95 Long_t lProcessedChunks = 0;
96 Long_t lProcessedChunksGood = 0;
97 Long_t lProcessedChunksBad = 0;
99 Long_t lGlobalTracks = 0;
100 TString *lChunkName = new TString();
104 *lChunkName = *llFileName;
106 cout<<"TEST "<<lChunkName->Data() <<", track = "<<lTracks<<", globals = "<<lGlobalTracks<<" " << llFileName->Data() << endl;
108 for(Long_t iEvent = 1; iEvent<ftree->GetEntries(); iEvent++){
109 ftree->GetEntry(iEvent);
110 if( !llFileName->EqualTo(*lChunkName) ){
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++;
120 //cout<<"GOOD CHUNK at "<<lChunkName<<endl;
121 osgood<<lChunkName->Data()<<endl;
122 lProcessedChunksGood++;
124 //Get ready to loop over new chunk
125 *lChunkName = *llFileName;
127 lGlobalTracks = llNGlobalTracks;
128 if(lProcessedChunks%5000==0) cout<<"---> Processed "<<lProcessedChunks<<"..."<<endl;
130 lTracks += llNTracks;
131 lGlobalTracks += llNGlobalTracks;
134 //CLOSE the processing: one extra pass...
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++;
143 //cout<<"GOOD CHUNK at "<<lChunkName<<endl;
144 osgood<<lChunkName->Data()<<endl;
145 lProcessedChunksGood++;
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;
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;
170 cout<<"---> Good chunks saved to \"goodguys.txt\""<<endl;
171 cout<<"---> Bad chunks saved to \"badguys.txt\""<<endl;