12 #include "spinDbAPI.h"
14 #include "spinDbV124.hh"
15 #include "spinDbStar.hh"
16 #include "spinDbBXmask.hh"
21 SpinDbIOBase::SpinDbIOBase (
int nelem,
int size)
25 bytePtr =
new char[bytes];
26 indexArr =
new int[nElem];
28 for(
int i=0;i<nElem;i++) indexArr[i]=i;
31 SpinDbIOBase::~SpinDbIOBase() {
32 if(bytePtr )
delete [] bytePtr ;
33 if(indexArr)
delete [] indexArr;
41 SpinDbV124IO::data (
int i) {
return ( (
spinDbV124 *)bytePtr + i ); };
46 SpinDbV124IO::read(FILE *f) {
48 memset(bytePtr,0x00,bytes);
53 for(i=0;i<SPINDbMaxRing;i++) nV+=fscanf(f,
"%d",&t->bucketOffset[i]);
54 for(i=0;i<SPINDbMaxRing;i++) nV+=fscanf(f,
"%d",&t->rotatorState[i]);
58 for(i=0;i<SPINDbMaxBuckets;i++) {
61 nV=fscanf(f,
"%8s %d ",cx,&ix);
68 if(cx[j]==
'1') val+=(1<<(7-j));
69 else if(cx[j]!=
'0')
return 0;
77 if(comment) strncpy(t->comment,comment,SPINDbMaxComment-1);
87 SpinDbV124IO::write(FILE *f) {
92 for(i=0;i<SPINDbMaxRing;i++) fprintf(f,
"%d ",t->bucketOffset[i]);
94 for(i=0;i<SPINDbMaxRing;i++) fprintf(f,
"%d ",t->rotatorState[i]);
96 for(i=0;i<SPINDbMaxBuckets;i++) {
97 unsigned char val= t->v124bits[i];
101 if(val& (1<<(7-j))) bb=1;
102 fprintf(stdout,
"%d",bb);
104 fprintf(stdout,
" %3d\n",i+1);
106 setComment(t->comment);
118 SpinDbStarIO::data (
int i) {
return ( (
spinDbStar *)bytePtr + i ); };
123 SpinDbStarIO::read(FILE *f) {
125 memset(bytePtr,0x00,bytes);
129 int nV=fscanf(f,
"%d %d",&t->bXoff7, &t->bXoff48);
131 fprintf(stdout,
"Read in %d values\n",nV);
133 if(comment) strncpy(t->comment,comment,SPINDbMaxComment-1);
142 SpinDbStarIO::write(FILE *f) {
146 fprintf(f,
"%d %d\n",t->bXoff7, t->bXoff48);
147 setComment(t->comment);
161 SpinDbBXmaskIO::data (
int i) {
return ( (
spinDbBXmask *)bytePtr + i ); };
166 SpinDbBXmaskIO::read(FILE *f) {
167 fprintf(stdout,
"Jestem w SpinDbBXmaskIO file->DB\n");
168 memset(bytePtr,0x00,bytes);
174 int ret=fscanf(f,
"%d ",&val);
177 if(val<0 || val>=SPINDbMaxBXings)
return 0;
182 fprintf(stdout,
"Read in %d values\n",nV);
184 if(comment) strncpy(t->comment,comment,SPINDbMaxComment-1);
186 write(stdout); fprintf(f,
"\ncomm=%s=\n",t->comment);
194 SpinDbBXmaskIO::write(FILE *f) {
195 fprintf(stdout,
"Jestem w SpinDbBXmaskIO DB-->FILE\n");
198 for(i=0;i<SPINDbMaxBXings;i++){
199 if(t->bXmask[i]==0)
continue;
202 if(k%16==0)fprintf(f,
"\n");
205 setComment(t->comment);