# Reading all events of a ROOT Tree

    //*CMZ :          10/01/97  11.38.56  by  Rene Brun
    //*-- Author :    Rene Brun   10/01/97
    {
    //  This macro read all events generated by the test program Event
    //  provided in $ROOTSYS/test.
    //
    //  NOTE: Before executing this macro, you must have executed
    //  the macro eventload to load a shared library.
    //
    //  This small program simply counts the number of bytes read and dump
    //  the first 2 events.

       gROOT->Reset();

    //   Connect file generated in $ROOTSYS/test
       TFile f("Event.root");

    //   Set a maximum for tree buffers in memory at 20 Mbytes
       T.SetMaxVirtualSize(20000000);

    //   Create a timer object to benchmark this loop
       TStopwatch timer;
       timer.Start();

    //   Start main loop on all events
       Event *event = new Event();   //we create the event object once outside the loop
       TClonesArray *tracks = 0;
       TBranch *branch = T.GetBranch("event");
       branch->SetAddress(event);
       Int_t nevent = T.GetEntries();
       Int_t nb = 0;
       for (Int_t i=0;i<nevent;i++) {
          if(i%50 == 0) printf("Event:%d\n",i);
          nb += T.GetEvent(i);                   //read complete event in memory
          if (i < 3) event->Dump();              //dump the first 3 events
          tracks = event->GetTracks();           //get pointer to the TClonesArray object
          tracks->Clear();                       //clear it
       }

    //  Stop timer and print results
       timer.Stop();
       Float_t mbytes = 0.000001*nb;
       Double_t rtime = timer.RealTime();
       Double_t ctime = timer.CpuTime();
       printf("%d events and %d bytes read.\n",nevent,nb);
       printf("file compression factor = %f\n",f.GetCompressionFactor());
       printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
       printf("You read %f Mbytes/Realtime seconds\n",mbytes/rtime);
       printf("You read %f Mbytes/Cputime seconds\n",mbytes/ctime);

    //  Delete ClonesArray and track objects
       event->Finish();
    }