/* ======================================================================== *\ ! ! * ! * This file is part of MARS, the MAGIC Analysis and Reconstruction ! * Software. It is distributed to you in the hope that it can be a useful ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes. ! * It is distributed WITHOUT ANY WARRANTY. ! * ! * Permission to use, copy, modify and distribute this software and its ! * documentation for any purpose is hereby granted without fee, ! * provided that the above copyright notice appear in all copies and ! * that both that copyright notice and this permission notice appear ! * in supporting documentation. It is provided "as is" without express ! * or implied warranty. ! * ! ! ! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de) ! ! Copyright: MAGIC Software Development, 2000-2001 ! ! \* ======================================================================== */ ///////////////////////////////////////////////////////////////////////////// // // // MReadTree // // // // This tasks opens all branches in a specified tree and creates the // // corresponding parameter containers if not already existing in the // // parameter list. // // // // The Process function reads one events from the tree. To go through the // // events of one tree make sure that the event number is increased from // // outside. It makes also possible to go back by decreasing the number. // // // ///////////////////////////////////////////////////////////////////////////// #include "MReadTree.h" #include #include #include #include #include #include "MLog.h" #include "MLogManip.h" #include "MTime.h" #include "MParList.h" ClassImp(MReadTree) // -------------------------------------------------------------------------- MReadTree::MReadTree(const char *tname, const char *fname, const char *name, const char *title) { *fName = name ? name : "MReadTree"; *fTitle = title ? title : "Task to loop over all events in one single tree"; fVetoList = new TArrayC; // // open the input stream // fChain = new TChain(tname); if (fname) fChain->Add(fname); } // -------------------------------------------------------------------------- MReadTree::~MReadTree() { delete fChain; delete fVetoList; } // -------------------------------------------------------------------------- /*Int_t*/ void MReadTree::AddFile(const char *fname) { // // FIXME! A check is missing whether the file already exists or not. // // // returns the number of file which were added // /*return root >3.0*/ fChain->Add(fname); } // -------------------------------------------------------------------------- // // open file and check if file is really open // Bool_t MReadTree::PreProcess (MParList *pList) { // // get number of events in this tree // fNumEntries = (UInt_t)fChain->GetEntries(); if (!fNumEntries) { *fLog << dbginf << "No Entries found in chain (file/s)." << endl; return kFALSE; } // // set pointer to first event // fNumEntry = 0; // // output logging information // *fLog << fNumEntries << " Entries found in file(s)." << endl; // // Get all branches of this tree and // create the Iterator to loop over all branches // TIter Next(fChain->GetListOfBranches()); TBranch *branch=NULL; // // loop over all tasks for processing // while ( (branch=(TBranch*)Next()) ) { // // Get Name of Branch // const char *name = branch->GetName(); // // Check if enabeling the branch is allowed // if (HasVeto(name)) continue; // // check if object is existing in the list // MParContainer *pcont = pList->FindCreateObj(name); if (!pcont) { // // if class is not existing in the (root) environment // we cannot proceed reading this branch // *fLog << "MReadTree::PreProcess - Warning: Class '" << name << "' not existing in dictionary. Branch skipped." << endl; continue; } // // here pcont is a pointer the to container in which the data from // the actual branch should be stored - enable branch. // branch->SetAddress(&pcont); } return kTRUE; } // -------------------------------------------------------------------------- Bool_t MReadTree::Process() { // // check for end of file // if (fNumEntry==fNumEntries) return kFALSE; // // get entry // fChain->GetEntry(fNumEntry ); fNumEntry ++ ; return kTRUE; } // -------------------------------------------------------------------------- // // Close File // Bool_t MReadTree::PostProcess() { //fFile->Close(); return kTRUE; } // -------------------------------------------------------------------------- // // Get the Event with the current EventNumber fNumEntry // Bool_t MReadTree::GetEvent() { fChain->GetEntry(fNumEntry); return kTRUE; } // -------------------------------------------------------------------------- // // Decrease the number of the event which is read by Process() next // by one or more // Bool_t MReadTree::DecEventNum(UInt_t dec) { //! //! this function makes Process() read the event one (or more) before //! the actual position (event) in the tree //! if (fNumEntry < dec/*+1*/) { *fLog << "MReadTree::SetPrevEvent: WARNING: " << fNumEntry/*-1*/ << "-" << dec << " out of Range." << endl; return kFALSE; } fNumEntry -= dec/*+1*/; return kTRUE; } // -------------------------------------------------------------------------- // // Increase the number of the event which is read by Process() next // by one or more // Bool_t MReadTree::IncEventNum(UInt_t inc) { //! //! this function makes Process() read the next (or more) after //! the actual position (event) in the tree //! (Be careful: IncEventNum() or IncEventNum(1) does not chenge anything //! in the standard behaviour of the task) //! if (fNumEntry+inc/*-1*/ >= fNumEntries) { *fLog << "MReadTree::SkipEvents: WARNING: " << fNumEntry/*-1*/ << "+" << inc << " out of Range." << endl; return kFALSE; } fNumEntry += inc/*-1*/; return kTRUE; } // -------------------------------------------------------------------------- // // this function makes Process() read event number nr next // Bool_t MReadTree::SetEventNum(UInt_t nr) { if (nr>=fNumEntries) { *fLog << "MReadTree::SetEventNum: WARNING: " << nr << " out of Range." << endl; return kFALSE; } fNumEntry = nr; return kTRUE; } // -------------------------------------------------------------------------- // // This function checks if the Branch Name is part of the Veto List. // This means, that the preprocess doesn't enable the branch. // Bool_t MReadTree::HasVeto(const char *name) const { const size_t nlen = strlen(name)+1; char *pos = fVetoList->GetArray(); size_t len = fVetoList->GetSize(); // // now we compare the 'strings' in the list word by word // (string or word in this context means a zero terminated // array of chars // for (;;) { // // Search for the first byte of the name // char *c = (char*)memchr(pos, name[0], len); // // if we don't find the first byte, the list cannot contain 'name' // if (!c) return kFALSE; // // calculate and check how many bytes remains in the list // len -= c-pos; // // if there are not enough bytes to match the query we are done // if (lenGetSize(); const int tsz = strlen(name)+1; fVetoList->Set(sz+tsz); memcpy(fVetoList->GetArray()+sz, name, tsz); }