//*-- Author : Manuel Sanchez //*-- Modified : 13/05/99 by Manuel Sanchez //*-- Modified : 5/05/98 by Manuel Sanchez //*-- Copyright : GENP (Univ. Santiago de Compostela) ////////////////////////////////////////////////////// // HRootSource // // This data source can read data from a ROOT file generated by //HYDRA, this includes both the reconstruction and simulation software. // // The data source takes care of instantiating the appropiate classes even //if they are non-standard. That is, if you have an input file with //HMdcHitSim instead of HMdcHit; HRootSource will take care of using //HMdcHitSim during the analysis. // ////////////////////////////////////////////////////// #include "hrootsource.h" #include "hades.h" #include "hevent.h" #include ClassImp(HRootSource) HRootSource::HRootSource(void) { //Class' constructor. fInputTree=NULL; fInputFile=NULL; fEventInFile=0; fCursor=0; } HRootSource::~HRootSource(void) { //Class destructor, it clears the data source. Clear(); } Bool_t HRootSource::init(void) { //Initializes the data source connecting the parts of the input tree in //the input ROOT file to the event structure used for the analysis. If //no event structure has been set by the user, HRootSource::init() will //set one taken from the input file. Bool_t r=kTRUE; if (fEventInFile!=0 && fInputFile!=0) { //If there is an active event structure if (gHades->getCurrentEvent()!=0) { Warning("init","Using user defined event structure"); } else gHades->setEvent(fEventInFile); if ( fInputTree!=NULL) { Char_t sl=*(strchr(fInputTree->GetTitle(),'.')+1); switch (sl) { case '0' : fSplitLevel=0; break; case '1' : fSplitLevel=1; break; case '2' : fSplitLevel=2; break; default : fSplitLevel=0; } fInputTree->SetBranchStatus("*",kFALSE); gHades->activateTree(fInputTree); r=kTRUE; } else { Clear(); r=kFALSE; } } else { r=kFALSE; } return r; } EDsState HRootSource::getNextEvent(void) { //Retrieves next event in the input file. if (fInputTree) { if (fInputTree->GetEvent(fCursor)>0) { fCursor++; } else return kDsEndData; } else return kDsError; return kDsOk; } Bool_t HRootSource::getEvent(Int_t eventN) { //Retrieves event in position eventN in the input file, copying the //information to the event structure. if (fInputTree) { if (fInputTree->GetEvent(eventN)>0) return kTRUE; else return kFALSE; } return kFALSE; } void HRootSource::Clear(void) { //Closes the input file. if (fInputTree) delete fInputTree; if (fInputFile) delete fInputFile; } Bool_t HRootSource::setInput(Text_t *fileName,Text_t *treeName) { //Sets the input file and tree. Opening the corresponding files, it also //loads in memory the input event description so the disableCategory() //method can be used. fInputFile=new TFile(fileName); if (!fInputFile) return kFALSE; fInputTree=(TTree *)fInputFile->Get(treeName); if (!fInputTree) return kFALSE; fEventInFile=(HEvent *)fInputFile->Get("Event"); if (!fEventInFile) return kFALSE; return kTRUE; } Bool_t HRootSource::disableCategory(Cat_t aCat) { //Disables the category aCat so it is not read event if it is stored in //the input file. This method shouldn't be called after init() //Returns kTRUE if the aCat was stored in the input file and has succesfully //been disabled, otherwise the return value is kFALSE. if (!fEventInFile) return kFALSE; return fEventInFile->removeCategory(aCat); } inline Int_t HRootSource::getSplitLevel(void) { //Returns the split level of the input tree. return fSplitLevel; } void HRootSource::deactivateBranch(Text_t *branchName) { //Deactivates a branch so it is not read. //This method is deprecated, use disableCategory() instead. if (fInputTree) { fInputTree->SetBranchStatus(branchName,kFALSE); } } TTree *HRootSource::getTree(void) { //Returns the input tree. return fInputTree; }