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