#ifndef INCLUDE_TEVENTSAMPLE_H #define INCLUDE_TEVENTSAMPLE_H #include "TChain.h" #include "TClonesArray.h" #include "TEventSampleInfo.h" #include #include class TTree; using namespace seed; namespace seed { class TSeedABC; class TProcessEventABC; class TSeedList; } //_________________________________________________________________________________ // This is Seed's interface class. It allows to convert n-tuple data to // object oriented Seed data (also known as tree, filled with objects) and to // read this data back after the transformation. // // First, the seed::TEventSample::Create method transforms n-tuple data into // objects. This is done internally with the help of seed::TSeedList, which // holds and indexes all active seeds deriving from seed::TSeedABC. For each // entry in the n-tuple each active seed's fill method is called (see // seed::TSeedABC::FillSeedData). The implementation of this method has to // be provided by the user: It reads data from the n-tuple (via // seed::TSingleEntryTree) and puts it into objects. Each seed is // responsible for the translation between a fixed n-tuple layout (branch // names, leaf names) and a fixed object type (this is called "data class" // in this documentation). There are several options how to transform the // data, see // // SetSeedActivationFile(const Char_t *cSAF = "SeedActivation.ini"); // SetOutputFileName(const Char_t *cSeedFileName, // SetOutputFileOption(const Char_t *cOption = "NEW"); // SetAuthor(const Char_t *cAuthor = ""); // SetFirstEntry(const Int_t iFirstEntry = 0); // SetNumEntries(const Int_t iNumEntries = -1); // SetUserParameter(void* pUserParameter = NULL); // SetSaveOutput(Bool_t bSave = kTRUE); // SetProcessEvent(seed::TProcessEventABC *pProcessEvent = NULL); // SetDebug(const Int_t iDebugLevel = 1); // // ReadSettings(const Char_t *cSettingsFile); // SaveSettings(const Char_t *cSettingsFile); // PrintSettings(); // // // After the seed data is created the static method // TEventSample::Load loads a TEventSample from a file and returns // a pointer to this TEventSample. It can even load several files in // parallel (like TChain), see TEventSample::Load. // (Although TEventSample::Load looks like a singleton's ::GetInstance // it's not. There can be several TEventSamples around.) // // Now one can access the data stored in the TEventSample by accessing // each event with SetEvent and each event's data with classes deriving // from seed::TSeedABC. // namespace seed { class TEventSample: public TObject { friend class seed::TSeedList; friend class seed::TSeedABC; public: TEventSample(); TEventSample(const TEventSample & es); virtual ~ TEventSample(); static Bool_t ShowNtuple( const Char_t *cNTupleFileName, const Char_t *strNTupleID=NULL); static Bool_t MakeSeed( const Char_t *cNtupleFileName, const Char_t *cNtupleID=NULL, const Char_t *cBranch=NULL, const Char_t *cSeedName="TMySeed", const Char_t *cDataClass=NULL); static Bool_t MakeSeed( TTree* pNtupleTree=NULL, const Char_t *cBranch=NULL, const Char_t *cSeedName="TMySeed", const Char_t *cDataClass=NULL); static seed::TEventSample * Load( const Char_t *strRootFileName, const Char_t* cSAFName = "SeedActivation.ini"); TEventSample& AddFile(const Char_t* strRootFileName); Bool_t Create( const Char_t *cNtupleFileName, const Char_t *cNtupleID=NULL); Bool_t Create(TTree* pNtupleTree); Bool_t AddGlobalObject(const Char_t *cName, TObject * pObj); TObject *GetGlobalObject(const Char_t *cName) const; static TString Ntuple2SeedFileName(const Char_t * strNTupleFileName); /********** Initialization methods for Create ***********/ TEventSample& SetSeedActivationFile(const Char_t *cSAF = "SeedActivation.ini"); TEventSample& SetOutputFileName(const Char_t *cSeedFileName); TEventSample& SetOutputFileOption(const Char_t *cOption = "NEW"); TEventSample& SetDebug(const Int_t iDebugLevel = 1); TEventSample& SetAuthor(const Char_t *cAuthor = ""); TEventSample& SetFirstEntry(const Int_t iFirstEntry = 0); TEventSample& SetNumEntries(const Int_t iNumEntries = -1); TEventSample& SetNEvents(const Int_t iNumEntries = -1); TEventSample& SetUserParameter(void* pUserParameter = NULL); TEventSample& SetUserParameter(const Char_t* strSeed, void* pUserParameter = NULL); TEventSample& SetSaveOutput(Bool_t bSave = kTRUE); TEventSample& SetProcessEvent(seed::TProcessEventABC *pProcessEvent = NULL); TEventSample& SetCrossEventRefs(Bool_t bCER = kFALSE); Bool_t ReadSettings(const Char_t *cSettingsFile); Bool_t SaveSettings(const Char_t *cSettingsFile); TEventSample& PrintSettings(); inline Int_t GetNEvents() const { return (fTreeEvent?(Int_t) fTreeEvent->GetEntries():-1); }; inline Int_t GetNumEntries() const { return (fTreeEvent?(Int_t) fTreeEvent->GetEntries():-1); }; Bool_t SetEvent(const Int_t iEventIdx); Int_t GetNumberOf(const Char_t *strSeed); inline TTree *GetTree() { return fTreeEvent; }; TFile* GetCurrentFile() const; inline Int_t GetDebugLevel() const { return (fDebug>gDebug?fDebug:gDebug);}; Bool_t EnableSeed(const Char_t* cSeed, Bool_t bEnable=kTRUE); TClonesArray * GetClonesArray(const Char_t *strSeed); static void AddWarning(); static void AddError(); static Int_t GetNumWarnings(); static Int_t GetNumErrors(); static void ResetErrorCounter(); protected: TClonesArray * const * GetCAPtrAddr(const Char_t *strSeed); TClonesArray **CreateCA(seed::TSeedABC * pSeed); static Bool_t ParseSeedActivationFile(const Char_t *cSAFName); static TTree* GetNtupleFromFile( const Char_t *cNtupleFileName, const Char_t *cNtupleID, Int_t debug=1); TFile* CreateOutputFile(); Bool_t SetupBranches(); static Bool_t MakeSeed_Branch( std::ofstream &fsHeader, std::ofstream &fsSource, TBranch* pB); static Bool_t MakeSeed_Leaf( std::ofstream &fsHeader, std::ofstream &fsSource, TLeaf* pL, Int_t iNumLeaves); protected: seed::TEventSampleInfo fEsInfo; // some information on the TEventSample TTree *fTreeEvent; //! tree of data classes filled by seeds, written and read "by hand" std::map < std::string, TClonesArray * > fMapCA; //! pointer to TClonesArrays in Seeds std::map < std::string, TObject * > fMapGlobalObjects; //! map of global objects which have to be streamed in Create Bool_t fDisableSetEntry; //! to temporarily disable seed::TEvenTSample::SetEvent, e.g. for OnTheFly std::map < std::string, void * > fMapUserParameters; //! map of seed specific user parameters // initialization members -- for Create TString fStrClassFileName; // where to store the TEventSample - as it's a member one can always rename it to its original filename (might be nice) const Char_t *fNtupleFileName; //! name of the ntuple (input) file const Char_t *fNtupleID; //! name of the ntuple's key in ntuple file const Char_t *fSeedFileOption; //! options for opening the seed data (ouput) file const Char_t *fSAFName; //! name of the seed activation file Int_t fDebug; //! local debug level, debug level = max(fDebug, gDebug) Int_t fFirstEntry; //! first entry to be processed in ntuple Int_t fNumEntries; //! number of entries to be processed in ntuple void* fUserParameter; //! user defined parameter, passed to seed::TSeedABC::FillSeedData TTree *fNtupleTree; //! pointer to ntuple (input) TTree Bool_t fSaveSeedData; //! the seed data (output) is saved to file seed::TProcessEventABC *fProcessEvent; //! class to be used for on-the-fly analysis of seed data Bool_t fCrossEventRefs; //! allow TRefs to span different events TFile* fFileCF; //! class file for Create static Int_t fNumErrors; // number of errors issued during creation / load static Int_t fNumWarnings; // number of warnings issued during creation / load ClassDef(TEventSample, 2) // contains and interfaces seed data }; } // namespace seed #endif