ROOT logo
#include "hgeantsource.h"
#include "TROOT.h"
#include "hgeantreader.h"
#include "hrecevent.h"
#include "hpartialevent.h"
#include "hcategory.h"

//*-- Author : Manuel Sanchez
//*-- Modified : 26/08/99 by R. Holzmann
//*-- Modified : 26/02/99 by Ilse Koenig
//*-- Modified : 2/11/98 by Manuel Sanchez 
//*-- Modified : /30/09/1998 by Manuel Sanchez
//*-- Modified : 17/06/98 by Manuel Sanchez

//_HADES_CLASS_DESCRIPTION 
//////////////////////////////
// HGeantSource
//
//  This class is a data source to read the simulated data obtained from
//GEANT.
//
//  HGeantSource acts as a container of different HGeantReader objects, which
//do the actual work by getting the data from a file and putting those data
//in the corresponding categories when their "execute" function is called
//
//  This kind of design, as in HLmdSource, allows the user to specifically 
//read only those parts of the event in which is interested.
////////////////////////////

HGeantSource::HGeantSource(void) {
  //Default constructor
}

HGeantSource::HGeantSource(HGeantSource &s) {
  fReaderList.Delete();
  fReaderList.AddAll(&s.fReaderList);
  fFileTable.Delete();
  fFileTable.AddAll(&s.fFileTable);
}

HGeantSource::~HGeantSource(void) {
  //Destructor. Deletes the readers
  fReaderList.Delete();
}

Bool_t HGeantSource::addGeantReader(HGeantReader *r,const Text_t *inputFile) {
  //This method allows to specify which readers will be used to get the data.
  //The first input is the actual reader to be used, and the second input is the
  //name of the file from where this reader will read data; specifying the name
  //here allows having several readers each of them taking data from a different file.
  //
  // The situation of two or more readers taking data from the same file is foreseen, 
  //the user just gives the same name for the input file when adding both readers.
  TFile *f=(TFile *)fFileTable.FindObject(inputFile);
  if (f==NULL) {
    f=new TFile(inputFile);
    if (f==NULL) Error("HGeantSource::addGeantReader","Specified file doesn't exist");
    fFileTable.Add(f);
    gROOT->cd();
  }
  r->setInput(f);
  fReaderList.Add(r);
  return kTRUE;
}

Bool_t HGeantSource::init(void) {
  // calls the init() functions of all readers
  TIter next(&fReaderList);
  HGeantReader *fReader;

  if (!(*fEventAddr)) {
    (*fEventAddr) = new HRecEvent;
  }
  HRecEvent* fEv = (HRecEvent*)(*fEventAddr);   // pointer to event
  HPartialEvent* fSimul = fEv->getPartialEvent(catSimul);
  if(fSimul == NULL) {
     fEv->addPartialEvent(catSimul,"Simul","Simulated event");
     fSimul = fEv->getPartialEvent(catSimul);
  }

  while ( (fReader=(HGeantReader*)next())!=NULL) {  // initialize readers
    if (!fReader->init()) return kFALSE;
  }

// set all Simul categories non-persistent, we don't want them to be written
  fSimul = ((HRecEvent*)(*fEventAddr))->getPartialEvent(catSimul);
  TObjArray* fCategories = fSimul->getCategories();
  Int_t nCategories = fCategories->GetEntriesFast(); 
  for (Int_t i=0; i<nCategories; i++) { 
     HCategory* cat = (HCategory*)(fCategories->At(i));
     if(cat) {  // execpt for KINE part
        if(cat->getCategory() != catGeantKine) cat->setPersistency(kFALSE);
     }
  }
  return kTRUE;
}

Bool_t HGeantSource::finalize(void) {
 TIterator *iter=0;
 HGeantReader *reader=0;
 iter=fReaderList.MakeIterator();
 while ( (reader=(HGeantReader *)iter->Next()) != 0 ) {
  if (!reader->finalize()) return kFALSE;
 }
 return kTRUE;
}

EDsState HGeantSource::getNextEvent(void) {
  //Tries to read a new event into the HEvent 
  //structure:
  //
  TIter next(&fReaderList);
  HGeantReader *reader;
  Int_t returnCode;
  while ( (reader=(HGeantReader *)next())!=NULL) {
    returnCode = reader->execute();
    if(returnCode != kTRUE) return kDsEndData; // error or end of data
  }
  return kDsOk;
}  

ClassImp(HGeantSource)









 hgeantsource.cc:1
 hgeantsource.cc:2
 hgeantsource.cc:3
 hgeantsource.cc:4
 hgeantsource.cc:5
 hgeantsource.cc:6
 hgeantsource.cc:7
 hgeantsource.cc:8
 hgeantsource.cc:9
 hgeantsource.cc:10
 hgeantsource.cc:11
 hgeantsource.cc:12
 hgeantsource.cc:13
 hgeantsource.cc:14
 hgeantsource.cc:15
 hgeantsource.cc:16
 hgeantsource.cc:17
 hgeantsource.cc:18
 hgeantsource.cc:19
 hgeantsource.cc:20
 hgeantsource.cc:21
 hgeantsource.cc:22
 hgeantsource.cc:23
 hgeantsource.cc:24
 hgeantsource.cc:25
 hgeantsource.cc:26
 hgeantsource.cc:27
 hgeantsource.cc:28
 hgeantsource.cc:29
 hgeantsource.cc:30
 hgeantsource.cc:31
 hgeantsource.cc:32
 hgeantsource.cc:33
 hgeantsource.cc:34
 hgeantsource.cc:35
 hgeantsource.cc:36
 hgeantsource.cc:37
 hgeantsource.cc:38
 hgeantsource.cc:39
 hgeantsource.cc:40
 hgeantsource.cc:41
 hgeantsource.cc:42
 hgeantsource.cc:43
 hgeantsource.cc:44
 hgeantsource.cc:45
 hgeantsource.cc:46
 hgeantsource.cc:47
 hgeantsource.cc:48
 hgeantsource.cc:49
 hgeantsource.cc:50
 hgeantsource.cc:51
 hgeantsource.cc:52
 hgeantsource.cc:53
 hgeantsource.cc:54
 hgeantsource.cc:55
 hgeantsource.cc:56
 hgeantsource.cc:57
 hgeantsource.cc:58
 hgeantsource.cc:59
 hgeantsource.cc:60
 hgeantsource.cc:61
 hgeantsource.cc:62
 hgeantsource.cc:63
 hgeantsource.cc:64
 hgeantsource.cc:65
 hgeantsource.cc:66
 hgeantsource.cc:67
 hgeantsource.cc:68
 hgeantsource.cc:69
 hgeantsource.cc:70
 hgeantsource.cc:71
 hgeantsource.cc:72
 hgeantsource.cc:73
 hgeantsource.cc:74
 hgeantsource.cc:75
 hgeantsource.cc:76
 hgeantsource.cc:77
 hgeantsource.cc:78
 hgeantsource.cc:79
 hgeantsource.cc:80
 hgeantsource.cc:81
 hgeantsource.cc:82
 hgeantsource.cc:83
 hgeantsource.cc:84
 hgeantsource.cc:85
 hgeantsource.cc:86
 hgeantsource.cc:87
 hgeantsource.cc:88
 hgeantsource.cc:89
 hgeantsource.cc:90
 hgeantsource.cc:91
 hgeantsource.cc:92
 hgeantsource.cc:93
 hgeantsource.cc:94
 hgeantsource.cc:95
 hgeantsource.cc:96
 hgeantsource.cc:97
 hgeantsource.cc:98
 hgeantsource.cc:99
 hgeantsource.cc:100
 hgeantsource.cc:101
 hgeantsource.cc:102
 hgeantsource.cc:103
 hgeantsource.cc:104
 hgeantsource.cc:105
 hgeantsource.cc:106
 hgeantsource.cc:107
 hgeantsource.cc:108
 hgeantsource.cc:109
 hgeantsource.cc:110
 hgeantsource.cc:111
 hgeantsource.cc:112
 hgeantsource.cc:113
 hgeantsource.cc:114
 hgeantsource.cc:115
 hgeantsource.cc:116
 hgeantsource.cc:117
 hgeantsource.cc:118
 hgeantsource.cc:119
 hgeantsource.cc:120
 hgeantsource.cc:121
 hgeantsource.cc:122
 hgeantsource.cc:123
 hgeantsource.cc:124
 hgeantsource.cc:125
 hgeantsource.cc:126
 hgeantsource.cc:127
 hgeantsource.cc:128
 hgeantsource.cc:129
 hgeantsource.cc:130
 hgeantsource.cc:131