Go to the documentation of this file.00001 #include "TFaspSource.h"
00002
00003 #include "TClass.h"
00004
00005 #include <stdlib.h>
00006
00007 #include "TGo4EventErrorException.h"
00008 #include "TGo4EventEndException.h"
00009 #include "TGo4EventTimeoutException.h"
00010 #include "TGo4UserSourceParameter.h"
00011 #include "TGo4MbsEvent.h"
00012 #include "TGo4Log.h"
00013
00014 #include "base/commons.h"
00015
00016 TFaspSource::TFaspSource(const char* name,
00017 const char* args,
00018 Int_t port) :
00019 TGo4EventSource(name),
00020 fbIsOpen(kFALSE),
00021 fxFile(0)
00022 {
00023 SetName(name);
00024 Open();
00025 }
00026
00027 TFaspSource::TFaspSource(TGo4UserSourceParameter* par) :
00028 TGo4EventSource(" "),
00029 fbIsOpen(kFALSE),
00030 fxFile(0)
00031 {
00032 if(par) {
00033 SetName(par->GetName());
00034 Open();
00035 } else {
00036 TGo4Log::Info("TFaspSource constructor with zero parameter!");
00037 }
00038 }
00039
00040 TFaspSource::TFaspSource() :
00041 TGo4EventSource("default Fasp source"),
00042 fbIsOpen(kFALSE),
00043 fxFile(0)
00044 {
00045 }
00046
00047 TFaspSource::~TFaspSource()
00048 {
00049 Close();
00050 }
00051
00052 Bool_t TFaspSource::CheckEventClass(TClass* cl)
00053 {
00054 return cl->InheritsFrom(TGo4MbsEvent::Class());
00055 }
00056
00057 Bool_t TFaspSource::BuildEvent(TGo4EventElement* dest)
00058 {
00059 TGo4MbsEvent* evnt = dynamic_cast<TGo4MbsEvent*> (dest);
00060 if (evnt==0) return kFALSE;
00061
00062
00063
00064 uint8_t rawbuf[44];
00065 size_t rz = fread(rawbuf, 1, 44, fxFile);
00066
00067 if (rz<44) {
00068 Close();
00069 SetEventStatus(1);
00070 throw TGo4EventEndException(this);
00071 }
00072
00073 unsigned id = rawbuf[34] * 0x10000 + rawbuf[35] * 0x100 + rawbuf[36];
00074
00075 Int_t fiEventLen = 44 / sizeof(Short_t);
00076 UInt_t fullid = roc::proc_FASP ;
00077 evnt->AddSubEvent(fullid, (Short_t*) rawbuf, fiEventLen+2, kTRUE);
00078 evnt->SetDlen(fiEventLen+2+4);
00079
00080 evnt->SetCount(id);
00081
00082 return kTRUE;
00083 }
00084
00085 Int_t TFaspSource::Open()
00086 {
00087 if(fbIsOpen) return -1;
00088
00090 fxFile = fopen(GetName(),"r");
00091 if(fxFile==0) {
00092 SetCreateStatus(1);
00093 SetErrMess(Form("Eror opening user file:%s", GetName()));
00094 throw TGo4EventErrorException(this);
00095 }
00096
00097 fbIsOpen = kTRUE;
00098 return 0;
00099 }
00100
00101 Int_t TFaspSource::Close()
00102 {
00103 if(!fbIsOpen) return -1;
00104 fclose(fxFile); fxFile = 0;
00105 fbIsOpen = kFALSE;
00106 return 0;
00107 }