GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4MbsEvent.cxx
Go to the documentation of this file.
1// $Id$
2//-----------------------------------------------------------------------
3// The GSI Online Offline Object Oriented (Go4) Project
4// Experiment Data Processing at EE department, GSI
5//-----------------------------------------------------------------------
6// Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7// Planckstr. 1, 64291 Darmstadt, Germany
8// Contact: http://go4.gsi.de
9//-----------------------------------------------------------------------
10// This software can be used under the license agreements as stated
11// in Go4License.txt file which is part of the distribution.
12//-----------------------------------------------------------------------
13
14#include "TGo4MbsEvent.h"
15
16#include "TObjArray.h"
17
18#include "TGo4Log.h"
19#include "TGo4MbsSource.h"
20
21extern "C" {
22 #include "f_ut_utime.h"
23}
24
27 fxHeader(),
28 fiSubEvIndex(0),
29 fbIsReference(kFALSE)
30{
31 GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent()",__LINE__, __FILE__));
32 //TGo4Log::Info( "MBS Event default ctor");
33}
34
35TGo4MbsEvent::TGo4MbsEvent(UInt_t subnum, Short_t *subids, UInt_t datasize) :
36 TGo4EventElement("MbsEvent101"),
37 fxHeader(),
38 fiSubEvIndex(0),
39 fbIsReference(kFALSE)
40{
41 GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent(UInt_t, Short_t *, UInt_t)",__LINE__, __FILE__));
42 fxSubEvArray = new TObjArray(subnum+5);
43 fxSubEvArray->SetOwner(kTRUE); // important for streamer
44 for (UInt_t t = 0; t < subnum; ++t) {
45 TGo4MbsSubEvent *subeve = new TGo4MbsSubEvent(datasize);
46 fxSubEvArray->AddLast(subeve);
47 subeve->SetProcid(subids[t]);
48 }
49 Clear();
50}
51
53 Char_t *subcrates,
54 Char_t *controls,
55 Short_t *procids,
56 UInt_t *datasizes) :
57 TGo4EventElement("MbsEvent101"),
58 fxHeader(),
59 fiSubEvIndex(0),
60 fbIsReference(kFALSE)
61{
62 GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent(UInt_t, Char_t *, Char_t *, Short_t *, UInt_t *)",__LINE__, __FILE__));
63 fxSubEvArray = new TObjArray(subnum+5);
64 fxSubEvArray->SetOwner(kTRUE); // important for streamer
65 for (UInt_t t = 0; t < subnum; ++t) {
66 TGo4MbsSubEvent *subeve = new TGo4MbsSubEvent(datasizes[t]);
67 fxSubEvArray->AddLast(subeve);
68 subeve->SetSubcrate(subcrates[t]);
69 subeve->SetControl(controls[t]);
70 subeve->SetProcid(procids[t]);
71 }
72 Clear();
73}
74
75
77 TGo4EventElement("MbsEvent101"), // note that name parameter is dummy to be consistent with file source!
78 fxHeader(),
79 fiSubEvIndex(0),
80 fbIsReference(kFALSE)
81{
82 GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent(const char *)",__LINE__, __FILE__));
83 SimpleInit();
84}
85
87{
88 fxSubEvArray = new TObjArray(5);
89 fxSubEvArray->SetOwner(kTRUE); // important for streamer
90 // we just add one arbitrary subevent to the array.
91 // actually subevents will be appended dynamically later
92 TGo4MbsSubEvent *subeve = new TGo4MbsSubEvent(1024);
93 fxSubEvArray->AddLast(subeve);
94 subeve->SetSubcrate(0);
95 subeve->SetControl(0);
96 subeve->SetProcid(0);
97 Set();
98 Clear();
99}
100
102{
103 GO4TRACE((12,"TGo4MbsEvent::~TGo4MbsEvent()",__LINE__, __FILE__));
104 //TGo4Log::Info( "MBS Event dtor...");
105 if (!fbIsReference) {
106 if (fxSubEvArray)
107 fxSubEvArray->Delete();
108 delete fxSubEvArray;
109 fxSubEvArray = nullptr;
110 // TGo4Log::Info( "MBS Event dtor deleted obj array");
111 }
112}
113
114void TGo4MbsEvent::Clear(Option_t *)
115{
116 GO4TRACE((11,"TGo4MbsEvent::Clear()",__LINE__, __FILE__));
117 if(!fbIsReference) {
118 // here iterate all subevents and clear them
120 while (auto sub = NextSubEvent(kTRUE))
121 sub->Clear();
122 }
123}
124
126{
127 if(!ref) return;
128 if(!fbIsReference) {
129 // clean up previous data if existing
130 if(fxSubEvArray) fxSubEvArray->Delete();
131 delete fxSubEvArray;
132 }
133 fbIsReference = true;
134 // copy event headers:
135 fxHeader.fiCount=ref->fxHeader.fiCount;
136 fxHeader.fsDummy=ref->fxHeader.fsDummy;
137 fxHeader.fsTrigger=ref->fxHeader.fsTrigger;
138 fxHeader.fxGSIHeader.fiDlen=ref->fxHeader.fxGSIHeader.fiDlen;
139 fxHeader.fxGSIHeader.fsSubtype=ref->fxHeader.fxGSIHeader.fsSubtype;
140 fxHeader.fxGSIHeader.fsType=ref->fxHeader.fxGSIHeader.fsType;
141
142 //assign external array:
144}
145
147{
148 if(fbIsReference)
149 SimpleInit();
150 fbIsReference = kFALSE;
151}
152
153void TGo4MbsEvent::Set(Int_t dlen, Short_t type, Short_t subtype,
154 Short_t dummy, Short_t trigger, Int_t count)
155{
156 SetDlen(dlen);
157 SetType(type);
158 SetSubtype(subtype);
159 SetDummy(dummy);
160 SetTrigger(trigger);
161 SetCount(count);
162}
163
165{
167// TGo4EventElement::PrintEvent();
168//
169// std::cout << "MBS Event printout:"
170// << dec << std::setw(8) << (Int_t) GetCount()
171// << " t/s " << std::setw(4) << (Int_t) GetType()
172// << " " << std::setw(4) << (Int_t) GetSubtype()
173// << " len " << std::setw(8) << (Int_t) GetDlen()
174// << " trig " << std::setw(4) << (Int_t) GetTrigger()
175// << std::endl;
176// ResetIterator();
177// while (auto sub=NextSubEvent())
178// sub->PrintEvent();
179
180 // very new style - just using printf
182}
183
185{
186 s_filhe* head = GetMbsSourceHeader();
187 if (!head) return;
188 printf("***** File header:\n");
189 printf("\tdatalen: %d \n", head->filhe_dlen);
190 printf("\tfilename_l: %d \n", head->filhe_file_l);
191 printf("\tfilename: %s\n", head->filhe_file);
192 printf("\ttype: %d \n", head->filhe_type);
193 printf("\tsubtype: %d\n", head->filhe_subtype);
194 printf("\t#commentlines: %d\n", head->filhe_lines);
195 for (Int_t i = 0; i < head->filhe_lines; ++i)
196 printf("\t\t %s\n", head->s_strings[i].string);
197}
198
200{
201 s_bufhe* head = GetMbsBufferHeader();
202 if (!head) return;
203
204 printf("***** Buffer header:\n");
205 printf("\tbuffernumber: %d \n", head->l_buf);
206 printf("\tdatalen: %d \n", head->l_dlen);
207 printf("\ttime lo: %u\n", head->l_time[0]); // seconds since epoch 1970
208 printf("\ttime hi: %u\n", head->l_time[1]); // microseconds since time lo
209 char sbuf[1000];
210 f_ut_utime(head->l_time[0], head->l_time[1], sbuf);
211 printf("\ttimestring: %s\n", sbuf);
212 printf("\ttype: %d \n", head->i_type);
213 printf("\tsubtype: %d \n", head->i_subtype);
214}
215
216
217void TGo4MbsEvent::PrintMbsEvent(Int_t subid, Bool_t longw, Bool_t hexw, Bool_t dataw, Bool_t bufhead, Bool_t filhead)
218{
219 static TString oldfname = "";
220 static TString timestring = "";
221 if (filhead) {
222 s_filhe* head = GetMbsSourceHeader();
223 if (head && (TString(head->filhe_file) != oldfname)) {
224 oldfname=head->filhe_file;
226 }
227 }
228 static int oldbnum = 0;
229 if (bufhead) {
230 s_bufhe* head = GetMbsBufferHeader();
231 if ( head && (head->l_buf != oldbnum) ) {
232 // only print if buffernumber has changed
233 oldbnum = head->l_buf;
234 char sbuf[1000];
235 f_ut_utime(head->l_time[0], head->l_time[1], sbuf);
236 timestring = sbuf;
237
239 }
240 }
241
242 if (GetType()==10) {
243 printf("Event %9d Type/Subtype %5d %5d Length %5d[w] Trigger %2d %s\n",
244 GetCount(), GetType(), GetSubtype(), GetDlen(), GetTrigger(), timestring.Data());
245 } else {
246 printf("Event type %d, subtype %d, data longwords %d",
247 GetType(), GetSubtype(), GetDlen()/2);
248 }
249
251 while (auto sub = NextSubEvent()) {
252
253 if ((subid >= 0) && (sub->GetProcid() != subid)) continue;
254
255 sub->PrintMbsSubevent(longw, hexw, dataw);
256 }
257}
258
259
260void TGo4MbsEvent::SetPrintEvent(Int_t num, Int_t sid, Int_t longw, Int_t hexw, Int_t dataw)
261{
262 TGo4MbsSource* src = dynamic_cast<TGo4MbsSource*> (GetEventSource());
263 if (src) src->SetPrintEvent(num, sid, longw, hexw, dataw);
264}
265
266
268{
269 GO4TRACE((11, "TGo4MbsEvent::NextSubEvent()", __LINE__, __FILE__));
270
271 if (!fxSubEvArray)
272 return nullptr;
273
274 TGo4MbsSubEvent *sub = nullptr;
275 do {
276 if (fiSubEvIndex > fxSubEvArray->GetLast())
277 return nullptr;
278 sub = (TGo4MbsSubEvent *)(fxSubEvArray->At(fiSubEvIndex++));
279 if (!sub)
280 break;
281 } while (!all && !sub->IsFilled()); // skip not filled subevents
282 return sub;
283}
284
285TGo4MbsSubEvent *TGo4MbsEvent::GetSubEvent(Char_t subcrate, Char_t ctrl, Short_t procid)
286{
287 GO4TRACE((11,"TGo4MbsEvent::GetSubEvent(Char_t)",__LINE__, __FILE__));
289 while (auto sub = NextSubEvent())
290 if ((sub->GetSubcrate() == subcrate) && (sub->GetControl() == ctrl) && (sub->GetProcid() == procid))
291 return sub;
292 return nullptr;
293}
294
296{
297 GO4TRACE((11,"TGo4MbsEvent::GetSubEvent(Short_t)",__LINE__, __FILE__));
299 while (auto sub = NextSubEvent())
300 if(sub->GetProcid()== procid)
301 return sub;
302 return nullptr;
303}
304
305
307{
308 TGo4MbsSource* src = dynamic_cast<TGo4MbsSource*> (GetEventSource());
309 return src ? src->GetInfoHeader() : nullptr;
310}
311
313{
314 TGo4MbsSource* src = dynamic_cast<TGo4MbsSource*> (GetEventSource());
315 return src ? src->GetBufferHeader() : nullptr;
316}
317
318TGo4MbsSubEvent *TGo4MbsEvent::AddSubEvent(Int_t fullID, Short_t *source, Int_t datalength, Bool_t copydata)
319{
320 Int_t fieldlength = 0;
321 TGo4MbsSubEvent *subtarget = nullptr; // the subevent in use
322 if(datalength > 2)
323 fieldlength = (datalength-2) / (sizeof(Int_t) / sizeof(Short_t)); // field is Int_t
324 else {
325 TGo4Log::Debug(" !!! MbsSource -- EMPTY subevent #%d ", fullID);
326 fieldlength = 0; // for empty subevents (<- W.M.)
327 }
328
330 while (auto subtargetindex = NextSubEvent(kTRUE)) {
331 // get pointer to complete id longword in structures:
332 Int_t *subtargetid= &((subtargetindex->fxHeader).fiFullid);
333 if(*subtargetid == fullID) {
334 // subevent ids match:
335 if(!subtargetindex->fbIsFilled) {
336 // this has not been filled before, we fill this one
337 subtarget=subtargetindex;
338 break; // leave the loop, fill later
339 } else {
340 // was already filled in this cycle, continue for next sub
341 }
342 } else {
343 // no match, try next subevent
344 }
345 } // while (subtargetindex...)
346
347 if(!subtarget) {
348 // we found no matching id, create new TObjArray entry
349 subtarget = new TGo4MbsSubEvent(fieldlength);
350 Int_t *newsubtargetid= &((subtarget->fxHeader).fiFullid);
351 if(!copydata) {
352 subtarget->fbIsDataOwner = kFALSE;
353 delete [] (subtarget->fiData); // remove default field
354 subtarget->fiAllocLen = 0;
355 }
356 *newsubtargetid = fullID;
357 TGo4Log::Debug(" Created new output subevent for event\n\tpid:%d subcrate:%d ctrl:%d",
358 subtarget->GetProcid(),subtarget->GetSubcrate(), subtarget->GetControl());
359 if (!fxSubEvArray) fxSubEvArray = new TObjArray(5);
360 fxSubEvArray->AddLast(subtarget);
361 }
363 subtarget->SetDlen(datalength);
364 void *data = (void *) source;
365 if(copydata) {
366 subtarget->fbIsDataOwner = kTRUE;
367 subtarget->ReAllocate(fieldlength); // reallocate field if necessary
369 if(datalength>2)
370 memcpy((void *) (subtarget->fiData),
371 data, (datalength-2)*sizeof(Short_t));
372 } else {
373 // set reference to external data field in subevent
374 subtarget->fbIsDataOwner = kFALSE;
375 subtarget->fiAllocLen = fieldlength;
376 if(datalength>2)
377 subtarget->fiData = (Int_t *) data;
378 else
379 subtarget->fiData = nullptr; // reset for empty subevent
380 }// if(fbDataCopyMode)
381 subtarget->fbIsFilled = kTRUE; // remember we filled this one, never overwrite!
382 return subtarget;
383}
384
#define GO4TRACE(X)
Definition TGo4Log.h:25
TGo4EventSource * GetEventSource() const
TGo4GSIEventHeader fxGSIHeader
aggregationByValue
Short_t fsDummy
not used yet.
Short_t fsTrigger
Trigger number.
Short_t fsSubtype
Subtype.
Short_t fsType
Type number.
Int_t fiDlen
Length (16 bit words) of the data field following this header.
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:281
void PrintMbsFileHeader()
Method to print MBS source header.
void PrintEvent() override
Print event with default settings.
TGo4MbsSubEvent * GetSubEvent(Char_t subcrate, Char_t ctrl, Short_t procid)
Access to subevent in list by procid, subcrate and ctrl identifiers.
TGo4EventHeader10 fxHeader
aggregationByValue
Short_t GetType() const
Int_t GetDlen() const
void SetSubtype(Short_t subtype)
s_filhe * GetMbsSourceHeader()
Access to the info header of the current mbs source.
virtual ~TGo4MbsEvent()
TGo4MbsSubEvent * AddSubEvent(Int_t fullID, Short_t *source, Int_t datalength, Bool_t copydata=kFALSE)
Add new subevent to mbs event.
void SetPrintEvent(Int_t num, Int_t sid, Int_t longw, Int_t hexw, Int_t dataw)
Set print parameter for MBS event source See TGo4MbsSource for more details.
TObjArray * fxSubEvArray
dynamic array of subevents.
void SetDummy(Short_t dummy)
Int_t GetCount() const
void PrintMbsBufferHeader()
Method to print MBS buffer header.
void Clear(Option_t *opt="") override
Method called by the event owner (analysis step) to clear the event element.
TGo4MbsSubEvent * NextSubEvent(Bool_t all=kFALSE)
Iterator for subevent array.
Int_t fiSubEvIndex
Subevent index in array, replacement for Iterator.
s_bufhe * GetMbsBufferHeader()
Access to the buffer header of the current event.
void SetDlen(Int_t dlen)
void SetCount(Int_t count)
friend class TGo4MbsSource
void Set(Int_t dlen=0, Short_t type=10, Short_t subtype=1, Short_t dummy=0, Short_t trigger=0, Int_t count=0)
void PrintMbsEvent(Int_t subid=-1, Bool_t longw=kTRUE, Bool_t hexw=kTRUE, Bool_t dataw=kTRUE, Bool_t bufhead=kFALSE, Bool_t filhead=kFALSE)
Print MBS event.
void ResetIterator()
Set the internal iterator of the subevent array to the beginning of the array.
void SetTrigger(Short_t trigger)
Short_t GetTrigger() const
void SetType(Short_t type)
void AssignReference(TGo4MbsEvent *ref)
Bool_t fbIsReference
Indicates if this object is mere reference to another mbs event.
Short_t GetSubtype() const
void RemoveReference()
s_filhe * GetInfoHeader() const
User access to info header.
void SetPrintEvent(Int_t num=1, Int_t sid=-1, Int_t longw=1, Int_t hexw=1, Int_t dataw=0)
Set mbs source into printout (verbose) mode for the next num events.
virtual s_bufhe * GetBufferHeader()
User access to current event buffer header.
Subevent class for gsi mbs data.
Bool_t fbIsFilled
True if this subevent has already been filled in this event cycle.
void SetProcid(Short_t procid)
TGo4SubEventHeader10 fxHeader
aggregationByValue
Int_t * fiData
Pointer to external integer field containing the subevent data.
Char_t GetSubcrate() const
Bool_t IsFilled() const
true if this subevent was filled since the last Clear()
void SetSubcrate(Char_t subcrate)
void SetDlen(Int_t dlen)
void ReAllocate(Int_t newsize)
Allocate the data field with newsize.
Char_t GetControl() const
Short_t GetProcid() const
Bool_t fbIsDataOwner
True if subevent owns data field.
void SetControl(Char_t control)
Int_t fiAllocLen
Length of the allocated data field.
INTS4 f_ut_utime(INTS4, INTS4, CHARS *)
Definition f_ut_utime.c:57
CHARS string[78]
Definition s_filhe.h:22
INTS4 l_time[2]
Definition s_bufhe.h:53
INTS4 l_buf
Definition s_bufhe.h:50
INTS4 l_dlen
Definition s_bufhe.h:44
INTS2 i_subtype
Definition s_bufhe.h:46
INTS2 i_type
Definition s_bufhe.h:45
INTS2 filhe_file_l
Definition s_filhe.h:69
INTS4 filhe_lines
Definition s_filhe.h:78
struct cv_string s_strings[30]
Definition s_filhe.h:79
INTS2 filhe_subtype
Definition s_filhe.h:59
INTS2 filhe_type
Definition s_filhe.h:58
CHARS filhe_file[86]
Definition s_filhe.h:70
INTS4 filhe_dlen
Definition s_filhe.h:57