Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add chrono to test decompression time
  • Loading branch information
zzxuanyuan committed Feb 1, 2017
commit 2144790c950cdf8b1761409cfc23e0d60c8dae73
36 changes: 18 additions & 18 deletions test/Localcompression.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

ClassImp(TLarge)
ClassImp(TSmall)
ClassImp(TInt)
ClassImp(TFloat)

////////////////////////////////////////////////////////////////////////////////
/// Create an TLarge.
Expand All @@ -20,7 +20,7 @@ TLarge::TLarge(Int_t size)
fSize = size;
fLarge = new Float_t[fSize];
for(int i=0;i<fSize;++i) {
if (i%60==0) fLarge[i] = gRandom->Rndm(1);
if (i%6==0) fLarge[i] = gRandom->Rndm(1);
else fLarge[i] = fLarge[i-1];
}
}
Expand Down Expand Up @@ -117,52 +117,52 @@ void TSmall::Clear(Option_t * /*option*/)

///////////////////////////////////////////////////////////////////////////////
/// Create an TFloat.
TInt::TInt(Int_t size)
TFloat::TFloat(Int_t size)
{
fSize = size;
fInt = new Int_t[fSize];
fInt[0] = Int_t(gRandom->Rndm(1));
fFloat = new Float_t[fSize];
fFloat[0] = Float_t(gRandom->Rndm(1));
for(int i=1;i<fSize;++i) {
fInt[i] = fInt[0];
fFloat[i] = fFloat[0];
}
}

////////////////////////////////////////////////////////////////////////////////
/// Create an TSmall.
TInt::TInt(const TInt& aint) : TObject(aint)
TFloat::TFloat(const TFloat& afloat) : TObject(afloat)
{
Int_t *intermediate = aint.GetInt();
Int_t size = aint.GetSize();
fInt = new Int_t[size];
Float_t *intermediate = afloat.GetFloat();
Int_t size = afloat.GetSize();
fFloat = new Float_t[size];
for(int i=0;i<size;++i)
fInt[i] = intermediate[i];
fFloat[i] = intermediate[i];
}

////////////////////////////////////////////////////////////////////////////////

TInt::~TInt()
TFloat::~TFloat()
{
Clear();
delete fInt;
delete fFloat;
fSize = 0;
}

//////////////////////////////////////////////////////////////////////////////////

void TInt::Build()
void TFloat::Build()
{
fInt[0] = Int_t(gRandom->Rndm(1));
fFloat[0] = Float_t(gRandom->Rndm(1));
for(int i=1;i<fSize;++i) {
fInt[i] = fInt[0];
fFloat[i] = fFloat[0];
}
}

///////////////////////////////////////////////////////////////////////////////

void TInt::Clear(Option_t * /*option*/)
void TFloat::Clear(Option_t * /*option*/)
{
TObject::Clear();
for(int i=0;i<fSize;++i)
fInt[i] = 0;
fFloat[i] = 0;
}

17 changes: 9 additions & 8 deletions test/Localcompression.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#define LARGESIZE 1000000
#define SMALLSIZE 1000
#define FLOATSIZE 6

class TLarge : public TObject {

Expand Down Expand Up @@ -60,24 +61,24 @@ class TSmall : public TObject {
ClassDef(TSmall,1)
};

class TInt : public TObject {
class TFloat : public TObject {

private:
Int_t fSize;
Int_t *fInt; //[fSize]
Float_t *fFloat; //[fSize]

public:
TInt(Int_t size = 1);
TInt(const TInt& aint);
virtual ~TInt();
TInt &operator=(const TInt &aint);
TFloat(Int_t size = FLOATSIZE);
TFloat(const TFloat& aint);
virtual ~TFloat();
TFloat &operator=(const TFloat &afloat);

void Clear(Option_t *option ="");
void Build();
Int_t GetSize() const { return fSize; }
Int_t *GetInt() const { return fInt; }
Float_t *GetFloat() const { return fFloat; }

ClassDef(TInt,1)
ClassDef(TFloat,1)
};

#endif
2 changes: 1 addition & 1 deletion test/LocalcompressionLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

#pragma link C++ class TLarge+;
#pragma link C++ class TSmall+;
#pragma link C++ class TInt+;
#pragma link C++ class TFloat+;

#endif
26 changes: 13 additions & 13 deletions test/MainLocalcombine.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace std;

int main(int argc, char **argv)
{
Int_t nevent = 40; // by default create 400 events
Int_t nevent = 1000; // by default create 400 events
Int_t comp = 1; // by default file is compressed
Int_t read = 0;
Int_t object = 0;
Expand All @@ -39,9 +39,9 @@ int main(int argc, char **argv)
TTree *tree;
TLarge *eventlarge = 0;
TSmall *eventsmall = 0;
TInt *eventint = 0;
TFloat *eventfloat = 0;
Int_t nsmall = 1000;
Int_t nint = nsmall*100;
Int_t nfloat = nsmall*100;

TStopwatch timer;
timer.Start();
Expand All @@ -59,7 +59,7 @@ int main(int argc, char **argv)
TBranch *branch;
TBranch *branchsmall;
TBranch *branchlarge;
TBranch *branchint;
TBranch *branchfloat;

// Read case
if (read) {
Expand All @@ -72,8 +72,8 @@ int main(int argc, char **argv)
branch = tree->GetBranch("EventLarge");
branch->SetAddress(&eventlarge);
} else if (object == 2) {
branch = tree->GetBranch("EventInt");
branch->SetAddress(&eventint);
branch = tree->GetBranch("EventFloat");
branch->SetAddress(&eventfloat);
} else {
branch = 0;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ int main(int argc, char **argv)

eventsmall = new TSmall();
eventlarge = new TLarge();
eventint = new TInt();
eventfloat = new TFloat();

hfile->SetCompressionLevel(comp);
hfile->SetCompressionAlgorithm(algorithm);
Expand All @@ -132,11 +132,11 @@ int main(int argc, char **argv)
TTree::SetBranchStyle(branchStyle);
branchsmall = tree->Branch("EventSmall", &eventsmall, bufsize,0);
branchlarge = tree->Branch("EventLarge", &eventlarge, bufsize,0);
branchint = tree->Branch("EventInt", &eventint, bufsize, 0);
branchfloat = tree->Branch("EventFloat", &eventfloat, bufsize, 0);

branchsmall->SetAutoDelete(kFALSE);
branchlarge->SetAutoDelete(kFALSE);
branchint->SetAutoDelete(kFALSE);
branchfloat->SetAutoDelete(kFALSE);

if(branchStyle) tree->BranchRef();

Expand All @@ -155,9 +155,9 @@ int main(int argc, char **argv)
nbs += branchsmall->Fill();
// printf("event%d, iner%d, nb small = %lld\n", ev, i, nbs);
}
for (Int_t i = 0; i < nint; ++i) {
eventint->Build();
nbi += branchint->Fill();
for (Int_t i = 0; i < nfloat; ++i) {
eventfloat->Build();
nbi += branchfloat->Fill();
// printf("event%d, iner%d, nb int = %lld\n", ev, i, nbi);
}
// nb += tree->Fill(); //fill the tree
Expand All @@ -171,7 +171,7 @@ int main(int argc, char **argv)
// We own the event (since we set the branch address explicitly), we need to delete it.
delete eventsmall; eventsmall = 0;
delete eventlarge; eventlarge = 0;
delete eventint; eventint = 0;
delete eventfloat; eventfloat = 0;

// Stop timer and print results
timer.Stop();
Expand Down
16 changes: 8 additions & 8 deletions test/MainLocalcompression.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int argc, char **argv)
TBranch *branch = 0;
TLarge *eventlarge = 0;
TSmall *eventsmall = 0;
TInt *eventint = 0;
TFloat *eventfloat = 0;

// Fill event, header and tracks with some random numbers
// Create a timer object to benchmark this loop
Expand Down Expand Up @@ -70,10 +70,10 @@ int main(int argc, char **argv)
Int_t nentries = (Int_t)tree->GetEntries();
nevent = TMath::Min(nevent,nentries);
} else if (object == 2) {
hfile = new TFile("TInt.root");
hfile = new TFile("TFloat.root");
tree = (TTree*)hfile->Get("T");
branch = tree->GetBranch("event");
branch->SetAddress(&eventint);
branch->SetAddress(&eventfloat);
Int_t nentries = (Int_t)tree->GetEntries();
nevent = TMath::Min(nevent,nentries);
}
Expand Down Expand Up @@ -111,8 +111,8 @@ int main(int argc, char **argv)
hfile = new TFile("TLarge.root","RECREATE","TTree benchmark ROOT file");
eventlarge = new TLarge();
} else if (object == 2) {
hfile = new TFile("TInt.root","RECREATE","TTree benchmark ROOT file");
eventint = new TInt();
hfile = new TFile("TFloat.root","RECREATE","TTree benchmark ROOT file");
eventfloat = new TFloat();
}

hfile->SetCompressionLevel(comp);
Expand All @@ -130,7 +130,7 @@ int main(int argc, char **argv)
} else if (object == 0) {
branch = tree->Branch("event", &eventlarge, bufsize,0);
} else if (object == 2) {
branch = tree->Branch("event", &eventint, bufsize, 0);
branch = tree->Branch("event", &eventfloat, bufsize, 0);
}

branch->SetAutoDelete(kFALSE);
Expand All @@ -148,7 +148,7 @@ int main(int argc, char **argv)
} else if (object == 0) {
eventlarge->Build();
} else if (object == 2) {
eventint->Build();
eventfloat->Build();
}
nb += tree->Fill(); //fill the tree
}
Expand All @@ -161,7 +161,7 @@ int main(int argc, char **argv)
} else if (object == 0) {
delete eventlarge; eventlarge = 0;
} else if (object == 2) {
delete eventint; eventint = 0;
delete eventfloat; eventfloat = 0;
}

// Stop timer and print results
Expand Down
13 changes: 13 additions & 0 deletions tree/tree/src/TBasket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "TTimeStamp.h"
#include "RZip.h"

#include <chrono>
#include <iostream>

// TODO: Copied from TBranch.cxx
#if (__GNUC__ >= 3) || defined(__INTEL_COMPILER)
#if !defined(R__unlikely)
Expand All @@ -47,6 +50,9 @@ Manages buffers for branches of a Tree.
See picture in TTree.
*/

static std::chrono::steady_clock::duration globalDuration = std::chrono::steady_clock::duration::zero();//##
static std::chrono::steady_clock::time_point startDuration;
static std::chrono::steady_clock::time_point endDuration;
////////////////////////////////////////////////////////////////////////////////
/// Default contructor.

Expand Down Expand Up @@ -563,6 +569,8 @@ Int_t TBasket::ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file)
fBuffer = rawUncompressedBuffer;

oldCase = OLD_CASE_EXPRESSION;

startDuration = std::chrono::steady_clock::now();//##
// Case where ROOT thinks the buffer is compressed. Copy over the key and uncompress the object
if (fObjlen > fNbytes-fKeylen || oldCase) {
if (R__unlikely(TestBit(TBufferFile::kNotDecompressed) && (fNevBuf==1))) {
Expand Down Expand Up @@ -591,6 +599,8 @@ Int_t TBasket::ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file)
if (R__unlikely(oldCase && (nin > fObjlen || nbuf > fObjlen))) {
//buffer was very likely not compressed in an old version
memcpy(rawUncompressedBuffer+fKeylen, rawCompressedObjectBuffer+fKeylen, fObjlen);
endDuration = std::chrono::steady_clock::now();//##
globalDuration += endDuration - startDuration;//##
goto AfterBuffer;
}

Expand Down Expand Up @@ -620,9 +630,12 @@ Int_t TBasket::ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file)
// Nothing is compressed - copy over wholesale.
memcpy(rawUncompressedBuffer, rawCompressedBuffer, len);
}
endDuration = std::chrono::steady_clock::now();//##
globalDuration += endDuration - startDuration;//##

AfterBuffer:

std::cout << globalDuration.count() << std::endl;//##
fBranch->GetTree()->IncrementTotalBuffers(fBufferSize);

// Read offsets table if needed.
Expand Down