Detecting endianess of platform at runtime and generating warning if not on a little...
[u/mrichter/AliRoot.git] / HLT / MUON / utils / dHLTdumpraw.cxx
index dbbde5ecf2535641e63f093ddfe237ed8c1838d5..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;
@@ -1347,6 +1362,10 @@ int main(int argc, const char** argv)
                                unsigned long bufferSize = 0;
                                returnCode = ReadFile(filename[i], buffer, bufferSize);
                                if (returnCode != EXIT_SUCCESS) break;
+                               if (numOfFiles > 1)
+                               {
+                                       cout << "########## Start of dump for file: " << filename[i] << " ##########" << endl;
+                               }
                                int result = ParseBuffer(buffer, bufferSize, continueParse, filetype[i]);
                                if (buffer != NULL) delete [] buffer;
                                if (result != EXIT_SUCCESS)
@@ -1354,6 +1373,10 @@ int main(int argc, const char** argv)
                                        returnCode = result;
                                        if (not continueParse) break;
                                }
+                               if (numOfFiles > 1)
+                               {
+                                       cout << "##########   End of dump for file: " << filename[i] << " ##########" << endl;
+                               }
                        }
                }