/** @file CbmMCDataObject.h ** @author //Dr.Sys **/ #ifndef CBMMCDATAOBJECT_H #define CBMMCDATAOBJECT_H #include "CbmLink.h" #include "TString.h" #include #include #include class TChain; class TObject; /** @class CbmMCDataObject ** @brief Access to a MC data branch for time-based analysis ** @author //Dr.Sys ** @date 31 March 2015 ** ** This class provides cached access to data for an event-by-event MC data branch, ** which is used when matching time-based reconstruction data to the input MC data. ** Data objects from already used events are cached, which allows switching between ** events without the performance deterioration induced by frequent calls to ** TTree::GetEntry(). ** In legacy mode, the data from the current event will be retrieved from ** FairRootManager. **/ class CbmMCDataObject { friend class CbmMCDataManager; public: /** Destructor **/ virtual ~CbmMCDataObject() { } /** Get an object by CbmLink pointer ** @param link Pointer to CbmLink object ** @value Pointer to linked object **/ TObject* Get(const CbmLink* lnk) { return Get(lnk->GetFile(), lnk->GetEntry()); } /** Get an object by CbmLink reference ** @param link Reference to CbmLink object ** @value Pointer to linked object **/ TObject* Get(const CbmLink& lnk) { return Get(lnk.GetFile(), lnk.GetEntry()); } /** Get an object by file number and event number ** @param fileNumber Input file number ** @param eventNumber Event number ** @value Pointer to referenced object **/ TObject* Get(Int_t fileNumber, Int_t eventNumber); private: /** Default constructor. Should be called from CbmMCDataManager. **/ CbmMCDataObject() : fLegacy(0), fLegacyObject(nullptr), fBranchName(), fSize(0), fChains(), fTArr(), fN(0), fArrays() { } /** Standard constructor. Should be called from CbmMCDataManager. ** @param branchName Name of data branch ** @param fileList Vector of file list (one for each input source) **/ CbmMCDataObject(const char* branchName, const std::vector >& fileList); /** Constructor in legacy mode. Gets the branch from FairRootManager. ** @param branchName Name of data branch **/ CbmMCDataObject(const char* branchName); /** Copy constructor. Should not be called. **/ CbmMCDataObject(const CbmMCDataObject&); /** Done. Clear all arrays and delete file chain. **/ void Done(); /** Finish event. Delete all arrays to free memory. **/ void FinishEvent(); /** Make TChain number chainNum2 friend of TChain number chainNum2 ** @param chainNum1 a number of chain for which AddFriend is called ** @param chainNum2 number of chain which became a friend **/ void AddFriend(Int_t chainNum1, Int_t chainNum2); /** Get an object in legacy mode ** @param fileNumber Input number ** @param eventNumber Event number ** @value Pointer to referenced object **/ TObject* LegacyGet(Int_t fileNumber, Int_t eventNumber); //---- Private data members ------- Int_t fLegacy; //! If true, run in legacy mode TObject* fLegacyObject; //! Pointer to TObject for legacy mode TString fBranchName; //! Name of the data branch Int_t fSize; //! Number of input file lists (one per source) std::vector fChains; //! Arrays of chains (one per input source) std::vector fTArr; //! Data objects from chains (one per input source) std::vector fN; //! Number of entries in chains /** Cached data objects. The vector index is the input source number, the map ** index is the event number. **/ std::vector > fArrays; //! CbmMCDataObject& operator=(const CbmMCDataObject&); ClassDef(CbmMCDataObject, 1); }; #endif