00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4MbsEvent.h"
00017
00018 #include "Riostream.h"
00019 #include "TObjArray.h"
00020
00021 #include "TGo4Log.h"
00022 #include "Go4Exceptions.h"
00023 #include "TGo4MbsSubEvent.h"
00024 #include "TGo4MbsSource.h"
00025 #include "TGo4RevServ.h"
00026 #include "TGo4TreeSource.h"
00027 #include "TGo4FileSource.h"
00028
00029 TGo4MbsEvent::TGo4MbsEvent() :
00030 TGo4EventElement(),
00031 fxHeader(),
00032 fxSubEvArray(0),
00033 fxIterator(0),
00034 fxMbsSource(0),
00035 fxTreeSource(0),
00036 fxFileSource(0)
00037 {
00038 TRACE((12,"TGo4MbsEvent::TGo4MbsEvent()",__LINE__, __FILE__));
00039 }
00040
00041 TGo4MbsEvent::TGo4MbsEvent(UInt_t subnum, Short_t* subids, UInt_t datasize) :
00042 TGo4EventElement("MbsEvent-10-1"),
00043 fxHeader(),
00044 fxSubEvArray(0),
00045 fxIterator(0),
00046 fxMbsSource(0),
00047 fxTreeSource(0),
00048 fxFileSource(0)
00049 {
00050 TRACE((12,"TGo4MbsEvent::TGo4MbsEvent(UInt_t, Short_t, UInt_t)",__LINE__, __FILE__));
00051 fxSubEvArray=new TObjArray(subnum+5);
00052
00053
00054 fxIterator = fxSubEvArray->MakeIterator();
00055 ResetIterator();
00056 TGo4MbsSubEvent* subeve;
00057 for (UInt_t t=0;t<subnum;++t)
00058 {
00059 subeve= new TGo4MbsSubEvent(datasize);
00060 fxSubEvArray->AddLast(subeve);
00061 subeve->SetProcid(subids[t]);
00062 }
00063 Clear();
00064 }
00065
00066 TGo4MbsEvent::TGo4MbsEvent(UInt_t subnum,
00067 Char_t* subcrates,
00068 Char_t* controls,
00069 Short_t* procids,
00070 UInt_t* datasizes) :
00071 TGo4EventElement("MbsEvent-10-1"),
00072 fxHeader(),
00073 fxSubEvArray(0),
00074 fxIterator(0),
00075 fxMbsSource(0),
00076 fxTreeSource(0),
00077 fxFileSource(0)
00078 {
00079 TRACE((12,"TGo4MbsEvent::TGo4MbsEvent(UInt_t, Char_t*, Char_t*, Short_t* UInt_t)",__LINE__, __FILE__));
00080 fxSubEvArray=new TObjArray(subnum+5);
00081
00082
00083 fxIterator = fxSubEvArray->MakeIterator();
00084 ResetIterator();
00085 TGo4MbsSubEvent* subeve;
00086 for (UInt_t t=0;t<subnum;++t)
00087 {
00088 subeve= new TGo4MbsSubEvent(datasizes[t]);
00089 fxSubEvArray->AddLast(subeve);
00090 subeve->SetSubcrate(subcrates[t]);
00091 subeve->SetControl(controls[t]);
00092 subeve->SetProcid(procids[t]);
00093 }
00094 Clear();
00095 }
00096
00097 TGo4MbsEvent::~TGo4MbsEvent()
00098 {
00099 TRACE((12,"TGo4MbsEvent::~TGo4MbsEvent()",__LINE__, __FILE__));
00100 delete fxIterator;
00101 if(fxSubEvArray) fxSubEvArray->Delete();
00102 delete fxSubEvArray;
00103 }
00104
00105 Int_t TGo4MbsEvent::Fill()
00106 {
00107 TRACE((11,"TGo4MbsEvent::Fill()",__LINE__, __FILE__));
00108
00109 Int_t rev=0;
00110 if(fxMbsSource!=0)
00111 {
00112 Clear();
00113 rev=fxMbsSource->NextEvent();
00114 if(rev!=GETEVT__SUCCESS)
00115 {
00116
00117 TGo4Log::Debug(" Mbs Event -- !!! NextEvent() error: %s !!! ",
00118 fxMbsSource->GetErrMess());
00119 return rev;
00120 }
00121 else
00122 {
00123 fxMbsSource->BuildMbsEvent(this);
00124 return rev;
00125 }
00126 }
00127
00128 else if(fxTreeSource!=0)
00129 {
00130 Clear();
00131 if(fxTreeSource->BuildEvent(this))
00132 {
00133 return 0;
00134 }
00135 else
00136 {
00137
00138 return 1;
00139 }
00140
00141 }
00142 else if(fxFileSource!=0)
00143 {
00144 Clear();
00145 if(fxFileSource->BuildEvent(this))
00146 {
00147 delete fxIterator;
00148 if(fxSubEvArray)
00149 fxIterator = fxSubEvArray->MakeIterator();
00150 else
00151 fxIterator=0;
00152 return 0;
00153 }
00154 else
00155 {
00156
00157 return 1;
00158 }
00159
00160 }
00161
00162 else
00163 {
00164
00165 TGo4Log::Debug(" !!! MbsEvent: Fill ERROR: unknown event source !!! ");
00166 return 1;
00167 }
00168
00169 return 0;
00170 }
00171
00172 Int_t TGo4MbsEvent::Init()
00173 {
00174 TRACE((11,"TGo4MbsEvent::Init()",__LINE__, __FILE__));
00175
00176
00177 if(CheckEventSource("TGo4MbsSource"))
00178 {
00179 fxMbsSource = dynamic_cast<TGo4MbsSource*> (GetEventSource());
00180 fxTreeSource=0;
00181 fxFileSource=0;
00182 }
00183 else if(CheckEventSource("TGo4TreeSource"))
00184 {
00185 fxTreeSource = dynamic_cast<TGo4TreeSource*> (GetEventSource());
00186 fxMbsSource=0;
00187 fxFileSource=0;
00188 }
00189 else if(CheckEventSource("TGo4FileSource"))
00190 {
00191 fxFileSource = dynamic_cast<TGo4FileSource*> (GetEventSource());
00192 fxTreeSource=0;
00193 fxMbsSource=0;
00194 }
00195 else
00196 {
00197 TGo4Log::Debug(" !!! MbsEvent: Init ERROR: unknown event source !!! ");
00198 return 1;
00199 }
00200 return 0;
00201 }
00202
00203 void TGo4MbsEvent::Clear(Option_t *t)
00204 {
00205 TRACE((11,"TGo4MbsEvent::Clear()",__LINE__, __FILE__));
00206
00207 TGo4MbsSubEvent* sub;
00208 ResetIterator();
00209 while ((sub = NextSubEvent(kTRUE)) !=0)
00210 {
00211 sub->Clear();
00212
00213 }
00214
00215
00216 }
00217
00218
00219 void TGo4MbsEvent::Set(Int_t dlen, Short_t type, Short_t subtype,
00220 Short_t dummy, Short_t trigger, Int_t count)
00221 {
00222 SetDlen(dlen);
00223 SetType(type);
00224 SetSubtype(subtype);
00225 SetDummy(dummy);
00226 SetTrigger(trigger);
00227 SetCount(count);
00228 }
00229
00230 void TGo4MbsEvent::PrintEvent() {
00231 TGo4EventElement::PrintEvent();
00232
00234
00235
00236
00237
00238
00239
00240
00241
00243 cout << "MBS Event printout:"
00244 << dec << setw(8) << (Int_t) GetCount()
00245 << " t/s " << setw(4) << (Int_t) GetType()
00246 << " " << setw(4) << (Int_t) GetSubtype()
00247 << " len " << setw(8) << (Int_t) GetDlen()
00248 << " trig " << setw(4) << (Int_t) GetTrigger()
00249 << endl;
00250 TGo4MbsSubEvent* sub;
00251 ResetIterator();
00252 while ((sub = NextSubEvent() ) !=0)
00253 {
00254 sub->PrintEvent();
00255 }
00256
00257
00258
00259 }
00260
00261 void TGo4MbsEvent::ResetIterator()
00262 {
00263 TRACE((11,"TGo4MbsEvent::ResetIterator()",__LINE__, __FILE__));
00264 if(fxIterator!=0)
00265 {
00266 fxIterator->Reset();
00267 }
00268 else
00269 {
00270 if(fxSubEvArray)
00271 fxIterator = fxSubEvArray->MakeIterator();
00272 }
00273 }
00274
00275 TGo4MbsSubEvent* TGo4MbsEvent::NextSubEvent(Bool_t all)
00276 {
00277 TRACE((11,"TGo4MbsEvent::NextSubEvent()",__LINE__, __FILE__));
00278 if(fxIterator==0) return 0;
00279 TGo4MbsSubEvent* sub=0;
00280 do
00281 {
00282 sub= dynamic_cast<TGo4MbsSubEvent*> (fxIterator ->Next());
00283 if(sub==0) break;
00284 }while(!all && !sub->IsFilled());
00285 return sub;
00286 }
00287
00288
00289
00290
00291
00292 TGo4MbsSubEvent * TGo4MbsEvent::GetSubEvent(Char_t subcrate, Char_t ctrl, Short_t procid)
00293 {
00294 TRACE((11,"TGo4MbsEvent::GetSubEvent(Char_t)",__LINE__, __FILE__));
00295 TGo4MbsSubEvent* result=0;
00296 TGo4MbsSubEvent* sub=0;
00297 ResetIterator();
00298 while ((sub = NextSubEvent() ) !=0)
00299 {
00300 if( (sub->GetSubcrate() == subcrate)
00301 && (sub->GetControl() == ctrl)
00302 && (sub->GetProcid()== procid) )
00303 {
00304 result=sub;
00305 break;
00306 }
00307 }
00308 return result;
00309 }
00310
00311 TGo4MbsSubEvent * TGo4MbsEvent::GetSubEvent(Short_t procid)
00312 {
00313 TRACE((11,"TGo4MbsEvent::GetSubEvent(Short_t)",__LINE__, __FILE__));
00314 TGo4MbsSubEvent* result=0;
00315 TGo4MbsSubEvent* sub=0;
00316 ResetIterator();
00317 while ((sub = NextSubEvent() ) !=0)
00318 {
00319 if(sub->GetProcid()== procid)
00320 {
00321 result=sub;
00322 break;
00323 }
00324 }
00325 return result;
00326 }
00327
00328
00329
00330
00331
00332
00333 s_filhe * TGo4MbsEvent::GetMbsSourceHeader()
00334 {
00335 if(fxMbsSource)
00336 return (fxMbsSource->GetInfoHeader());
00337 else
00338 return 0;
00339 }
00340
00341
00342 s_bufhe * TGo4MbsEvent::GetMbsBufferHeader()
00343 {
00344 if(fxMbsSource)
00345 return (fxMbsSource->GetBufferHeader());
00346 else
00347 return 0;
00348 }
00349
00350 void TGo4MbsEvent::SetPrintEvent(Int_t num, Int_t sid, Int_t longw, Int_t hexw, Int_t dataw)
00351 {
00352 if(fxMbsSource)
00353 return (fxMbsSource->SetPrintEvent(num,sid,longw,hexw,dataw));
00354 }
00355
00356