Go to the documentation of this file.00001 #include "roc/Iterator.h"
00002
00003 roc::Iterator::Iterator(int fmt) :
00004 fFormat(fmt),
00005 fBuffer(0),
00006 fBufferLen(0),
00007 fBufferPos(0),
00008 fMsgSize(0),
00009 fMsg(),
00010 fEpoch(0),
00011 fBoard(0),
00012 fOwner(false)
00013 {
00014 fMsgSize = roc::Message::RawSize(fFormat);
00015 for (unsigned n=0;n<MaxGet4;n++) fEpoch2[n] = 0;
00016 }
00017
00018 roc::Iterator::Iterator(const Iterator& src) :
00019 fFormat(src.fFormat),
00020 fBuffer(src.fBuffer),
00021 fBufferLen(src.fBufferLen),
00022 fBufferPos(src.fBufferPos),
00023 fMsgSize(src.fMsgSize),
00024 fMsg(src.fMsg),
00025 fEpoch(src.fEpoch),
00026 fBoard(0),
00027 fOwner(false)
00028 {
00029 for (unsigned n=0;n<MaxGet4;n++) fEpoch2[n] = src.fEpoch2[n];
00030 }
00031
00032
00033 roc::Iterator::Iterator(base::Board* brd, bool owner) :
00034 fFormat(brd ? brd->getMsgFormat() : roc::formatNormal),
00035 fBuffer(0),
00036 fBufferLen(0),
00037 fBufferPos(0),
00038 fMsgSize(0),
00039 fMsg(),
00040 fEpoch(0),
00041 fBoard(brd),
00042 fOwner(owner)
00043 {
00044 fMsgSize = roc::Message::RawSize(fFormat);
00045 setRocNumber(brd->boardNumber());
00046 for (unsigned n=0;n<MaxGet4;n++) fEpoch2[n] = 0;
00047 }
00048
00049 roc::Iterator::Iterator(const char* filename) :
00050 fFormat(roc::formatEth1),
00051 fBuffer(0),
00052 fBufferLen(0),
00053 fBufferPos(0),
00054 fMsgSize(0),
00055 fMsg(),
00056 fEpoch(0),
00057 fBoard(0),
00058 fOwner(false)
00059 {
00060 for (unsigned n=0;n<MaxGet4;n++) fEpoch2[n] = 0;
00061 roc::Board* brd = roc::Board::Connect(filename);
00062 if (brd!=0) {
00063 fBoard = brd;
00064 fOwner = true;
00065 brd->startDaq();
00066
00067 fFormat = brd->getMsgFormat();
00068 setRocNumber(brd->rocNumber());
00069 fMsgSize = roc::Message::RawSize(fFormat);
00070 }
00071 }
00072
00073 roc::Iterator::~Iterator()
00074 {
00075 if (fOwner) {
00076 base::Board::Close(fBoard);
00077 fBoard = 0;
00078 fOwner = false;
00079 }
00080 }
00081
00082 bool roc::Iterator::isFile() const
00083 {
00084 if (fBoard==0) return false;
00085
00086 return fBoard->isFile();
00087 }
00088
00089
00090 void roc::Iterator::setFormat(int fmt)
00091 {
00092 fFormat = fmt;
00093 fMsgSize = roc::Message::RawSize(fFormat);
00094 }
00095
00096
00097 void roc::Iterator::setRocNumber(uint16_t rocnum)
00098 {
00099 if (fFormat == formatEth2)
00100 fMsg.setRocNumber(rocnum);
00101 }
00102
00103 void roc::Iterator::resetEpochs()
00104 {
00105 fEpoch = 0;
00106 for (unsigned n=0;n<MaxGet4;n++) fEpoch2[n] = 0;
00107 }
00108
00109 bool roc::Iterator::assign(void* buf, uint32_t len)
00110 {
00111 fBuffer = buf;
00112 fBufferLen = len;
00113 fBufferPos = 0;
00114
00115 return len >= fMsgSize;
00116 }
00117
00118 bool roc::Iterator::nextBuffer(base::Board* brd, double tmout)
00119 {
00120 if (brd==0) return false;
00121
00122 void *buf = 0;
00123 unsigned len = 0;
00124
00125 if (!brd->getNextBuffer(buf, len, tmout)) return false;
00126
00127 fFormat = brd->getMsgFormat();
00128 setRocNumber(brd->boardNumber());
00129 fMsgSize = roc::Message::RawSize(fFormat);
00130
00131 return assign(buf, len);
00132 }
00133
00134 void roc::Iterator::printMessage(unsigned kind)
00135 {
00136 msg().printData(kind, getMsgEpoch());
00137 }
00138
00139
00140 void roc::Iterator::printMessages(unsigned cnt, unsigned kind)
00141 {
00142 while (cnt-- > 0) {
00143 if (!next()) return;
00144 msg().printData(kind, getMsgEpoch());
00145 }
00146 }