11 #include <TStopwatch.h>
14 #include <Riostream.h>
17 #define BUFSIZE 32*1024
19 Float_t
write_sys(
const char *filename =
"data.tmp")
21 int nbblock = 30000;
char buf[
BUFSIZE];
23 printf(
"Writing %d Mbytes (%d blocks) with the system function write \n",nbblock*
BUFSIZE/(1024*1024),nbblock);
25 int id = open(filename,O_WRONLY | O_CREAT);
27 printf(
"Cannot open file \n");
34 for (
int i = 0; i < nbblock; i++ ) write(
id,buf,
BUFSIZE);
37 printf(
" --> Writing rate %f MB/s \n",nbblock*
BUFSIZE/(1024*1024*watch.RealTime()));
41 return nbblock*
BUFSIZE/(1024*1024*watch.RealTime());
44 Float_t
read_sys(
const char *filename =
"data.tmp")
46 int nbblock = 30000;
char buf[
BUFSIZE];
48 printf(
"Reading %d Mbytes (%d blocks) with the system function read \n",nbblock*
BUFSIZE/(1024*1024),nbblock);
49 int id = open(filename,O_RDONLY);
51 printf(
"Cannot open file \n");
58 for (
int i = 0; i < nbblock; i++ ) read(
id,buf,
BUFSIZE);
61 printf(
" --> Reading rate %f MB/s \n",nbblock*
BUFSIZE/(1024*1024*watch.RealTime()));
64 return nbblock*
BUFSIZE/(1024*1024*watch.RealTime());
67 Float_t
write_tree(
const char *filename =
"data.root", Int_t nbevents = 10000000, Int_t compression = 0)
69 printf(
"Writing %d events in a root tree with compression level %d \n",nbevents,compression);
71 TFile *fileout =
new TFile(filename,
"recreate");
72 if ( fileout->IsZombie() ) {
73 printf(
"Cannot open file \n");
76 fileout->SetCompressionLevel(compression);
78 Double_t wbytes = 0.0;
79 Int_t nbgamma; Int_t e[1000];
80 for (Int_t i = 1; i < 1000; i++) e[i] = 200*i;
83 treeout =
new TTree(
"TEST",
"TEST");
84 treeout->Branch(
"mult",&nbgamma,
"nbgamma/I"); treeout->Branch(
"e",e,
"e[nbgamma]/I");
89 for (
int i = 0; i < nbevents; i++ ) {
90 nbgamma = 2 + i % 5; wbytes += 4.0; wbytes += nbgamma * 4.0;
95 printf(
" --> Writing rate %f MB/s [%f] \n",wbytes/(1024*1024*watch.RealTime()),wbytes/(1024*1024));
97 fileout->Close();
delete fileout;
102 Float_t
read_tree(
const char *filename =
"data.root", Double_t bytes = 10000000)
104 printf(
"Reading events from a root tree \n");
106 TFile *filein =
new TFile(filename,
"READ");
107 if ( filein->IsZombie() ) {
108 printf(
"Cannot open file \n");
112 Int_t nbgamma; Int_t e[1000];
115 treein = (TTree *)filein->Get(
"TEST");
116 if ( treein == NULL )
return 0;
118 treein->SetBranchAddress(
"mult",&nbgamma);
119 treein->SetBranchAddress(
"e",&e);
125 treein->Draw(
"e",
"",
"goff");
128 cout <<
" --> Reading rate " << bytes / (1024*1024*watch.RealTime()) <<
" MB/s"<<
endl ;
130 filein->Close();
delete filein;
return bytes / (1024*1024*watch.RealTime()) ;
135 const char *fname1 =
"testio.tmp";
136 printf(
"\n************ Basic I/O from the system ************ \n");
139 printf(
"\n************ ROOT/TTree I/O ************ \n");
140 const char *fname2 =
"testio.root";
printf("******************************************************************** \n")
Float_t write_sys(const char *filename="data.tmp")
Float_t read_sys(const char *filename="data.tmp")
Float_t write_tree(const char *filename="data.root", Int_t nbevents=10000000, Int_t compression=0)
ADF::LogMessage & endl(ADF::LogMessage &log)
Float_t read_tree(const char *filename="data.root", Double_t bytes=10000000)