00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4MbsEvent.h"
00015
00016 #include "TObjArray.h"
00017
00018 #include "TGo4Log.h"
00019 #include "Go4Exceptions.h"
00020 #include "TGo4MbsSubEvent.h"
00021 #include "TGo4MbsSource.h"
00022 #include "TGo4RevServ.h"
00023 #include "TGo4TreeSource.h"
00024 #include "TGo4FileSource.h"
00025
00026
00027 extern "C" {
00028 #include "f_ut_utime.h"
00029 }
00030
00031 TGo4MbsEvent::TGo4MbsEvent() :
00032 TGo4EventElement(),
00033 fxHeader(),
00034 fxSubEvArray(0),
00035 fiSubEvIndex(0),
00036 fbIsReference(kFALSE)
00037 {
00038 GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent()",__LINE__, __FILE__));
00039
00040 }
00041
00042 TGo4MbsEvent::TGo4MbsEvent(UInt_t subnum, Short_t* subids, UInt_t datasize) :
00043 TGo4EventElement("MbsEvent101"),
00044 fxHeader(),
00045 fxSubEvArray(0),
00046 fiSubEvIndex(0),
00047 fbIsReference(kFALSE)
00048 {
00049 GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent(UInt_t, Short_t, UInt_t)",__LINE__, __FILE__));
00050 fxSubEvArray=new TObjArray(subnum+5);
00051 fxSubEvArray->SetOwner(kTRUE);
00052 for (UInt_t t=0;t<subnum;++t) {
00053 TGo4MbsSubEvent* subeve = new TGo4MbsSubEvent(datasize);
00054 fxSubEvArray->AddLast(subeve);
00055 subeve->SetProcid(subids[t]);
00056 }
00057 Clear();
00058 }
00059
00060 TGo4MbsEvent::TGo4MbsEvent(UInt_t subnum,
00061 Char_t* subcrates,
00062 Char_t* controls,
00063 Short_t* procids,
00064 UInt_t* datasizes) :
00065 TGo4EventElement("MbsEvent101"),
00066 fxHeader(),
00067 fxSubEvArray(0),
00068 fiSubEvIndex(0),
00069 fbIsReference(kFALSE)
00070 {
00071 GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent(UInt_t, Char_t*, Char_t*, Short_t* UInt_t)",__LINE__, __FILE__));
00072 fxSubEvArray = new TObjArray(subnum+5);
00073 fxSubEvArray->SetOwner(kTRUE);
00074 for (UInt_t t=0;t<subnum;++t) {
00075 TGo4MbsSubEvent* subeve = new TGo4MbsSubEvent(datasizes[t]);
00076 fxSubEvArray->AddLast(subeve);
00077 subeve->SetSubcrate(subcrates[t]);
00078 subeve->SetControl(controls[t]);
00079 subeve->SetProcid(procids[t]);
00080 }
00081 Clear();
00082 }
00083
00084
00085 TGo4MbsEvent::TGo4MbsEvent(const char* ) :
00086 TGo4EventElement("MbsEvent101"),
00087 fxHeader(),
00088 fxSubEvArray(0),
00089 fiSubEvIndex(0),
00090 fbIsReference(kFALSE)
00091 {
00092 GO4TRACE((12,"TGo4MbsEvent::TGo4MbsEvent(const char)",__LINE__, __FILE__));
00093 SimpleInit();
00094 }
00095
00096 void TGo4MbsEvent::SimpleInit()
00097 {
00098 fxSubEvArray = new TObjArray(5);
00099 fxSubEvArray->SetOwner(kTRUE);
00100
00101
00102 TGo4MbsSubEvent* subeve = new TGo4MbsSubEvent(1024);
00103 fxSubEvArray->AddLast(subeve);
00104 subeve->SetSubcrate(0);
00105 subeve->SetControl(0);
00106 subeve->SetProcid(0);
00107 Set();
00108 Clear();
00109 }
00110
00111 TGo4MbsEvent::~TGo4MbsEvent()
00112 {
00113 GO4TRACE((12,"TGo4MbsEvent::~TGo4MbsEvent()",__LINE__, __FILE__));
00114
00115 if(!fbIsReference)
00116 {
00117 if(fxSubEvArray) fxSubEvArray->Delete();
00118 delete fxSubEvArray;
00119
00120 }
00121 }
00122
00123 void TGo4MbsEvent::Clear(Option_t *)
00124 {
00125 GO4TRACE((11,"TGo4MbsEvent::Clear()",__LINE__, __FILE__));
00126 if(!fbIsReference) {
00127
00128 TGo4MbsSubEvent* sub(0);
00129 ResetIterator();
00130 while ((sub = NextSubEvent(kTRUE))!=0) sub->Clear();
00131 }
00132 }
00133
00134 void TGo4MbsEvent::AssignReference(TGo4MbsEvent* ref)
00135 {
00136 if(!ref) return;
00137 if(!fbIsReference) {
00138
00139 if(fxSubEvArray) fxSubEvArray->Delete();
00140 delete fxSubEvArray;
00141 }
00142 fbIsReference = true;
00143
00144 fxHeader.fiCount=ref->fxHeader.fiCount;
00145 fxHeader.fsDummy=ref->fxHeader.fsDummy;
00146 fxHeader.fsTrigger=ref->fxHeader.fsTrigger;
00147 fxHeader.fxGSIHeader.fiDlen=ref->fxHeader.fxGSIHeader.fiDlen;
00148 fxHeader.fxGSIHeader.fsSubtype=ref->fxHeader.fxGSIHeader.fsSubtype;
00149 fxHeader.fxGSIHeader.fsType=ref->fxHeader.fxGSIHeader.fsType;
00150
00151
00152 fxSubEvArray=ref->fxSubEvArray;
00153 }
00154
00155 void TGo4MbsEvent::RemoveReference()
00156 {
00157 if(fbIsReference)
00158 SimpleInit();
00159 fbIsReference = kFALSE;
00160 }
00161
00162 void TGo4MbsEvent::Set(Int_t dlen, Short_t type, Short_t subtype,
00163 Short_t dummy, Short_t trigger, Int_t count)
00164 {
00165 SetDlen(dlen);
00166 SetType(type);
00167 SetSubtype(subtype);
00168 SetDummy(dummy);
00169 SetTrigger(trigger);
00170 SetCount(count);
00171 }
00172
00173 void TGo4MbsEvent::PrintEvent()
00174 {
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 PrintMbsEvent();
00191 }
00192
00193 void TGo4MbsEvent::PrintMbsFileHeader()
00194 {
00195 s_filhe* head = GetMbsSourceHeader();
00196 if (head==0) return;
00197 printf("***** File header:\n");
00198 printf("\tdatalen: %d \n", head->filhe_dlen);
00199 printf("\tfilename_l: %d \n", head->filhe_file_l);
00200 printf("\tfilename: %s\n", head->filhe_file);
00201 printf("\ttype: %d \n", head->filhe_type);
00202 printf("\tsubtype: %d\n", head->filhe_subtype);
00203 printf("\t#commentlines: %d\n", head->filhe_lines);
00204 for(Int_t i=0; i<head->filhe_lines;++i)
00205 printf("\t\t %s\n", head->s_strings[i].string);
00206 }
00207
00208 void TGo4MbsEvent::PrintMbsBufferHeader()
00209 {
00210 s_bufhe* head = GetMbsBufferHeader();
00211 if (head==0) return;
00212
00213 printf("***** Buffer header:\n");
00214 printf("\tbuffernumber: %d \n", head->l_buf);
00215 printf("\tdatalen: %d \n", head->l_dlen);
00216 printf("\ttime lo: %u\n", head->l_time[0]);
00217 printf("\ttime hi: %u\n", head->l_time[1]);
00218 char sbuf[1000];
00219 f_ut_utime(head->l_time[0], head->l_time[1], sbuf);
00220 printf("\ttimestring: %s\n", sbuf);
00221 printf("\ttype: %d \n", head->i_type);
00222 printf("\tsubtype: %d \n", head->i_subtype);
00223 }
00224
00225
00226 void TGo4MbsEvent::PrintMbsEvent(Int_t subid, Bool_t longw, Bool_t hexw, Bool_t dataw, Bool_t bufhead, Bool_t filhead)
00227 {
00228 static TString oldfname = "";
00229 static TString timestring = "";
00230 if (filhead) {
00231 s_filhe* head = GetMbsSourceHeader();
00232 if (head && (TString(head->filhe_file) != oldfname)) {
00233 oldfname=head->filhe_file;
00234 PrintMbsFileHeader();
00235 }
00236 }
00237 static int oldbnum = 0;
00238 if (bufhead) {
00239 s_bufhe* head = GetMbsBufferHeader();
00240 if ( head && (head->l_buf != oldbnum) ) {
00241
00242 oldbnum = head->l_buf;
00243 char sbuf[1000];
00244 f_ut_utime(head->l_time[0], head->l_time[1], sbuf);
00245 timestring = sbuf;
00246
00247 PrintMbsBufferHeader();
00248 }
00249 }
00250
00251 if (GetType()==10) {
00252 printf("Event %9d Type/Subtype %5d %5d Length %5d[w] Trigger %2d %s\n",
00253 GetCount(), GetType(), GetSubtype(), GetDlen(), GetTrigger(), timestring.Data());
00254 } else {
00255 printf("Event type %d, subtype %d, data longwords %d",
00256 GetType(), GetSubtype(), GetDlen()/2);
00257 }
00258
00259
00260 TGo4MbsSubEvent *sub(0);
00261 ResetIterator();
00262 while ((sub=NextSubEvent())!=0) {
00263
00264 if ((subid>=0) && (sub->GetProcid()!=subid)) continue;
00265
00266 sub->PrintMbsSubevent(longw, hexw, dataw);
00267 }
00268 }
00269
00270
00271 TGo4MbsSubEvent* TGo4MbsEvent::NextSubEvent(Bool_t all)
00272 {
00273 GO4TRACE((11,"TGo4MbsEvent::NextSubEvent()",__LINE__, __FILE__));
00274
00275 if (fxSubEvArray==0) return 0;
00276
00277 TGo4MbsSubEvent* sub(0);
00278 do {
00279 if (fiSubEvIndex>fxSubEvArray->GetLast()) return 0;
00280 sub = (TGo4MbsSubEvent*) (fxSubEvArray->At(fiSubEvIndex++));
00281 if(sub==0) break;
00282 } while(!all && !sub->IsFilled());
00283 return sub;
00284 }
00285
00286
00287 TGo4MbsSubEvent * TGo4MbsEvent::GetSubEvent(Char_t subcrate, Char_t ctrl, Short_t procid)
00288 {
00289 GO4TRACE((11,"TGo4MbsEvent::GetSubEvent(Char_t)",__LINE__, __FILE__));
00290 TGo4MbsSubEvent* sub(0);
00291 ResetIterator();
00292 while ((sub = NextSubEvent())!=0)
00293 if((sub->GetSubcrate()==subcrate) &&
00294 (sub->GetControl()==ctrl) &&
00295 (sub->GetProcid()==procid)) return sub;
00296 return 0;
00297 }
00298
00299 TGo4MbsSubEvent * TGo4MbsEvent::GetSubEvent(Short_t procid)
00300 {
00301 GO4TRACE((11,"TGo4MbsEvent::GetSubEvent(Short_t)",__LINE__, __FILE__));
00302 TGo4MbsSubEvent* sub(0);
00303 ResetIterator();
00304 while ((sub = NextSubEvent())!=0)
00305 if(sub->GetProcid()== procid) return sub;
00306 return 0;
00307 }
00308
00309
00310 s_filhe * TGo4MbsEvent::GetMbsSourceHeader()
00311 {
00312 TGo4MbsSource* src = dynamic_cast<TGo4MbsSource*> (GetEventSource());
00313 return src ? src->GetInfoHeader() : 0;
00314 }
00315
00316 s_bufhe * TGo4MbsEvent::GetMbsBufferHeader()
00317 {
00318 TGo4MbsSource* src = dynamic_cast<TGo4MbsSource*> (GetEventSource());
00319 return src ? src->GetBufferHeader() : 0;
00320 }
00321
00322 TGo4MbsSubEvent* TGo4MbsEvent::AddSubEvent(Int_t fullID, Short_t* source, Int_t datalength, Bool_t copydata)
00323 {
00324 Int_t fieldlength =0;
00325 TGo4MbsSubEvent* subtarget=0;
00326 TGo4MbsSubEvent* subtargetindex=0;
00327 if(datalength>2)
00328 fieldlength = (datalength-2) / (sizeof(Int_t) / sizeof(Short_t));
00329 else {
00330 TGo4Log::Debug(" !!! MbsSource -- EMPTY subevent #%d ", fullID);
00331 fieldlength =0;
00332 }
00333
00334 ResetIterator();
00335 while ( ( subtargetindex = NextSubEvent(kTRUE) ) !=0 ) {
00336
00337 Int_t* subtargetid= &((subtargetindex->fxHeader).fiFullid);
00338 if(*subtargetid == fullID) {
00339
00340 if(!subtargetindex->fbIsFilled) {
00341
00342 subtarget=subtargetindex;
00343 break;
00344 } else {
00345
00346 }
00347 } else {
00348
00349 }
00350 }
00351
00352 if(!subtarget) {
00353
00354 subtarget = new TGo4MbsSubEvent(fieldlength);
00355 Int_t* newsubtargetid= &((subtarget->fxHeader).fiFullid);
00356 if(!copydata) {
00357 subtarget->fbIsDataOwner = kFALSE;
00358 delete [] (subtarget->fiData);
00359 subtarget->fiAllocLen=0;
00360 }
00361 *newsubtargetid = fullID;
00362 TGo4Log::Debug(" Created new output subevent for event\n\tpid:%d subcrate:%d ctrl:%d",
00363 subtarget->GetProcid(),subtarget->GetSubcrate(), subtarget->GetControl());
00364 if (fxSubEvArray == 0) fxSubEvArray = new TObjArray(5);
00365 fxSubEvArray->AddLast(subtarget);
00366 }
00368 subtarget->SetDlen(datalength);
00369 void* data = (void*) source;
00370 if(copydata) {
00371 subtarget->fbIsDataOwner = kTRUE;
00372 subtarget->ReAllocate(fieldlength);
00374 if(datalength>2)
00375 memcpy((void*) (subtarget->fiData),
00376 data, (datalength-2)*sizeof(Short_t));
00377 } else {
00378
00379 subtarget->fbIsDataOwner=kFALSE;
00380 subtarget->fiAllocLen=fieldlength;
00381 if(datalength>2)
00382 subtarget->fiData= (Int_t*) data;
00383 else
00384 subtarget->fiData= 0;
00385 }
00386 subtarget->fbIsFilled = kTRUE;
00387 return subtarget;
00388 }
00389