Byte Swapping

Hello,

I am running ROOT 4.04/02g on Mac OS 10.4.7. I am writing code to analyze list-mode gamma spectra generated on a Windows PC. Consequently, the byte ordering in the binary file is different between the two platforms. Currently I process the binary file with a standalone C++ program, which uses the nonstandard C++ function “swab()” (compiled with gcc 4.0.0) to swap bytes rather elegantly in one line of code, and produce an intermediate file that is read by my ROOT application. The swab() method does not appear to be supported in ROOT.

I would like to read data from the binary files directly into my ROOT application. Does there exist a method in ROOT to swap bytes?

Thanks very much for any feedback.

Cheers,
Bryan

Simply compile your script (via ACLiC) or generate a dictionary entry for the swab function. You can do the later easily (also using ACLiC)
With the file myswab.h#include <unistd.h> void swab(const void *from, void *to, ssize_t n);
do

and now swab is available on the root command line.

Cheers,
Philippe

Hello Phillipe,

Thanks very much! Your suggestion worked perfectly.

Regards,
Bryan