More information on this package is here.
// Author:  Maurik Holtrop <http://www.physics.unh.edu/~maurik>
//____________________ 
//  TMiniDSTReader is a calls implements tools for Reading ROOT DST's
//  without any run group specific details. 
//  It will contain tools only to read EVENT and Scaller trees.
// 
// ________________________________________________________________
//
//   Author : G.Gavalian (UNH) 04/02/2002
//  
//


#include "TMiniDSTReader.h"


ClassImp(TMiniDSTReader)

TMiniDSTReader::TMiniDSTReader()
{
  //  Default Constructor.
  //  Default Debug mode is 1
  //  To change it use SetDebugMode(debugmode)

  //  fDebug_Mode   = kDBG_Error+kDBG_Info;

  //  fDebug_Mode = kDBG_Error+kDBG_Info;

  //  fDebug_Mode   = 0;

  fEventChain   = new TChain("E1DEVNT");
  fEvntHeader   = new TMiniHEADClass();
  fPElectron    = new TMiniDSTClass();
  fPProton      = new TMiniDSTClass();

  fCurrentEvent  = -1;

  // Initialize Clone Arrays
  fcaPARTStore = NULL;
  InitClones();

  //  fEventChain->SetNotify(this);
}

TMiniDSTReader::~TMiniDSTReader()
{
  // Default Destructor
  //  Destroys Chains
  //

  delete fEventChain;
}


Int_t TMiniDSTReader::AddFile(const Char_t *filename)
{
//   AddFile(const Char_t *filename)
//  
//   This Method Adds new File into Chain of
//  files to be analysed. Changes Value of 
// variable nFilesinChain 
//
//  cout << "Looking for file File " << filename << endl;
  if(access(filename,R_OK) == 0){
    //  cout << "TClasTool::AddFile : File \"" << filename << "\" is added to Chain" << endl;
    if(!fEventChain->Add(filename) || fEventChain->GetNtrees() == 0){
      cerr << "Could not properly add the file " << filename << " to event chain.\n";
    }

    if( GetNFiles() == 1 ) {
      // One File in the chain, so this is first time we added one.
      cout << "TClasTool::AddFile (INFO): First file added. Initializing Branches" << endl;
      InitBranches();
    }

    return 0;

  } else {

    cout << "TClasTool::AddFile (ERROR): Cannot access \"" << filename << "\" file for reading" << endl;
    return -1;
  }

}

Int_t TMiniDSTReader::ReadNext(){
  return Next();
}

Int_t TMiniDSTReader::ReadEvent(Int_t evtnum){
  cout << "TMiniDSTReader::ReadEvent: this function is not implemented yet." << endl;
  return 0;
}


Int_t TMiniDSTReader::Next(){
  // Next() reads next available Entry in TREE into 
  // Clone Arrays. On success returns 0 otherwise -1 will
  // be returned..
  //  fCurrentEvent = 17;
  Int_t status = 0;
  if(fCurrentEvent >= fEventChain->GetEntries()-1){
    cout << "TMiniDSTReader::Next : End of Event Entries Reached !" << endl;
    status = -1;
  } else {
    //    cout  << "Reading next event " <<  fEventChain->GetEntries() << endl;
    CleanEventClones();
    fEventChain->GetEntry(++fCurrentEvent);
    //    PrintEventStatus();
  }
  return status;
}


Bool_t TMiniDSTReader::Notify(){
  // This is a virtual stub. The code does nothing, but is intended to be
  // overwriten by your own code. It will be called by ReadScaler() 
  // every time a new scaler was read. 
  cout << "DSTReader: File in chain has changed..." << endl;
  return kTRUE;
}



void TMiniDSTReader::InitClones(){
  //   InitClones Initializes Clone Arrays for Banks if they are 
  //  not initialized.  
  // Initialize EVNT Clones Array 

  if(fcaPARTStore==NULL){
    fcaPARTStore = new TClonesArray("TMiniDSTClass",10,kTRUE);
    cout << "TMiniDSTReader::InitClones : Initializing EVNT Clones Array" << endl;
  }
  // Initialize SCPB Clones Array 
}

//--------------------------------------------------------------------------------
void TMiniDSTReader::CleanEventClones(){
  //  CleanClones Cleans Clone arrays to Read new 
  //  Entry from the tree.
  //  Calls Clear() which is faster than Delete(),
  //  according to TClonesArray documentation Clear() should be faster.
  //
    if(fcaPARTStore != NULL) fcaPARTStore->Clear();
}

//--------------------------------------------------------------------------------

//--------------------------------------------------------------------------------
void TMiniDSTReader::InitBranches(){
  //  InitBranches Initialize Branches 
  //
  // Setup Event Branches and set branch addresses
  // to  ClonesArrays
  //

  if(fEventChain){
    fEventChain->SetBranchAddress("HEADER",&fEvntHeader);
    fEventChain->SetBranchAddress("ELECTRON",&fPElectron);
    fEventChain->SetBranchAddress("PROTON",&fPProton);
    fEventChain->SetBranchAddress("NTPART",&fcaPARTStore);
  }
  fEventChain->SetBranchStatus("*",1);
}


void TMiniDSTReader::PrintSummary(){
  // Print the counters to the standard output.

  cout << "Summary of statistics:  \n\n";
  //  fCounters.Print();
}

//--------------------------------------------------------------------------------
void TMiniDSTReader::PrintEventStatus(){
//
// For Debugging ETC, print usefull information on this event.
// (To be extended )
//
  if (fCurrentEvent < 0) {
    cout << "No Current Event to Display! Make sure you have some event read in!" << endl;
  } else {
    cout << endl << "Status on Run # " << fEvntHeader->NRun <<" Event #" << fEvntHeader->NEvent
	 << " NROWS : " << GetNRows("PART") << endl;
  }
}

//--------------------------------------------------------------------------------

Int_t TMiniDSTReader::GetNRows(const Char_t *bankname){
//   This Function returns number of rows (number of 
// entries) of specified Bank (Clones Array). The string
// argument passed to function is the name of bank.
// EVNT,ECPB,SCPB,DCPB,CCPB or LCPB.
// Any other string passed to function will return -1 
// indicating that there is no bank with that name...
//
  Int_t nRows = fcaPARTStore->GetEntries() + 2;
  return nRows;
}

Int_t     TMiniDSTReader::GetEventNumber()
{
  return fCurrentEvent;
}
TObject  *TMiniDSTReader::GetBankRow(const Char_t *bankname,Int_t nrow){
  //
  // Get a specific bank given the bankname at a specific row given the row name  

  if(nrow==0) return fPElectron;
  if(nrow==1) return fPProton;

  if(nrow>1&&nrow<GetNPart()){
    return fcaPARTStore->At(nrow-2);
  }

  return NULL;
}


Int_t   TMiniDSTReader::GetChainEntries()
{
  return (Int_t) fEventChain->GetEntries();
}

Int_t  TMiniDSTReader::GetNPart(){
  return GetNRows("EVNT");
}

TVector3  TMiniDSTReader::GetPart3Vector(int indx){
  TVector3 v3vect(0,0,0);
  if(indx>GetNPart()) return v3vect;

  if(indx==0||indx==1){
    if(indx==0){
      v3vect.SetXYZ(fPElectron->GetPx(),fPElectron->GetPy(),fPElectron->GetPz());
    } else {
      v3vect.SetXYZ(fPProton->GetPx(),fPProton->GetPy(),fPProton->GetPz());
    }
  } else {
    TMiniDSTClass *mdst = (TMiniDSTClass *) GetBankRow("PART",indx);
    v3vect.SetXYZ(mdst->GetPx(),mdst->GetPy(),mdst->GetPz());
  }
  return v3vect;
}

Int_t     TMiniDSTReader::GetPartID(int indx){
  Int_t  p_id = 2212;
  if(indx==0) p_id = 11;
  if(indx >1) p_id = 22;
  return p_id;
}

Int_t     TMiniDSTReader::GetPartCharge(int indx){
  Int_t p_ch = 1;
  if(indx>1) p_ch  = 0;
  if(indx==0) p_ch = -1;
  return p_ch;
}

TString   TMiniDSTReader::GetReaderType(){
  TString rtype = "ROOTMINIDSTR2.0";
  return rtype;
}

Int_t     TMiniDSTReader::GetHelicity()
{
  return  fEvntHeader->Helicity;
}


Author: Maurik Holtrop
Last update:
CopyLeft - This code is freely available.

ROOT Home page - ClasTool Class index - Class Hierarchy - Top of the page