#include <TMap.h>
#include <TClass.h>
#include <TFile.h>
+#include <TTreeCache.h>
+#include <TEnv.h>
#include <TMath.h>
#include <TH1.h>
#include <TMethodCall.h>
fExtraFiles(),
fFileInfoLog(),
fAutoBranchHandling(kTRUE),
+ fAsyncReading(kTRUE), // default prefetching on
fTable(),
fRunFromPath(0),
fNcalls(0),
fMaxEntries(0),
+ fCacheSize(100000000), // default 100 MB
fStatisticsMsg(),
fRequestedBranches(),
fStatistics(0),
fExtraFiles(other.fExtraFiles),
fFileInfoLog(other.fFileInfoLog),
fAutoBranchHandling(other.fAutoBranchHandling),
+ fAsyncReading(other.fAsyncReading),
fTable(),
fRunFromPath(0),
fNcalls(other.fNcalls),
fMaxEntries(other.fMaxEntries),
+ fCacheSize(other.fCacheSize),
fStatisticsMsg(other.fStatisticsMsg),
fRequestedBranches(other.fRequestedBranches),
fStatistics(other.fStatistics),
fgCommonFileName = "AnalysisResults.root";
fgAnalysisManager = this;
fAutoBranchHandling = other.fAutoBranchHandling;
+ fAsyncReading = other.fAsyncReading;
fTable.Clear("nodelete");
fRunFromPath = other.fRunFromPath;
fNcalls = other. fNcalls;
fMaxEntries = other.fMaxEntries;
+ fCacheSize = other.fCacheSize;
fStatisticsMsg = other.fStatisticsMsg;
fRequestedBranches = other.fRequestedBranches;
fStatistics = other.fStatistics;
delete fInitTimer;
}
+//______________________________________________________________________________
+void AliAnalysisManager::CreateReadCache()
+{
+// Create cache for reading according fCacheSize and fAsyncReading.
+ if (!fTree || !fTree->GetCurrentFile()) {
+ Error("CreateReadCache","Current tree or tree file not yet defined");
+ return;
+ }
+ if (!fCacheSize) {
+ if (fDebug) Info("CreateReadCache","=== Read caching disabled ===");
+ return;
+ }
+// gEnv->SetValue("TFile.AsyncPrefetching",(Int_t)fAsyncReading);
+// if (fAsyncReading) gEnv->SetValue("Cache.Directory",Form("file://%s/cache", gSystem->WorkingDirectory()));
+ if (fAsyncReading) gEnv->SetValue("TFile.AsyncReading",1);
+ fTree->SetCacheSize(fCacheSize);
+ TTreeCache::SetLearnEntries(1); //<<< we can take the decision after 1 entry
+ fTree->AddBranchToCache("*",kTRUE); //<<< add all branches to the cache
+ if (fDebug) {
+ Info("CreateReadCache","Read cache enabled %lld bytes with async reading=%d",fCacheSize, (Int_t)fAsyncReading);
+ }
+ return;
+}
+
//______________________________________________________________________________
Int_t AliAnalysisManager::GetEntry(Long64_t entry, Int_t getall)
{
if (!fInitOK) InitAnalysis();
if (!fInitOK) return kFALSE;
fTree = tree;
+ CreateReadCache();
fTable.Rehash(100);
AliAnalysisDataContainer *top = fCommonInput;
if (!top) top = (AliAnalysisDataContainer*)fInputs->At(0);
// Init timer should be already started
// Apply debug options
ApplyDebugOptions();
-
+ if (fCacheSize && fMCtruthEventHandler) fMCtruthEventHandler->SetCacheSize(fCacheSize);
if (!CheckTasks()) Fatal("SlaveBegin", "Not all needed libraries were loaded");
static Bool_t isCalled = kFALSE;
Bool_t init = kFALSE;
GetAnalysisType() const {return fMode;}
void GetAnalysisTypeString(TString &type) const;
Bool_t GetAutoBranchLoading() const {return fAutoBranchHandling;}
+ Long64_t GetCacheSize() const {return fCacheSize;}
static const char *GetCommonFileName() {return fgCommonFileName.Data();}
AliAnalysisDataContainer *
GetCommonInputContainer() const {return fCommonInput;}
TObjArray *GetContainers() const {return fContainers;}
Long64_t GetCurrentEntry() const {return fCurrentEntry;}
UInt_t GetDebugLevel() const {return fDebug;}
+ Bool_t GetAsyncReading() const {return fAsyncReading;}
TString GetExtraFiles() const {return fExtraFiles;}
AliVEventPool* GetEventPool() const {return fEventPool;}
Bool_t GetFileFromWrapper(const char *filename, const TList *source);
void SetAnalysisType(EAliAnalysisExecMode mode) {fMode = mode;}
void SetAutoBranchLoading(Bool_t b) { fAutoBranchHandling = b; }
void SetCurrentEntry(Long64_t entry) {fCurrentEntry = entry;}
+ void SetCacheSize(Long64_t size) {fCacheSize = size;}
void SetCollectSysInfoEach(Int_t nevents=0) {fNSysInfo = nevents;}
void SetCollectThroughput(Bool_t flag) {Changed(); TObject::SetBit(kCollectThroughput,flag);}
static void SetCommonFileName(const char *name) {fgCommonFileName = name;}
void SetDebugLevel(UInt_t level);
void SetDisableBranches(Bool_t disable=kTRUE) {Changed(); TObject::SetBit(kDisableBranches,disable);}
+ void SetAsyncReading(Bool_t flag=kTRUE) {fAsyncReading = flag;}
void SetExternalLoop(Bool_t flag) {Changed(); TObject::SetBit(kExternalLoop,flag);}
void SetEventPool(AliVEventPool* const epool) {Changed(); fEventPool = epool;}
void SetFileInfoLog(const char *name) {TObject::SetBit(kCollectThroughput,kTRUE); fFileInfoLog = name;}
void UnLock();
void Changed();
protected:
+ void CreateReadCache();
void ImportWrappers(TList *source);
void SetEventLoop(Bool_t flag=kTRUE) {TObject::SetBit(kEventLoop,flag);}
void DoLoadBranch(const char *name);
TString fExtraFiles; // List of extra files to be merged
TString fFileInfoLog; // File name for fileinfo logs
Bool_t fAutoBranchHandling; // def=kTRUE, turn off if you use LoadBranch
+ Bool_t fAsyncReading; // Enable async reading
THashTable fTable; // keep branch ptrs in case of manual branch loading
Int_t fRunFromPath; // Run number retrieved from path to input data
Int_t fNcalls; // Total number of calls (events) of ExecAnalysis
Long64_t fMaxEntries; // Maximum number of entries
+ Long64_t fCacheSize; // Cache size in bytes
static Int_t fPBUpdateFreq; // Progress bar update freq.
TString fStatisticsMsg; // Statistics user message
TString fRequestedBranches; // Requested branch names
Double_t fInitTime; //! Cumulated time in initialization
static TString fgCommonFileName; //! Common output file name (not streamed)
static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
- ClassDef(AliAnalysisManager,17) // Analysis manager class
+ ClassDef(AliAnalysisManager,18) // Analysis manager class
};
#endif
#include "AliLog.h"
#include <TTree.h>
+#include <TTreeCache.h>
#include <TFile.h>
#include <TList.h>
#include <TParticle.h>
fInitOk(kFALSE),
fSubsidiaryHandlers(0),
fEventsInContainer(0),
- fPreReadMode(kNoPreRead)
+ fPreReadMode(kNoPreRead),
+ fCacheSize(0),
+ fCacheTK(0),
+ fCacheTR(0)
{
//
// Default constructor
fInitOk(kFALSE),
fSubsidiaryHandlers(0),
fEventsInContainer(0),
- fPreReadMode(kNoPreRead)
+ fPreReadMode(kNoPreRead),
+ fCacheSize(0),
+ fCacheTK(0),
+ fCacheTR(0)
{
//
// Constructor
delete fFileE;
delete fFileK;
delete fFileTR;
+ delete fCacheTK;
+ delete fCacheTR;
}
Bool_t AliMCEventHandler::Init(Option_t* opt)
if (!fInitOk) return kFALSE;
Int_t inew = iev / fEventsPerFile;
+ Bool_t firsttree = (fTreeK==0) ? kTRUE : kFALSE;
+ Bool_t newtree = firsttree;
if (inew != fFileNumber) {
+ newtree = kTRUE;
fFileNumber = inew;
if (!OpenFile(fFileNumber)){
return kFALSE;
// Connect TR to MCEvent
fMCEvent->ConnectTreeTR(fTreeTR);
}
-
- //
+ // Now setup the caches if not yet done
+ if (fCacheSize) {
+ if (firsttree) {
+ fTreeK->SetCacheSize(fCacheSize);
+ fCacheTK = (TTreeCache*) fFileK->GetCacheRead(fTreeK);
+ TTreeCache::SetLearnEntries(1);
+ fTreeK->AddBranchToCache("*",kTRUE);
+ Info("LoadEvent","Read cache enabled %lld bytes for TreeK",fCacheSize);
+ if (fTreeTR) {
+ fTreeTR->SetCacheSize(fCacheSize);
+ fCacheTR = (TTreeCache*) fFileTR->GetCacheRead(fTreeTR);
+ TTreeCache::SetLearnEntries(1);
+ fTreeTR->AddBranchToCache("*",kTRUE);
+ Info("LoadEvent","Read cache enabled %lld bytes for TreeTR",fCacheSize);
+ }
+ } else {
+ // We need to reuse the previous caches and every new event is a new tree
+ if (fCacheTK) {
+ fCacheTK->ResetCache();
+ if (fFileK) fFileK->SetCacheRead(fCacheTK, fTreeK);
+ fCacheTK->UpdateBranches(fTreeK);
+ }
+ if (fCacheTR) {
+ fCacheTR->ResetCache();
+ if (fFileTR) fFileTR->SetCacheRead(fCacheTR, fTreeTR);
+ fCacheTR->UpdateBranches(fTreeTR);
+ }
+ }
+ }
return kTRUE;
}
fkExtension = "";
}
-
+ if (fFileK && fCacheTK) fFileK->SetCacheRead(0, fTreeK);
delete fFileK;
fFileK = TFile::Open(Form("%sKinematics%s.root", fPathName->Data(), fkExtension));
if (!fFileK) {
}
if (fReadTR) {
- delete fFileTR;
- fFileTR = TFile::Open(Form("%sTrackRefs%s.root", fPathName->Data(), fkExtension));
- if (!fFileTR) {
- AliWarning(Form("AliMCEventHandler:TrackRefs%s.root not found in directory %s ! \n", fkExtension, fPathName->Data()));
- fInitOk = kFALSE;
- return kFALSE;
- }
+ if (fFileTR && fCacheTR) fFileTR->SetCacheRead(0, fTreeTR);
+ delete fFileTR;
+ fFileTR = TFile::Open(Form("%sTrackRefs%s.root", fPathName->Data(), fkExtension));
+ if (!fFileTR) {
+ AliWarning(Form("AliMCEventHandler:TrackRefs%s.root not found in directory %s ! \n", fkExtension, fPathName->Data()));
+ fInitOk = kFALSE;
+ return kFALSE;
+ }
}
fInitOk = kTRUE;
Bool_t AliMCEventHandler::FinishEvent()
{
// Clean-up after each event
- delete fDirTR; fDirTR = 0;
- delete fDirK; fDirK = 0;
+ if (fFileK && fCacheTK) fFileK->SetCacheRead(0, fTreeK);
+ if (fFileTR && fCacheTR) fFileTR->SetCacheRead(0, fTreeTR);
+ delete fDirTR; fDirTR = 0;
+ delete fDirK; fDirK = 0;
if (fInitOk) fMCEvent->FinishEvent();
if (fSubsidiaryHandlers) {
class TFile;
class TTree;
class TList;
+class TTreeCache;
class TParticle;
class TString;
virtual void AddSubsidiaryHandler(AliMCEventHandler* handler);
virtual void SetNumberOfEventsInContainer(Int_t nev) {fEventsInContainer = nev;}
virtual void SetPreReadMode(PreReadMode_t mode) {Changed(); fPreReadMode = mode;}
+ virtual void SetCacheSize(Long64_t size) {if (fCacheSize==0) fCacheSize = size;}
//
AliMCEvent* MCEvent() const {return fMCEvent;}
TTree* TreeTR() const {return fTreeTR;}
TList *fSubsidiaryHandlers; //! List of subsidiary MC handlers (for example for Background)
Int_t fEventsInContainer; //! Number of events in container class
PreReadMode_t fPreReadMode; // Pre reading mode
+ Long64_t fCacheSize; // Cache size for kinematics tree
+ TTreeCache *fCacheTK; //! Cache for kinematics tree
+ TTreeCache *fCacheTR; //! Cache for track references tree
- ClassDef(AliMCEventHandler,2) //MC Truth EventHandler class
+ ClassDef(AliMCEventHandler,3) //MC Truth EventHandler class
};
#endif
void Lock();
void UnLock();
void Changed();
+ virtual void SetCacheSize(Long64_t) {}
private :
ClassDef(AliVEventHandler, 1);
};