Detecting endianess of platform at runtime and generating warning if not on a little...
authoraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 9 May 2008 12:56:30 +0000 (12:56 +0000)
committeraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 9 May 2008 12:56:30 +0000 (12:56 +0000)
HLT/MUON/utils/dHLTdumpraw.cxx

index 81891062de845fe0f8974f9470126cf855b31ec5..ad82fd84f5179aa5dd51c48fc5cc4c66f33f0f2c 100644 (file)
 
 #include "AliHLTMUONUtils.h"
 
-/*TODO: fix this. Need a platform independant way of checking the endian encoding.
- * This does not want to work on Apple Mac OS compiler: i686-apple-darw
- * Handle this with #ifdef __APPLE__ ?
-#include <endian.h>
-#ifndef LITTLE_ENDIAN
-#error Handling of internal data for non little endian machines not yet implemented.
-#endif
-*/
-
 #include <cstdlib>
 #include <cassert>
 #include <new>
@@ -1326,6 +1317,30 @@ int ParseCommandLine(
 
 int main(int argc, const char** argv)
 {
+       // Test endianess of this machine during runtime and print warning if it is not
+       // little endian.
+       union
+       {
+               int dword;
+               char byte[4];
+       } endianTest;
+       endianTest.dword = 0x1;
+       if (endianTest.byte[0] != 0x1)
+       {
+               cerr << "!!!! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!!!!" << endl;
+               cerr << "!!!! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!!!!" << endl;
+               cerr << "!!                                                                     !!" << endl;
+               cerr << "!! This is not a little endian machine, but dHLT raw data is normally  !!" << endl;
+               cerr << "!! generated in little endian format. Unless you are looking at localy !!" << endl;
+               cerr << "!! created simulated data, then this program will not show you correct !!" << endl;
+               cerr << "!! output.                                                             !!" << endl;
+               cerr << "!!                                                                     !!" << endl;
+               cerr << "!!!! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!!!!" << endl;
+               cerr << "!!!! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!!!!" << endl;
+               cerr << endl;
+       }
+
+
        int numOfFiles = 0;
        bool continueParse = false;
        int returnCode = EXIT_SUCCESS;