Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:44

0001 /* 
0002 ** dataBlock.C
0003 ** 
0004 ** Author: $Author: phoncs $  
0005 **   Date: $Date: 2010/09/21 19:37:49 $ 
0006 ** 
0007 ** $Log: dataBlock.C,v $
0008 ** Revision 1.2  2010/09/21 19:37:49  phoncs
0009 ** DLW: change name of DWORD to PHDWORD
0010 **
0011 ** Revision 1.1.1.1  2000/07/21 01:51:11  purschke
0012 ** mlp -- adding the new automakified "basic" module to CVS.
0013 **
0014 **
0015 ** Revision 1.4  1998/12/11 22:02:00  markacs
0016 ** (stephen markacs) adding log into cvs tags
0017 ** 
0018 */
0019 /*
0020 **  These are the routines for acces to and modification 
0021 **  of the data block descriptor which are not inlined within
0022 **  dataBlock.h.  
0023 **/
0024 #include "dataBlock.h"
0025 
0026 /*
0027 **  Return the number of "words" stored in the unstructured block
0028 **    where a word is defined by the length stored in the descriptor
0029 */
0030 VALUE_ret getUnstructPacketDataLengthBytes (PACKET_ptr packet_ptr)
0031 {
0032   PHDWORD dataBlockLengthDwords, dataBlockLengthBytes, paddingBytes;
0033 
0034   dataBlockLengthDwords = getPacketDataLength(packet_ptr);
0035   if (dataBlockLengthDwords == valueFailure) return valueFailure;
0036 
0037   dataBlockLengthBytes = dataBlockLengthDwords*DWORD_SIZE;
0038   paddingBytes = getUnstructPacketDataPadding(packet_ptr);
0039   return dataBlockLengthBytes - paddingBytes;
0040 }
0041 
0042 /*
0043 **  Return the number of "words" stored in the unstructured block
0044 **    where a word is defined by the length stored in the descriptor
0045 */
0046 VALUE_ret getUnstructPacketDataLengthWords (PACKET_ptr packet_ptr)
0047 {
0048   PHDWORD dataLengthBytes = getUnstructPacketDataLengthBytes(packet_ptr);
0049   UINT wordSize = getUnstructPacketWordSize(packet_ptr);
0050   PHDWORD dataLengthWords = dataLengthBytes/wordSize;
0051 
0052   if (dataLengthBytes % wordSize != 0) {
0053     setPacketError(FORMAT_ERR_DATA_INCONSISTENCY,packet_ptr,dataLengthBytes);
0054     return valueFailure;
0055   }
0056   else return dataLengthWords;
0057 }
0058 
0059 /*
0060 ** Returns the length in DWORDS of the data block after addWords
0061 **   "words" of size wordSize are added to the data block in the
0062 **   packet. Updates the padding field in the packet.
0063 */
0064 VALUE_ret extendUnstructPacketDataBlock (PACKET_ptr packet_ptr, 
0065                      UINT addWords)
0066 {
0067   PHDWORD currentLength;
0068   PHDWORD newLength, newLengthBytes, newLengthDwords;
0069   UINT newPadding;
0070   UINT modulo;
0071 
0072   /*
0073   ** Get the current data block length
0074   */
0075   currentLength = getUnstructPacketDataLengthWords(packet_ptr);
0076   if (currentLength == valueFailure) return valueFailure;
0077 
0078   /*
0079   ** Calculate the new length 
0080   */
0081   newLength = currentLength + addWords;
0082   newLengthBytes = newLength*getUnstructPacketWordSize(packet_ptr);
0083 
0084   /*
0085   **  Calculate the new length in dwords
0086   */
0087   modulo = newLengthBytes % DWORD_SIZE;
0088   if (modulo > 0) newPadding = DWORD_SIZE - modulo;
0089   else newPadding = 0;
0090 
0091   newLengthDwords = (newLengthBytes + newPadding)/DWORD_SIZE;
0092 
0093   /*
0094   **  Now set the padding field
0095   */
0096   setUnstructPacketDataPadding(packet_ptr, newPadding);
0097 
0098   return newLengthDwords;
0099 }