Skip to content

Commit 8a8be27

Browse files
Implementation of TRestEventTimeSelectionProcess to select events by their timeStamp (#540)
* Implementation of process to select events by their timeStamp * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * implement start and end time margins * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix typo * refactor event time selection logic for clarity * improve documentation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * validate time format in event time selection process * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * improve GetTimeStampCut method * enhance PrintMetadata output with total time fraction * add ReadFileWithTimes method to streamline time range file processing * add specific methods to set active and dead time states * add margin time parameters to documentation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * improve the example in the doc --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 39b457e commit 8a8be27

File tree

2 files changed

+458
-0
lines changed

2 files changed

+458
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*************************************************************************
2+
* This file is part of the REST software framework. *
3+
* *
4+
* Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5+
* For more information see http://gifna.unizar.es/trex *
6+
* *
7+
* REST is free software: you can redistribute it and/or modify *
8+
* it under the terms of the GNU General Public License as published by *
9+
* the Free Software Foundation, either version 3 of the License, or *
10+
* (at your option) any later version. *
11+
* *
12+
* REST is distributed in the hope that it will be useful, *
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15+
* GNU General Public License for more details. *
16+
* *
17+
* You should have a copy of the GNU General Public License along with *
18+
* REST in $REST_PATH/LICENSE. *
19+
* If not, see http://www.gnu.org/licenses/. *
20+
* For the list of contributors see $REST_PATH/CREDITS. *
21+
*************************************************************************/
22+
23+
#ifndef RestProcess_TRestEventTimeSelectionProcess
24+
#define RestProcess_TRestEventTimeSelectionProcess
25+
26+
#include <TRestEventProcess.h>
27+
28+
#include <iostream>
29+
30+
class TRestEventTimeSelectionProcess : public TRestEventProcess {
31+
private:
32+
TRestEvent* fEvent; //!
33+
std::string fFileWithTimes;
34+
Bool_t fIsActiveTime;
35+
Char_t fDelimiter;
36+
Long_t fTimeOffsetInSeconds;
37+
Long_t fTimeStartMarginInSeconds;
38+
Long_t fTimeEndMarginInSeconds;
39+
std::vector<std::pair<std::string, std::string>> fStartEndTimes;
40+
41+
/// Information about the events processed
42+
43+
Int_t fNEventsRejected;
44+
Int_t fNEventsSelected;
45+
Double_t fTotalTimeInSeconds;
46+
47+
void Initialize() override;
48+
49+
protected:
50+
public:
51+
RESTValue GetInputEvent() const override { return fEvent; }
52+
RESTValue GetOutputEvent() const override { return fEvent; }
53+
54+
void InitProcess() override;
55+
TRestEvent* ProcessEvent(TRestEvent* inputEvent) override;
56+
void EndProcess() override;
57+
58+
void PrintMetadata() override;
59+
60+
// Constructor
61+
TRestEventTimeSelectionProcess();
62+
// Destructor
63+
~TRestEventTimeSelectionProcess() {}
64+
65+
const char* GetProcessName() const override { return "EventTimeSelectionProcess"; }
66+
67+
std::string GetFileWithTimes() const { return fFileWithTimes; }
68+
69+
Bool_t GetIsActiveTime() const { return fIsActiveTime; }
70+
Char_t GetDelimiter() const { return fDelimiter; }
71+
72+
std::vector<std::pair<std::string, std::string>> GetStartEndTimes() const { return fStartEndTimes; }
73+
std::string GetTimeStampCut(std::string timeStampObsName = "timeStamp", Bool_t useOffset = true,
74+
Bool_t useMargins = true, Int_t nTimes = -1);
75+
Int_t GetNEventsRejected() const { return fNEventsRejected; }
76+
Int_t GetNEventsSelected() const { return fNEventsSelected; }
77+
Double_t GetTotalTimeInSeconds() const { return fTotalTimeInSeconds; }
78+
Long_t GetTimeOffsetInSeconds() const { return fTimeOffsetInSeconds; }
79+
Long_t GetTimeStartMarginInSeconds() const { return fTimeStartMarginInSeconds; }
80+
Long_t GetTimeEndMarginInSeconds() const { return fTimeEndMarginInSeconds; }
81+
82+
Double_t CalculateTotalTimeInSeconds();
83+
static std::vector<std::pair<std::string, std::string>> ReadFileWithTimes(std::string fileWithTimes,
84+
Char_t delimiter = ',');
85+
86+
void SetAsActiveTime() { fIsActiveTime = true; }
87+
void SetAsDeadTime() { fIsActiveTime = false; }
88+
void SetFileWithTimes(const std::string& fileWithTimes) { fFileWithTimes = fileWithTimes; }
89+
void SetIsActiveTime(Bool_t isActiveTime) { fIsActiveTime = isActiveTime; }
90+
void SetDelimiter(Char_t delimiter) { fDelimiter = delimiter; }
91+
void SetStartEndTimes(const std::vector<std::pair<std::string, std::string>>& startEndTimes) {
92+
fStartEndTimes = startEndTimes;
93+
}
94+
void SetTimeOffsetInSeconds(Long_t timeOffsetInSeconds) { fTimeOffsetInSeconds = timeOffsetInSeconds; }
95+
void SetTimeStartMarginInSeconds(Long_t timeStartMarginInSeconds) {
96+
fTimeStartMarginInSeconds = timeStartMarginInSeconds;
97+
}
98+
void SetTimeEndMarginInSeconds(Long_t timeEndMarginInSeconds) {
99+
fTimeEndMarginInSeconds = timeEndMarginInSeconds;
100+
}
101+
102+
ClassDefOverride(TRestEventTimeSelectionProcess, 1);
103+
};
104+
#endif

0 commit comments

Comments
 (0)