45 #include "StDaqLib/GENERIC/EventReader.hh"
48 using namespace OLDEVP;
52 int numberOfLadders[3] = {8,12,16};
53 int numberOfWafers[3] = {4,6,7};
67 if (w < (numberOfWafers[0] * numberOfLadders[0])) {
69 ladder = w/numberOfWafers[0] + 1;
70 wafer = w%numberOfWafers[0] + 1;
72 else if( (w1 = w - numberOfWafers[0]*numberOfLadders[0]) <
73 (numberOfWafers[1] * numberOfLadders[1])) {
75 ladder = w1/numberOfWafers[1] + 1;
76 wafer = w1%numberOfWafers[1] + 1;
79 w1 = w - numberOfWafers[0]*numberOfLadders[0]
80 - numberOfWafers[1]*numberOfLadders[1];
82 ladder = w1/numberOfWafers[2] + 1;
83 wafer = w1%numberOfWafers[2] + 1;
92 const int mezzIndex[] = {1,2,2,1};
93 if (wafer > 2) hyperSector = 1;
95 rcb = (ladder-1)/2 + ladder;
96 mezz = mezzIndex[wafer-1];
102 const int mezzIndex[3][6] = { {1,1,3,3,1,1},
105 if (wafer > 3) hyperSector = 1;
106 else hyperSector = 3;
109 mezz = mezzIndex[(ladder-1)%3][wafer-1];
110 transitionBoard = (ladder-1)%3 + 1;
115 const int mezzIndex[] = {2,2,3,3,3,1,1};
116 if (wafer > (4-(ladder%2))) hyperSector = 1;
117 else hyperSector = 3;
118 rcb = (ladder-1)/4 + (ladder+1)/2;
120 mezz = mezzIndex[wafer-1];
121 if (hyperSector == 1) transitionBoard = 1;
122 else transitionBoard = 3;
125 mezz = mezzIndex[7-wafer];
126 if (hyperSector == 1) transitionBoard = 3;
127 else transitionBoard = 1;
144 adcd_p = (classname(Bank_SVTADCD) *)NULL;
145 adcx_p = (classname(Bank_SVTADCX) *)NULL;
146 seqd_p = (classname(Bank_SVTSEQD) *)NULL;
148 for (
int ii=0; ii<SVT_HYBRIDS; ii++) HybridSpacePts[ii] = 0;
151 SVTV1P0_ZS_SR::SVTV1P0_ZS_SR(
int b,
int l,
int w,
SVTV1P0_Reader *det)
162 const int mezzIndex[] = {1,2,2,1};
163 if (wafer > 2) hyperSector = 1;
164 else hyperSector = 3;
165 rcb = (ladder-1)/2 + ladder;
166 mezz = mezzIndex[wafer-1];
172 const int mezzIndex[3][6] = { {1,1,3,3,1,1},
175 if (wafer > 3) hyperSector = 1;
176 else hyperSector = 3;
179 mezz = mezzIndex[(ladder-1)%3][wafer-1];
180 transitionBoard = (ladder-1)%3 + 1;
185 const int mezzIndex[] = {2,2,3,3,3,1,1};
186 if (wafer > (4-(ladder%2))) hyperSector = 1;
187 else hyperSector = 3;
188 rcb = (ladder-1)/4 + (ladder+1)/2;
190 mezz = mezzIndex[wafer-1];
191 if (hyperSector == 1) transitionBoard = 1;
192 else transitionBoard = 3;
195 mezz = mezzIndex[7-wafer];
196 if (hyperSector == 1) transitionBoard = 3;
197 else transitionBoard = 1;
209 adcd_p = (classname(Bank_SVTADCD) *)NULL;
210 adcx_p = (classname(Bank_SVTADCX) *)NULL;
211 seqd_p = (classname(Bank_SVTSEQD) *)NULL;
213 for (
int ii=0; ii<SVT_HYBRIDS; ii++) HybridSpacePts[ii] = 0;
216 int SVTV1P0_ZS_SR::initialize()
220 for (
int hyb=0; hyb<SVT_HYBRIDS; hyb++) {
221 for (
int anode=0; anode<SVT_ANODES; anode++) {
222 Anode_array[hyb][anode].nseq = 0;
223 Anode_array[hyb][anode].seq = (
Sequence *)0;
228 adcd_p = detector->getBankSVTADCD(hyperSector, rcb, mezz);
229 if ((
void *)adcd_p != NULL) {
230 if (detector->ercpy->verbose) printf(
"found ADCD RB%d MZ%d\n",rcb,mezz);
233 seqd_p = detector->getBankSVTSEQD(hyperSector, rcb, mezz);
235 if ((
void *)seqd_p != NULL) {
236 if (detector->ercpy->verbose) printf(
"found SEQD RB%d MZ%d\n",rcb,mezz);
239 if((adcd_p == NULL) || (seqd_p == NULL)) {
246 int banklen = seqd_p->header.BankLength - (
sizeof(
Bank_Header)/4);
247 int numseq = (4*banklen)/
sizeof(
short);
250 for (
int hybrid=1; hybrid<=SVT_HYBRIDS; hybrid++) {
254 (transitionBoard << 5);
260 for(i=0;i<numseq;i++) {
261 unsigned short x = seqd_p->sequence[i];
267 if((x & 0x7fff) / 256 == hybridID) {
280 adcd_offset += x & 0x1f;
299 int anode = -1, oldtb=0;
301 if (seqd_p->sequence[i] & 0x8000) {
302 anode = (seqd_p->sequence[i])& 0xff;
303 INT32 seq_hybridID = (seqd_p->sequence[i]>>8)& 0x7f;
305 if (seq_hybridID != hybridID)
break;
306 if (anode == 255)
break;
310 unsigned short work = seqd_p->sequence[i];
311 int tb = (work>>6) & 0xff;
313 int last = work & 0x20;
316 printf(
"Time bins are messed up old=%d, new=%d\n",oldtb,tb);
321 Anode_array[hybrid-1][anode-1].nseq++;
323 char *t = (
char *)malloc(Anode_array[hybrid-1][anode-1].nseq *
326 Anode_array[hybrid-1][anode-1].seq = (
Sequence *)t;
329 printf(
"Failed to malloc() sequence structures\n");
346 u_char *adc_locn = (u_char *)&(adcd_p->ADC[adcd_offset]);
350 if (seqd_p->sequence[i] & 0x8000) {
351 anode = (seqd_p->sequence[i])& 0xff;
352 INT32 seq_hybridID = (seqd_p->sequence[i]>>8)& 0x7f;
354 if (anode == 255)
break;
355 if (seq_hybridID != hybridID)
break;
360 unsigned short work = seqd_p->sequence[i];
361 int tb = (work>>6) & 0xff;
362 int len = work & 0x1f;
363 int last = work & 0x20;
365 Anode_array[hybrid-1][anode-1].seq[anode_seq].startTimeBin = tb;
366 Anode_array[hybrid-1][anode-1].seq[anode_seq].Length = len;
367 Anode_array[hybrid-1][anode-1].seq[anode_seq].FirstAdc = adc_locn;
386 SVTV1P0_ZS_SR::~SVTV1P0_ZS_SR()
389 for (
int hyb=0; hyb<SVT_HYBRIDS; hyb++) {
390 for (
int anode=0; anode<SVT_ANODES; anode++) {
391 void *memaddr = Anode_array[hyb][anode].seq;
392 if (memaddr) free (memaddr);
394 if (HybridSpacePts[hyb])
395 free(HybridSpacePts[hyb]);
399 int SVTV1P0_ZS_SR::getPadList(
int Hybrid, u_char **anodeList)
401 if ((Hybrid < 1) || (Hybrid > 2))
return -1;
405 for (anode=1; anode<241; anode++) {
406 if (Anode_array[Hybrid-1][anode-1].nseq)
407 anodelist[Hybrid-1][nanode++] = anode;
410 *anodeList = &anodelist[Hybrid-1][0];
415 int SVTV1P0_ZS_SR::getSequences(
int Hybrid,
int Anode,
int *nSeq,
418 *nSeq = Anode_array[Hybrid-1][Anode-1].nseq;
419 *SeqData = Anode_array[Hybrid-1][Anode-1].seq;
423 int SVTV1P0_ZS_SR::getFeeSequences(
int Fee,
int Pin,
int *nSeq,
431 int SVTV1P0_ZS_SR::getSpacePts(
int Hybrid,
int *nSpacePts,
SpacePt **SpacePts)
433 classname(Bank_SVTMZCLD) *cld;
438 (transitionBoard << 5);
441 *SpacePts = HybridSpacePts[Hybrid-1];
444 if (HybridSpacePts[Hybrid-1])
445 free(HybridSpacePts[Hybrid-1]);
447 cld = detector->getBankSVTMZCLD(hyperSector, rcb, mezz);
449 if (cld == (classname(Bank_SVTMZCLD) *)NULL) {
451 if (detector->ercpy->verbose) {
452 printf(
"SVTMZCLD for HS %d, Receiver %d, Mezz %d does not exist\n",
453 hyperSector, rcb, mezz);
457 int numHybrids = cld->NumHybrids;
458 if (numHybrids > 0) {
459 int *ptr = (
int *)&cld->stuff;
461 while (i < numHybrids) {
462 INT32 cld_hybridID = *ptr++;
464 if (cld_hybridID == hybridID) {
465 if (detector->ercpy->verbose)
466 cout <<
"Barrel " << barrel <<
"ladder " << ladder <<
"wafer "
467 << wafer <<
" hybrid " << Hybrid <<
": found "
468 << nsp <<
" space pts" << endl;
470 HybridSpacePts[Hybrid-1] = (
SpacePt *)malloc(nsp *
sizeof(
struct SpacePt));
471 if (HybridSpacePts[Hybrid] == NULL) {
472 cout <<
"failed to malloc() Space Point structures " << endl;
476 for (
int isp=0; isp<nsp; isp++, ptr+=2) {
477 HybridSpacePts[Hybrid-1][isp] = *(
SpacePt *)ptr;
492 int SVTV1P0_ZS_SR::MemUsed()