//_____________________________________________________________________________ void WordLoc::Load( const THaEvData& evdata ) { // Load data at header/notoskip position from crate data buffer typedef const UInt_t rawdata_t; Int_t roclen = evdata.GetRocLength(crate); if( roclen < ntoskip+1 ) return; rawdata_t* cratebuf = evdata.GetRawDataBuffer(crate), *endp = cratebuf+roclen; assert(cratebuf); // Must exist if roclen > 0 // Accelerated search for the header word. Coded explicitly because there // is no "memstr" in the standard library. //FIXME: Can this be made faster because each header is followed by the offset // to the next header? // Get the first byte of the header, regardless of byte order int h = ((UChar_t*)&header)[0]; rawdata_t* p = cratebuf; while( (p = (rawdata_t*)memchr(p,h,sizeof(rawdata_t)*(endp-p-1)+1)) && p <= endp-ntoskip-1 ) { // The header must be aligned at a word boundary int off = (p-cratebuf) & (sizeof(rawdata_t)-1); // same as % sizeof() if( off != 0 ) { p += sizeof(rawdata_t)-off; continue; } // Compare all 4 bytes of the header word if( memcmp(p,&header,sizeof(rawdata_t)) == 0 ) { // Fetch the requested word (as UInt_t, i.e. 4 bytes) // BTW, notoskip == 0 makes no sense since it would fetch the header itself data = *(p+ntoskip); break; } p += sizeof(rawdata_t); } }