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