ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/root/runSizeAnalyzer.C
Revision: 1.1
Committed: Tue Apr 10 01:49:46 2012 UTC (13 years, 1 month ago) by paus
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_028, Mit_027a, Mit_027, Mit_026, HEAD
Log Message:
Ready for 2012 data.

File Contents

# User Rev Content
1 paus 1.1 // $Id: runSimpleFileCataloger.C,v 1.2 2012/03/29 23:41:59 paus Exp $
2    
3     #if !defined(__CINT__) || defined(__MAKECINT__)
4     #include <TROOT.h>
5     #include <TSystem.h>
6     #include <TFile.h>
7     #include <TTree.h>
8     #include <TBranch.h>
9     #include <TBasket.h>
10     #include <TCanvas.h>
11     #include <TPie.h>
12     #endif
13    
14     const TString slash = "/";
15     const TString hadoopDoor = "root://xrootd.cmsaf.mit.edu/";
16    
17     void analyzeBranchSizes(const char *dir, const char *file);
18    
19     //--------------------------------------------------------------------------------------------------
20     void runSizeAnalyzer(const char *dir = "/mnt/hadoop/cmsprod/filefi/025/r11b-pho-j16-v1",
21     const char *file = "FA6DDCFE-1D43-E111-8E71-002590200900.root")
22     {
23     // -----------------------------------------------------------------------------------------------
24     // This script runs a full cataloging action on the given directory
25     // -----------------------------------------------------------------------------------------------
26     analyzeBranchSizes(dir,file);
27     return;
28     }
29    
30     //--------------------------------------------------------------------------------------------------
31     Long64_t RawBytes(TBranch* branch, UInt_t recursion=0)
32     {
33     Long64_t totBytes = branch->GetTotBytes();
34     TObjArray *subBranches = branch->GetListOfBranches();
35     for (Int_t i=0; i<subBranches->GetEntries(); ++i) {
36     TBranch *subBranch = (TBranch*)subBranches->At(i);
37     totBytes += RawBytes(subBranch, recursion+1);
38     }
39     return totBytes;
40     }
41    
42     //--------------------------------------------------------------------------------------------------
43     Long64_t ZipBytes(TBranch* branch, Double_t ratio, UInt_t recursion=0)
44     {
45     //TBasket* currentBasket = branch->GetBasket(branch->GetReadBasket());
46     //currentBasket->SetWriteMode();
47     //branch->WriteBasket(currentBasket,0);
48    
49     Long64_t totBytes = branch->GetZipBytes();
50     TObjArray *subBranches = branch->GetListOfBranches();
51     for (Int_t i=0; i<subBranches->GetEntries(); ++i) {
52     TBranch *subBranch = (TBranch*) subBranches->At(i);
53     totBytes += ZipBytes(subBranch,ratio,recursion+1);
54     }
55     return totBytes;
56     }
57    
58     //--------------------------------------------------------------------------------------------------
59     void analyzeBranchSizes(const char *dir, const char *file)
60     {
61     TString fileName = TString(dir) + slash + + TString(file);
62     if (fileName.Index("castor/cern.ch") != -1)
63     fileName = TString("castor:") + fileName;
64     if (fileName.Index("mnt/hadoop/cms/store") != -1) {
65     fileName.Remove(0,15);
66     fileName = hadoopDoor + fileName;
67     }
68    
69     TFile* f = TFile::Open(fileName.Data());
70     TTree* tree = (TTree*) f->FindObjectAny("Events");
71     printf("XX-CATALOG-XX %s %lld\n",fileName.Data(),tree->GetEntries());
72    
73     Long64_t evtRawSize = tree->GetTotBytes();
74     Long64_t evtZipSize = tree->GetZipBytes();
75    
76     Double_t evtComp = (Double_t) evtRawSize/evtZipSize;
77    
78     TObjArray *evtBranches = tree->GetListOfBranches();
79     UInt_t nBranches = evtBranches->GetEntries();
80    
81     Long64_t rawTotal = 0;
82     Long64_t zipTotal = 0;
83    
84     printf("\nSizes in bytes\n");
85     printf( "===============\n");
86     for (UInt_t i=0; i<nBranches; ++i) {
87     TBranch* branch = (TBranch*) evtBranches->At(i);
88     Long64_t branchSizeZip = ZipBytes(branch, evtComp);
89     Long64_t branchSizeRaw = RawBytes(branch);
90    
91     printf("%-40s Size = %10lld %10lld\n",branch->GetName(),branchSizeRaw,branchSizeZip);
92    
93     rawTotal += branchSizeRaw;
94     zipTotal += branchSizeZip;
95    
96     }
97    
98     printf("\nSizes relative to total in percent\n");
99     printf( "==================================\n");
100     for (UInt_t i=0; i<nBranches; ++i) {
101     TBranch* branch = (TBranch*) evtBranches->At(i);
102     Long64_t branchSizeZip = ZipBytes(branch, evtComp);
103     Long64_t branchSizeRaw = RawBytes(branch);
104    
105     printf("%-40s Size = %10f %10f\n",branch->GetName(),
106     100*double(branchSizeRaw)/double(rawTotal),
107     100*double(branchSizeZip)/double(zipTotal));
108     }
109    
110    
111     TTree* allTree = (TTree*) f->FindObjectAny("AllEvents");
112     if (allTree)
113     printf("XX-CATALOG-XX %s %lld %lld\n",fileName.Data(),tree->GetEntries(),allTree->GetEntries());
114     else
115     printf("\n WARNING -- All event tree not found in this file.\n\n");
116     }