41 #include <sys/types.h>
43 #include "RecHeaderFormats.hh"
51 using namespace OLDEVP;
53 char* OLDEVP::name2str(
char* type)
55 static char name[9] = {0} ;
62 void OLDEVP::dump_data(
char* buffer,
int size,
int width )
64 uint* data_base = (uint*)buffer ;
70 data_char = (
char*) data ;
71 for(
int w = 0 ; w < size ; w++)
73 if((w > 0) && (!(w%width)))
76 data_char = (
char*)(&data[w - width]);
77 for(
int l = 0 ; l < width*4 ; l++)
79 if(((uint)data_char[l]) < 0x21 || ((uint)data_char[l]) > 0x176)
82 printf(
"%c",data_char[l]) ;
86 printf(
"0X%08X ",data[w]) ;
88 int left_over =size%width ;
92 data_char = (
char*)(&data[size - width ] ) ;
93 for(
int l = 0 ; l < width*4 ; l++)
95 if(((uint)data_char[l]) < 0x21 || ((uint)data_char[l]) > 0x176)
98 printf(
"%c",data_char[l]) ;
106 for(
int ll = 0 ; ll < (width - left_over) ; ll++) printf(
" ") ;
108 data_char = (
char*)(&data[size - left_over ] ) ;
109 for(
int l = 0 ; l < left_over*4 ; l++)
111 if(((uint)data_char[l]) < 0x21 || ((uint)data_char[l]) > 0x176)
114 printf(
"%c",data_char[l]) ;
122 int Logical_Record_Header::swap()
125 int iret = swap_raw(ByteOrder,&BankLength,
130 void Logical_Record_Header::print()
132 if(ByteOrder != 0x04030201)
135 memcpy(&lbh ,
this ,
sizeof(lbh)) ;
136 int iret = lbh.swap() ;
137 if(iret < 0 ) printf(
"swapping failed %s %d\n",__FILE__,__LINE__) ;
141 printf(
"Logical Record Header:\n");
142 printf(
"BankType Length RunNum FormatVersion ByteOrder RES1 RES2 RES3 CRC\n") ;
143 printf(
"%-8s %06d %03d %04d.%04d 0X%08X %04d %05d 0X%08X 0X%08X\n",
144 name2str(BankType),BankLength,RunNumber,FormatVersion >> 16 ,
145 FormatVersion & 0x0000FFFF, ByteOrder, reserved1,
146 reserved2, reserved3 , CRC) ;
151 int Logical_Record::swap()
154 int words = header.BankLength ;
155 int iret = swap_raw(header.ByteOrder,&words,1) ;
161 if(iret < 0 )
return(iret) ;
165 iret = swap_raw(header.ByteOrder,&RecordLength,2);
167 iret = swap_raw(header.ByteOrder,&CRC,1);
177 void Logical_Record::set_CRC()
180 header.CRC = compute_crc_bank((
Bank *)
this) ;
183 int Logical_Record::test_CRC()
189 if(header.CRC == 0)
return(-1) ;
190 unsigned int old_crc = header.CRC ;
191 unsigned int test = compute_crc_bank((
Bank *)
this) ;
192 header.CRC = old_crc ;
193 swap_raw(header.ByteOrder ,(
int*)&old_crc, 1);
194 if(old_crc != test)
return(0) ;
198 void Logical_Record::print(
int level)
202 int words = header.BankLength ;
203 swap_raw(header.ByteOrder,&words,1);
205 dump_data(((
char *)
this) +
sizeof(header),words -
sizeof(header)/4);
209 int Bank_Header::swap()
212 int iret = swap_raw(ByteOrder,&BankLength,((
sizeof(
Bank_Header))/4 - 2));
216 void Bank_Header::print()
218 if(ByteOrder != 0x04030201)
221 memcpy(&lbh ,
this ,
sizeof(lbh)) ;
222 int iret = lbh.swap() ;
223 if(iret < 0 )printf(
"swapping failed %s %d\n",__FILE__,__LINE__) ;
227 printf(
"Bank Header:\n");
228 printf(
"BankType Length BankId FormatVersion ByteOrder FormatNumber Token RES CRC\n") ;
229 printf(
"%-8s %06d %03d %04d.%04d 0X%08X %04d %05d 0X%08X 0X%08X\n",
230 name2str(BankType),BankLength,BankId,FormatVersion >> 16 ,
231 FormatVersion & 0x0000FFFF, ByteOrder, FormatNumber,
232 Token, reserved1 , CRC) ;
244 int words = header.BankLength ;
245 int iret = swap_raw(header.ByteOrder,&words,1) ;
251 if(iret < 0 )
return(iret) ;
254 words -= (
sizeof(header)/4) ;
255 int* start = (
int*)
this + (
sizeof(header)/4) ;
256 iret = swap_raw(header.ByteOrder,start,words) ;
268 header.CRC = compute_crc_bank(
this) ;
277 if(!header.CRC)
return(-1) ;
278 unsigned int old_crc = header.CRC ;
279 unsigned int test = compute_crc_bank(
this) ;
280 header.CRC = old_crc ;
282 swap_raw(header.ByteOrder ,(
int*)&old_crc, 1);
283 if(old_crc != test)
return(0) ;
287 void Bank::print(
int level)
291 int words = header.BankLength ;
292 swap_raw(header.ByteOrder,&words,1);
294 printf(
"XXXXXX: length= %d, %d\n", words, words*4);
295 dump_data(((
char *)
this) +
sizeof(header),words -
sizeof(header)/4);