Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataBlock.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file dataBlock.C
1 /*
2 ** dataBlock.C
3 **
4 ** Author: $Author: phoncs $
5 ** Date: $Date: 2010/09/21 19:37:49 $
6 **
7 ** $Log: dataBlock.C,v $
8 ** Revision 1.2 2010/09/21 19:37:49 phoncs
9 ** DLW: change name of DWORD to PHDWORD
10 **
11 ** Revision 1.1.1.1 2000/07/21 01:51:11 purschke
12 ** mlp -- adding the new automakified "basic" module to CVS.
13 **
14 **
15 ** Revision 1.4 1998/12/11 22:02:00 markacs
16 ** (stephen markacs) adding log into cvs tags
17 **
18 */
19 /*
20 ** These are the routines for acces to and modification
21 ** of the data block descriptor which are not inlined within
22 ** dataBlock.h.
23 **/
24 #include "dataBlock.h"
25 
26 /*
27 ** Return the number of "words" stored in the unstructured block
28 ** where a word is defined by the length stored in the descriptor
29 */
31 {
32  PHDWORD dataBlockLengthDwords, dataBlockLengthBytes, paddingBytes;
33 
34  dataBlockLengthDwords = getPacketDataLength(packet_ptr);
35  if (dataBlockLengthDwords == valueFailure) return valueFailure;
36 
37  dataBlockLengthBytes = dataBlockLengthDwords*DWORD_SIZE;
38  paddingBytes = getUnstructPacketDataPadding(packet_ptr);
39  return dataBlockLengthBytes - paddingBytes;
40 }
41 
42 /*
43 ** Return the number of "words" stored in the unstructured block
44 ** where a word is defined by the length stored in the descriptor
45 */
47 {
48  PHDWORD dataLengthBytes = getUnstructPacketDataLengthBytes(packet_ptr);
49  UINT wordSize = getUnstructPacketWordSize(packet_ptr);
50  PHDWORD dataLengthWords = dataLengthBytes/wordSize;
51 
52  if (dataLengthBytes % wordSize != 0) {
53  setPacketError(FORMAT_ERR_DATA_INCONSISTENCY,packet_ptr,dataLengthBytes);
54  return valueFailure;
55  }
56  else return dataLengthWords;
57 }
58 
59 /*
60 ** Returns the length in DWORDS of the data block after addWords
61 ** "words" of size wordSize are added to the data block in the
62 ** packet. Updates the padding field in the packet.
63 */
65  UINT addWords)
66 {
67  PHDWORD currentLength;
68  PHDWORD newLength, newLengthBytes, newLengthDwords;
69  UINT newPadding;
70  UINT modulo;
71 
72  /*
73  ** Get the current data block length
74  */
75  currentLength = getUnstructPacketDataLengthWords(packet_ptr);
76  if (currentLength == valueFailure) return valueFailure;
77 
78  /*
79  ** Calculate the new length
80  */
81  newLength = currentLength + addWords;
82  newLengthBytes = newLength*getUnstructPacketWordSize(packet_ptr);
83 
84  /*
85  ** Calculate the new length in dwords
86  */
87  modulo = newLengthBytes % DWORD_SIZE;
88  if (modulo > 0) newPadding = DWORD_SIZE - modulo;
89  else newPadding = 0;
90 
91  newLengthDwords = (newLengthBytes + newPadding)/DWORD_SIZE;
92 
93  /*
94  ** Now set the padding field
95  */
96  setUnstructPacketDataPadding(packet_ptr, newPadding);
97 
98  return newLengthDwords;
99 }