#include #include #include "event.h" #include "monitor.h" /* changes 2.12.2005 size = ProcessEquipment(eptr, event->eventVersion); int ProcessEquipment(char *ptr, int evn_version) //Equipment Size is WITHOUT the Header of the Equipment !! in the old Version ! if (evn_version<196610) size = size + hsize; if (eheader->equipmentType!= 17) return size; ------------------------------------------------ two FEC have the same addr 000 -> set the 12th bit of the addres for the second one Solution only works when all 128 channels are read out; global variable int fnch[32]; int ProcessAltroChannel(unsigned char *ptr,short* channel, int evn_version) if (evn_version<196610) { if (fnch[TrailerWordHWAddr>>7]>0x7f) { (*Trailer) |= 0x800; } fnch[TrailerWordHWAddr>>7]++; } */ void printError( char *where, int errorCode ) { fprintf( stderr, "Error in %s: %s\n", where, monitorDecodeError( errorCode ) ); exit( 1 ); } int PrintEquipmentHeader(struct equipmentHeaderStruct *e){ fprintf( stdout,"EQ size=%d type=%d id=%d ", e->equipmentSize, e->equipmentType, e->equipmentId); char *ptr=(char *) e; unsigned int * data = (unsigned int *) (((struct equipmentStruct * )(ptr))->equipmentRawData); fprintf(stdout,"roi=0x%x trgcl=%d id=%d status=0x%x L1Trg=%d\n", data[6],data[4],data[3]& 0xfff,(data[3]>>12)& 0x3ffff ,(data[1]>>16)&0xff ); return 0; } int PrintEventHeader(struct eventHeaderStruct *event){ static int cnt=0; fprintf(stdout,"EVN %5d size=%d SWAP=%d type=%d ldc=%d gdc=%d id:%d ver=%d head=%d runNb=%d, data=%d\n", cnt++, event->eventSize, event->eventMagic == EVENT_MAGIC_NUMBER_SWAPPED, event->eventType, event->eventLdcId, event->eventGdcId, EVENT_ID_GET_NB_IN_RUN(event->eventId), event->eventVersion, event->eventHeadSize, event->eventRunNb, event->eventSize - event->eventHeadSize); return 0; } int fnch[32]; int PrintAltroChannel(long long * x ){ int TrailerWordHWAddr = (*x)&0xfff; int TrailerWordWCount = ((*x)>>16)&0x3ff; int HWCAddr = TrailerWordHWAddr&0x7f; TrailerWordHWAddr = TrailerWordHWAddr >> 7; fprintf(stdout,"HW %03d ch=%03d %03d\n", TrailerWordHWAddr, HWCAddr,TrailerWordWCount ); return 0; } short get10BitWord(unsigned short * x, int pos) { return ( (*x) >> pos ) & 0x3ff; } int ProcessAltroChannel(unsigned char *ptr,short* channel, int evn_version) { unsigned short fchanneltemp; long long *Trailer = ((long long *) (ptr-4)); int TrailerWordHWAddr = (*Trailer) &0xfff; int TrailerWordWCount = ((*Trailer)>>16)&0x3ff; if (evn_version<196610) { if (fnch[TrailerWordHWAddr>>7]>0x7f) { (*Trailer) |= 0x800; } fnch[TrailerWordHWAddr>>7]++; } PrintAltroChannel( Trailer ); ptr -= 8; // skip trailer (5) + 3 short wordShift = 6 - (TrailerWordWCount % 4)*2; for(int i = 0 ; i < TrailerWordWCount; i++){ fchanneltemp = get10BitWord( (unsigned short *) ptr, wordShift ); wordShift-=2; ptr--; if( wordShift == -2) { wordShift = 6; ptr-- ; } // fprintf(stdout,"%d ",fchanneltemp); } channel[0] = TrailerWordHWAddr; return TrailerWordWCount/4+2; } int ProcessEquipment(char *ptr, int evn_version){ struct equipmentHeaderStruct * eheader= (struct equipmentHeaderStruct *) (ptr); PrintEquipmentHeader(eheader); short Pad[2000]; unsigned char * data = (unsigned char *) (((struct equipmentStruct * )(ptr))->equipmentRawData); unsigned int * fmemory = (unsigned int *) data; int size = eheader->equipmentSize; const int hsize = sizeof(struct equipmentHeaderStruct); //Equipment Size is WITHOUT the Header of the Equipment !! in the old Version ! if (evn_version<196610) { size = size + hsize; for (int i=0;i<32;i++) fnch[i]=0; } if (eheader->equipmentType!= 17) return size; const int fsize = (size-hsize)/4; int f40BitArraySize = fmemory[fsize-1]; // last word of the equipment int n40BitWords = f40BitArraySize-1; const int offset=28; unsigned char *cptr =&data[f40BitArraySize*5+offset-1];// last data pointer int k=0; while( n40BitWords >0){ int wc = ProcessAltroChannel(cptr,Pad, evn_version); n40BitWords -= wc; cptr-=5*wc; k++; }; fprintf(stdout,"AltroChannels %d\n", k); return size; } int ProcessEvent(char *ptr){ char *eptr = ptr; struct eventHeaderStruct * event = (struct eventHeaderStruct *) (ptr); int esize = event->eventSize; int size = esize; // skip header size = event->eventHeadSize; eptr += size; esize -= size; PrintEventHeader(event); if (event->eventType != PHYSICS_EVENT) return event->eventSize; while (esize>0 && size>0){ if(TEST_SYSTEM_ATTRIBUTE( event->eventTypeAttribute, ATTR_SUPER_EVENT ) == 1){ size = ProcessEvent(eptr); } else { size = ProcessEquipment(eptr, event->eventVersion); } eptr += size; esize -= size; } return event->eventSize; } int main(int argc, char **argv) { int status; // status = monitorSetDataSource( ":" ); if (argc<2){ fprintf(stderr,"Usage %s \n",argv[0]); fprintf(stderr,"%s /data2/run98.012.raw\n",argv[0]); exit(1); } status = monitorSetDataSource( argv[1] ); if ( status != 0 ) printError( "monitorSetDataSource", status ); status = monitorDeclareMp( "C demo mp" ); if ( status != 0 ) printError( "monitorDeclareMp", status ); for (;;){ /* Start of endless loop */ void *ptr; struct eventHeaderStruct *event; status = monitorGetEventDynamic( &ptr ); if ( status != 0 ) printError( "monitorGetEventDynamic", status ); event = (struct eventHeaderStruct *)ptr; ProcessEvent((char *) ptr); free( ptr ); } /* End of endless loop */ } /* End of main */