00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4MbsSubEvent.h"
00017
00018 #include "Riostream.h"
00019 #include "TGo4Log.h"
00020 #include "TGo4MbsSource.h"
00021 #include "TGo4Log.h"
00022 #include "Go4Exceptions.h"
00023
00024 TGo4MbsSubEvent::TGo4MbsSubEvent() :
00025 TGo4EventElement(),
00026 fbIsFilled(kFALSE),
00027 fbIsDataOwner(kFALSE),
00028 fxHeader(),
00029 fiAllocLen(0),
00030 fiData(0)
00031 {
00032 TRACE((12,"TGo4MbstSubEvent::TGo4MbsSubEvent()",__LINE__, __FILE__));
00033 }
00034
00035 TGo4MbsSubEvent::TGo4MbsSubEvent(Int_t datasize) :
00036 TGo4EventElement(),
00037 fbIsFilled(kFALSE),
00038 fbIsDataOwner(kTRUE),
00039 fxHeader(),
00040 fiAllocLen(0),
00041 fiData(0)
00042 {
00043 TRACE((12,"TGo4MbsSubEvent::TGo4MbsSubEvent(UInt_t)",__LINE__, __FILE__));
00044 if(fbIsDataOwner) {
00045 fiData= new Int_t[datasize];
00046 fiAllocLen=datasize;
00047 }
00048 }
00049
00050 TGo4MbsSubEvent::~TGo4MbsSubEvent()
00051 {
00052 TRACE((12,"TGo4MbsSubEvent::~TGo4MbsSubEvent()",__LINE__, __FILE__));
00053
00054 Clear();
00055 if(fbIsDataOwner)
00056 {
00057 for(Int_t t=0; t<GetAllocatedLength() ;++t)
00058 {
00059 if(fiData[t]!=0)
00060 {
00061 TGo4Log::Debug( " MBS SubEvent dtor WARNING: Data(%d) not zero after Clear !!! ",t);
00062 }
00063 else {}
00064 }
00065 delete [] fiData;
00066 }
00067 }
00068
00069
00070
00071 void TGo4MbsSubEvent::PrintEvent() {
00072 TRACE((11,"TGo4MbsSubEvent::PrintEvent()",__LINE__, __FILE__));
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00103 Bool_t printhexa=kFALSE;
00104 Int_t* pData = (Int_t *) GetDataField();
00105 cout << " Mbs Subevent t/s "
00106 << dec << setw(4) << (Int_t)GetType()
00107 << " " << setw(4) << (Int_t)GetSubtype()
00108 << " len " << setw(8) << (Int_t)GetDlen()
00109 << " procid " << setw(4) << (Int_t)GetProcid()
00110 << " ctrl " << setw(4) << (Int_t)GetControl()
00111 << " cr " << setw(4) << (Int_t)GetSubcrate()
00112 << endl;
00113 if(printhexa) cout << hex; else cout << dec;
00114 for(Int_t i=0; i < GetDlen()/2-1; i++)
00115 {
00116 cout << setw(12) << *pData << " ";
00117 if((i-3) % 4 == 0) cout << endl;
00118 pData++;
00119 }
00120 cout << endl;
00121 }
00122
00123 void TGo4MbsSubEvent::Set(Int_t dlen,
00124 Short_t type,
00125 Short_t subtype,
00126 Short_t procid,
00127 Char_t subcrate,
00128 Char_t ctrl)
00129 {
00130 SetDlen(dlen);
00131 SetType(type);
00132 SetSubtype(subtype);
00133
00134
00135
00136 }
00137
00138 void TGo4MbsSubEvent::Clear(Option_t *t)
00139 {
00140 TRACE((11,"TGo4MbsSubEvent::Clear()",__LINE__, __FILE__));
00141 fbIsFilled=kFALSE;
00142 if(fbIsDataOwner)
00143 {
00144
00145 Int_t dleng= GetDlen();
00146 if(dleng==0) dleng=2;
00147
00148
00149 Int_t fieldlength= (dleng-2) / TGo4MbsSource::fguLONGBYSHORT ;
00150 if(fieldlength>fiAllocLen)
00151 fieldlength=fiAllocLen;
00152
00153 if(fieldlength==0)
00154 fiData[0]=0;
00155 for(Int_t t=0; t<fieldlength;++t)
00156 {
00157 fiData[t]=0;
00158
00159 }
00160
00161 fxHeader.Clear();
00162 Set(dleng);
00163 }
00164 else {}
00165 }
00166
00167 void TGo4MbsSubEvent::ReAllocate(Int_t newsize)
00168 {
00169 TRACE((11,"TGo4MbsSubEvent::ReAllocate(UInt_t)",__LINE__, __FILE__));
00170 if(!fbIsDataOwner) return;
00171 if( newsize <= fiAllocLen )
00172 {
00173
00174 }
00175 else
00176 {
00177 delete [] fiData;
00178 fiData= new Int_t[newsize];
00179
00180 TGo4Log::Debug(" MbsSubEvent: Reallocating Data field from %d to %d longwords ",fiAllocLen,newsize);
00181 fiAllocLen=newsize;
00182 Clear();
00183 }
00184 }
00185
00186
00187