GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4MbsSubEvent.cxx
Go to the documentation of this file.
1 // $Id: TGo4MbsSubEvent.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 "TGo4MbsSubEvent.h"
15 
16 #include "TGo4Log.h"
17 #include "TGo4MbsSource.h"
18 
21  fbIsFilled(kFALSE),
22  fbIsDataOwner(kTRUE),
23  fxHeader(),
24  fiAllocLen(0),
25  fiData(0)
26 {
27  GO4TRACE((12,"TGo4MbstSubEvent::TGo4MbsSubEvent()",__LINE__, __FILE__));
28  //TGo4Log::Info( "MBS SubEvent default ctor.");
29 }
30 
33  fbIsFilled(kFALSE),
34  fbIsDataOwner(kTRUE),
35  fxHeader(),
36  fiAllocLen(0),
37  fiData(0)
38 {
39  GO4TRACE((12,"TGo4MbsSubEvent::TGo4MbsSubEvent(UInt_t)",__LINE__, __FILE__));
40  //TGo4Log::Info( "MBS SubEvent normal ctor.");
41  if(fbIsDataOwner) {
42  fiData = new Int_t[datasize];
43  fiAllocLen = datasize;
44  for(Int_t t=0; t<datasize; t++) fiData[t] = 0;
45  }
46 }
47 
49 {
50  GO4TRACE((12,"TGo4MbsSubEvent::~TGo4MbsSubEvent()",__LINE__, __FILE__));
51  // check if Clear with only the used field elements worked correctly
52  //TGo4Log::Info( "MBS SubEvent dtor...");
53  Clear();
54  if(fbIsDataOwner && (fiData!=0)) {
55  for(Int_t t=0; t<GetAllocatedLength(); t++)
56  if(fiData[t]!=0)
57  TGo4Log::Debug( " MBS SubEvent dtor WARNING: Data(%d) not zero after Clear !!! ",t);
58  delete [] fiData;
59  //TGo4Log::Info( "MBS SubEvent dtor deleted data field");
60  }
61 }
62 
63 
65 {
66  GO4TRACE((11,"TGo4MbsSubEvent::PrintEvent()",__LINE__, __FILE__));
67 
69 /* Bool_t printhexa=kFALSE;
70  Int_t* pData = (Int_t *) GetDataField();
71  std::cout << " Mbs Subevent t/s "
72  << dec << std::setw(4) << (Int_t)GetType()
73  << " " << std::setw(4) << (Int_t)GetSubtype()
74  << " len " << std::setw(8) << (Int_t)GetDlen()
75  << " procid " << std::setw(4) << (Int_t)GetProcid()
76  << " ctrl " << std::setw(4) << (Int_t)GetControl()
77  << " cr " << std::setw(4) << (Int_t)GetSubcrate()
78  << std::endl;
79  if(printhexa) std::cout << hex; else std::cout << dec;
80  for(Int_t i=0; i < GetDlen()/2-1; i++) {
81  std::cout << std::setw(12) << *pData << " ";
82  if((i-3) % 4 == 0) std::cout << std::endl;
83  pData++;
84  }
85  std::cout << std::endl;
86 */
87 
88  // very new style just using printf
90 }
91 
92 
93 void TGo4MbsSubEvent::PrintMbsSubevent(Bool_t longw, Bool_t hexw, Bool_t dataw)
94 {
95  // print header
96  printf(" SubEv ID %6d Type/Subtype %5d %5d Length %5d[w] Control %2d Subcrate %2d\n",
98 
99  if(!dataw) return;
100  // print data
101 
102  Int_t *pl_data = GetDataField();
103  Int_t ll = GetIntLen();
104 
105  if(longw) {
106  /* In this case we assume data as one longword per channel */
107  for(Int_t l=0; l<ll; l++) {
108  if(l%8 == 0) printf(" ");
109  if(hexw) printf("%04x.%04x ", (unsigned) ((*pl_data>>16) & 0xffff), (unsigned) (*pl_data & 0xffff));
110  else printf("%8u ", (unsigned) *pl_data);
111  pl_data++;
112  if(l%8 == 7) printf("\n");
113  }
114 
115  if (ll%8 != 0) printf("\n");
116  } else {
117  /* In this case we assume data as two words per channel */
118  for(Int_t l=0;l<ll;l++) {
119  if(l%4 == 0) printf(" ");
120  if(hexw) printf("%6x%6x", (unsigned) (*pl_data&0xffff), (unsigned) ((*pl_data>>16)&0xffff));
121  else printf("%8u%8u", (unsigned) (*pl_data&0xffff), (unsigned) ((*pl_data>>16)&0xffff));
122  pl_data++;
123  if(l%4 == 3) printf("\n");
124  }
125  if(ll%4 != 0) printf("\n");
126  }
127 }
128 
129 void TGo4MbsSubEvent::Set(Int_t dlen,
130  Short_t type,
131  Short_t subtype,
132  Short_t procid,
133  Char_t subcrate,
134  Char_t ctrl)
135 {
136  SetDlen(dlen);
137  SetType(type);
138  SetSubtype(subtype);
139  //SetProcid(procid); do not change procid and identifiers!!
140  //SetSubcrate(subcrate);
141  //SetControl(ctrl);
142 }
143 
144 void TGo4MbsSubEvent::Clear(Option_t *t)
145 {
146  GO4TRACE((11,"TGo4MbsSubEvent::Clear()",__LINE__, __FILE__));
147  fbIsFilled = kFALSE;
148  if(fbIsDataOwner && (fiData!=0)) {
149  // clear array of data
150  Int_t dleng = GetDlen();
151  if(dleng==0) dleng=2; // default value for dleng is not zero!!
152  // only clear regions which were used by the previous fill...
153  //std::cout <<"Mbssubevent::Clear: dlen=" << dleng << std::endl;
154  Int_t fieldlength = (dleng-2) / TGo4MbsSource::fguLONGBYSHORT ; // field is Int_t
155  if(fieldlength>fiAllocLen)
156  fieldlength=fiAllocLen;
157 
158  if(fieldlength==0)
159  fiData[0]=0; // clear in case of zero subevents!
160 
161  for(Int_t t=0; t<fieldlength;++t)
162  fiData[t]=0;
163  //std::cout<< std::endl<< "Subevent: cleared "<< fiAllocLen << "int field at "<<fiData << std::endl;
164  fxHeader.Clear();
165  Set(dleng); // set to default values, but remember last datalength
166  }//if(fbIsDataOwner)
167 }
168 
169 void TGo4MbsSubEvent::ReAllocate(Int_t newsize)
170 {
171  GO4TRACE((11,"TGo4MbsSubEvent::ReAllocate(UInt_t)",__LINE__, __FILE__));
172  if(!fbIsDataOwner) return;
173  if( newsize <= fiAllocLen ) {
174  // newsize is smaller, we do not reallocate
175  } else {
176  delete [] fiData;
177  fiData = new Int_t[newsize];
178  //std::cout<< "Subevent: Reallocating " << newsize << ", previous:"<< fiAllocLen<< std::endl;
179  TGo4Log::Debug(" MbsSubEvent: Reallocating Data field from %d to %d longwords ",fiAllocLen,newsize);
180  fiAllocLen = newsize;
181  Clear();
182  }
183 }
virtual void Clear(Option_t *t="")
void PrintMbsSubevent(Bool_t longw=kTRUE, Bool_t hexw=kTRUE, Bool_t dataw=kTRUE)
Int_t GetDlen() const
void SetDlen(Int_t dlen)
int l
Definition: f_mbs_status.c:31
Short_t GetType() const
TGo4SubEventHeader10 fxHeader
virtual void Clear(Option_t *opt="")
Int_t * GetDataField()
virtual void PrintEvent()
virtual ~TGo4MbsSubEvent()
void SetType(Short_t type)
#define GO4TRACE(X)
Definition: TGo4Log.h:26
Short_t GetProcid() const
Int_t GetIntLen() const
Char_t GetSubcrate() const
Short_t GetSubtype() const
Char_t GetControl() const
void SetSubtype(Short_t subtype)
static const UInt_t fguLONGBYSHORT
void Set(Int_t dlen, Short_t type=10, Short_t subtype=1, Short_t procid=0, Char_t subcrate=0, Char_t ctrl=0)
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:274
Int_t GetAllocatedLength() const
void ReAllocate(Int_t newsize)