littleendian_strings.cxx File Reference

#include <cstring>
#include "Rtypes.h"
#include "RawData/littleendian_strings.h"

Go to the source code of this file.

Functions

UInt_t nwords_in_string (const Char_t *x)
void pack_string_in_lel (Int_t *dest_i, const Char_t *src_c)
Char_t * unpack_lel_to_string (const Int_t *src_i, UInt_t nwd)

Function Documentation

UInt_t nwords_in_string ( const Char_t *  x  ) 

Definition at line 7 of file littleendian_strings.cxx.

Referenced by pack_string_in_lel(), RawConfigFilesBlock::RawConfigFilesBlock(), RawRunCommentBlock::RawRunCommentBlock(), and RawRunConfigBlock::RawRunConfigBlock().

00007                                          {
00008    // add 1 for \0, pad up to the next Int_t
00009    UInt_t csize = strlen(x);
00010    return ((csize+1)+(sizeof(Int_t)-1))/sizeof(Int_t);
00011 }

void pack_string_in_lel ( Int_t *  dest_i,
const Char_t *  src_c 
)

Definition at line 14 of file littleendian_strings.cxx.

References minos_htolel, and nwords_in_string().

Referenced by RawConfigFilesBlock::RawConfigFilesBlock(), RawRunCommentBlock::RawRunCommentBlock(), and RawRunConfigBlock::RawRunConfigBlock().

00014                                                             {
00015    // Put string in an array of little endian long words (32 bit)
00016    // pad out to full word as necessary
00017    // Assume destination has sufficient space
00018 
00019    UInt_t nchar = strlen(src_c);
00020    UInt_t nwd   = nwords_in_string(src_c);
00021 
00022    Char_t* dest_c = (Char_t*) dest_i;
00023 
00024    dest_i[nwd-1] = 0;           // pad out last full word to zeros
00025    memcpy(dest_c,src_c,nchar);  // copy up to '\0'
00026 
00027    // byte swap as necessary to get little endian ordering
00028    for (UInt_t i=0; i<nwd; ++i) 
00029       dest_i[i] = (Int_t)minos_htolel((UInt_t)dest_i[i]);
00030 }

Char_t* unpack_lel_to_string ( const Int_t *  src_i,
UInt_t  nwd 
)

Definition at line 33 of file littleendian_strings.cxx.

References minos_letohl.

Referenced by RawConfigFilesBlock::GetConfigFile(), RawRunCommentBlock::GetRunComment(), and RawRunConfigBlock::GetRunConfig().

00033                                                              {
00034    // return the string that is packed into an array of little endian
00035    // long words (32 bit)
00036    // NOTE: the user is responsible for deleting this memory
00037   
00038    const UInt_t cperl = sizeof(Int_t)/sizeof(Char_t);
00039 
00040    UInt_t nchar = nwd*cperl;
00041 
00042    Char_t* dest_c = new Char_t [nchar];
00043    Int_t*  dest_i = (Int_t*) dest_c;
00044    const Char_t* src_c  = (const Char_t*) src_i;
00045    memcpy(dest_c,src_c,nchar);
00046 
00047    // byte swap as necessary to deal with original little endian-ness
00048    for (UInt_t i=0; i<nwd; ++i) 
00049       dest_i[i] = (Int_t)minos_letohl((UInt_t)dest_i[i]);
00050 
00051    return dest_c;
00052 }


Generated on 8 Jul 2019 for loon by  doxygen 1.6.1