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

//*-- Author : R. Holzmann
//*-- Modified : 02/03/2000 by R. Holzmann

//_HADES_CLASS_DESCRIPTION 
//////////////////////////////
// HDirectSource
//
//  This class is a data source to operate directly under HGeant control
//
//  HDirectSource acts like HGeantSource, but instead of taking the data from
//  HGeant Root file(s) it is launched from within HGeant and gets the data
//  directly from the simulation categories in memory
//////////////////////////////

HDirectSource::HDirectSource(void) {
  //Default constructor
  fCurrentRunId = 0;
}

HDirectSource::HDirectSource(HDirectSource &s) {
  fReaderList.Delete();
  fReaderList.AddAll(&s.fReaderList);
  fCurrentRunId = s.fCurrentRunId;
}

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

Bool_t HDirectSource::addGeantReader(HGeantReader *r) {
  //This method is provided to stay compatible with readers
  //like HMdcGeantRootReader, which do part of the digitization
  //The input is the actual reader to be used.

  r->setInput(NULL);   // the file input of the reader is set to NULL
  fReaderList.Add(r);
  return kTRUE;
}

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

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

  HRecEvent* fEv = (HRecEvent*)(*fEventAddr);   // pointer to event
  if(fEv == NULL) {
     printf("\n*** No HRecEvent exists.\n");
     return kFALSE;   
  }
  HPartialEvent* fSimul = fEv->getPartialEvent(catSimul);
  if(fSimul == NULL) {
     printf("\n*** No Simul partial event exists.\n");
     return kFALSE;
  }

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

EDsState HDirectSource::getNextEvent(void) {
  //Produce a new event and fill into the HEvent structure
  //
  TIter next(&fReaderList);
  HGeantReader *fReader;
  Int_t returnCode;
  gROOT->ProcessLine("doGeant(\"trigger 1\");");  // make 1 event here
  while ( (fReader=(HGeantReader *)next())!=NULL) {
     returnCode = fReader->execute();
     if(returnCode != kTRUE) return kDsEndData;   // error or end of data
  }
  return kDsOk;
}  

ClassImp(HDirectSource)

//extern void doGeant(Char_t*);   // this is an HGeant function








 hdirectsource.cc:1
 hdirectsource.cc:2
 hdirectsource.cc:3
 hdirectsource.cc:4
 hdirectsource.cc:5
 hdirectsource.cc:6
 hdirectsource.cc:7
 hdirectsource.cc:8
 hdirectsource.cc:9
 hdirectsource.cc:10
 hdirectsource.cc:11
 hdirectsource.cc:12
 hdirectsource.cc:13
 hdirectsource.cc:14
 hdirectsource.cc:15
 hdirectsource.cc:16
 hdirectsource.cc:17
 hdirectsource.cc:18
 hdirectsource.cc:19
 hdirectsource.cc:20
 hdirectsource.cc:21
 hdirectsource.cc:22
 hdirectsource.cc:23
 hdirectsource.cc:24
 hdirectsource.cc:25
 hdirectsource.cc:26
 hdirectsource.cc:27
 hdirectsource.cc:28
 hdirectsource.cc:29
 hdirectsource.cc:30
 hdirectsource.cc:31
 hdirectsource.cc:32
 hdirectsource.cc:33
 hdirectsource.cc:34
 hdirectsource.cc:35
 hdirectsource.cc:36
 hdirectsource.cc:37
 hdirectsource.cc:38
 hdirectsource.cc:39
 hdirectsource.cc:40
 hdirectsource.cc:41
 hdirectsource.cc:42
 hdirectsource.cc:43
 hdirectsource.cc:44
 hdirectsource.cc:45
 hdirectsource.cc:46
 hdirectsource.cc:47
 hdirectsource.cc:48
 hdirectsource.cc:49
 hdirectsource.cc:50
 hdirectsource.cc:51
 hdirectsource.cc:52
 hdirectsource.cc:53
 hdirectsource.cc:54
 hdirectsource.cc:55
 hdirectsource.cc:56
 hdirectsource.cc:57
 hdirectsource.cc:58
 hdirectsource.cc:59
 hdirectsource.cc:60
 hdirectsource.cc:61
 hdirectsource.cc:62
 hdirectsource.cc:63
 hdirectsource.cc:64
 hdirectsource.cc:65
 hdirectsource.cc:66
 hdirectsource.cc:67
 hdirectsource.cc:68
 hdirectsource.cc:69
 hdirectsource.cc:70
 hdirectsource.cc:71
 hdirectsource.cc:72
 hdirectsource.cc:73
 hdirectsource.cc:74
 hdirectsource.cc:75
 hdirectsource.cc:76
 hdirectsource.cc:77
 hdirectsource.cc:78
 hdirectsource.cc:79
 hdirectsource.cc:80
 hdirectsource.cc:81
 hdirectsource.cc:82
 hdirectsource.cc:83
 hdirectsource.cc:84
 hdirectsource.cc:85
 hdirectsource.cc:86
 hdirectsource.cc:87
 hdirectsource.cc:88
 hdirectsource.cc:89
 hdirectsource.cc:90
 hdirectsource.cc:91
 hdirectsource.cc:92
 hdirectsource.cc:93
 hdirectsource.cc:94
 hdirectsource.cc:95
 hdirectsource.cc:96
 hdirectsource.cc:97
 hdirectsource.cc:98
 hdirectsource.cc:99
 hdirectsource.cc:100
 hdirectsource.cc:101
 hdirectsource.cc:102
 hdirectsource.cc:103