]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/BadChunkFilter/ProcessBadChunks02.C
end-of-line normalization
[u/mrichter/AliRoot.git] / ANALYSIS / BadChunkFilter / ProcessBadChunks02.C
index 8ec628e30abc2c753c941d36fff6efd0600f4af0..67ece64044155733c9e23a6e3ac4129d11af953f 100644 (file)
-/********************************************************************\r
\r
- Bad Chunks Checking code, 15th April 2013\r
\r
- --- This version is a bit more "automatized" in that you give it a\r
- dataset string as a parameter and it spits out appropriately named \r
- text files. Some small customization for each usage case (output \r
- directory, in the first lines of the function below) may still \r
- be needed when being used in general. \r
\r
- --- Also note: the code expects to find an "output" directory to \r
- store text files with summaries. If it does not exist, please create\r
- it or also chang the path!\r
\r
-********************************************************************/\r
\r
-\r
-#include <iostream>\r
-#include <fstream>\r
-\r
-#include "TFile.h"\r
-#include "TTree.h"\r
-#include "TString.h"\r
-\r
-using namespace std;\r
-\r
-int ProcessBadChunks02(TString lDataset ){\r
-  \r
-  //Path to output files: change as needed\r
-  TString lFileName = "/Volumes/MyPassport/work/download/badchunk/";\r
-  lFileName.Append(lDataset.Data());\r
-  lFileName.Append(".root");\r
-  \r
-  //Print out "I'm alive"\r
-  cout<<"----------------------------------------------------"<<endl;\r
-  cout<<" Bad Chunk Analysis Macro"<<endl;\r
-  cout<<"----------------------------------------------------"<<endl;\r
-  cout<<" Dataset identified as......: "<<lDataset<<endl;\r
-  cout<<" Filename to open...........: "<<lFileName<<endl;\r
-  \r
-  //Open...\r
-  // Open the file\r
-  TFile* file = TFile::Open(lFileName, "READ");\r
-  if (!file || !file->IsOpen()) {\r
-    cout<<"File not found!"<<endl;\r
-    return 1;\r
-  }\r
-  // Get the tree\r
-  TTree* ftree = (TTree*)file->FindObjectAny("fTree");\r
-  if (!ftree) {\r
-    cout<<"File doesn't contain fTree!"<<endl;\r
-    return 2;\r
-  }\r
-  \r
-  cout<<" Entries in Event Tree......: "<<ftree->GetEntries()<<endl;\r
-  cout<<"----------------------------------------------------"<<endl;\r
-  //return 0;\r
-  Int_t llRunNumber = 0;\r
-  TString * llFileName = 0x0;\r
-  Int_t llNTracks = 0;\r
-  Int_t llNGlobalTracks = 0;\r
-  \r
-  ftree->SetBranchAddress("fRunNumber"      ,&llRunNumber     );\r
-  ftree->SetBranchAddress("fFileName"       , &llFileName   );\r
-  ftree->SetBranchAddress("fNTracks"        ,&llNTracks       );\r
-  ftree->SetBranchAddress("fNGlobalTracks"  ,&llNGlobalTracks );\r
-\r
-  //Output ostreams: text files with chunk location, good and bad\r
-  \r
-  //Save by default to "output" directory\r
-  TString lGoodName = "output/GoodChunks-";\r
-  lGoodName.Append(lDataset.Data());\r
-  lGoodName.Append(".txt");\r
-  TString lBadName = "output/BadChunks-";\r
-  lBadName.Append(lDataset.Data());\r
-  lBadName.Append(".txt");\r
-\r
-  TString lReport = "output/Datasetreport-";\r
-  lReport.Append(lDataset.Data());\r
-  lReport.Append(".txt");\r
-  \r
-  filebuf fbgood;\r
-  fbgood.open (lGoodName,ios::out);\r
-  ostream osgood(&fbgood);\r
-\r
-  filebuf fbbad;\r
-  fbbad.open (lBadName,ios::out);\r
-  ostream osbad(&fbbad);\r
-\r
-  filebuf fbreport;\r
-  fbreport.open (lReport,ios::out);\r
-  ostream osreport(&fbreport);\r
-  \r
-  //Main Tree Loop\r
-  Long_t lProcessedChunks = 0;\r
-  Long_t lProcessedChunksGood = 0;\r
-  Long_t lProcessedChunksBad = 0;\r
-  Long_t lTracks = 0;\r
-  Long_t lGlobalTracks = 0;\r
-  TString *lChunkName = new TString();\r
-  \r
-  //First Chunk entry\r
-  ftree->GetEntry(0);\r
-  *lChunkName = *llFileName;\r
-  \r
-  cout<<"TEST  "<<lChunkName->Data() <<", track = "<<lTracks<<", globals = "<<lGlobalTracks<<" " << llFileName->Data()  << endl;\r
-  \r
-  for(Long_t iEvent = 1; iEvent<ftree->GetEntries(); iEvent++){\r
-    ftree->GetEntry(iEvent);\r
-    if( !llFileName->EqualTo(*lChunkName) ){\r
-      lProcessedChunks++;\r
-      //Change Chunk\r
-      if( lTracks > 0 && lGlobalTracks ==0){\r
-        //Candidate bad chunk found!\r
-        cout<<"BAD CHUNK at "<<lChunkName->Data() <<", track = "<<lTracks<<", globals = "<<lGlobalTracks<< endl;\r
-        osbad<<lChunkName->Data()<<endl;\r
-        lProcessedChunksBad++;\r
-      }else{\r
-        //This looks OK...\r
-        //cout<<"GOOD CHUNK at "<<lChunkName<<endl;\r
-        osgood<<lChunkName->Data()<<endl;\r
-        lProcessedChunksGood++;\r
-      }\r
-      //Get ready to loop over new chunk\r
-      *lChunkName = *llFileName;\r
-      lTracks = llNTracks;\r
-      lGlobalTracks = llNGlobalTracks;\r
-      if(lProcessedChunks%5000==0) cout<<"---> Processed "<<lProcessedChunks<<"..."<<endl;\r
-    }else{\r
-      lTracks        += llNTracks;\r
-      lGlobalTracks  += llNGlobalTracks;\r
-    }\r
-  }\r
-  //CLOSE the processing: one extra pass...\r
-  lProcessedChunks++;\r
-  if( lTracks > 0 && lGlobalTracks ==0){\r
-    //Candidate bad chunk found!\r
-    cout<<"BAD CHUNK at "<<lChunkName->Data()<<endl;\r
-    osbad<<lChunkName->Data() <<endl;\r
-    lProcessedChunksBad++;\r
-  }else{\r
-    //This looks OK...\r
-    //cout<<"GOOD CHUNK at "<<lChunkName<<endl;\r
-    osgood<<lChunkName->Data()<<endl;\r
-    lProcessedChunksGood++;\r
-  }\r
-  fbgood.close();\r
-  fbbad.close();\r
-\r
-  cout<<"----------------------------------------------------"<<endl;\r
-  cout<<"Processed chunks, total..: "<<lProcessedChunks<<endl;\r
-  cout<<"Processed chunks, good...: "<<lProcessedChunksGood<<endl;\r
-  cout<<"Processed chunks, bad....: "<<lProcessedChunksBad<<endl;\r
-  cout<<"Corruption rate..........: "<<((double)lProcessedChunksBad)/((double)lProcessedChunks)<<endl;\r
-  cout<<"Corruption rate, percent.: "<<100.*((double)lProcessedChunksBad)/((double)lProcessedChunks)<<" percent"<<endl;\r
-  cout<<"----------------------------------------------------"<<endl;\r
-\r
-  //Write report file \r
-  osreport<<"----------------------------------------------------"<<endl;\r
-  osreport<<" "<<lDataset<<" Processed chunks, total..: "<<lProcessedChunks<<endl;\r
-  osreport<<" "<<lDataset<<" Processed chunks, good...: "<<lProcessedChunksGood<<endl;\r
-  osreport<<" "<<lDataset<<" Processed chunks, bad....: "<<lProcessedChunksBad<<endl;\r
-  osreport<<" "<<lDataset<<" Corruption rate..........: "<<((double)lProcessedChunksBad)/((double)lProcessedChunks)<<endl;\r
-  osreport<<" "<<lDataset<<" Corruption rate, percent.: "<<100.*((double)lProcessedChunksBad)/((double)lProcessedChunks)<<" percent"<<endl;\r
-  osreport<<"----------------------------------------------------"<<endl;\r
-  \r
-  \r
-  fbreport.close();\r
-  cout<<endl;\r
-  cout<<"---> Good chunks saved to \"goodguys.txt\""<<endl;\r
-  cout<<"---> Bad chunks saved to \"badguys.txt\""<<endl;\r
-  cout<<endl;\r
-  cout<<"DONE!"<<endl;\r
-  return 0;\r
-   \r
-}\r
+/********************************************************************
+ Bad Chunks Checking code, 15th April 2013
+ --- This version is a bit more "automatized" in that you give it a
+ dataset string as a parameter and it spits out appropriately named 
+ text files. Some small customization for each usage case (output 
+ directory, in the first lines of the function below) may still 
+ be needed when being used in general. 
+ --- Also note: the code expects to find an "output" directory to 
+ store text files with summaries. If it does not exist, please create
+ it or also chang the path!
+********************************************************************/
+
+#include <iostream>
+#include <fstream>
+
+#include "TFile.h"
+#include "TTree.h"
+#include "TString.h"
+
+using namespace std;
+
+int ProcessBadChunks02(TString lDataset ){
+  
+  //Path to output files: change as needed
+  TString lFileName = "/Volumes/MyPassport/work/download/badchunk/";
+  lFileName.Append(lDataset.Data());
+  lFileName.Append(".root");
+  
+  //Print out "I'm alive"
+  cout<<"----------------------------------------------------"<<endl;
+  cout<<" Bad Chunk Analysis Macro"<<endl;
+  cout<<"----------------------------------------------------"<<endl;
+  cout<<" Dataset identified as......: "<<lDataset<<endl;
+  cout<<" Filename to open...........: "<<lFileName<<endl;
+  
+  //Open...
+  // Open the file
+  TFile* file = TFile::Open(lFileName, "READ");
+  if (!file || !file->IsOpen()) {
+    cout<<"File not found!"<<endl;
+    return 1;
+  }
+  // Get the tree
+  TTree* ftree = (TTree*)file->FindObjectAny("fTree");
+  if (!ftree) {
+    cout<<"File doesn't contain fTree!"<<endl;
+    return 2;
+  }
+  
+  cout<<" Entries in Event Tree......: "<<ftree->GetEntries()<<endl;
+  cout<<"----------------------------------------------------"<<endl;
+  //return 0;
+  Int_t llRunNumber = 0;
+  TString * llFileName = 0x0;
+  Int_t llNTracks = 0;
+  Int_t llNGlobalTracks = 0;
+  
+  ftree->SetBranchAddress("fRunNumber"      ,&llRunNumber     );
+  ftree->SetBranchAddress("fFileName"       , &llFileName   );
+  ftree->SetBranchAddress("fNTracks"        ,&llNTracks       );
+  ftree->SetBranchAddress("fNGlobalTracks"  ,&llNGlobalTracks );
+
+  //Output ostreams: text files with chunk location, good and bad
+  
+  //Save by default to "output" directory
+  TString lGoodName = "output/GoodChunks-";
+  lGoodName.Append(lDataset.Data());
+  lGoodName.Append(".txt");
+  TString lBadName = "output/BadChunks-";
+  lBadName.Append(lDataset.Data());
+  lBadName.Append(".txt");
+
+  TString lReport = "output/Datasetreport-";
+  lReport.Append(lDataset.Data());
+  lReport.Append(".txt");
+  
+  filebuf fbgood;
+  fbgood.open (lGoodName,ios::out);
+  ostream osgood(&fbgood);
+
+  filebuf fbbad;
+  fbbad.open (lBadName,ios::out);
+  ostream osbad(&fbbad);
+
+  filebuf fbreport;
+  fbreport.open (lReport,ios::out);
+  ostream osreport(&fbreport);
+  
+  //Main Tree Loop
+  Long_t lProcessedChunks = 0;
+  Long_t lProcessedChunksGood = 0;
+  Long_t lProcessedChunksBad = 0;
+  Long_t lTracks = 0;
+  Long_t lGlobalTracks = 0;
+  TString *lChunkName = new TString();
+  
+  //First Chunk entry
+  ftree->GetEntry(0);
+  *lChunkName = *llFileName;
+  
+  cout<<"TEST  "<<lChunkName->Data() <<", track = "<<lTracks<<", globals = "<<lGlobalTracks<<" " << llFileName->Data()  << endl;
+  
+  for(Long_t iEvent = 1; iEvent<ftree->GetEntries(); iEvent++){
+    ftree->GetEntry(iEvent);
+    if( !llFileName->EqualTo(*lChunkName) ){
+      lProcessedChunks++;
+      //Change Chunk
+      if( lTracks > 0 && lGlobalTracks ==0){
+        //Candidate bad chunk found!
+        cout<<"BAD CHUNK at "<<lChunkName->Data() <<", track = "<<lTracks<<", globals = "<<lGlobalTracks<< endl;
+        osbad<<lChunkName->Data()<<endl;
+        lProcessedChunksBad++;
+      }else{
+        //This looks OK...
+        //cout<<"GOOD CHUNK at "<<lChunkName<<endl;
+        osgood<<lChunkName->Data()<<endl;
+        lProcessedChunksGood++;
+      }
+      //Get ready to loop over new chunk
+      *lChunkName = *llFileName;
+      lTracks = llNTracks;
+      lGlobalTracks = llNGlobalTracks;
+      if(lProcessedChunks%5000==0) cout<<"---> Processed "<<lProcessedChunks<<"..."<<endl;
+    }else{
+      lTracks        += llNTracks;
+      lGlobalTracks  += llNGlobalTracks;
+    }
+  }
+  //CLOSE the processing: one extra pass...
+  lProcessedChunks++;
+  if( lTracks > 0 && lGlobalTracks ==0){
+    //Candidate bad chunk found!
+    cout<<"BAD CHUNK at "<<lChunkName->Data()<<endl;
+    osbad<<lChunkName->Data() <<endl;
+    lProcessedChunksBad++;
+  }else{
+    //This looks OK...
+    //cout<<"GOOD CHUNK at "<<lChunkName<<endl;
+    osgood<<lChunkName->Data()<<endl;
+    lProcessedChunksGood++;
+  }
+  fbgood.close();
+  fbbad.close();
+
+  cout<<"----------------------------------------------------"<<endl;
+  cout<<"Processed chunks, total..: "<<lProcessedChunks<<endl;
+  cout<<"Processed chunks, good...: "<<lProcessedChunksGood<<endl;
+  cout<<"Processed chunks, bad....: "<<lProcessedChunksBad<<endl;
+  cout<<"Corruption rate..........: "<<((double)lProcessedChunksBad)/((double)lProcessedChunks)<<endl;
+  cout<<"Corruption rate, percent.: "<<100.*((double)lProcessedChunksBad)/((double)lProcessedChunks)<<" percent"<<endl;
+  cout<<"----------------------------------------------------"<<endl;
+
+  //Write report file 
+  osreport<<"----------------------------------------------------"<<endl;
+  osreport<<" "<<lDataset<<" Processed chunks, total..: "<<lProcessedChunks<<endl;
+  osreport<<" "<<lDataset<<" Processed chunks, good...: "<<lProcessedChunksGood<<endl;
+  osreport<<" "<<lDataset<<" Processed chunks, bad....: "<<lProcessedChunksBad<<endl;
+  osreport<<" "<<lDataset<<" Corruption rate..........: "<<((double)lProcessedChunksBad)/((double)lProcessedChunks)<<endl;
+  osreport<<" "<<lDataset<<" Corruption rate, percent.: "<<100.*((double)lProcessedChunksBad)/((double)lProcessedChunks)<<" percent"<<endl;
+  osreport<<"----------------------------------------------------"<<endl;
+  
+  
+  fbreport.close();
+  cout<<endl;
+  cout<<"---> Good chunks saved to \"goodguys.txt\""<<endl;
+  cout<<"---> Bad chunks saved to \"badguys.txt\""<<endl;
+  cout<<endl;
+  cout<<"DONE!"<<endl;
+  return 0;
+   
+}