00001 #include "roc/FileInput.h" 00002 00003 #include "dabc/Buffer.h" 00004 #include "dabc/logging.h" 00005 #include "roc/Iterator.h" 00006 00032 roc::FileInput::FileInput(mbs::LmdInput* inp, int selectroc) : 00033 roc::Board(), 00034 fInput(inp), 00035 fHdr(0), 00036 fSubev(0), 00037 fSelectRoc(selectroc) 00038 { 00039 setRole(base::roleDAQ); 00040 } 00041 00042 roc::FileInput::~FileInput() 00043 { 00044 if (fInput) { delete fInput; fInput = 0; } 00045 } 00046 00047 bool roc::FileInput::getNextBuffer(void* &buf, unsigned& len, double tmout) 00048 { 00049 if (fInput==0) return false; 00050 00051 while (true) { 00052 if (fHdr==0) { 00053 fHdr = fInput->ReadEvent(); 00054 if (fHdr==0) return false; 00055 fSubev = 0; 00056 } 00057 00058 fSubev = fHdr->NextSubEvent(fSubev); 00059 if (fSubev!=0) { 00060 buf = fSubev->RawData(); 00061 len = fSubev->RawDataSize(); 00062 00063 if ( (fSubev->iProcId == roc::proc_ErrEvent) || 00064 (fSubev->iProcId==roc::proc_RocEvent) || 00065 (fSubev->iProcId==roc::proc_MergedEvent) || 00066 (fSubev->iProcId==roc::proc_RawData) ) { 00067 00068 if ((fSelectRoc>=0) && (fSelectRoc != fSubev->iSubcrate)) continue; 00069 00070 //if (fSelectRoc<0) fSelectRoc = fSubev->iSubcrate; 00071 00072 // bool calibrated = (fSubev->iProcId == proc_MergedEvent); 00073 00074 roc::Iterator iter(fSubev->iControl); 00075 00076 iter.assign(buf, len); 00077 00078 if (!iter.last()) { 00079 EOUT(("Cannot jump to end of raw buffer len = %d", len)); 00080 continue; 00081 } 00082 00083 // exclude last SYNC message 00084 if (!iter.msg().isSyncMsg()) { 00085 EOUT(("Not an sync message in the end")); 00086 continue; 00087 } 00088 00089 unsigned msg_size = roc::Message::RawSize(iter.getFormat()); 00090 00091 len -= msg_size; 00092 00093 if (!iter.prev()) { 00094 EOUT(("Cannot roll back one message")); 00095 continue; 00096 } 00097 00098 // exclude last EPOCH message, belonging to SYNC 00099 if (iter.msg().isEpochMsg()) len -= msg_size; 00100 } else 00101 continue; // do not take non-nXYTER event 00102 00103 fBrdNumber = fSubev->iSubcrate; 00104 00105 // check if not an empty event 00106 // check in calibration that empty event not produced at all 00107 if (len>0) return true; 00108 } 00109 00110 fHdr = 0; 00111 } 00112 00113 return false; 00114 } 00115 00116 int roc::FileInput::getTransportKind() const 00117 { 00118 return roc::kind_File; 00119 00120 /* roc::MessageFormat fmt = getMsgFormat(); 00121 00122 return ((fmt == formatOptic1) || (fmt==formatOptic2)) ? roc::kind_ABB : roc::kind_UDP; 00123 */ 00124 } 00125 00126 00127 int roc::FileInput::getMsgFormat() const 00128 { 00129 return fSubev ? fSubev->iControl : roc::formatEth1; 00130 }