/***************************************************** * generate_hb_maps.c * * C Program to creat SS and AM maps fo HB for extensive * tests. These maps should allow easy access to all HLM * location in all combination of SSsizes. * * In HB SS map output the last bits are used to define SS size (2,4,8): * reporting form the HB document: * SS bits SSsize in Hit List Memory * <15...2> <1> <0> * SS ss 0 2 * SS 0 1 4 * SS 1 1 8 * * here ss indicates that bit1 i part of the SS number for size2 * SuperStrips. * Given the 64K location in the HB Hit List Memory (HLM) there * can be up to 32k size2 SS, 16k size4 and 8K size8. * With 8 layers, in each layer we can have at most 4k, 2k and 1k SS's. * * We keep thing simple by making SS map as diagonal as possible, * rember that the 4 lsbits of each hit are dropped and only * the next 17 bits are used as SS address. * In output we need at most 32k word, so 16 bits, so we just take * 15 bits from the input: * SuperStrip: SS MAP will use LSSS as 16-bit address (msb=0 !) and * map LSSSn --> LSSS. Note that actually L=llls, i.e. * the 3 msbits are the 3 layer bits, and the next one is * part of a 13-bit SuperStrip id inside a layer, so * allowing to allocate up to 4k SS per layer as needed. * The MAP then adds the needed lsbits as indicated in the * previous table to correctly specify the size, so: * size=2 ==> add 0 at right * size=4 ==> shift 1 place left and add 01 at right * size=8 ==> shift 2 places left and add 011 at right * right and thus only 14/13 bits are needed!). * More explicitely, here is how each hit word will be interpreted: * * bit 2 1 * field 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 * SIZE=2 E P l l l x s s s s s s s s s s s s s x x x x * SIZE=4 E P l l l x x s s s s s s s s s s s s x x x x * SIZE=8 E P l l l x x x s s s s s s s s s s s x x x x * * and the output is: * l l l s s s s s s s s s s s s s * * here: E = EndEvent bit 22 * P = EndPacket bit 21 * l = bit used as layer bit (3 total, bits 18-20) * s = bit used as SuperStrip id * x = bit ignored in the mappint hit-->SuperStrip id * * * ROADS: AM MAP is very simple in this version, * thre are as many road as SupeStrips in each layer * (2K for SSsize=2 or 4, 1K for SSsize=8) and * each road has the same SS in all 8 layers, with * SS = Road #., * each road has the same SuperStrip in all layer, with * SuperStrip number equal to the Road number ! * From N_SS on all roads are invalid (AM_MAP=FFFF) * * S.Belforte 16 Oct, 1999. * * revision history: * *****************************************************/ #include #include int main (int argc, char *argv[]) { int SSsize; int N_SS; /* number of SuperStrip per layer */ unsigned long layer, SS, road; unsigned long i, data; FILE* SSsize_file; FILE* ss_map; FILE* am_map; int iran (int imin, int imax); if ( (SSsize_file = fopen("SS_size", "r")) == NULL) { printf("cannot open file SS_size \n"); exit(0); } else { fscanf(SSsize_file,"%d", &SSsize); printf("file read, SSsize : %d \n", SSsize); } if (SSsize==2) N_SS = 4*1024; /* 4k SS for each of 8 layers */ else if (SSsize==4) N_SS = 2*1024; /* 2k SS for each of 8 layers */ else if (SSsize==8) N_SS = 1024; /* 1k SS for each of 8 layers */ else {printf(" Illegal SSsize specification %d. Abort\n", SSsize); exit(0);} /* SS_MAP, loop on all possible addresses and inteprete them as LSSS */ printf (" will use SSsize = %d\n",SSsize); ss_map = fopen ("HB_SS_MAP","w"); for (i=0; i<128*1024; i++){ layer = (i & 0x1C000) >> 14; if (layer>7) printf("layer>7 !! layer= %d \n",layer); if (SSsize == 2) { SS = (i & 0x1FFF); data = (layer<<13) | (SS<<1) | 0x0 ; } if (SSsize == 4) { SS = (i & 0xFFF); data = (layer<<13) | (SS<<2) | 0x1 ; } if (SSsize == 8) { SS = (i & 0x7FF); data = (layer<<13) | (SS<<3) | 0x3 ; } fprintf (ss_map,"%04X\n", data); } fclose (ss_map); /* AM_MAP, loop on all possible addresses and inteprete them as L-Road */ am_map = fopen ("HB_AM_MAP","w"); for (i=0; i<1024*1024; i++) /* AM_MAP address = 20 bits = 1 Mega-bit */ { layer = (i & 0xE0000) >> 17; road = (i & 0x1FFFF) ; if (road < N_SS) /* for the first N_SS roads, things are simple */ SS = road; /* for each layer/road the SSid is the road # */ else /* for the rest of the roads */ SS = iran(0, N_SS-1 ); /* just pick the SS at random */ /* the SSadd is built as for the SS map */ if (SSsize == 2) data = (layer<<13) | (SS<<1) | 0x0 ; if (SSsize == 4) data = (layer<<13) | (SS<<2) | 0x1 ; if (SSsize == 8) data = (layer<<13) | (SS<<3) | 0x3 ; if (i<10) {printf("i %x, layer %x, road %x, data %x\n", i, layer, road, data);} if (layer==7 & road<10) {printf("i %x, layer %x, road %x, data %x\n", i, layer, road, data);} fprintf (am_map,"%04X\n", data); } fclose (am_map); } /* end of main */ /* * Returns an integer random number * uniformly distributed in [imin,imax] * both imin and imax are possible return values */ #include int iran (int imin, int imax) { float r; /* random in [0,1), 0 included, 1 excluded */ r=1.; while (r==1.) r = (float)rand() / ((float)RAND_MAX + 1.); return imin+(int)(r*(float)(imax-imin+1)); } int ulran (unsigned long ulmin, unsigned long ulmax) { float r; /* random in [0,1), 0 included, 1 excluded */ r=1.; while (r==1.) r = (float)rand() / (float)RAND_MAX; return ulmin+(unsigned long)(r*(float)(ulmax-ulmin+1)); } float fran() { float fmin=0.; float fmax=1.; float r; r=1.; while (r==1.) r=(float)(drand48()/1.); return (fmin+(r*(fmax-fmin))); }