ROOT file much larger than it should be

I have old c code that produces a data structure for each event that looks like,

#define maxLength 2048

typedef struct recordTag {
  bool C1,C2,C3,C4;
  int numberSamples;
  int eventCounter;
  long int eventTime;
  short waveForm1[2048];
  short waveForm2[2048];
  short waveForm3[2048];
  short waveForm4[2048];
} RECORD;

I’m putting this into a TTree like this,

  //                                                                            
  // Tree structure                                                             
  //                                                                            
  // File header Header                                                         
  //                                                                            
  const Int_t kMaxSample=200003;
  Int_t nChan;
  Int_t startTime;
  Int_t startDate;
  Int_t stopTime;
  Int_t stopDate;
  //                                                                            
  // Traces                                                                     
  //                                                                            
  Float_t t[kMaxSample];
  Short_t trace1V[kMaxSample];
  Short_t trace2V[kMaxSample];
  Short_t trace3V[kMaxSample];
  Short_t trace4V[kMaxSample];
  //                                                                            
  // Event Header                                                               
  //                                                                            
  Int_t eventNumber;
  Int_t eventTime;
  Int_t eventDate;

and,

  TTree::SetMaxTreeSize(10000000000);
  std::cout << "Making root TTrees and opening " <<
    outfile << std::endl;
  TFile* rout=new TFile(outfile,"recreate");;
  TTree* myHeader=new TTree("myHeader","File Header Data");
  myHeader->Branch("startTime",&startTime,"startTime/I");
  myHeader->Branch("startDate",&startDate,"startDate/I");
  myHeader->Branch("stopTime",&stopTime,"stopTime/I");
  myHeader->Branch("stopDate",&stopDate,"stopDate/I");
  myHeader->Branch("nChan",&nChan,"nChan/I");
  myHeader->Branch("t",t,"t[nChan]/F");
  TTree* myEvent=new TTree("myEvent","event data");
  nChan=maxLength;
  myEvent->Branch("nChan",&nChan,"nChan/I");
  if(C1==true)myEvent->Branch("trace1V",trace1V,"trace1V[nChan]/S");
  if(C2==true)myEvent->Branch("trace2V",trace2V,"trace2V[nChan]/S");
  if(C3==true)myEvent->Branch("trace3V",trace3V,"trace3V[nChan]/S");
  if(C4==true)myEvent->Branch("trace4V",trace4V,"trace4V[nChan]/S");
  myEvent->Branch("eventNumber",&eventNumber,"eventNumber/I");
  myEvent->Branch("eventTime",&eventTime,"eventTime/I");
  myEvent->Branch("eventDate",&eventDate,"eventDate/I");
  //                                                                            
  // Open file                                                                  
  //

Each binary file is 2.5Gb long, but the resulting root file is more like 40 Gb. Here is the Print(“all”) of the TTrees at the end of 1,000 events,

******************************************************************************
*Tree    :myHeader  : File Header Data                                       *
*Entries :        1 : Total =           12103 bytes  File  Size =       8103 *
*        :          : Tree compression factor =   1.19                       *
******************************************************************************
*Br    0 :startTime : startTime/I                                            *
*Entries :        1 : Total  Size=        593 bytes  File Size  =         84 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    1 :startDate : startDate/I                                            *
*Entries :        1 : Total  Size=        593 bytes  File Size  =         84 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    2 :stopTime  : stopTime/I                                             *
*Entries :        1 : Total  Size=        588 bytes  File Size  =         83 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    3 :stopDate  : stopDate/I                                             *
*Entries :        1 : Total  Size=        588 bytes  File Size  =         83 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    4 :nChan     : nChan/I                                                *
*Entries :        1 : Total  Size=        573 bytes  File Size  =         80 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    5 :t         : t[nChan]/F                                             *
*Entries :        1 : Total  Size=       8844 bytes  File Size  =       6872 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.20     *
*............................................................................*
******************************************************************************
*Tree    :myEvent   : event data                                             *
*Entries :     1000 : Total =        13055665 bytes  File  Size =    1415289 *
*        :          : Tree compression factor =   9.37                       *
******************************************************************************
*Br    0 :nChan     : nChan/I                                                *
*Entries :     1000 : Total  Size=     103309 bytes  File Size  =      79000 *
*Baskets :     1000 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    1 :trace1V   : trace1V[nChan]/S                                       *
*Entries :     1000 : Total  Size=    4209404 bytes  File Size  =     777115 *
*Baskets :     1000 : Basket Size=      32000 bytes  Compression=   5.39     *
*............................................................................*
*Br    2 :trace2V   : trace2V[nChan]/S                                       *
*Entries :     1000 : Total  Size=    4209404 bytes  File Size  =     134000 *
*Baskets :     1000 : Basket Size=      32000 bytes  Compression=  31.23     *
*............................................................................*
*Br    3 :trace4V   : trace4V[nChan]/S                                       *
*Entries :     1000 : Total  Size=    4209404 bytes  File Size  =     134000 *
*Baskets :     1000 : Basket Size=      32000 bytes  Compression=  31.23     *
*............................................................................*
*Br    4 :eventNumber : eventNumber/I                                        *
*Entries :     1000 : Total  Size=     109333 bytes  File Size  =      85000 *
*Baskets :     1000 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    5 :eventTime : eventTime/I                                            *
*Entries :     1000 : Total  Size=     107325 bytes  File Size  =      83000 *
*Baskets :     1000 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    6 :eventDate : eventDate/I                                            *
*Entries :     1000 : Total  Size=     107325 bytes  File Size  =      83000 *
*Baskets :     1000 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*

the sizes of the TTrees given above are consistent with what I calculate from the binary final, but the resulting .root file is 25 M, about twice what it should be. Things get worse as the number of events increases:

No. events .root file size .root event size
1,000 25 M 25k
2,000 96 M 48 k
4,000 382 M 95 k
8,000 1,500 M 1,875 k

Clear I am doing something very wrong…

Peter

ROOT Version: 6.25
Platform: Apple Desktop Pro
Compiler: gcc version 10.2.1 20210110 (Debian 10.2.1-6)


Is ‘nChan’ a constant or is it updated for each entry?

I see

Is the discrepancy (2048 vs 200003) intentional?

No, but I changed kMaxSample to 2048 and still see the same problem.

Never mind! The geometric progress got me thinking that I must be re-writing a copy of the whole tree each iteration and I was. I had

     myEvent->Fill();
     rout->Write();
}

rather than

}
rout->Write()

Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.