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