-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring of sources - making separate class for virtual sources.
- Loading branch information
1 parent
7e3d0fc
commit d8fbdf8
Showing
10 changed files
with
238 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* VirtualIOManager2.cxx | ||
* | ||
* Created on: 19 gru 2024 | ||
* Author: daniel | ||
*/ | ||
|
||
#include "VirtualIOManager.h" | ||
|
||
#include <TFile.h> | ||
#include <TTree.h> | ||
|
||
#include "Cout.h" | ||
#include "InputDataInfo.h" | ||
#include "Std.h" | ||
#include "VirtualSource.h" | ||
|
||
namespace Hal { | ||
VirtualIOManager::VirtualIOManager(VirtualSource* source, Int_t events) : | ||
Hal::IOManager(new Hal::InputDataInfo("/dev/null")), | ||
fInFileName("/dev/null"), | ||
fOutTreeName("HalTree"), | ||
fEntries(events), | ||
fInFile(nullptr), | ||
fOutFile(nullptr), | ||
fOutTree(nullptr), | ||
fSource(source) {} | ||
|
||
Bool_t VirtualIOManager::InitInternal() { | ||
Hal::Cout::PrintInfo("IO manager internal init", Hal::EInfo::kDebugInfo); | ||
Hal::Cout::PrintInfo(fInFileName, Hal::EInfo::kDebugInfo); | ||
fInFile = new TFile(fInFileName, "recreate"); | ||
fOutFile = new TFile(fOutFileName, "recreate"); | ||
fOutTree = new TTree(fOutTreeName, fOutTreeName); | ||
Hal::Cout::PrintInfo(Form("Creating output tree %s", fOutTreeName.Data()), Hal::EInfo::kDebugInfo); | ||
fSource->RegisterInputs(); | ||
return kTRUE; | ||
} | ||
|
||
Int_t VirtualIOManager::GetEntries() const { return fEntries; } | ||
|
||
void VirtualIOManager::RegisterInternal(const char* name, const char* folderName, TNamed* obj, Bool_t toFile) { | ||
if (toFile) { fOutTree->Branch(name, obj); } | ||
} | ||
|
||
void VirtualIOManager::RegisterInternal(const char* name, const char* Foldername, TCollection* obj, Bool_t toFile) { | ||
if (toFile) { fOutTree->Branch(name, obj); } | ||
} | ||
|
||
Int_t VirtualIOManager::GetEntry(Int_t i, Int_t flag) { | ||
if (i < fEntries) { | ||
if (fSource) fSource->GetEvent(i, flag); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
TFile* VirtualIOManager::GetInFile() { return fInFile; } | ||
|
||
void VirtualIOManager::SetInChain(TChain* /*tempChain*/, Int_t /*ident*/) {} | ||
|
||
void VirtualIOManager::FillTree() { fOutTree->Fill(); } | ||
|
||
void VirtualIOManager::CloseManager() { | ||
fOutTree->Write(); | ||
fOutFile->Close(); | ||
} | ||
|
||
VirtualIOManager::~VirtualIOManager() { | ||
if (fOutFile) delete fOutFile; | ||
if (fInFile) delete fInFile; | ||
} | ||
|
||
} /* namespace Hal */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* VirtualIOManager2.h | ||
* | ||
* Created on: 19 gru 2024 | ||
* Author: daniel | ||
*/ | ||
|
||
#ifndef HAL_DATA_IO_VIRTUALIOMANAGER_H_ | ||
#define HAL_DATA_IO_VIRTUALIOMANAGER_H_ | ||
|
||
#include <RtypesCore.h> | ||
#include <TString.h> | ||
|
||
#include "IOManager.h" | ||
|
||
class TTree; | ||
namespace Hal { | ||
class VirtualSource; | ||
} /* namespace Hal */ | ||
|
||
namespace Hal { | ||
|
||
class VirtualIOManager : public IOManager { | ||
TString fInFileName; | ||
TString fOutFileName; | ||
TString fOutTreeName; | ||
Int_t fEntries; | ||
TFile* fInFile; | ||
TFile* fOutFile; | ||
TTree* fOutTree; | ||
VirtualSource* fSource; | ||
|
||
protected: | ||
virtual void RegisterInternal(const char* name, const char* folderName, TNamed* obj, Bool_t toFile); | ||
virtual void RegisterInternal(const char* name, const char* Foldername, TCollection* obj, Bool_t toFile); | ||
virtual Bool_t InitInternal(); | ||
|
||
public: | ||
VirtualIOManager(VirtualSource* source = nullptr, Int_t events = 10000); | ||
void SetOutput(TString name) { fOutFileName = name; } | ||
void SetOutTreeName(TString name) { fOutTreeName = name; } | ||
Int_t GetEntries() const; | ||
virtual Int_t GetEntry(Int_t i, Int_t flag); | ||
virtual TFile* GetInFile(); | ||
virtual void AddFriend(TString /*name*/) {}; | ||
virtual void SetInChain(TChain* tempChain, Int_t ident = -1); | ||
virtual void FillTree(); | ||
virtual void CloseManager(); | ||
virtual ~VirtualIOManager(); | ||
ClassDef(VirtualIOManager, 1) | ||
}; | ||
|
||
} /* namespace Hal */ | ||
|
||
#endif /* */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* VirtualRootSource.cxx | ||
* | ||
* Created on: 19 gru 2024 | ||
* Author: daniel | ||
*/ | ||
|
||
#include "VirtualSource.h" | ||
|
||
#include <TFile.h> | ||
#include <TTree.h> | ||
|
||
#include "Cout.h" | ||
#include "InputDataInfo.h" | ||
#include "Std.h" | ||
#include "VirtualIOManager.h" | ||
|
||
namespace Hal { | ||
|
||
VirtualSource::VirtualSource(Int_t nevents) : Hal::Source("/dev/null"), fEvents(nevents) { | ||
fManager = new VirtualIOManager(this, nevents); | ||
} | ||
|
||
VirtualSource::VirtualSource(IOManager* mngr, Int_t nevents) : Source(mngr), fEvents(nevents) {} | ||
|
||
Bool_t VirtualSource::Init() { return kTRUE; } | ||
|
||
void VirtualSource::GetEvent(Int_t /*i*/, Int_t /*flag*/) { ++fEvents; } | ||
|
||
} /* namespace Hal */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* VirtualRootSource.h | ||
* | ||
* Created on: 19 gru 2024 | ||
* Author: daniel | ||
*/ | ||
|
||
#ifndef HAL_DATA_IO_VIRTUALSOURCE_H_ | ||
#define HAL_DATA_IO_VIRTUALSOURCE_H_ | ||
|
||
#include <RtypesCore.h> | ||
#include <TString.h> | ||
#include <vector> | ||
|
||
#include "IOManager.h" | ||
#include "Source.h" | ||
|
||
class TTree; | ||
|
||
namespace Hal { | ||
class VirtualIOManager; | ||
/** | ||
* class that represents source without a physical input (e.g. for generation data on the fly) | ||
*/ | ||
class VirtualSource : public Source { | ||
friend class VirtualIOManager; | ||
|
||
protected: | ||
Int_t fEvents = {0}; | ||
Bool_t fRegister = {kFALSE}; | ||
/** | ||
* register input data and sent pointers to generators, this cannot be done until Init method | ||
* because data manager does not exist yet | ||
*/ | ||
virtual void RegisterInputs() {}; | ||
VirtualSource(IOManager* mngr, Int_t nevents = 1000); | ||
|
||
public: | ||
VirtualSource(Int_t nevents = 1000); | ||
virtual Bool_t Init(); | ||
/** | ||
* register generated data in output | ||
*/ | ||
virtual void Register() { fRegister = kTRUE; } | ||
virtual void GetEvent(Int_t i, Int_t flag); | ||
virtual ~VirtualSource() {}; | ||
ClassDef(VirtualSource, 1) | ||
}; | ||
} /* namespace Hal */ | ||
|
||
#endif /* HAL_DATA_IO_VIRTUALSOURCE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.