REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestEvent.cxx
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
49
50#include "TRestEvent.h"
51
52#include "TRestRun.h"
53
54using namespace std;
55
56ClassImp(TRestEvent);
57
62
67
74 fEventID = 0;
75 fEventTime = 0;
76 fSubEventID = 0;
77 fSubEventTag = "";
78 fOk = true;
79 fPad = nullptr;
80}
81
85void TRestEvent::SetTime(Double_t time) {
86 auto seconds = (Int_t)time;
87 auto nanoseconds = (Int_t)((time - seconds) * 1E9);
88
89 fEventTime.SetSec(seconds);
90 fEventTime.SetNanoSec(nanoseconds);
91}
92
99 if (this->ClassName() != target->ClassName()) {
100 cout << "In TRestEvent::CloneTo() : Event type doesn't match! (This :" << this->ClassName()
101 << ", Target : " << target->ClassName() << ")" << endl;
102 return;
103 }
104
105 TBufferFile buffer(TBuffer::kWrite);
106 buffer.MapObject(this); // register obj in map to handle self reference
107 {
108 Bool_t isRef = this->TestBit(kIsReferenced);
109 ((TObject*)this)->ResetBit(kIsReferenced);
110
111 ((TObject*)this)->Streamer(buffer);
112
113 if (isRef) ((TObject*)this)->SetBit(kIsReferenced);
114 }
115
116 // read new object from buffer
117 buffer.SetReadMode();
118 buffer.ResetMap();
119 buffer.SetBufferOffset(0);
120 buffer.MapObject(target); // register obj in map to handle self reference
121 target->Streamer(buffer);
122 target->ResetBit(kIsReferenced);
123 target->ResetBit(kCanDelete);
124}
125
129void TRestEvent::SetTime(Double_t seconds, Double_t nanoseconds) {
130 fEventTime.SetSec((Int_t)seconds);
131 fEventTime.SetNanoSec((Int_t)nanoseconds);
132}
133
138 if (eve != nullptr) {
139 SetID(eve->GetID());
140 SetSubID(eve->GetSubID());
141 SetTimeStamp(eve->GetTimeStamp());
142 SetSubEventTag(eve->GetSubEventTag());
143 SetOK(eve->isOk());
144 }
145}
146
147void TRestEvent::RestartPad(Int_t nElements) {
148 if (fPad != nullptr) {
149 delete fPad;
150 fPad = nullptr;
151 }
152
153 fPad = new TPad(this->GetName(), "", 0., 0., 1., 1.);
154
155 if (nElements == 1) fPad->Divide(1, 1);
156 if (nElements == 2) fPad->Divide(2, 1);
157 if (nElements == 3 || nElements == 4) fPad->Divide(2, 2);
158 if (nElements == 5) fPad->Divide(3, 2);
159 if (nElements == 6) fPad->Divide(3, 2);
160 if (nElements > 6) fPad->Divide(3, 3);
161
162 if (nElements > 9) {
163 cout << "REST_WARNING. TRestEvent::RestartPad. Maximum number of pad "
164 "elements reached!"
165 << endl;
166 cout << "Setting the pad elements to 9" << endl;
167 nElements = 9;
168 }
169
170 fPad->Draw();
171}
172
173void TRestEvent::InitializeWithMetadata(TRestRun* run) { Initialize(); }
174
176 fRun = run;
177 SetRunOrigin(fRun->GetRunNumber());
178 SetSubRunOrigin(fRun->GetSubRunNumber());
179}
180
188 cout << endl;
189 cout << TString::Format("EventID: %d - SubEventID: %d", fEventID, fSubEventID).Data() << endl;
190 cout << TString::Format("- Timestamp: %s", fEventTime.AsString()) << endl;
191 if (!fSubEventTag.IsNull()) {
192 cout << "- Tag: " << fSubEventTag << endl;
193 }
194 if (!fOk) {
195 cout << "- Status not OK" << endl;
196 }
197}
A base class for any REST event.
Definition: TRestEvent.h:38
void SetTime(Double_t time)
Definition: TRestEvent.cxx:85
virtual void InitializeReferences(TRestRun *run)
Initialize dynamical references when loading the event from a root file.
Definition: TRestEvent.cxx:175
virtual void CloneTo(TRestEvent *target)
Clone the content of this TRestEvent object to another.
Definition: TRestEvent.cxx:98
virtual ~TRestEvent()
Definition: TRestEvent.cxx:66
void SetEventInfo(TRestEvent *eve)
Definition: TRestEvent.cxx:137
virtual void PrintEvent() const
Definition: TRestEvent.cxx:187
TString fSubEventTag
A short length label to identify the sub-Event.
Definition: TRestEvent.h:44
TTimeStamp fEventTime
Absolute event time.
Definition: TRestEvent.h:45
Bool_t fOk
Flag to be used by processes to define an event status. fOk=true is the default.
Definition: TRestEvent.h:46
virtual void Initialize()=0
Definition: TRestEvent.cxx:73
Int_t fEventID
Event identification number.
Definition: TRestEvent.h:42
Int_t fSubEventID
Sub-Event identification number.
Definition: TRestEvent.h:43
Data provider and manager in REST.
Definition: TRestRun.h:18