// File: /workspace/github_cpp_makefile_star2_O2/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::ReadHM1Header()
__int32	LMF_IO::ReadHM1Header()
/////////////////////////////////////////////////////////////////
{
	__int32		byte_counter;
	byte_counter = 0;

	HM1.use_normal_method = false;

	*input_lmf >> frequency;	byte_counter += sizeof(double);		// frequency is always 4th value
	*input_lmf >> IOaddress;	byte_counter += sizeof(__int32);		// IO address (parameter 1) always 5th value
	*input_lmf >> timestamp_format;	byte_counter += sizeof(__int32);	// TimeInfo (parameter 2) always 6th value  (0,1,2)*32Bit

	*input_lmf >> DAQ_info_Length;	byte_counter += sizeof(__int32);		// Length of DAQInfo always 7th value
	__int8 * __int8_temp = new __int8[DAQ_info_Length+1];
	input_lmf->read(__int8_temp,DAQ_info_Length);	// DAQInfo always 8th value
	__int8_temp[DAQ_info_Length] = 0;
	DAQ_info = __int8_temp;
	delete[] __int8_temp; __int8_temp = 0;
	byte_counter += DAQ_info_Length;


	__int32 nominalHeaderLength;
	nominalHeaderLength = sizeof(__int32)*21 + sizeof(double)*2 + DAQ_info_Length;	// size of user defined header
	if (DAQ_ID == DAQ_ID_HM1_ABM) nominalHeaderLength += 24*sizeof(__int32);

	if (DAQVersion >= 20080507) HM1.use_normal_method = true;

	if ((unsigned) nominalHeaderLength == User_header_size) HM1.use_normal_method = true;

	if (DAQVersion >= 20020408 && HM1.use_normal_method) {
		*input_lmf >> LMF_Version; byte_counter += sizeof(__int32);
	}

	*input_lmf >> system_timeout; byte_counter += sizeof(__int32);		//   system time-out
	*input_lmf >> time_reference; byte_counter += sizeof(__int32);
	*input_lmf >> HM1.FAK_DLL_Value; byte_counter += sizeof(__int32);
	*input_lmf >> HM1.Resolution_Flag; byte_counter += sizeof(__int32);
	*input_lmf >> HM1.trigger_mode_for_start; byte_counter += sizeof(__int32);
	*input_lmf >> HM1.trigger_mode_for_stop; byte_counter += sizeof(__int32);
	*input_lmf >> tdcresolution; byte_counter += sizeof(double);		// tdc resolution in ns

	if (DAQVersion >= 20020408 && HM1.use_normal_method) {
		*input_lmf >> TDCDataType; byte_counter += sizeof(__int32);
	}

	*input_lmf >> HM1.Even_open_time; byte_counter += sizeof(__int32);
	*input_lmf >> HM1.Auto_Trigger; byte_counter += sizeof(__int32);

	if (DAQVersion >= 20020408) {
		__int64 i64_dummy;
		*input_lmf >> i64_dummy; number_of_channels = (unsigned __int32)i64_dummy; byte_counter += sizeof(__int64);			// number of channels
		*input_lmf >> i64_dummy; max_number_of_hits = (unsigned __int32)i64_dummy; byte_counter += sizeof(__int64);			// number of hits
	} else {
	*input_lmf >> number_of_channels; byte_counter += sizeof(__int32);			// number of channels
	*input_lmf >> max_number_of_hits; byte_counter += sizeof(__int32);			// number of hits
	}
	if (int(number_of_channels) > num_channels)	{errorflag = 19;	return -100000;}
	if (int(max_number_of_hits) > num_ions)		{errorflag = 20;	return -100000;}
	*input_lmf >> HM1.set_bits_for_GP1; byte_counter += sizeof(__int32);
	*input_lmf >> data_format_in_userheader;	byte_counter += sizeof(__int32);				// data format (2=short integer)
	*input_lmf >> module_2nd;	byte_counter += sizeof(__int32);		// indicator for 2nd module data

	if (DAQ_ID == DAQ_ID_2HM1) {
		*input_lmf >> DAQSubVersion;						byte_counter += sizeof(__int32);
		*input_lmf >> HM1.TWOHM1_FAK_DLL_Value;				byte_counter += sizeof(__int32);  // parameter 10-1
		*input_lmf >> HM1.TWOHM1_Resolution_Flag;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.TWOHM1_trigger_mode_for_start;	byte_counter += sizeof(__int32);
		*input_lmf >> HM1.TWOHM1_trigger_mode_for_stop;		byte_counter += sizeof(__int32);
		*input_lmf >> HM1.TWOHM1_res_adjust;				byte_counter += sizeof(__int32);
		*input_lmf >> HM1.TWOHM1_tdcresolution;				byte_counter += sizeof(double);
		*input_lmf >> HM1.TWOHM1_test_overflow;				byte_counter += sizeof(__int32);
		*input_lmf >> HM1.TWOHM1_number_of_channels;		byte_counter += sizeof(__int32);
		*input_lmf >> HM1.TWOHM1_number_of_hits;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.TWOHM1_set_bits_for_GP1;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.TWOHM1_HM1_ID_1;					byte_counter += sizeof(__int32);
		*input_lmf >> HM1.TWOHM1_HM1_ID_2;					byte_counter += sizeof(__int32);
	}

	if (DAQ_ID == DAQ_ID_HM1_ABM) {
		max_number_of_hits = 1;
		*input_lmf >> HM1.ABM_m_xFrom;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_m_xTo;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_m_yFrom;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_m_yTo;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_m_xMin;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_m_xMax;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_m_yMin;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_m_yMax;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_m_xOffset;		byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_m_yOffset;		byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_m_zOffset;		byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_Mode;				byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_OsziDarkInvert;	byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_ErrorHisto;		byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_XShift;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_YShift;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_ZShift;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_ozShift;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_wdShift;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_ucLevelXY;		byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_ucLevelZ;			byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_uiABMXShift;		byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_uiABMYShift;		byte_counter += sizeof(__int32);
		*input_lmf >> HM1.ABM_uiABMZShift;		byte_counter += sizeof(__int32);
		if (DAQVersion > 20080507) {
			__int32 i32Dummy;
			*input_lmf >> i32Dummy;		byte_counter += sizeof(__int32);
		}
	}

	if (DAQ_ID == 1 && DAQVersion == 20080507 && LMF_Version == 7) {
		input_lmf->flush();
		input_lmf->seek(Headersize+User_header_size);
		input_lmf->flush();
	}

	return byte_counter;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
xorl %ebp, %ebp
movb %bpl, 0x13bc(%rdi)
movq 0x2b18(%rdi), %rdi
leaq 0x12c8(%rbx), %rsi
callq 0x110e4
movq 0x2b18(%rbx), %rdi
leaq 0x2a4(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x2a8(%rbx), %rsi
callq 0x10d66
movq 0x2b18(%rbx), %rdi
leaq 0x129c(%rbx), %rsi
callq 0x10fca
movslq 0x129c(%rbx), %r14
movq %r14, %rdi
incq %rdi
callq 0x2030
movq %rax, %r15
movq 0x2b18(%rbx), %rdi
movq %rax, %rsi
movl %r14d, %edx
callq 0x10d8a
movslq 0x129c(%rbx), %rax
movb %bpl, (%r15,%rax)
leaq 0xa0(%rbx), %rdi
movq %r15, %rsi
callq 0x2230
movq %r15, %rdi
callq 0x21a0
movl 0x129c(%rbx), %r12d
movl 0x280(%rbx), %eax
leal 0x64(%r12), %edx
cmpl $0x6, 0x288(%rbx)
leal 0xc4(%r12), %ecx
cmovnel %edx, %ecx
cmpl $0x132677b, %eax        # imm = 0x132677B
jb 0x5821
movb $0x1, 0x13bc(%rbx)
cmpl 0x29c(%rbx), %ecx
jne 0x5830
movb $0x1, 0x13bc(%rbx)
leaq 0x1340(%rbx), %r14
leal 0x14(%r12), %r15d
cmpl $0x1317cb8, %eax        # imm = 0x1317CB8
jb 0x5866
cmpb $0x1, 0x13bc(%rbx)
jne 0x5866
movq 0x2b18(%rbx), %rdi
leaq 0x12a4(%rbx), %rsi
callq 0x10fca
addl $0x18, %r12d
movl %r12d, %r15d
movq 0x2b18(%rbx), %rdi
leaq 0x128c(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x240(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
movq %r14, %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1344(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1348(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x134c(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x12b8(%rbx), %rsi
callq 0x110e4
leal 0x20(%r15), %ebp
cmpl $0x1317cb8, 0x280(%rbx) # imm = 0x1317CB8
jb 0x591a
cmpb $0x1, 0x13bc(%rbx)
jne 0x591a
movq 0x2b18(%rbx), %rdi
leaq 0x12ac(%rbx), %rsi
callq 0x10fca
addl $0x24, %r15d
movl %r15d, %ebp
movq 0x2b18(%rbx), %rdi
leaq 0x1350(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1354(%rbx), %rsi
callq 0x10fca
cmpl $0x1317cb8, 0x280(%rbx) # imm = 0x1317CB8
jb 0x5986
movq 0x2b18(%rbx), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x110f6
movl (%r14), %eax
movl %eax, 0x2b4(%rbx)
movq 0x2b18(%rbx), %rdi
movq %r14, %rsi
callq 0x110f6
movl (%r14), %eax
movl %eax, 0x2bc(%rbx)
addl $0x18, %ebp
jmp 0x59af
movq 0x2b18(%rbx), %rdi
leaq 0x2b4(%rbx), %rsi
callq 0x10d66
movq 0x2b18(%rbx), %rdi
leaq 0x2bc(%rbx), %rsi
callq 0x10d66
addl $0x10, %ebp
movl 0x2b4(%rbx), %eax
cmpl 0x2b70(%rbx), %eax
jle 0x59c9
movl $0x13, 0x12e0(%rbx)
jmp 0x59e1
movl 0x2bc(%rbx), %eax
cmpl 0x2b74(%rbx), %eax
jle 0x59f5
movl $0x14, 0x12e0(%rbx)
movl $0xfffe7960, %ebp       # imm = 0xFFFE7960
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x2b18(%rbx), %rdi
leaq 0x1358(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x290(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1288(%rbx), %rsi
callq 0x10fca
movl 0x288(%rbx), %eax
cmpl $0x4, %eax
jne 0x5b3f
movq 0x2b18(%rbx), %rdi
leaq 0x1284(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13c0(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13c4(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13c8(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13cc(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13d0(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13d8(%rbx), %rsi
callq 0x110e4
movq 0x2b18(%rbx), %rdi
leaq 0x13e0(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13e4(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13e8(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13ec(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13f0(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13f4(%rbx), %rsi
callq 0x10fca
addl $0x44, %ebp
movl 0x288(%rbx), %eax
jmp 0x5b42
addl $0xc, %ebp
cmpl $0x6, %eax
jne 0x5d42
movl $0x1, 0x2bc(%rbx)
movq 0x2b18(%rbx), %rdi
leaq 0x135c(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1360(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1364(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1368(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x136c(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1370(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1374(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1378(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x137c(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1380(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1384(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1388(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x138c(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1390(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1394(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x1398(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x139c(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13a0(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13a4(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13a8(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13ac(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13b0(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13b4(%rbx), %rsi
callq 0x10fca
movq 0x2b18(%rbx), %rdi
leaq 0x13b8(%rbx), %rsi
callq 0x10fca
cmpl $0x132677c, 0x280(%rbx) # imm = 0x132677C
jb 0x5d3f
movq 0x2b18(%rbx), %rdi
leaq 0x4(%rsp), %rsi
callq 0x10fca
addl $0x64, %ebp
jmp 0x5d42
addl $0x60, %ebp
cmpl $0x1, 0x288(%rbx)
jne 0x59e6
cmpl $0x132677b, 0x280(%rbx) # imm = 0x132677B
jne 0x59e6
cmpl $0x7, 0x12a4(%rbx)
jne 0x59e6
movq 0x2b18(%rbx), %rdi
callq 0x110dc
movq 0x2b18(%rbx), %rdi
movl 0x29c(%rbx), %esi
addl 0x298(%rbx), %esi
callq 0x235c
movq 0x2b18(%rbx), %rdi
callq 0x110dc
jmp 0x59e6
nop