Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "packet_idcstr.h"
0002 #include <stdio.h>
0003 
0004 Packet_idcstr::Packet_idcstr(PACKET_ptr data)
0005   : Packet_w1 (data)
0006 {
0007   sarray = 0;
0008 }
0009   
0010 Packet_idcstr::~Packet_idcstr()
0011 {
0012   if ( sarray) delete [] sarray;
0013 }
0014 
0015 
0016 int Packet_idcstr::iValue(const int i)
0017 {
0018 
0019   int n;
0020   if ( ! sarray ) decode ( &n);
0021 
0022   if ( i < 0 || i >= allocated_length)
0023     {
0024       return 0;
0025     }
0026 
0027   int c = sarray[i];
0028   return c;
0029 
0030 }
0031 
0032 
0033 
0034 int *Packet_idcstr::decode ( int *nwout)
0035 {
0036 
0037   int dlength = getDataLength();
0038 
0039   // std::cout << __FILE__ << "  " << __LINE__ << " datalength: " 
0040   //        << getDataLength() << " padding " << getPadding() << std::endl;
0041 
0042   if ( dlength <=0) dlength =1; // need at least an array of 1
0043    
0044   unsigned char *SubeventData = ( unsigned char * ) findPacketDataStart(packet);
0045   sarray = new unsigned char[dlength+1];
0046   memcpy ( sarray, SubeventData,dlength); 
0047   sarray[dlength] = 0;
0048   allocated_length = dlength;
0049 
0050   return 0;
0051 
0052 }
0053 
0054 void Packet_idcstr::dump ( OSTREAM &os)
0055 {
0056 
0057   int n;
0058   if ( ! sarray ) decode ( &n);
0059 
0060   os.write( (const char *) sarray, allocated_length);
0061   os << std::flush;
0062 
0063 }
0064