00001 /* @version $Revision: 1776 $ * @modifiedby $Author: jacquem $ * @lastmodified $Date: 2012-06-13 16:43:36 +0200 (Wed, 13 Jun 2012) $ */ 00002 00003 00004 #include "parser/AcquisitionParser.hh" 00005 #include "tools/Log.hh" 00006 00007 00008 using namespace std; 00009 00010 AcquisitionParser::AcquisitionParser(Run& aRun, FILE *anInputFile,ui32 _lastEventId) : run(aRun),computeCrc(false), skipNbEvent(0) { 00011 inputFile = anInputFile; 00012 lastEventId = _lastEventId; 00013 crc = new CrcCheck(); 00014 FILE_LOG(logDEBUG) << "--AcquisitionParser crc = new CrcCheck()["<< crc << "]" << endl; 00015 00016 00017 }; // AquisitionParser 00018 00019 00020 00021 //------------------------------------------------------------------- 00022 /* Convert given gray code into binary */ 00023 /* 1101011001 (gray) -> 1001101110 (binary) */ 00024 /* The purpose of this function is to convert an unsigned 00025 binary number to reflected binary Gray code. */ 00026 unsigned int AcquisitionParser::binaryToGray(unsigned int bin) { 00027 return (bin >> 1) ^ bin; 00028 } // binaryToGray 00029 00030 /* Convert given binary into gray code */ 00031 /* 1101011001 (binary) -> 1011110101 (gray) */ 00032 /* all codes give the same result */ 00033 00034 00035 //------------------------------------------------------------------- 00036 unsigned int AcquisitionParser::grayToBinary(unsigned int gray) { 00037 00038 // loop always for 32 bits 00039 unsigned int bin = ((gray >> 31) & 1) << 31; 00040 for (int bit = 30; bit >= 0; --bit) 00041 bin += ( ((gray >> bit) & 1) ^ ((bin >> (bit + 1)) & 1) ) << bit; 00042 return(bin); 00043 00044 00045 } // grayToBinary 00046 00047 00048 //------------------------------------------------------------------- 00049 void AcquisitionParser::setComputeCrcFlag(bool value ) 00050 { 00051 computeCrc = value ; 00052 if ( value == true ) 00053 { 00054 crc->reset() ; // reset crc value to 0xFFFF for next control 00055 } 00056 } 00057