Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 /* 
0002 ** CframeV1.h
0003 ** 
0004 ** Author: $Author: purschke $  
0005 **   Date: $Date: 2000/07/21 01:51:10 $ 
0006 ** 
0007 ** $Log: CframeV1.h,v $
0008 ** Revision 1.1.1.1  2000/07/21 01:51:10  purschke
0009 ** mlp -- adding the new automakified "basic" module to CVS.
0010 **
0011 **
0012 ** Revision 1.9  1999/05/17 19:47:06  markacs
0013 ** (stephen) added findNextError and whole indirection chain
0014 **
0015 ** Revision 1.8  1999/04/16 20:12:10  markacs
0016 ** (stephen) fixing findFrameErrorStart, findFrameHistoryStart, adjustFrameLength to deal correctly with padding
0017 **
0018 ** Revision 1.7  1999/04/13 18:27:37  markacs
0019 ** (stephen) put history block access in
0020 **
0021 ** Revision 1.6  1998/12/16 15:40:51  markacs
0022 ** (stephen markacs) changes to rawFormat code to stop using bool,true,false
0023 **
0024 ** Revision 1.5  1998/12/11 22:01:12  markacs
0025 ** (stephen markacs) adding log into cvs tags
0026 ** 
0027 */
0028 /*
0029 ** CframeV1.h
0030 **
0031 ** Now contains combination of old CframeV1.h and CframeV1.C.
0032 ** This change was made to allow inlining
0033 ** 
0034 ** The layout of the file is as follows:
0035 **
0036 ** (1) definition of version-dependent field parameters
0037 ** (2) includes of phenixOnline.h, etc.
0038 ** (3) prototypes of functions defined later in this file
0039 ** (4) include of Cframe.h
0040 ** (5) defintion of V1 functions
0041 **
0042 **
0043 ** For additional comments, see Cframe.h
0044 **
0045 */
0046 
0047 #ifndef _CFRAMEV1_
0048 #define _CFRAMEV1_
0049 
0050 #ifdef __cplusplus
0051 extern "C" {
0052 #endif
0053 
0054 #include "phenixOnline.h"
0055 #include "formatError.h"
0056 #include "framePublic.h"
0057 #include "frameV1Public.h"
0058 #include "frameHdrV1.h"
0059 #include "Cframe.h"
0060 
0061 /*
0062 **  Function prototype definitions
0063 **  ============================================================
0064 */
0065 
0066 VALUE_ret makeFrameHdrV1 (PHDWORD*, UINT, UINT, UINT, UINT);
0067 VALUE_ret getFrameDataLengthV1 (FRAME_ptr);
0068 VALUE_ret adjustFrameHistoryLengthV1 (FRAME_ptr, UINT);
0069 VALUE_ret adjustFrameErrorLengthV1 (FRAME_ptr, UINT);
0070 VALUE_ret orFrameStatusV1 (FRAME_ptr, UINT);
0071 
0072 INLINE_P LOGIC_ret validFrameHdrV1 (FRAME_ptr);
0073 INLINE_P LOGIC_ret emptyFrameV1 (FRAME_ptr);
0074 
0075 INLINE_P VALUE_ret getFrameErrorLengthV1 (FRAME_ptr);
0076 INLINE_P VALUE_ret getFrameHistoryLengthV1 (FRAME_ptr);
0077 INLINE_P VALUE_ret getFrameAlignLengthV1 (FRAME_ptr);
0078 INLINE_P VALUE_ret getFramePaddingV1 (FRAME_ptr);
0079 
0080 INLINE_P VALUE_ret getFrameSourceIdV1 (FRAME_ptr);
0081 INLINE_P VALUE_ret getFrameTypeV1 (FRAME_ptr);
0082 INLINE_P VALUE_ret getFrameDataTypeV1 (FRAME_ptr);
0083 INLINE_P VALUE_ret getFrameStatusV1 (FRAME_ptr);
0084 
0085 INLINE_P VALUE_ret adjustFrameDataLengthV1 (FRAME_ptr, UINT);
0086 INLINE_P VALUE_ret setFramePaddingV1 (FRAME_ptr, UINT);
0087 
0088 INLINE_P LOGIC_ret setDataTypeV1(FRAME_ptr, UINT);
0089 INLINE_P LOGIC_ret setFrameTypeV1(FRAME_ptr, UINT);
0090 INLINE_P LOGIC_ret setSourceIdV1(FRAME_ptr, UINT);
0091 INLINE_P LOGIC_ret setFrameHistoryLengthV1(FRAME_ptr, UINT);
0092 INLINE_P LOGIC_ret setFrameErrorLengthV1(FRAME_ptr, UINT);
0093 INLINE_P LOGIC_ret setFrameAlignLengthV1(FRAME_ptr, UINT);
0094 INLINE_P LOGIC_ret setFrameStatusV1(FRAME_ptr, UINT);
0095 
0096 INLINE_P PTR_ret findFrameAlignBlockV1 (FRAME_ptr);
0097 INLINE_P PTR_ret findFrameErrorStartV1 (FRAME_ptr);
0098 INLINE_P PTR_ret findFrameHistoryStartV1 (FRAME_ptr);
0099 
0100 INLINE_P VALUE_ret getAlignBlockV1 (FRAME_ptr, PHDWORD*, UINT);
0101 INLINE_P LOGIC_ret setAlignBlockV1 (FRAME_ptr, PHDWORD*, UINT);
0102 
0103 INLINE_P VALUE_ret getHistoryEntryV1 (FRAME_ptr, UINT);
0104 INLINE_P VALUE_ret getHistoryStageV1 (FRAME_ptr, UINT);
0105 INLINE_P VALUE_ret getHistorySourceIndexV1 (FRAME_ptr, UINT);
0106 INLINE_P VALUE_ret getHistoryStatusV1 (FRAME_ptr, UINT);
0107 
0108 /* note: the following three are not referenced by indirection
0109    from outside */
0110 INLINE_P VALUE_ret getStageFromHistoryEntryV1 (PHDWORD);  
0111 INLINE_P VALUE_ret getSourceIndexFromHistoryEntryV1 (PHDWORD);
0112 INLINE_P VALUE_ret getStatusFromHistoryEntryV1 (PHDWORD);
0113 
0114 INLINE_P PTR_ret findNextErrorV1 (FRAME_ptr, FRAME_ptr);
0115 
0116 /*
0117 ** Inlined routines
0118 ** ============================================================
0119 */
0120 
0121 /* Check to see if this can really be a valid V1 header 
0122 */
0123 INLINE_D LOGIC_ret validFrameHdrV1 (FRAME_ptr frame_ptr)
0124 {
0125   if (getFrameHdrLength(frame_ptr) == V1_FRAMEHDR_LENGTH) {
0126     setFrameSuccess();
0127     return TRUE;
0128   }
0129   else {
0130     setFrameError (FORMAT_ERR_INVALID_HEADER, frame_ptr, 0);
0131     return FALSE;
0132   }
0133 }
0134 
0135 
0136 /* Check to see if this is an empty frame.
0137 */
0138 INLINE_D LOGIC_ret emptyFrameV1 (FRAME_ptr frame_ptr)
0139 {
0140   return getFrameHdrLength(frame_ptr) == getFrameLength(frame_ptr);
0141 }
0142 
0143 
0144 INLINE_D VALUE_ret getFramePaddingV1 (FRAME_ptr frame_ptr)
0145 {
0146   return getBitsMACRO(frame_ptr,               
0147               PADDING_OFFSET_OF_DWORD,
0148                       PADDING_OFFSET_IN_DWORD, 
0149               PADDING_MASK            );
0150 }
0151 
0152 
0153 INLINE_D VALUE_ret getFrameSourceIdV1 (FRAME_ptr frame_ptr)
0154 {
0155   return getBitsMACRO(frame_ptr,                 
0156               SOURCE_ID_OFFSET_OF_DWORD,
0157                       SOURCE_ID_OFFSET_IN_DWORD, 
0158               SOURCE_ID_MASK            );
0159 }
0160 
0161 
0162 INLINE_D VALUE_ret getFrameDataTypeV1 (FRAME_ptr frame_ptr)
0163 {
0164   return getBitsMACRO(frame_ptr,                 
0165               DATA_TYPE_OFFSET_OF_DWORD,
0166                       DATA_TYPE_OFFSET_IN_DWORD, 
0167               DATA_TYPE_MASK            );
0168 }
0169 
0170 
0171 INLINE_D VALUE_ret getFrameTypeV1 (FRAME_ptr frame_ptr)
0172 {
0173   return getBitsMACRO(frame_ptr,                  
0174               FRAME_TYPE_OFFSET_OF_DWORD,
0175                       FRAME_TYPE_OFFSET_IN_DWORD, 
0176               FRAME_TYPE_MASK           );
0177 }
0178 
0179 
0180 INLINE_D VALUE_ret getFrameStatusV1 (FRAME_ptr frame_ptr)
0181 {
0182   return getBitsMACRO(frame_ptr,              
0183               STATUS_OFFSET_OF_DWORD,
0184                       STATUS_OFFSET_IN_DWORD, 
0185               STATUS_MASK            );
0186 }
0187 
0188 
0189 INLINE_D VALUE_ret getFrameErrorLengthV1 (FRAME_ptr frame_ptr) 
0190 {
0191   return getBitsMACRO(frame_ptr,                    
0192               ERROR_LENGTH_OFFSET_OF_DWORD,
0193                       ERROR_LENGTH_OFFSET_IN_DWORD, 
0194               ERROR_LENGTH_MASK           );
0195 }
0196 
0197 
0198 INLINE_D VALUE_ret getFrameHistoryLengthV1 (FRAME_ptr frame_ptr) 
0199 {
0200   return getBitsMACRO(frame_ptr,                       
0201               HISTORY_LENGTH_OFFSET_OF_DWORD,
0202                       HISTORY_LENGTH_OFFSET_IN_DWORD,  
0203               HISTORY_LENGTH_MASK           );
0204 }
0205 
0206 
0207 INLINE_D VALUE_ret getFrameAlignLengthV1 (FRAME_ptr frame_ptr) 
0208 {
0209   return getBitsMACRO(frame_ptr,                      
0210               ALIGN_LENGTH_OFFSET_OF_DWORD,
0211                       ALIGN_LENGTH_OFFSET_IN_DWORD,   
0212               ALIGN_LENGTH_MASK            );
0213 }
0214 
0215 
0216 /* Return pointer to start of error block in frame 
0217 */
0218 INLINE_D PTR_ret findFrameErrorStartV1 (FRAME_ptr frame_ptr)
0219 {
0220   return frame_ptr + getFrameLength(frame_ptr) 
0221                    - getFrameErrorLengthV1(frame_ptr)
0222                    - getFramePadding(frame_ptr); 
0223 }
0224 
0225 
0226 /* Return pointer to start of history block in frame 
0227 */
0228 INLINE_D PTR_ret findFrameHistoryStartV1 (FRAME_ptr frame_ptr)
0229 {
0230   return frame_ptr + getFrameLength(frame_ptr) 
0231                    - getFrameErrorLengthV1(frame_ptr)
0232                    - getFrameHistoryLengthV1(frame_ptr)
0233                    - getFramePadding(frame_ptr);
0234 }
0235 
0236 
0237 /* Return pointer to start of alignment block */
0238 INLINE_D PTR_ret findFrameAlignBlockV1 (FRAME_ptr frame_ptr)
0239 {
0240   return frame_ptr + ALIGN_OFFSET_OF_DWORD;
0241 }
0242 
0243 INLINE_D VALUE_ret setFramePaddingV1 (FRAME_ptr frame_ptr, UINT numPadDwords)
0244 {
0245   setBitsMACRO(frame_ptr,
0246                PADDING_OFFSET_OF_DWORD,
0247                PADDING_OFFSET_IN_DWORD,
0248                PADDING_MASK,
0249                numPadDwords            );
0250   return TRUE;
0251 }
0252 
0253 
0254 /*
0255 **  Adjust the size of the data block in the frame header.
0256 **
0257 **    Note: this routine is only intended to change an explicit
0258 **          size that appears in a header. For V1 frames no such
0259 **          field is present so we simply return the current data
0260 **          block size.
0261 */
0262 
0263 INLINE_D UINT adjustFrameDataLengthV1 (FRAME_ptr frame_ptr, UINT newDwords)
0264 {
0265   UINT currentDataLength = getFrameDataLengthV1 (frame_ptr);
0266 
0267   if (currentDataLength == valueFailure)
0268     return valueFailure;
0269   else
0270     return currentDataLength + newDwords; 
0271 }
0272 
0273 INLINE_D LOGIC_ret setDataTypeV1(FRAME_ptr frame_ptr, UINT dataType)
0274 {
0275 #ifndef DCM_CHECK
0276  if (dataType > maxByteValue) return FALSE;
0277 #endif
0278  setBitsMACRO(frame_ptr,
0279               DATA_TYPE_OFFSET_OF_DWORD,
0280           DATA_TYPE_OFFSET_IN_DWORD,
0281               DATA_TYPE_MASK,
0282               dataType                  );
0283  return TRUE;
0284 }
0285 
0286 
0287 INLINE_D LOGIC_ret setFrameTypeV1(FRAME_ptr frame_ptr, UINT frameType)
0288 {
0289 #ifndef DCM_CHECK
0290   if (frameType > maxByteValue) return FALSE;
0291 #endif
0292   setBitsMACRO(frame_ptr,
0293                FRAME_TYPE_OFFSET_OF_DWORD,
0294                FRAME_TYPE_OFFSET_IN_DWORD,
0295                FRAME_TYPE_MASK,
0296                frameType                  );
0297   return TRUE;
0298 }
0299 
0300 
0301 INLINE_D LOGIC_ret setSourceIdV1(FRAME_ptr frame_ptr, UINT sourceId)
0302 {
0303 #ifndef DCM_CHECK
0304   if (sourceId > maxSwordValue) return FALSE;
0305 #endif
0306   setBitsMACRO(frame_ptr,
0307                SOURCE_ID_OFFSET_OF_DWORD,
0308                SOURCE_ID_OFFSET_IN_DWORD,
0309                SOURCE_ID_MASK,
0310                sourceId                   );
0311   return TRUE;
0312 }
0313 
0314 
0315 INLINE_D LOGIC_ret setFrameHistoryLengthV1(FRAME_ptr frame_ptr, UINT historyLength)
0316 {
0317 #ifndef DCM_CHECK
0318   if (historyLength > maxSwordValue) return FALSE;
0319 #endif
0320   setBitsMACRO(frame_ptr,
0321                HISTORY_LENGTH_OFFSET_OF_DWORD,
0322                HISTORY_LENGTH_OFFSET_IN_DWORD,
0323                HISTORY_LENGTH_MASK,
0324                historyLength                   );
0325   return TRUE;
0326 }
0327 
0328 
0329 INLINE_D LOGIC_ret setFrameErrorLengthV1(FRAME_ptr frame_ptr, UINT errorLength)
0330 {
0331 #ifndef DCM_CHECK
0332   if (errorLength > maxSwordValue) return FALSE;
0333 #endif
0334   setBitsMACRO(frame_ptr,
0335                ERROR_LENGTH_OFFSET_OF_DWORD,
0336                ERROR_LENGTH_OFFSET_IN_DWORD,
0337                ERROR_LENGTH_MASK,
0338                errorLength                    );
0339   return TRUE;
0340 }
0341 
0342 
0343 INLINE_D LOGIC_ret setFrameAlignLengthV1(FRAME_ptr frame_ptr, UINT alignLength)
0344 {
0345 #ifndef DCM_CHECK
0346   if (alignLength > maxByteValue) return FALSE;
0347 #endif
0348   setBitsMACRO(frame_ptr,
0349                ALIGN_LENGTH_OFFSET_OF_DWORD,
0350            ALIGN_LENGTH_OFFSET_IN_DWORD,
0351                ALIGN_LENGTH_MASK,
0352                alignLength                   );
0353   return TRUE;
0354 }
0355 
0356 INLINE_D LOGIC_ret setFrameStatusV1(FRAME_ptr frame_ptr, UINT status)
0357 {
0358 #ifndef DCM_CHECK
0359   if (status > maxSwordValue) return FALSE;
0360 #endif
0361   setBitsMACRO(frame_ptr,
0362            STATUS_OFFSET_OF_DWORD,
0363            STATUS_OFFSET_IN_DWORD,
0364            STATUS_MASK,
0365            status                  );
0366   return TRUE;
0367 }
0368 
0369 
0370 INLINE_D VALUE_ret getAlignBlockV1 (FRAME_ptr frame_ptr, PHDWORD* alignDestination, 
0371                UINT maxNumDwords)
0372 {
0373   UINT alignLength = getFrameAlignLength(frame_ptr);
0374   if (maxNumDwords < alignLength) return valueFailure;
0375   dwordCopy(alignDestination, (frame_ptr+ALIGN_OFFSET_OF_DWORD), alignLength);
0376   return alignLength;
0377 }
0378 
0379 
0380 INLINE_D LOGIC_ret setAlignBlockV1 (FRAME_ptr frame_ptr, PHDWORD* alignSource, 
0381                UINT numDwords)
0382 {
0383   UINT alignLength = getFrameAlignLength(frame_ptr);
0384   if (numDwords != alignLength) return FALSE;
0385   dwordCopy((frame_ptr+ALIGN_OFFSET_OF_DWORD), alignSource, alignLength);
0386   return TRUE;
0387 }
0388 
0389 /* get entry in history block by entry index, where indices count
0390    from THE BOTTOM */
0391 
0392 INLINE_D VALUE_ret getHistoryEntryV1 (FRAME_ptr frame_ptr, UINT index)
0393 {
0394   UINT historyLength = getFrameHistoryLength(frame_ptr);
0395   if (index>=historyLength) return valueFailure;
0396   return *(findFrameHistoryStart(frame_ptr)+(historyLength-index-1));
0397 }
0398 
0399 INLINE_D VALUE_ret getStageFromHistoryEntryV1(PHDWORD historyEntry)
0400 {
0401   return (historyEntry&0xf0000000)>>28;
0402 }
0403 
0404 INLINE_D VALUE_ret getSourceIndexFromHistoryEntryV1(PHDWORD historyEntry)
0405 {
0406   return (historyEntry&0x0fff0000)>>16;
0407 }
0408 
0409 INLINE_D VALUE_ret getStatusFromHistoryEntryV1(PHDWORD historyEntry)
0410 {
0411   return historyEntry&0x0000ffff;
0412 }
0413 
0414 INLINE_D VALUE_ret getHistoryStageV1(FRAME_ptr frame_ptr, UINT index)
0415 {
0416   return getStageFromHistoryEntryV1(getHistoryEntryV1(frame_ptr,index));
0417 }
0418 
0419 INLINE_D VALUE_ret getHistorySourceIndexV1(FRAME_ptr frame_ptr, UINT index)
0420 {
0421   return getSourceIndexFromHistoryEntryV1(getHistoryEntryV1(frame_ptr,index));
0422 }
0423 
0424 INLINE_D VALUE_ret getHistoryStatusV1(FRAME_ptr frame_ptr, UINT index)
0425 {
0426   return getStatusFromHistoryEntryV1(getHistoryEntryV1(frame_ptr,index));
0427 }
0428 
0429 INLINE_D PTR_ret findNextErrorV1(FRAME_ptr frame_ptr, FRAME_ptr thisError)
0430 {
0431   if (thisError < findFrameErrorStart(frame_ptr) || 
0432       thisError > findFrameEnd(frame_ptr) ) return ptrFailure;
0433   PHDWORD errorType = *thisError;
0434   FRAME_ptr temp_ptr;
0435   switch (errorType)
0436   {
0437   case 1111573574: temp_ptr = thisError+3; break;             // "BADF" : bad frame
0438   case 1296651078: temp_ptr = thisError+2; break;              // "MISF" : missing frame
0439   case 1111573584: temp_ptr = thisError+4; break;               // "BADP" : bad packet
0440   case 1296651088: temp_ptr = thisError+3; break;                // "MISP" : missing packet
0441   case 1430537542: temp_ptr = thisError+(*(thisError+1)); break; // "UDEF" : undefined error
0442           default: return ptrFailure;
0443   }
0444   if (temp_ptr > findFrameEnd(frame_ptr)) return ptrFailure;
0445   return temp_ptr;
0446 }
0447 
0448 #ifdef __cplusplus
0449 }
0450 #endif
0451 
0452 #endif /* end of ifndef _CFRAMEV1_ */
0453 
0454 
0455 
0456 
0457 
0458 
0459 
0460 
0461 
0462 
0463 
0464