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
52using namespace std;
53
54ClassImp(TRestEvent);
55
60
65
72 fEventID = 0;
73 fEventTime = 0;
74 fSubEventID = 0;
75 fSubEventTag = "";
76 fOk = true;
77 fPad = nullptr;
78}
79
83void TRestEvent::SetTime(Double_t time) {
84 auto seconds = (Int_t)time;
85 auto nanoseconds = (Int_t)((time - seconds) * 1E9);
86
87 fEventTime.SetSec(seconds);
88 fEventTime.SetNanoSec(nanoseconds);
89}
90
97 if (this->ClassName() != target->ClassName()) {
98 cout << "In TRestEvent::CloneTo() : Event type doesn't match! (This :" << this->ClassName()
99 << ", Target : " << target->ClassName() << ")" << endl;
100 return;
101 }
102
103 TBufferFile buffer(TBuffer::kWrite);
104 buffer.MapObject(this); // register obj in map to handle self reference
105 {
106 Bool_t isRef = this->TestBit(kIsReferenced);
107 ((TObject*)this)->ResetBit(kIsReferenced);
108
109 ((TObject*)this)->Streamer(buffer);
110
111 if (isRef) ((TObject*)this)->SetBit(kIsReferenced);
112 }
113
114 // read new object from buffer
115 buffer.SetReadMode();
116 buffer.ResetMap();
117 buffer.SetBufferOffset(0);
118 buffer.MapObject(target); // register obj in map to handle self reference
119 target->Streamer(buffer);
120 target->ResetBit(kIsReferenced);
121 target->ResetBit(kCanDelete);
122}
123
127void TRestEvent::SetTime(Double_t seconds, Double_t nanoseconds) {
128 fEventTime.SetSec((Int_t)seconds);
129 fEventTime.SetNanoSec((Int_t)nanoseconds);
130}
131
136 if (eve != nullptr) {
137 SetID(eve->GetID());
138 SetSubID(eve->GetSubID());
139 SetTimeStamp(eve->GetTimeStamp());
140 SetSubEventTag(eve->GetSubEventTag());
141 SetOK(eve->isOk());
142 }
143}
144
145void TRestEvent::RestartPad(Int_t nElements) {
146 if (fPad != nullptr) {
147 delete fPad;
148 fPad = nullptr;
149 }
150
151 fPad = new TPad(this->GetName(), "", 0., 0., 1., 1.);
152
153 if (nElements == 1) fPad->Divide(1, 1);
154 if (nElements == 2) fPad->Divide(2, 1);
155 if (nElements == 3 || nElements == 4) fPad->Divide(2, 2);
156 if (nElements == 5) fPad->Divide(3, 2);
157 if (nElements == 6) fPad->Divide(3, 2);
158 if (nElements > 6) fPad->Divide(3, 3);
159
160 if (nElements > 9) {
161 cout << "REST_WARNING. TRestEvent::RestartPad. Maximum number of pad "
162 "elements reached!"
163 << endl;
164 cout << "Setting the pad elements to 9" << endl;
165 nElements = 9;
166 }
167
168 fPad->Draw();
169}
170
171void TRestEvent::InitializeWithMetadata(TRestRun* run) { Initialize(); }
172
174
182 cout << endl;
183 cout << TString::Format("EventID: %d - SubEventID: %d", fEventID, fSubEventID).Data() << endl;
184 cout << TString::Format("- Timestamp: %s", fEventTime.AsString()) << endl;
185 if (!fSubEventTag.IsNull()) {
186 cout << "- Tag: " << fSubEventTag << endl;
187 }
188 if (!fOk) {
189 cout << "- Status not OK" << endl;
190 }
191}
A base class for any REST event.
Definition: TRestEvent.h:38
void SetTime(Double_t time)
Definition: TRestEvent.cxx:83
virtual void InitializeReferences(TRestRun *run)
Initialize dynamical references when loading the event from a root file.
Definition: TRestEvent.cxx:173
virtual void CloneTo(TRestEvent *target)
Clone the content of this TRestEvent object to another.
Definition: TRestEvent.cxx:96
virtual ~TRestEvent()
Definition: TRestEvent.cxx:64
void SetEventInfo(TRestEvent *eve)
Definition: TRestEvent.cxx:135
virtual void PrintEvent() const
Definition: TRestEvent.cxx:181
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:71
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