BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
////////////////////////////////////////////////////////////////
//                                                            //
// BrGeantInput provides an interface to GBRAHMS output       //
// 
// The class is derived from the general input/output class
// and falls natural into the hierachi of module classes.
// 
// The data read from the GBRAHMS file by the Event method will
// add several data tables to the BrEventNode. They are
// named
//
//  "GeantTracks"      a BrDataTable with objects of BrGeantTrack  
//  "GeantHits [name]" a BrDataTable with objects of BrGeantHit
//                     belonging to the detector with the given name
//                     e.g. T1, T2, TPM1 
//  "GeantHeader"      a BrGeantHeader object.
//
// This class is meant to interacts with the gbr2c.f comis routine
// that is presently the sole output method used by GBRAHMS. Thus it
// is crucial that changed in gbr2c and BrGeantInput, BrGeantTrack are
// coordinated and that versions are properly kept. For a description
// of the file format consult the code and comments of gbr2c.f
//
//
////////////////////////////////////////////////////////////////

//
// April 21 : fIOStatus was not set properly following i/o actions.
//            This was the reason the TestBase.C failed for a non
//            existing file Note that the code has also been changed
//            for Linux, ensure updates are merged.
//
// April 24/25 Add handling of the protected variables (from
//             BrIOModule) fError and FEof to ensure uniform handling
//             of errors, and end-of-data across different BrIOModules.
//
// July 8      Increase size of GeantHits to include Pid of hit
//
// April 4,1999 Add safe guards; Add documentation
//
//
// $Id: BrGeantInput.cxx,v 1.6 2002/04/23 14:45:18 videbaek Exp $
// $Author: videbaek $
// $Date: 2002/04/23 14:45:18 $
// $Copyright: (c) 2001 BRAHMS Collaboration <brahmlib@rcf.rhic.bnl.gov>
//
//#define debug
//#define BR_DEBUG
#include <iostream.h>
#include <fcntl.h>
#include <math.h>
#include <string.h>
#ifndef WIN32
#   include <unistd.h>
#else
#   include <sys/stat.h>
#   include <sys/types.h>
#   include <sys/stat.h>
#   include <sys/types.h>
#endif
#ifndef BRAT_BrGeantInput
#include "BrGeantInput.h"
#endif
#ifndef BRAT_BrDataTable
#include "BrDataTable.h"
#endif
#ifndef BRAT_BrGeantHit
#include "BrGeantHit.h"
#endif
#ifndef BRAT_BrGeantTrack
#include "BrGeantTrack.h"
#endif
#ifndef BRAT_BrGeantHeader
#include "BrGeantHeader.h"
#endif
#ifndef BRAT_BrEvent
#include "BrEvent.h"
#endif
#ifndef BRAT_BrTableNames
#include "BrTableNames.h"
#endif
#ifndef ROOT_TSystem
#include "TSystem.h"
#endif

#ifndef ROOT_TClass
#include "TClass.h"
#endif

//______________________________________________________________________
ClassImp(BrGeantInput);

const int OLD_END_OF_STREAM_EVENT = -1;
const int END_OF_STREAM_EVENT = -802;
const int EVENT_STREAM_HEADER = 1;
const int EVENT_STREAM_HIT = 2;
const int EVENT_STREAM_TRACK =  3;



//______________________________________________________________________
 BrGeantInput::BrGeantInput()
{
  //
  //  Constructor. Set fFilePointer and fEventCounter to NULL
  //  In root environment use the named constructor normally.
#ifdef _BRDEBUG
  cout << "Ctor : BrGeantInput " << endl;
#endif

#if USE_FSTREAM
  fFilePointer  = NULL;
#else
  fFileDescriptor  = -1;
#endif
  fEventCounter = 0;
  rHeader = kFALSE;
  fByteSwap = kFALSE;
  fFillHitList = kFALSE;
}
//_____________________________________________________________________
 BrGeantInput::BrGeantInput(const Char_t *name, const Char_t* title) :
  BrIOModule(name, title ? title : name)
{
  //
  // Constructor. Set fFilePointer and fEventCounter to NULL
  // name becomes Name and Title for the Module.
  // No data file is opened this has to be done in
  // the Open() method.
  //
#if USE_FSTREAM
  fFilePointer  = NULL;
#else
  fFileDescriptor  = -1;
#endif
  fEventCounter = 0;
  rHeader       = kFALSE;
  fByteSwap     = kFALSE;
  fFillHitList  = kFALSE;
}
//_______________________________________________________________________
 BrGeantInput::~BrGeantInput(){
  //
  //  Destructor for BrGeantInput. Close the file if open.
  //
#if USE_FSTREAM
  if(fFilePointer) {
    fFilePointer->close();
    delete fFilePointer;
  }
#else
  if(fFileDescriptor != -1)
    close(fFileDescriptor);
#endif
}
//____________________________________________________________________
 Bool_t BrGeantInput::Open(const Char_t *fname, const Option_t *)
{
  // Open the C stream file with fname. Returns kFALSE
  // if the file can't be opened.
  // Otherwise the fFileName data member is set to the 
  // corresponding filepointer. The file header is read
  // and the volume information is stored in the intrinsic arrays
  //
  fIOStatus = 0;
  if(!fname) {
    Stop("Open", "can't open file : %s", fname);
    return kFALSE;
  }

  //  sprintf(fFileName,"%s",fname);
  //  File name expansion adapted from TFile constructor
  const char *name;
  if ((name = gSystem->ExpandPathName(fname))) {
    fFileName = name;
    delete [] (char*)name;
  } else {
    Stop("Open", "can't expand path: %s", fname);
    return kFALSE;
  }

#if USE_FSTREAM
  if(!fFilePointer)
    fFilePointer = new ifstream(fFileName,ios::binary);
  // Check if file is created 
  if(!fFilePointer || fFilePointer->fail()) {
    Stop("Open", "can't create fFilePointer object %s", fFileName.Data());
    delete fFilePointer;
    fFilePointer = 0;
    fError       = kTRUE;
    return kFALSE;
  }
  else {
    fIOStatus = 1;
    fError = kFALSE;
    fEof   = kFALSE;
    return ReadStreamHeader();
    fNumBytesRead =0;
  }
#else
#ifndef WIN32
  fFileDescriptor = open(fFileName, O_RDONLY);
#else
  fFileDescriptor = open(fFileName, O_RDONLY|O_BINARY);
#endif
  if(fFileDescriptor == -1) {
    Stop("Open", "Can't open File '%s'", fFileName.Data());
    fError = kTRUE;
    return kFALSE;
  }
  else {
    fIOStatus = 1;
    fNumBytesRead =0;
    return ReadStreamHeader();
  }

#endif
}

//____________________________________________________________________
 Bool_t BrGeantInput::Close()
{
  // Close the file Opened by the object. Return 
  // kFALSE if no file was open.

#if USE_FSTREAM
  if(fFilePointer)  {
    fFilePointer->close();
    delete fFilePointer;
    fFilePointer = NULL;
    return kTRUE;
  }
  else
    return kFALSE;
#else
  if(fFileDescriptor != -1) {
    close(fFileDescriptor);
    fFileDescriptor = -1;
  }
  return kTRUE;
#endif
}

//____________________________________________________________________
 Bool_t BrGeantInput::ReadStreamHeader()
{
  //
  // Read the volume information from the header.
  // At this time it is only used to define the Names
  // of the hit structures. The information is not used by other parts
  // of the reconstruction even though one could imagine that
  // the code could 'inquire' on volume information for a specific
  // detector.
  // This is not implemented. A better way will also be to have a general
  // method for passing geometries around.
  //
  Int_t nb = 4; Int_t nread;
  
  Char_t * numvol = (Char_t *) (&fNumberOfVolumes);
  // assume that the .cdat file is in old format that do
  // not have the embedded version number as the first integer
  // variable in stream.
  fVersion = 1;
  fEndOfStreamEvent = OLD_END_OF_STREAM_EVENT;

#if USE_FSTREAM
  fFilePointer->read(numvol,nb);
#else
  nread = read(fFileDescriptor, numvol, nb);
  if(nb != nread){
    if(nb == 0) {
      if (Verbose() > 24)
	Warning("ReadStreamHeader", "at end of file");
      fEof = kTRUE;
    }
    if(nb == -1) {
      if (Verbose() > 24)
	Error("ReadStreamHeader", "while reading file");
      fError = kTRUE;
    }
    return kFALSE;
  }
#endif

  fNumBytesRead +=nb;
  if (DebugLevel() > 4)
    cout << "Reading stream header, number of volumes: " 
	 << fNumberOfVolumes << endl;

  if (TMath::Abs(fNumberOfVolumes) > 63535){
    fByteSwap = kTRUE;
    SwapLong(&fNumberOfVolumes, 4);
    if (Verbose() > 4) 
      cout << "Byte Swapping turned on, Number of volumes = "
	   << fNumberOfVolumes << endl;
  }
  
  if (fNumberOfVolumes > 1000) {
    fVersion          = fNumberOfVolumes;
    fEndOfStreamEvent = END_OF_STREAM_EVENT;
#if USE_FSTREAM
    fFilePointer->read(numvol,nb);
#else
    nread = read(fFileDescriptor, numvol, nb);
    if(DebugLevel() > 3) 
      cout<< "Place 1 nb = " << nb << ", nread = " << nread << endl;

    if (nb != nread) {
      if(nb == 0) {
	if (Verbose() > 24)
	  Warning("ReadStreamHeader", "at end of file");
	fEof = kTRUE;
      }
      if(nb == -1) {
	if (Verbose() > 24)
	  Error("ReadStreamHeader", "while reading file");
	fError = kTRUE;
      }
      return kFALSE;
    }
#endif
    fNumBytesRead +=nb;
    if (fByteSwap)
      SwapLong(&fNumberOfVolumes, 4);
    if (DebugLevel() > 3) 
      cout<< "Number of Volumes = " << fNumberOfVolumes << endl;
  };


  for (Int_t ivol = 0; ivol < fNumberOfVolumes; ivol++) {
    Char_t *bufp = (Char_t*) (&fVolume[ivol]);
    nb           = sizeof(GeantVol);

#if USE_FSTREAM
    fFilePointer->read(bufp, nb);
#else
    nread = read(fFileDescriptor, bufp, nb);
    if(nb != nread){
      if(nb == 0) {
	if (Verbose() > 24)
	  Warning("ReadStreamHeader", "at end of file");
	fEof = kTRUE;
      }
      if(nb == -1) {
	if (Verbose() > 24)
	  Error("ReadStreamHeader", "while reading file");
	fError = kTRUE;
      }
      return kFALSE;
    }
#endif
    if (fByteSwap) {
      SwapLong((int*)&fVolume[ivol].shape,8);
      //    The following statement is an attempt to make us less sensitive
      //    to GeantVol changing lengths.  This does depend, however on the
      //    first 12 bytes staying where they are.
      Int_t gswaplen = sizeof(GeantVol) - 12;
      SwapLong((int*)&fVolume[ivol].pos[0],gswaplen);
    }
    fNumBytesRead +=nb;
    //need to do this because fortran(geant?) pads with blank
    for(unsigned i = 0; i < sizeof(fVolume[ivol].Name); i++)
      if(fVolume[ivol].Name[i] == ' ') 
	fVolume[ivol].Name[i] = 0;

  }
  SetrHeader( kTRUE);
  return kTRUE;
}

//____________________________________________________________________
 void BrGeantInput::SkipEvent(Int_t numevt)
{
  BrEvent *dummyevent;
  Bool_t saveFillHitList = fFillHitList;
  fFillHitList = kFALSE;
  for (Int_t i = 0; i < numevt; i++) {
    dummyevent = new BrEvent("Dummy",0,0);
    Event(dummyevent);
    delete dummyevent;
  }
  fFillHitList = saveFillHitList;
}

//____________________________________________________________________
 void BrGeantInput::Event(BrEvent* event)
{
  // Reads one event from the C-stream  data file.The BrEvent 
  // object has hitlist and tracklist added to the Event.
  // 
  // This object is filled with data read from the file. 
  //  It is the responsibility of the calling program to have created the
  //  event.
  // 
  // Releasing the memory for this event is the responsibility
  // of the function/macro calling Event();
  // Status of the reading can be checked via the methods IsError() and
  // IsEof(). 
  SetState(kEvent); 
  
  Int_t      rectyp=0, nb, ivol, nread;
  Char_t*    bufp;
  struct GeantEventHeader EventHeader;
  //  Int_t EventHeader[5];
  // version 1    : Eventheader[2]
  // version 1001 : Eventheader[5]
  Char_t            name[64];
  GeantStreamHits   fHits;
  GeantStreamTracks fTracks;
  BrDataTable*      HitBuffer[MAXGIVOLU];
  int               iskip;
  //
  //
  // Create new data container for Geant Tracks and
  // Geant Hits (for each of the possible volumes
  //
  fRepair = kFALSE;
  //BrDataTable *TrackBuffer = new BrDataTable("GeantTracks");
  BrDataTable *TrackBuffer = new BrDataTable(BRTABLENAMES kGeantTracks);

  for(ivol = 0; ivol < fNumberOfVolumes; ivol++) {
    if (fVolume[ivol].Active == 1) {
      // Use precision (max. size of string) as argument
      // since Name is no longer guaranteed to be NULL terminated.
      //     sprintf(name,"GeantHits %.*s",(int)sizeof(fVolume[ivol].Name),
      //                                               fVolume[ivol].Name);
      sprintf(name,"%s %.*s", BRTABLENAMES kGeantHits, 
	      (Int_t)sizeof(fVolume[ivol].Name), fVolume[ivol].Name);

      if (DebugLevel() > 4) 
	cout << "Creating HitBuffer[" << ivol << "] with name " 
	     << name << endl;

      HitBuffer[ivol] = new BrDataTable(name);
      event->AddDataTable(HitBuffer[ivol]);
    }
  }

  event->AddDataTable(TrackBuffer);

  BrGeantHeader* geantheader = 
    new BrGeantHeader("GeantHeader","GeantInput");
  event->AddObject(geantheader);

  //
  fIOStatus = 1;
  fEof      = kFALSE;
  fError    = kFALSE;
  
  while(rectyp != fEndOfStreamEvent) {
    nb = 4;
    bufp = (char*) &rectyp;
#if USE_FSTREAM
    fFilePointer->read(bufp, nb);

    if(fFilePointer->eof()) {
      if (Verbose() > 9)
	cout << "End of STREAM file found: closing file" << endl;
      fFilePointer->close();
      fFilePointer = NULL;
      fEof         = kTRUE;
      fIOStatus    = 0;
      return;
    }
    if(fFilePointer->bad()) {
      Stop("Event", "Unexpected Bad file");
      fIOStatus = 0;
      fError    = kTRUE;
#ifdef debug
      cout << nread << " " << fIOStatus << endl;
      OutStatus();
#endif
      return;
    }
#else
    nread = read(fFileDescriptor, bufp, nb);
    if(DebugLevel() > 9) 
      cout<< " Place 2 nb = "<< nb << ", nread = " << nread << endl;
    if(nb != nread) {    
      if(nread == 0) {
	if (Verbose() > 24)
	  Warning("Event", "at end of file");
	fEof = kTRUE;
      }
      if(nread < 0) {
	if (Verbose() > 24)
	  Error("Event", "while reading file");
	fError = kTRUE;
      }
      fIOStatus = 0;
#ifdef debug
      cout << nread << " " << fIOStatus << endl;
#endif
      return;
    }
#endif
    if(fByteSwap) 
      SwapLong(&rectyp,nb);

    fNumBytesRead +=nb;

    if(DebugLevel() > 9) 
      cout << " rectyp = " <<rectyp << " fNumBytesRead = "  
	   << fNumBytesRead <<endl;

    switch (rectyp) {
    case END_OF_STREAM_EVENT:
      break;
    case OLD_END_OF_STREAM_EVENT:
      break;
    case  EVENT_STREAM_HEADER:
      if(fVersion == 1) {
	nb = 8;
	EventHeader.RunNumber       = 0;
	EventHeader.VertexPos       = 0.0;
	EventHeader.ImpactParameter = 0.0;
      } 
      else
	nb = sizeof(EventHeader);

      bufp = (char*) &EventHeader;
#if USE_FSTREAM
      fFilePointer->read(bufp,nb);
#else
      nread = read(fFileDescriptor, bufp, nb);
      if(nb != nread) {
	if(nread == 0) {
	  if (Verbose() > 24)
	    Warning("Event", "at end of file");
	  fEof = kTRUE;
	}
	if(nread < 0) {
	  if (Verbose() > 24)
	    Error("Event", "while reading file");
	  fError = kTRUE;
	}
	fIOStatus = 0;
#ifdef debug
	cout << nread << " " << fIOStatus << endl;
	OutStatus();
#endif
	return;
      }
#endif
      if(fByteSwap) 
	SwapLong((int*) bufp, nb);
      fNumBytesRead +=nb;

      if(DebugLevel() > 9) 
	cout << "Starting to Set event headers ... " << flush;

      event->GetEventHeader()->SetRunNumber(EventHeader.RunNumber);
      event->GetEventHeader()->SetEventNumber(EventHeader.NevUsr);
      geantheader->SetVertex(EventHeader.VertexPos);
      geantheader->SetImpactParameter(EventHeader.ImpactParameter);

      if(DebugLevel() > 9) 
	cout << "done" << endl;

      break;
      
    case  EVENT_STREAM_TRACK:
      nb   = sizeof(GeantStreamTracks);
      bufp = (char*) &fTracks;

#if USE_FSTREAM
      fFilePointer->read(bufp,nb);
      
      if(fFilePointer->bad()) {
	cerr << "Bad status" << endl;
	fIOStatus = 0;
	return;
      }
      if(fFilePointer->eof()) {
	cerr << "EOF status" << endl;
	fIOStatus = 0;
	return;
      }
      if(fFilePointer->fail()) {
	cerr << "Fail status" <<endl;
	fIOStatus = 0;
	return;
      }
#else
      nread = read(fFileDescriptor, bufp, nb);
      if(DebugLevel()>9)
	cout << " Place 3 nb = "<< nb << ", nread = " << nread <<endl;

      if(nb != nread){
	if(nread == 0) {
	  if (Verbose() > 24)
	    Warning("Event", "at end of file");
	  fEof = kTRUE;
	}
	if(nread < 0) {
	  if (Verbose() > 24)
	    Error("Event", "while reading file");
	  fError = kTRUE;
	}
	fIOStatus = 0;
#ifdef debug
	cout << nread << " " << fIOStatus << endl;
	cout << fIOStatus << endl;
	OutStatus();
#endif
	return;
      }
#endif
      if(fByteSwap) 
	SwapLong((int*)bufp,nb);

      fNumBytesRead +=nb;
      if(DebugLevel() > 4)
	cout << "Adding new track" << endl;

      TrackBuffer->Add(new BrGeantTrack(fTracks));
      break;
      
    case  EVENT_STREAM_HIT:
      nb   = sizeof(GeantStreamHits);
      bufp = (char*) & fHits;
#if USE_FSTREAM
      fFilePointer->read(bufp,nb);
      
      if(fFilePointer->bad()) {
	cerr << "Bad status" << endl;
	fIOStatus = 0;
	return;
      }
      if(fFilePointer->eof()) {
	cerr << "EOF status" << endl;
	fIOStatus = 0;
	return;
      }
      if(fFilePointer->fail()) {
	cerr << "Fail status" << endl;
	fIOStatus = 0;
#ifdef debug
	cout << fIOStatus << endl;
	OutStatus();
#endif
	return;
      }
      
#else
      nread = read(fFileDescriptor, bufp, nb);
      if(DebugLevel() > 9)
	cout<< " Place 4 nb = " << nb << ", nread = " << nread << endl;
      if(nb != nread){
	if(nread == 0) {
	  if (Verbose() > 24)
	    Warning("Event", "at end of file");
	  fEof = kTRUE;
	}
	if(nread < 0) {
	  if (Verbose() > 24)
	    Error("Event", "while reading file");
	  fError = kTRUE;
	}
	fIOStatus = 0;
#ifdef debug
	cout << nread << " " << fIOStatus << endl;
	OutStatus();
#endif
	return;
      }
#endif
      if (fByteSwap) {
	if (DebugLevel() > 9) 
	  cout<<"Swapping bytes"<<endl;      
	SwapLong((int*)bufp,nb);
      }
      

      if (DebugLevel() > 14) 
	cout << "  trackno = " << fHits.trackno 
	     << " DetectorId = " << fHits.DetectorId 
	     << " tof = " << fHits.Tof << endl;

      fNumBytesRead += nb;
      ivol          =  fHits.DetectorId - 1; 
      if (ivol < 0) 
	ivol++;

      // Sometimes it seems that we have an under/overflow in these
      // registers, so we get out here if that is the case. 
      if (ivol < 0) {
	Warning("Event", "very odd volume number (%d)", ivol);
	continue;
      }

      if(DebugLevel() > 14) 
	cout<< "ivol = "<< ivol
	    << " fNumBytesRead = " << fNumBytesRead 
	    << " fHits.dedx = " << fHits.dedx
	    << " fVolume[" << ivol << "].Active = " 
	    << fVolume[ivol].Active << endl;

      if (fHits.dedx > 0) {
        if(DebugLevel() > 14) 
	  cout << "Adding new hit for ivol = " << ivol << endl;
        HitBuffer[ivol]->Add(new BrGeantHit(fHits));
      }
      break;

    default:
      //          This should not happen!!
      //          Indicates logic error.
      fIOStatus = 0;
      fError    = kTRUE;
      cout << "*** Problem in data after :" << fNumBytesRead 
	   << " bytes" << endl 
	   << " rectype in stream file is " << rectyp<< endl;
      //
      // attempt to skip until (-1) is seen
      // This should be a valid end_of_stream (event)
      // this is not a safe method sinc particle with charge -1
      // do also show up in lists.
      //
      // Delete all tables in event since they are recreated at top
      //
      iskip = 0;
      while(rectyp != fEndOfStreamEvent) {
	nb    = 4;
	bufp  = (char*) &rectyp;
	nread = read(fFileDescriptor, bufp, nb);
	if(nb != nread){
	  if(nread == 0) {
	    if (Verbose() > 24)
	      Warning("Event", "at end of file");
	    fEof = kTRUE;
	  }
	  if(nread < 0) {
	    if (Verbose() > 24)
	      Error("Event", "while reading file");
	    fError = kTRUE;
	  }
	  return;
	}
	if(fByteSwap) 
	  SwapLong(&rectyp,nb);
	fNumBytesRead +=nb;
      }
      cerr << "Skipped " << iskip << " bytes" << endl;
      fRepair = kTRUE;
      fError  = kTRUE;
      return;
    }
  }
  // Set event number to be that from the last geant subevent
  //
  event->GetEventHeader()->SetEventNumber(EventHeader.NevUsr);
  sprintf(name, "event_%d_%d", event->GetRunNumber(), 
	  event->GetEventNumber());
  event->SetName(name);

  sprintf(name, "BrEvent %d %d", event->GetRunNumber(),
	  event->GetEventNumber());
  event->SetTitle(name);
  fEventCounter++;

  if (fFillHitList) {
    if (DebugLevel() > 9) 
      cout << "Filling hit list" << endl; 
    Int_t ntracks = TrackBuffer->GetEntries();
    for (ivol = 0; ivol < fNumberOfVolumes; ivol++)
      if (fVolume[ivol].Active) {
        Int_t nhits = HitBuffer[ivol]->GetEntries();

        for (Int_t ihit = 0; ihit < nhits; ihit++) {
          BrGeantHit* hit = (BrGeantHit*)HitBuffer[ivol]->At(ihit);
          Int_t trackno   = hit->TrackNo();

          for (Int_t itrack = 0; itrack < ntracks; itrack++) {
            BrGeantTrack* track = (BrGeantTrack*)TrackBuffer->At(itrack);

            if (track->TrackNo() == trackno) {
              track->AddHit(hit);
              track->SetHitBit(ivol);
              break;
            }
          }
        }
      }
  }

  if(DebugLevel() > 9){
    cout << "Fill track info into Hit" << endl;
  }
  Int_t ntracks = TrackBuffer->GetEntries();
  if(DebugLevel() > 9)
    cout << "#tracks = " << ntracks << endl;

  for (ivol=0; ivol < fNumberOfVolumes; ivol++)
    if (fVolume[ivol].Active) {
      Int_t nhits = HitBuffer[ivol]->GetEntries();

      if(DebugLevel() > 14)
	cout << "#nhits = " << nhits << endl;

      for (Int_t ihit = 0; ihit < nhits; ihit++) {
	BrGeantHit* hit     = (BrGeantHit*)HitBuffer[ivol]->At(ihit);
	Int_t       trackno = hit->TrackNo();
	
	for (Int_t itrack = 0; itrack < ntracks; itrack++) {
	  BrGeantTrack* track = (BrGeantTrack*)TrackBuffer->At(itrack);
	  if (track->TrackNo() == trackno) {
	    hit->SetTrack(track);
	    break;
	  }
	}
      }
    }
  
#ifdef debug
  cout << fIOStatus << endl;
  OutStatus();
#endif
  return;
}

//____________________________________________________________________
 void BrGeantInput::OutStatus()
{
  if(fEof)
    cout << "*      EOF   :  TRUE n";
  else
    cout << "*      EOF   : FALSE n";
  if(fError)
    cout << "*      ERROR :  TRUE n";
  else
    cout << "*      ERROR : FALSE n";
}

//_______________________________________________________________________
 void BrGeantInput::Print(Option_t* option) const
{
  // Standard information printout. 
  // 
  // Options: See BrModule::Print
  // 
  TString opt(option);
  opt.ToLower();
  
  BrIOModule::Print(option);
  if (opt.Contains("d"))
    cout << endl
         << "  Original author: Flemming Videbaek" << endl
         << "  Revisted by:     $Author: videbaek $" << endl
         << "  Revision date:   $Date: 2002/04/23 14:45:18 $"   << endl
         << "  Revision number: $Revision: 1.6 $ " << endl
         << endl
         << "*************************************************" << endl;
}

//____________________________________________________________________
 void BrGeantInput::SwapLong(int *buffer,int nb)
{
  int i,j;
  union {
    int il;
    char ib[4];
  } temp;

  union {
    int il;
    char ib[4];
  } temp1;

  j = 0;
  for(i=0;i<nb;i+=4) {
    temp.il = buffer[j];
    temp1.ib[0] = temp.ib[3];
    temp1.ib[1] = temp.ib[2];
    temp1.ib[2] = temp.ib[1];
    temp1.ib[3] = temp.ib[0];
    buffer[j] = temp1.il;
    j++;
  }
}

//____________________________________________________________________
 UInt_t BrGeantInput::GetDetectorBit(const Text_t *name) const
{
  // Return detector bit corresponding to volume (or 0)

  for (Int_t ivol = 0; ivol < fNumberOfVolumes; ivol++)
    if (strncmp(name,fVolume[ivol].Name,sizeof(fVolume[ivol].Name)) == 0)
      return BIT(ivol);

  Warning("GetDetectorBit","%s: Volume not found.", name);
  return 0;
}

//____________________________________________________________________
 void BrGeantInput::ListDetectors(UInt_t bits) const
{
  // List names of detectors corresponding to bits

  Int_t nout = 0;
  for (Int_t ivol = 0; bits; ivol++, bits >>= 1)
    if (bits & 1) {
      const int s = sizeof(fVolume[ivol].Name);
      char name[s+1];
      strncpy(name,fVolume[ivol].Name,s);
      name[s] = '0';
      if (nout++) cout << ',';
      cout << name;
    }
}

//  $Log: BrGeantInput.cxx,v $
//  Revision 1.6  2002/04/23 14:45:18  videbaek
//  remove ios::in flag
//
//  Revision 1.5  2002/04/22 16:59:03  cholm
//  Minor fixes
//
//  Revision 1.4  2002/01/03 19:51:51  cholm
//  Prepared to use BrTableNames class (or perhaps BrDetectorList) for table names
//
//  Revision 1.3  2001/12/14 15:37:43  cholm
//  Modified the classes to allow the concept of file set, introduced via
//  BrIOModule. Also use new Info method rather than explicit
//    if (Verbose() > 4)
//       cout << "Opening file ladida" << endl;
//
//  Revision 1.2  2001/08/12 09:50:17  cholm
//  Set the debug-level for output higher in most cases, so that it's
//  possible to be more selective on what is printed.  Also cleaned up
//  some of the code (basically reformating).
//
//  Revision 1.1.1.1  2001/06/21 14:55:08  hagel
//  Initial revision of brat2
//
//  Revision 1.31  2001/03/07 12:19:13  cholm
//  * Made the method BrModule::Info() const obsolete in favour of
//    BrModule::Print(Option_t* option="B") const.
//
//  Revision 1.30  2001/01/22 19:59:49  cholm
//  Because renamed BrIOModule::fStatus to BrIOModule::fIOStatus, the classes
//  BrGeantInput had to be updated.
//
//  Revision 1.29  2000/09/18 21:34:18  videbaek
//  Fill track pointer in BrGeantHit
//
//  Revision 1.28  2000/06/28 09:03:20  hagel
//  Added const to various char's in BrGeantInput
//
//  Revision 1.27  2000/05/17 10:59:53  ouerdane
//  *** empty log message ***
//
//  Revision 1.26  2000/03/17 01:13:45  hagel
//  Implemented table names from BrTableNames.h
//
//  Revision 1.25  2000/01/18 19:45:12  videbaek
//  increase number of possible geant volumes to 50
//
//  Revision 1.24  2000/01/18 18:37:48  videbaek
//  Added derived Info() method.
//
//  Revision 1.23  1999/10/22 18:33:40  videbaek
//  Update for bytes read/written i.e fNumBytesread instead of
//  fBytesTransferred
//
//  Revision 1.22  1999/04/09 19:37:18  videbaek
//  Add proper include guards.
//
//  Revision 1.21  1999/02/11 22:27:27  hagel
//  Changes to make run on Solaris
//
//  Revision 1.20  1999/01/15 16:32:32  videbaek
//  Added new class BrGeantHeader to take care of additional gbrahms
//  functionality
//  Updated makeNT (for non-cygnus win95)
//
//  Revision 1.19  1998/11/13 19:40:17  videbaek
//  Capability for reading different versions of cdat files (with more
//  information) and with reduced output for empty subevents.
//  Added data members for handling different versions of cdat files.
//
//  Revision 1.18  1998/09/27 17:09:10  alv
//  added member functions GetDetectorBit and ListDetectors
//  In Event
//    added code to set the HitBits of the tracks
//
//  Revision 1.17  1998/09/22 20:00:22  videbaek
//  Added TryRepair() boolean function.
//  This private variable used by function is set in the Event(entry).
//  This is used to indicate that logically bad record has been found
//  as observed in several .cdat files. After a while the events become
//  proper again.
//
//  Revision 1.16  1998/09/16 20:11:43  alv
//  In constructor
//   Added fFillHitList=kFALSE
//  In Open
//   Added expansion of file names ala ROOT (needed for CRS jobs).
//   Added second dummy parameter to Open to have same number of arguments
//    as BrEventIO::Open.
//  In Event
//   Added code (selectable by fFillHitList) to fill hit list of tracks.
//  In SkipEvent
//   Added code to switch off filling of hit list while skipping events.
//
//  Revision 1.15  1998/09/08 15:28:53  alv
//  Added fByteSwap=kFALSE in constructor.
//
//  Revision 1.14  1998/08/14 21:25:14  videbaek
//  changed include files for unix
//
//  Revision 1.13  1998/07/31 19:32:42  videbaek
//  Check and set error on read problems
//
//  Revision 1.12  1998/07/20 17:42:58  videbaek
//  Added Pid hit to hit structure. Needed for effecient handling
//  of detector response.
//
//  Revision 1.11  1998/07/17 02:20:08  hagel
//  Modifications for byte swapping in BrGeantInput
//
//  Revision 1.10  1998/06/23 20:22:28  hagel
//  Zero elements of many (not all) objects to avoid problems with overlaying in memory
//
//  Revision 1.9  1998/06/21 20:11:05  hagel
//  cleanup
//
//  Revision 1.8  1998/05/14 21:18:50  videbaek
//  update makefile - do not reload .so libraries
//
//  Revision 1.7  1998/04/30 22:30:00  hagel
//  Fix errors in WIN32 stuff again
//
//  Revision 1.6  1998/04/30 17:12:35  videbaek
//  Added functionality to BrGeantInput
//
//  Revision 1.3  1998/04/08 18:09:24  videbaek
//  changed GeantInput class to use open,read
//
//  Revision 1.2  1998/04/06 21:12:11  videbaek
//  Clean up and additions for Win95
//
//  Revision 1.1  1998/04/03 21:15:04  videbaek
//  part of first base release
//

This page automatically generated by script docBrat by Christian Holm

Copyright ; 2002 BRAHMS Collaboration <brahmlib@rcf.rhic.bnl.gov>
Last Update on by

Validate HTML
Validate CSS