Skip to content

Commit bdc0641

Browse files
authored
Merge pull request #181 from rest-for-physics/lobis-trestrun-getinputevent
Added templated TRestRun::GetInputEvent
2 parents 77c94ff + a72f9b9 commit bdc0641

File tree

4 files changed

+115
-129
lines changed

4 files changed

+115
-129
lines changed

scripts/TRestVersion.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

source/framework/core/inc/TRestRun.h

Lines changed: 74 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@
1212
#include "TRestEvent.h"
1313
#include "TRestMetadata.h"
1414

15-
//#include "TRestThread.h"
16-
1715
class TRestEventProcess;
1816

1917
/// Data provider and manager in REST
2018
class TRestRun : public TRestMetadata {
2119
protected:
22-
// runinfo
23-
Int_t fRunNumber; //< first identificative number
20+
// run info
21+
Int_t fRunNumber; //< first identification number
2422
Int_t fParentRunNumber;
2523
TString fRunClassName;
2624
TString fRunType; //< Stores bit by bit the type of run. e.g. calibration, background, pedestal,
27-
// simulation, datataking
25+
// simulation, data taking
2826
TString fRunUser; //< To identify the author it has created the run. It might be also a word describing
2927
// the origin of the run (I.e. REST_Prototype, T-REX, etc)
3028
TString fRunTag; //< A tag to be written to the output file
@@ -63,23 +61,23 @@ class TRestRun : public TRestMetadata {
6361
void InitFromConfigFile();
6462

6563
private:
66-
std::string ReplaceMetadataMember(const std::string instr);
64+
std::string ReplaceMetadataMember(const std::string& instr);
6765

6866
public:
6967
/// REST run class
7068
void Initialize();
7169

7270
// file operation
7371
void OpenInputFile(int i);
74-
void OpenInputFile(TString filename, std::string mode = "");
75-
void AddInputFileExternal(std::string file);
76-
void ReadFileInfo(std::string filename);
72+
void OpenInputFile(const TString& filename, const std::string& mode = "");
73+
void AddInputFileExternal(const std::string& file);
74+
void ReadFileInfo(const std::string& filename);
7775
void ReadInputFileMetadata();
7876
void ReadInputFileTrees();
7977

8078
void ResetEntry();
8179

82-
Int_t GetNextEvent(TRestEvent* targetevt, TRestAnalysisTree* targettree);
80+
Int_t GetNextEvent(TRestEvent* targetEvent, TRestAnalysisTree* targetTree);
8381
void GetEntry(int i) {
8482
if (fAnalysisTree != nullptr) {
8583
fAnalysisTree->GetEntry(i);
@@ -101,7 +99,7 @@ class TRestRun : public TRestMetadata {
10199
GetEntry(fCurrentEvent + 1);
102100
}
103101

104-
TString FormFormat(TString FilenameFormat);
102+
TString FormFormat(const TString& FilenameFormat);
105103
TFile* MergeToOutputFile(std::vector<std::string> filefullnames, std::string outputfilename = "");
106104
TFile* FormOutputFile();
107105
TFile* UpdateOutputFile();
@@ -115,112 +113,119 @@ class TRestRun : public TRestMetadata {
115113

116114
void CloseFile();
117115

118-
void ImportMetadata(TString rootFile, TString name, TString type, Bool_t store);
116+
void ImportMetadata(const TString& rootFile, const TString& name, const TString& type, Bool_t store);
119117

120118
/// add metadata object to the metadata list
121-
void AddMetadata(TRestMetadata* meta) {
119+
inline void AddMetadata(TRestMetadata* meta) {
122120
if (meta != nullptr) {
123121
fMetadata.push_back(meta);
124122
} else {
125-
warning << "REST Warning! A null matadata wants to be added in TRestRun!" << endl;
123+
warning << "REST Warning! A null metadata wants to be added in TRestRun!" << endl;
126124
}
127125
}
128126
void AddEventBranch(TRestEvent* eve);
129127
void SkipEventTree() {}
130128

131129
// Getters
132-
Int_t GetParentRunNumber() const { return fParentRunNumber; }
133-
Int_t GetRunNumber() const { return fRunNumber; }
134-
TString GetRunType() const { return fRunType; }
135-
TString GetRunUser() const { return fRunUser; }
136-
TString GetRunTag() const { return fRunTag; }
137-
TString GetRunDescription() const { return fRunDescription; }
138-
Double_t GetRunLength();
139-
Double_t GetStartTimestamp() const { return fStartTime; }
140-
Double_t GetEndTimestamp() const { return fEndTime; }
141-
TString GetExperimentName() const { return fExperimentName; }
142-
143-
std::vector<TString> GetInputFileNames() const { return fInputFileNames; }
144-
std::string GetInputFileName(int i) const {
130+
inline Int_t GetParentRunNumber() const { return fParentRunNumber; }
131+
inline Int_t GetRunNumber() const { return fRunNumber; }
132+
inline TString GetRunType() const { return fRunType; }
133+
inline TString GetRunUser() const { return fRunUser; }
134+
inline TString GetRunTag() const { return fRunTag; }
135+
inline TString GetRunDescription() const { return fRunDescription; }
136+
Double_t GetRunLength() const;
137+
inline Double_t GetStartTimestamp() const { return fStartTime; }
138+
inline Double_t GetEndTimestamp() const { return fEndTime; }
139+
inline TString GetExperimentName() const { return fExperimentName; }
140+
141+
inline std::vector<TString> GetInputFileNames() const { return fInputFileNames; }
142+
inline std::string GetInputFileName(int i) const {
145143
return i < fInputFileNames.size() ? (std::string)fInputFileNames[i] : "";
146144
}
147-
std::string GetInputFileNamepattern() const { return (std::string)fInputFileName; }
148-
TString GetOutputFileName() const { return fOutputFileName; }
149-
TFile* GetInputFile() const { return fInputFile; }
150-
TFile* GetOutputFile() const { return fOutputFile; }
151-
int GetCurrentEntry() const { return fCurrentEvent; }
152-
Long64_t GetBytesReaded() const { return fBytesRead; }
145+
inline std::string GetInputFileNamePattern() const { return fInputFileName.Data(); }
146+
inline TString GetOutputFileName() const { return fOutputFileName; }
147+
inline TFile* GetInputFile() const { return fInputFile; }
148+
inline TFile* GetOutputFile() const { return fOutputFile; }
149+
inline int GetCurrentEntry() const { return fCurrentEvent; }
150+
inline Long64_t GetBytesReaded() const { return fBytesRead; }
153151
Long64_t GetTotalBytes();
154-
int GetEntries();
152+
int GetEntries() const;
153+
154+
/// Calling `GetInputEvent()` will return a basic `TRestEvent*`
155+
inline TRestEvent* GetInputEvent() const { return fInputEvent; }
156+
/// Calling `GetInputEvent<TRestGeant4Event>()` will return a `TRestGeant4Event*`
157+
template <class T>
158+
inline T* GetInputEvent() {
159+
return static_cast<T*>(fInputEvent);
160+
}
155161

156-
TRestEvent* GetInputEvent() const { return fInputEvent; }
157-
TRestEvent* GetEventWithID(Int_t eventID, Int_t subEventID = -1, TString tag = "");
162+
TRestEvent* GetEventWithID(Int_t eventID, Int_t subEventID = -1, const TString& tag = "");
158163
std::vector<int> GetEventEntriesWithConditions(const std::string&, int startingIndex = 0,
159164
int maxNumber = -1);
160165
std::vector<int> GetEventIdsWithConditions(const std::string&, int startingIndex = 0, int maxNumber = -1);
161166
TRestEvent* GetNextEventWithConditions(const std::string&);
162-
TRestEventProcess* GetFileProcess() const { return fFileProcess; }
163-
std::string GetRunInformation(std::string info);
164-
Int_t GetObservableID(std::string name) { return fAnalysisTree->GetObservableID(name); }
165-
Bool_t ObservableExists(std::string name) { return fAnalysisTree->ObservableExists(name); }
166-
TString GetInputEventName() const { return fInputEvent->ClassName(); }
167-
TRestAnalysisTree* GetAnalysisTree() const { return fAnalysisTree; }
168-
TTree* GetEventTree() const { return fEventTree; }
169-
Int_t GetInputFileNumber() const { return fFileProcess == nullptr ? fInputFileNames.size() : 1; }
170-
171-
TRestMetadata* GetMetadata(TString name, TFile* f = nullptr);
172-
TRestMetadata* GetMetadataClass(TString type, TFile* f = nullptr);
167+
inline TRestEventProcess* GetFileProcess() const { return fFileProcess; }
168+
std::string GetRunInformation(const std::string& info);
169+
inline Int_t GetObservableID(const std::string& name) { return fAnalysisTree->GetObservableID(name); }
170+
inline Bool_t ObservableExists(const std::string& name) { return fAnalysisTree->ObservableExists(name); }
171+
inline TString GetInputEventName() const { return fInputEvent->ClassName(); }
172+
inline TRestAnalysisTree* GetAnalysisTree() const { return fAnalysisTree; }
173+
inline TTree* GetEventTree() const { return fEventTree; }
174+
inline Int_t GetInputFileNumber() const { return fFileProcess == nullptr ? fInputFileNames.size() : 1; }
175+
176+
TRestMetadata* GetMetadata(const TString& name, TFile* f = nullptr);
177+
TRestMetadata* GetMetadataClass(const TString& type, TFile* f = nullptr);
173178
std::vector<std::string> GetMetadataStructureNames();
174179
std::vector<std::string> GetMetadataStructureTitles();
175-
int GetNumberOfMetadataStructures() { return fMetadata.size(); }
180+
inline int GetNumberOfMetadataStructures() const { return fMetadata.size(); }
176181

177-
std::string GetMetadataMember(const std::string& instr) { return ReplaceMetadataMember(instr); }
178-
std::string ReplaceMetadataMembers(std::string instr);
182+
inline std::string GetMetadataMember(const std::string& instr) { return ReplaceMetadataMember(instr); }
183+
std::string ReplaceMetadataMembers(const std::string& instr);
179184

180185
Bool_t EvaluateMetadataMember(const std::string& instr);
181186

182187
// Setters
183-
void SetInputFileName(const std::string& s) {
188+
inline void SetInputFileName(const std::string& s) {
184189
fInputFileName = s;
185190
fInputFileNames = Vector_cast<std::string, TString>(
186191
TRestTools::GetFilesMatchingPattern((std::string)fInputFileName));
187192
}
188-
void SetOutputFileName(const std::string& s) { fOutputFileName = s; }
193+
inline void SetOutputFileName(const std::string& s) { fOutputFileName = s; }
189194
void SetExtProcess(TRestEventProcess* p);
190-
void SetCurrentEntry(int i) { fCurrentEvent = i; }
195+
inline void SetCurrentEntry(int i) { fCurrentEvent = i; }
191196
// void AddFileTask(TRestFileTask* t) { fFileTasks.push_back(t); }
192-
void SetInputEvent(TRestEvent* eve);
193-
void SetRunNumber(Int_t number) { fRunNumber = number; }
194-
void SetParentRunNumber(Int_t number) { fParentRunNumber = number; }
195-
void SetRunType(const TString& type) {
197+
void SetInputEvent(TRestEvent* event);
198+
inline void SetRunNumber(Int_t number) { fRunNumber = number; }
199+
inline void SetParentRunNumber(Int_t number) { fParentRunNumber = number; }
200+
inline void SetRunType(const TString& type) {
196201
std::string cleanType = RemoveWhiteSpaces((std::string)type);
197202
fRunType = (TString)cleanType;
198203
}
199-
void SetRunTag(const TString& tag) {
204+
inline void SetRunTag(const TString& tag) {
200205
std::string cleanTag = RemoveWhiteSpaces((std::string)tag);
201206
fRunTag = (TString)cleanTag;
202207
}
203-
void SetRunUser(const TString& user) {
208+
inline void SetRunUser(const TString& user) {
204209
std::string cleanUser = RemoveWhiteSpaces((std::string)user);
205210
fRunUser = (TString)cleanUser;
206211
}
207-
void SetRunDescription(const TString& description) { fRunDescription = description; }
208-
void SetStartTimeStamp(Double_t tStamp) { fStartTime = tStamp; }
209-
void SetEndTimeStamp(Double_t tStamp) { fEndTime = tStamp; }
210-
void SetTotalBytes(Long64_t b) { fTotalBytes = b; }
211-
void SetHistoricMetadataSaving(bool save) { fSaveHistoricData = save; }
212-
void HangUpEndFile() { fHangUpEndFile = true; }
213-
void ReleaseEndFile() { fHangUpEndFile = false; }
212+
inline void SetRunDescription(const TString& description) { fRunDescription = description; }
213+
inline void SetStartTimeStamp(Double_t timestamp) { fStartTime = timestamp; }
214+
inline void SetEndTimeStamp(Double_t timestamp) { fEndTime = timestamp; }
215+
inline void SetTotalBytes(Long64_t totalBytes) { fTotalBytes = totalBytes; }
216+
inline void SetHistoricMetadataSaving(bool save) { fSaveHistoricData = save; }
217+
inline void HangUpEndFile() { fHangUpEndFile = true; }
218+
inline void ReleaseEndFile() { fHangUpEndFile = false; }
214219
// Printers
215220
void PrintStartDate();
216221
void PrintEndDate();
217222

218223
void PrintMetadata();
219-
void PrintAllMetadata() {
224+
inline void PrintAllMetadata() {
220225
PrintMetadata();
221226
for (unsigned int i = 0; i < fMetadata.size(); i++) fMetadata[i]->PrintMetadata();
222227
}
223-
void PrintTrees() {
228+
inline void PrintTrees() const {
224229
if (fEventTree != nullptr) {
225230
fout << endl;
226231
fout << "=====EventTree=====" << endl;
@@ -236,7 +241,7 @@ class TRestRun : public TRestMetadata {
236241
if (fAnalysisTree != nullptr) fAnalysisTree->PrintObservables();
237242
}
238243

239-
void PrintEvent() { fInputEvent->PrintEvent(); }
244+
inline void PrintEvent() const { fInputEvent->PrintEvent(); }
240245
void PrintErrors();
241246
void PrintWarnings();
242247

source/framework/core/inc/TRestVersion.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
* #endif
1212
*
1313
*/
14-
#define REST_RELEASE "2.3.10"
15-
#define REST_RELEASE_DATE "Sat 29 Jan"
16-
#define REST_RELEASE_TIME "2022 11:51:37 AM CET"
17-
#define REST_GIT_COMMIT "56030bd8"
18-
#define REST_VERSION_CODE 131850
14+
#define REST_RELEASE "2.3.11"
15+
#define REST_RELEASE_DATE "Mon Mar 14"
16+
#define REST_RELEASE_TIME "16:36:38 CET 2022"
17+
#define REST_GIT_COMMIT "806bfa64"
18+
#define REST_VERSION_CODE 131851
1919
#define REST_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
2020
#define REST_SCHEMA_EVOLUTION "ON"
2121
#endif

0 commit comments

Comments
 (0)