GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4MbsEvent.cxx
Go to the documentation of this file.
1 // $Id: TGo4MbsEvent.cxx 2748 2020-04-16 09:50:56Z linev $
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 
21 extern "C" {
22  #include "f_ut_utime.h"
23 }
24 
27  fxHeader(),
28  fxSubEvArray(0),
29  fiSubEvIndex(0),
30  fbIsReference(kFALSE)
31 {
32  GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent()",__LINE__, __FILE__));
33  //TGo4Log::Info( "MBS Event default ctor");
34 }
35 
36 TGo4MbsEvent::TGo4MbsEvent(UInt_t subnum, Short_t* subids, UInt_t datasize) :
37  TGo4EventElement("MbsEvent101"),
38  fxHeader(),
39  fxSubEvArray(0),
40  fiSubEvIndex(0),
41  fbIsReference(kFALSE)
42 {
43  GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent(UInt_t, Short_t, UInt_t)",__LINE__, __FILE__));
44  fxSubEvArray=new TObjArray(subnum+5);
45  fxSubEvArray->SetOwner(kTRUE); // important for streamer
46  for (UInt_t t=0;t<subnum;++t) {
47  TGo4MbsSubEvent* subeve = new TGo4MbsSubEvent(datasize);
48  fxSubEvArray->AddLast(subeve);
49  subeve->SetProcid(subids[t]);
50  }
51  Clear();
52 }
53 
55  Char_t* subcrates,
56  Char_t* controls,
57  Short_t* procids,
58  UInt_t* datasizes) :
59  TGo4EventElement("MbsEvent101"),
60  fxHeader(),
61  fxSubEvArray(0),
62  fiSubEvIndex(0),
63  fbIsReference(kFALSE)
64 {
65  GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent(UInt_t, Char_t*, Char_t*, Short_t* UInt_t)",__LINE__, __FILE__));
66  fxSubEvArray = new TObjArray(subnum+5);
67  fxSubEvArray->SetOwner(kTRUE); // important for streamer
68  for (UInt_t t=0;t<subnum;++t) {
69  TGo4MbsSubEvent* subeve = new TGo4MbsSubEvent(datasizes[t]);
70  fxSubEvArray->AddLast(subeve);
71  subeve->SetSubcrate(subcrates[t]);
72  subeve->SetControl(controls[t]);
73  subeve->SetProcid(procids[t]);
74  }
75  Clear();
76 }
77 
78 
80  TGo4EventElement("MbsEvent101"), // note that name parameter is dummy to be consistent with file source!
81  fxHeader(),
82  fxSubEvArray(0),
83  fiSubEvIndex(0),
84  fbIsReference(kFALSE)
85 {
86  GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent(const char)",__LINE__, __FILE__));
87  SimpleInit();
88 }
89 
91 {
92  fxSubEvArray = new TObjArray(5);
93  fxSubEvArray->SetOwner(kTRUE); // important for streamer
94  // we just add one arbitrary subevent to the array.
95  // actually subevents will be appended dynamically later
96  TGo4MbsSubEvent* subeve = new TGo4MbsSubEvent(1024);
97  fxSubEvArray->AddLast(subeve);
98  subeve->SetSubcrate(0);
99  subeve->SetControl(0);
100  subeve->SetProcid(0);
101  Set();
102  Clear();
103 }
104 
106 {
107  GO4TRACE((12,"TGo4MbsEvent::~TGo4MbsEvent()",__LINE__, __FILE__));
108  //TGo4Log::Info( "MBS Event dtor...");
109  if(!fbIsReference)
110  {
111  if(fxSubEvArray) fxSubEvArray->Delete();
112  delete fxSubEvArray;
113  //TGo4Log::Info( "MBS Event dtor deleted obj array");
114  }
115 }
116 
117 void TGo4MbsEvent::Clear(Option_t *)
118 {
119  GO4TRACE((11,"TGo4MbsEvent::Clear()",__LINE__, __FILE__));
120  if(!fbIsReference) {
121  // here iterate all subevents and clear them
122  TGo4MbsSubEvent* sub(0);
123  ResetIterator();
124  while ((sub = NextSubEvent(kTRUE))!=0) sub->Clear();
125  }
126 }
127 
129 {
130  if(!ref) return;
131  if(!fbIsReference) {
132  // clean up previous data if existing
133  if(fxSubEvArray) fxSubEvArray->Delete();
134  delete fxSubEvArray;
135  }
136  fbIsReference = true;
137  // copy event headers:
144 
145  //assign external array:
147 }
148 
150 {
151  if(fbIsReference)
152  SimpleInit();
153  fbIsReference = kFALSE;
154 }
155 
156 void TGo4MbsEvent::Set(Int_t dlen, Short_t type, Short_t subtype,
157  Short_t dummy, Short_t trigger, Int_t count)
158 {
159  SetDlen(dlen);
160  SetType(type);
161  SetSubtype(subtype);
162  SetDummy(dummy);
163  SetTrigger(trigger);
164  SetCount(count);
165 }
166 
168 {
170 // TGo4EventElement::PrintEvent();
171 //
172 // std::cout << "MBS Event printout:"
173 // << dec << std::setw(8) << (Int_t) GetCount()
174 // << " t/s " << std::setw(4) << (Int_t) GetType()
175 // << " " << std::setw(4) << (Int_t) GetSubtype()
176 // << " len " << std::setw(8) << (Int_t) GetDlen()
177 // << " trig " << std::setw(4) << (Int_t) GetTrigger()
178 // << std::endl;
179 // TGo4MbsSubEvent *sub(0);
180 // ResetIterator();
181 // while ((sub=NextSubEvent())!=0) sub->PrintEvent();
182 
183  // very new style - just using printf
184  PrintMbsEvent();
185 }
186 
188 {
189  s_filhe* head = GetMbsSourceHeader();
190  if (head==0) return;
191  printf("***** File header:\n");
192  printf("\tdatalen: %d \n", head->filhe_dlen);
193  printf("\tfilename_l: %d \n", head->filhe_file_l);
194  printf("\tfilename: %s\n", head->filhe_file);
195  printf("\ttype: %d \n", head->filhe_type);
196  printf("\tsubtype: %d\n", head->filhe_subtype);
197  printf("\t#commentlines: %d\n", head->filhe_lines);
198  for(Int_t i=0; i<head->filhe_lines;++i)
199  printf("\t\t %s\n", head->s_strings[i].string);
200 }
201 
203 {
204  s_bufhe* head = GetMbsBufferHeader();
205  if (head==0) return;
206 
207  printf("***** Buffer header:\n");
208  printf("\tbuffernumber: %d \n", head->l_buf);
209  printf("\tdatalen: %d \n", head->l_dlen);
210  printf("\ttime lo: %u\n", head->l_time[0]); // seconds since epoch 1970
211  printf("\ttime hi: %u\n", head->l_time[1]); // microseconds since time lo
212  char sbuf[1000];
213  f_ut_utime(head->l_time[0], head->l_time[1], sbuf);
214  printf("\ttimestring: %s\n", sbuf);
215  printf("\ttype: %d \n", head->i_type);
216  printf("\tsubtype: %d \n", head->i_subtype);
217 }
218 
219 
220 void TGo4MbsEvent::PrintMbsEvent(Int_t subid, Bool_t longw, Bool_t hexw, Bool_t dataw, Bool_t bufhead, Bool_t filhead)
221 {
222  static TString oldfname = "";
223  static TString timestring = "";
224  if (filhead) {
225  s_filhe* head = GetMbsSourceHeader();
226  if (head && (TString(head->filhe_file) != oldfname)) {
227  oldfname=head->filhe_file;
229  }
230  }
231  static int oldbnum = 0;
232  if (bufhead) {
233  s_bufhe* head = GetMbsBufferHeader();
234  if ( head && (head->l_buf != oldbnum) ) {
235  // only print if buffernumber has changed
236  oldbnum = head->l_buf;
237  char sbuf[1000];
238  f_ut_utime(head->l_time[0], head->l_time[1], sbuf);
239  timestring = sbuf;
240 
242  }
243  }
244 
245  if (GetType()==10) {
246  printf("Event %9d Type/Subtype %5d %5d Length %5d[w] Trigger %2d %s\n",
247  GetCount(), GetType(), GetSubtype(), GetDlen(), GetTrigger(), timestring.Data());
248  } else {
249  printf("Event type %d, subtype %d, data longwords %d",
250  GetType(), GetSubtype(), GetDlen()/2);
251  }
252 
253 
254  TGo4MbsSubEvent *sub(0);
255  ResetIterator();
256  while ((sub=NextSubEvent())!=0) {
257 
258  if ((subid>=0) && (sub->GetProcid()!=subid)) continue;
259 
260  sub->PrintMbsSubevent(longw, hexw, dataw);
261  }
262 }
263 
264 
265 void TGo4MbsEvent::SetPrintEvent(Int_t num, Int_t sid, Int_t longw, Int_t hexw, Int_t dataw)
266 {
267  TGo4MbsSource* src = dynamic_cast<TGo4MbsSource*> (GetEventSource());
268  if (src) src->SetPrintEvent(num, sid, longw, hexw, dataw);
269 }
270 
271 
273 {
274  GO4TRACE((11,"TGo4MbsEvent::NextSubEvent()",__LINE__, __FILE__));
275 
276  if (fxSubEvArray==0) return 0;
277 
278  TGo4MbsSubEvent* sub(0);
279  do {
280  if (fiSubEvIndex>fxSubEvArray->GetLast()) return 0;
281  sub = (TGo4MbsSubEvent*) (fxSubEvArray->At(fiSubEvIndex++));
282  if(sub==0) break;
283  } while(!all && !sub->IsFilled()); // skip not filled subevents
284  return sub;
285 }
286 
287 
288 TGo4MbsSubEvent * TGo4MbsEvent::GetSubEvent(Char_t subcrate, Char_t ctrl, Short_t procid)
289 {
290  GO4TRACE((11,"TGo4MbsEvent::GetSubEvent(Char_t)",__LINE__, __FILE__));
291  TGo4MbsSubEvent* sub(0);
292  ResetIterator();
293  while ((sub = NextSubEvent())!=0)
294  if((sub->GetSubcrate()==subcrate) &&
295  (sub->GetControl()==ctrl) &&
296  (sub->GetProcid()==procid)) return sub;
297  return 0;
298 }
299 
301 {
302  GO4TRACE((11,"TGo4MbsEvent::GetSubEvent(Short_t)",__LINE__, __FILE__));
303  TGo4MbsSubEvent* sub(0);
304  ResetIterator();
305  while ((sub = NextSubEvent())!=0)
306  if(sub->GetProcid()== procid) return sub;
307  return 0;
308 }
309 
310 
312 {
313  TGo4MbsSource* src = dynamic_cast<TGo4MbsSource*> (GetEventSource());
314  return src ? src->GetInfoHeader() : 0;
315 }
316 
318 {
319  TGo4MbsSource* src = dynamic_cast<TGo4MbsSource*> (GetEventSource());
320  return src ? src->GetBufferHeader() : 0;
321 }
322 
323 TGo4MbsSubEvent* TGo4MbsEvent::AddSubEvent(Int_t fullID, Short_t* source, Int_t datalength, Bool_t copydata)
324 {
325  Int_t fieldlength =0;
326  TGo4MbsSubEvent* subtarget=0; // the subevent in use
327  TGo4MbsSubEvent* subtargetindex=0; // target subevent iterator
328  if(datalength>2)
329  fieldlength = (datalength-2) / (sizeof(Int_t) / sizeof(Short_t)); // field is Int_t
330  else {
331  TGo4Log::Debug(" !!! MbsSource -- EMPTY subevent #%d ", fullID);
332  fieldlength =0; // for empty subevents (<- W.M.)
333  }
334 
335  ResetIterator();
336  while ( ( subtargetindex = NextSubEvent(kTRUE) ) !=0 ) {
337  // get pointer to complete id longword in structures:
338  Int_t* subtargetid= &((subtargetindex->fxHeader).fiFullid);
339  if(*subtargetid == fullID) {
340  // subevent ids match:
341  if(!subtargetindex->fbIsFilled) {
342  // this has not been filled before, we fill this one
343  subtarget=subtargetindex;
344  break; // leave the loop, fill later
345  } else {
346  // was already filled in this cycle, continue for next sub
347  }
348  } else {
349  // no match, try next subevent
350  }
351  } // while (subtargetindex...)
352 
353  if(!subtarget) {
354  // we found no matching id, create new TObjArray entry
355  subtarget = new TGo4MbsSubEvent(fieldlength);
356  Int_t* newsubtargetid= &((subtarget->fxHeader).fiFullid);
357  if(!copydata) {
358  subtarget->fbIsDataOwner = kFALSE;
359  delete [] (subtarget->fiData); // remove default field
360  subtarget->fiAllocLen=0;
361  }
362  *newsubtargetid = fullID;
363  TGo4Log::Debug(" Created new output subevent for event\n\tpid:%d subcrate:%d ctrl:%d",
364  subtarget->GetProcid(),subtarget->GetSubcrate(), subtarget->GetControl());
365  if (fxSubEvArray == 0) fxSubEvArray = new TObjArray(5);
366  fxSubEvArray->AddLast(subtarget);
367  }
369  subtarget->SetDlen(datalength);
370  void* data = (void*) source;
371  if(copydata) {
372  subtarget->fbIsDataOwner = kTRUE;
373  subtarget->ReAllocate(fieldlength); // reallocate field if necessary
375  if(datalength>2)
376  memcpy((void*) (subtarget->fiData),
377  data, (datalength-2)*sizeof(Short_t));
378  } else {
379  // set reference to external data field in subevent
380  subtarget->fbIsDataOwner=kFALSE;
381  subtarget->fiAllocLen=fieldlength;
382  if(datalength>2)
383  subtarget->fiData= (Int_t*) data;
384  else
385  subtarget->fiData= 0; // reset for empty subevent
386  }// if(fbDataCopyMode)
387  subtarget->fbIsFilled = kTRUE; // remember we filled this one, never overwrite!
388  return subtarget;
389 }
390 
INTS2 filhe_file_l
Definition: s_filhe.h:69
CHARS filhe_file[86]
Definition: s_filhe.h:70
void SetCount(Int_t count)
Definition: TGo4MbsEvent.h:151
TGo4MbsSubEvent * AddSubEvent(Int_t fullID, Short_t *source, Int_t datalength, Bool_t copydata=kFALSE)
virtual void Clear(Option_t *t="")
s_bufhe * GetMbsBufferHeader()
virtual void Clear(Option_t *t="")
void PrintMbsSubevent(Bool_t longw=kTRUE, Bool_t hexw=kTRUE, Bool_t dataw=kTRUE)
CHARS string[78]
Definition: s_filhe.h:22
Short_t GetSubtype() const
Definition: TGo4MbsEvent.h:143
TGo4GSIEventHeader fxGSIHeader
void SetControl(Char_t control)
TGo4EventSource * GetEventSource() const
INTS2 filhe_subtype
Definition: s_filhe.h:59
INTS2 i_subtype
Definition: s_bufhe.h:46
void RemoveReference()
INTS4 filhe_lines
Definition: s_filhe.h:78
void SetDlen(Int_t dlen)
virtual void PrintEvent()
INTS2 filhe_type
Definition: s_filhe.h:58
INTS2 i_type
Definition: s_bufhe.h:45
TGo4SubEventHeader10 fxHeader
struct cv_string s_strings[30]
Definition: s_filhe.h:79
INTS4 l_dlen
Definition: s_bufhe.h:44
Bool_t IsFilled() const
Int_t fiSubEvIndex
Definition: TGo4MbsEvent.h:176
TGo4MbsSubEvent * NextSubEvent(Bool_t all=kFALSE)
Bool_t fbIsReference
Definition: TGo4MbsEvent.h:179
INTS4 filhe_dlen
Definition: s_filhe.h:57
Int_t GetDlen() const
Definition: TGo4MbsEvent.h:135
Short_t GetType() const
Definition: TGo4MbsEvent.h:140
s_filhe * GetInfoHeader()
void SetSubcrate(Char_t subcrate)
TGo4EventHeader10 fxHeader
Definition: TGo4MbsEvent.h:170
void SetSubtype(Short_t subtype)
Definition: TGo4MbsEvent.h:142
void SetDummy(Short_t dummy)
Definition: TGo4MbsEvent.h:145
void SetDlen(Int_t dlen)
Definition: TGo4MbsEvent.h:134
void SetType(Short_t type)
Definition: TGo4MbsEvent.h:139
void SetProcid(Short_t procid)
TObjArray * fxSubEvArray
Definition: TGo4MbsEvent.h:173
Int_t GetCount() const
Definition: TGo4MbsEvent.h:152
void SimpleInit()
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)
void AssignReference(TGo4MbsEvent *ref)
void PrintMbsFileHeader()
INTS4 f_ut_utime(INTS4, INTS4, CHARS *)
Definition: f_ut_utime.c:57
void PrintMbsBufferHeader()
s_filhe * GetMbsSourceHeader()
#define GO4TRACE(X)
Definition: TGo4Log.h:26
void SetPrintEvent(Int_t num, Int_t sid, Int_t longw, Int_t hexw, Int_t dataw)
virtual ~TGo4MbsEvent()
Short_t GetProcid() const
INTS4 l_buf
Definition: s_bufhe.h:50
INTS4 l_time[2]
Definition: s_bufhe.h:53
Char_t GetSubcrate() const
void SetPrintEvent(Int_t num=1, Int_t sid=-1, Int_t longw=1, Int_t hexw=1, Int_t dataw=0)
Short_t GetTrigger() const
Definition: TGo4MbsEvent.h:149
void ResetIterator()
Definition: TGo4MbsEvent.h:101
Char_t GetControl() const
virtual s_bufhe * GetBufferHeader()
TGo4MbsSubEvent * GetSubEvent(Char_t subcrate, Char_t ctrl, Short_t procid)
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 SetTrigger(Short_t trigger)
Definition: TGo4MbsEvent.h:148
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:274
void ReAllocate(Int_t newsize)