19 #include <daqFormats.h>
23 int SFS_ittr::findEventNumber()
26 #if defined(__USE_LARGEFILE64) || defined(_LARGEFILE64_SOURCE)
27 long long int orig_pos = wfile->lseek(0, SEEK_CUR);
28 LOG(DBG,
"findEventNumber: pos=%lld",orig_pos);
30 int orig_pos = wfile->lseek(0, SEEK_CUR);
31 LOG(DBG,
"findEventNumber: pos=%d",orig_pos);
36 ret = wfile->read(buff, 8);
37 if(ret == 0) { ret = 0;
break; }
38 if(ret != 8) { ret = -1;
break; }
40 #if defined(__USE_LARGEFILE64) || defined(_LARGEFILE64_SOURCE)
41 wfile->lseek(-((
long long int)8), SEEK_CUR);
43 wfile->lseek(-8, SEEK_CUR);
46 if(memcmp(buff,
"SFS V", 5) == 0) {
47 wfile->lseek(12, SEEK_CUR);
50 else if(memcmp(buff,
"LRHD", 4) == 0) {
51 wfile->lseek(60, SEEK_CUR);
54 else if(memcmp(buff,
"HEAD", 4) == 0) {
55 wfile->lseek(12, SEEK_CUR);
58 else if(memcmp(buff,
"DATAP", 5) == 0) {
60 ret = wfile->read(&datap,
sizeof(datap));
61 if(ret !=
sizeof(datap)) {
62 LOG(ERR,
"Error reading datap: %d",ret);
68 if(datap.bh.byte_order != 0x04030201) {
72 LOG(DBG,
"Got event #%d from DATAP",seq);
76 else if(memcmp(buff,
"FILE", 4) == 0) {
79 ret = wfile->read(fbuff,
sizeof(
SFS_File));
81 LOG(ERR,
"Error reading FILE: %d",ret);
86 if(f->byte_order != 0x04030201) {
91 if((
unsigned int)sz >
sizeof(
SFS_File)) {
96 ret = wfile->read(btogo, sztogo);
98 LOG(ERR,
"Error reading FILE: %d",ret);
104 ret = atoi(&f->name[2]);
106 LOG(DBG,
"Set event number to #%d from next FILE rec",ret);
115 wfile->lseek(orig_pos, SEEK_SET);
116 LOG(DBG,
"Returning %d",ret);
123 int SFS_ittr::findFullLength()
128 #if defined(__USE_LARGEFILE64) || defined(_LARGEFILE64_SOURCE)
129 wfile->lseek(-((
long long int)
sizeof(lrhd)),SEEK_CUR);
131 wfile->lseek(-(
sizeof(lrhd)),SEEK_CUR);
134 int ret = wfile->read(&lrhd,
sizeof(lrhd));
136 if(ret !=
sizeof(lrhd)) {
137 LOG(ERR,
"Error reading lrhd %d", ret);
141 int sz = lrhd.length;
142 if(lrhd.lh.byte_order != 0x04030201) {
151 int SFS_ittr::nextLRHD()
155 int ret = wfile->read(&lrhd,
sizeof(lrhd));
156 if(ret !=
sizeof(lrhd)) {
157 LOG(ERR,
"Error reading lrhd %d", ret);
161 #if defined(__USE_LARGEFILE64) || defined(_LARGEFILE64_SOURCE)
162 long long int xxx = wfile->lseek(-((
long long int)
sizeof(lrhd)),SEEK_CUR);
163 LOG(DBG,
"nextLRHD(): (%c%c%c%c) off=%lld",
164 lrhd.lh.bank_type[0],lrhd.lh.bank_type[1],
165 lrhd.lh.bank_type[2],lrhd.lh.bank_type[3], xxx);
167 int xxx = wfile->lseek(-(
sizeof(lrhd)),SEEK_CUR);
168 LOG(DBG,
"nextLRHD(): (%c%c%c%c) off=%d",
169 lrhd.lh.bank_type[0],lrhd.lh.bank_type[1],
170 lrhd.lh.bank_type[2],lrhd.lh.bank_type[3], xxx);
175 if(memcmp(lrhd.lh.bank_type,
"LRHD", 4) != 0) {
176 LOG(ERR,
"nextLRHD() not LRHD %c%c%c%c",
177 lrhd.lh.bank_type[0],lrhd.lh.bank_type[1],
178 lrhd.lh.bank_type[2],lrhd.lh.bank_type[3]);
183 if(memcmp(lrhd.record_type,
"DATA", 4) != 0) {
184 LOG(DBG,
"nextLRHD() not DATA %c%c%c%c",
185 lrhd.record_type[0],lrhd.record_type[1],
186 lrhd.record_type[2],lrhd.record_type[3]);
192 int n = findEventNumber();
195 memcpy(entry.type,
"FILE",4);
196 entry.byte_order = 0x04030201;
197 entry.sz =
sizeof(
LOGREC);
198 LOG(DBG,
"LRHD: entry.sz = %d",entry.sz);
199 sprintf(entry.name,
"/#%d/lrhd",n);
203 strcpy(fullpath, entry.name);
204 strcpy(ppath, entry.name);
205 striptofile(entry.name);
208 int ccc = wfile->lseek(0,SEEK_CUR);
212 #if defined(__USE_LARGEFILE64) || defined(_LARGEFILE64_SOURCE)
213 LOG(DBG,
"fullpath %s, entry.name: %s, fileoffset %lld (%d)/%d, sz %d head_sz %d",
214 fullpath, entry.name, fileoffset, ccc, filepos, entry.sz, entry.head_sz);
216 LOG(DBG,
"fullpath %s, entry.name: %s, fileoffset %d (%d)/%d, sz %d head_sz %d",
217 fullpath, entry.name, fileoffset, ccc, filepos, entry.sz, entry.head_sz);
223 int SFS_ittr::nextDatap()
225 int sz = findFullLength();
228 int ret = wfile->read(&datap,
sizeof(datap));
229 if(ret !=
sizeof(datap)) {
230 LOG(ERR,
"Bad read of datap %d",ret);
234 LOG(DBG,
"Nextdatap: (%c%c%c%c)",
235 datap.bh.bank_type[0],
236 datap.bh.bank_type[1],
237 datap.bh.bank_type[2],
238 datap.bh.bank_type[3]);
241 ret = wfile->read(buff, 8);
243 LOG(ERR,
"Bad read of datap %d",ret);
247 #if defined(__USE_LARGEFILE64) || defined(_LARGEFILE64_SOURCE)
248 wfile->lseek(-((
long long int)8),SEEK_CUR);
249 wfile->lseek(-((
long long int)
sizeof(
DATAP)), SEEK_CUR);
251 wfile->lseek(-8,SEEK_CUR);
252 wfile->lseek(-
sizeof(
DATAP), SEEK_CUR);
255 if(memcmp(buff,
"FILE", 4) == 0) {
256 LOG(DBG,
"No legacy because SFS follows");
260 LOG(DBG,
"Making legacy entry");
264 if(datap.bh.byte_order != 0x04030201) seq = swap32(seq);
266 memcpy(entry.type,
"FILE",4);
267 entry.byte_order = 0x04030201;
270 sprintf(entry.name,
"/#%d/legacy",seq);
274 strcpy(fullpath, entry.name);
275 strcpy(ppath, entry.name);
276 striptofile(entry.name);
279 int ccc = wfile->lseek(0,SEEK_CUR);
281 LOG(DBG,
"fullpath %s, entry.name: %s, fileoffset %d (%d)/%d, sz %d head_sz %d",
282 fullpath, entry.name, fileoffset, ccc, filepos, entry.sz, entry.head_sz);