Пример #1
0
// Fill the SysParams structure entries from externally parsed line
int SysParams_Parse( SysParams *params, int line_num )
{
	int bec;
	int ret;

	// Check for Null pointer
	if( params == (SysParams *)NULL )
	{
		fprintf( stderr, "%s: params=0\n", __FUNCTION__ );
		return D_RetCode_Err_Null_Pointer;
	}

	if( argc > 0 )
	{
		if( ( strcmp( argv[0], "Sys" ) == 0 ) || ( strcmp( argv[0], "MVT_Sys" ) == 0 ) || ( strcmp( argv[0], "FTT_Sys" ) == 0 ) )
		{
			// Common system parameters
			if( strcmp( argv[1], "Name" ) == 0 )
				sprintf( params->Name, "%s", argv[2]);
			else if( strcmp( argv[1], "RunMode" ) == 0 )
			{
				if( strcmp( argv[2], "Standalone" ) == 0 )
					params->RunMode = Standalone;
				else if( strcmp( argv[2], "Clas12" ) == 0 )
					params->RunMode = Clas12;
				else if( strcmp( argv[2], "Expert" ) == 0 )
					params->RunMode = Expert;
				else if( strcmp( argv[2], "Undefined" ) == 0 )
				{
					params->RunMode = SysModUdef;
					fprintf( stderr, "%s: line %d: Sys RunMode explicitly set to Undefined\n", __FUNCTION__, line_num ); 
					return D_RetCode_Err_Wrong_Param;
				}
				else
				{
					params->RunMode = SysModUdef;
					fprintf( stderr, "%s: line %d: attempt to set unknown Sys RunMode %s\n", __FUNCTION__, line_num, argv[2] ); 
					return D_RetCode_Err_Wrong_Param;
				}
			}
			else if( strcmp( argv[1], "ClkMode" ) == 0 )
			{
				if( strcmp( argv[2], "Smp48_Rd48" ) == 0 )
					params->ClkMode = Smp48_Rd48;
				else if( strcmp( argv[2], "Smp44_Rd44" ) == 0 )
					params->ClkMode = Smp44_Rd44;
				else if( strcmp( argv[2], "Smp40_Rd40" ) == 0 )
					params->ClkMode = Smp40_Rd40;
				else if( strcmp( argv[2], "Smp36_Rd36" ) == 0 )
					params->ClkMode = Smp36_Rd36;
				else if( strcmp( argv[2], "Smp32_Rd32" ) == 0 )
					params->ClkMode = Smp32_Rd32;
				else if( strcmp( argv[2], "Smp24_Rd48" ) == 0 )
					params->ClkMode = Smp24_Rd48;
				else if( strcmp( argv[2], "SysClkUdef" ) == 0 )
				{
					params->ClkMode = SysClkUdef;
					fprintf( stderr, "%s: line %d: Sys ClkMode explicitly set to Undefined\n", __FUNCTION__, line_num ); 
					return D_RetCode_Err_Wrong_Param;
				}
				else
				{
					params->ClkMode = SysClkUdef;
					fprintf( stderr, "%s: line %d: attempt to set unknown Sys ClkMode %s\n", __FUNCTION__, line_num, argv[2] ); 
					return D_RetCode_Err_Wrong_Param;
				}
			}
			else if( strcmp( argv[1], "SparseSmp" ) == 0 )
			{
				params->SparseSmp = atoi( argv[2] );
				// Check the parameter: has to be derived from FeuConfigParams.h
				if( (params->SparseSmp < 0) || (7 < params->SparseSmp) )
				{
					params->SparseSmp = 0;
					fprintf( stderr, "%s: line %d: attempt to set unsupported SparseSmp %s; must be in [0,7]\n", __FUNCTION__, line_num, argv[2] ); 
					return D_RetCode_Err_Wrong_Param;
				}
			}
			else if( strcmp( argv[1], "NbOfSmpPerEvt" ) == 0 )
			{
				params->NbOfSmpPerEvt = atoi( argv[2] );
				// Check the parameter: has to be derived from FeuConfigParams.h
				if( (params->NbOfSmpPerEvt < 1) || (256 < params->NbOfSmpPerEvt) )
				{
					params->NbOfSmpPerEvt = 0;
					fprintf( stderr, "%s: line %d: attempt to set unsupported NbOfSmpPerEvt %s; must be in [1,256]\n", __FUNCTION__, line_num, argv[2] ); 
					return D_RetCode_Err_Wrong_Param;
				}
			}
			else if( strcmp( argv[1], "NbOfEvtPerBlk" ) == 0 )
			{
				params->NbOfEvtPerBlk = atoi( argv[2] );
				// Check the parameter: has to be derived from BeuConfigParams.h
				if( (params->NbOfEvtPerBlk < 1) || (256 < params->NbOfEvtPerBlk) )
				{
					params->NbOfEvtPerBlk = 0;
					fprintf( stderr, "%s: line %d: attempt to set unsupported NbOfEvtPerBlk %s; must be in [1,256]\n", __FUNCTION__, line_num, argv[2] ); 
					return D_RetCode_Err_Wrong_Param;
				}
			}
			else if( strcmp( argv[1], "BlockPrescale" ) == 0 )
			{
				params->BlockPrescale = atoi( argv[2] );
				if( (params->BlockPrescale <= 0) )
				{
					params->BlockPrescale = 1;
					fprintf( stderr, "%s: line %d: attempt to set negative or 0 BlockPrescale %s; must be positive\n", __FUNCTION__, line_num, argv[2] ); 
					return D_RetCode_Err_Wrong_Param;
				}
			}
			else if( strcmp( argv[1], "RepRawData" ) == 0 )
			{
				params->RepRawData = atoi( argv[2] );
				if( (params->RepRawData < 0) || (1 < params->RepRawData) )
				{
					params->RepRawData = 0;
					fprintf( stderr, "%s: line %d: attempt to set unsupported RepRawData %s; must be 0 or 1\n", __FUNCTION__, line_num, argv[2] ); 
					return D_RetCode_Err_Wrong_Param;
				}
			}
			else
			{
				fprintf( stderr, "%s: line %d: Unknown or empty keywod for Sys entry %s\n", __FUNCTION__, line_num, argv[1] ); 
				return D_RetCode_Err_Wrong_Param;
			}
		}			
		else if( ( strcmp( argv[0], "Bec" ) == 0 ) || ( strcmp( argv[0], "MVT_Bec" ) == 0 ) || ( strcmp( argv[0], "FTT_Bec" ) == 0 ) )
		{
			bec = atoi( argv[1] );
			if( (bec < 1) || (DEF_MAX_NB_OF_BEC < bec) )
			{
				fprintf( stderr, "%s: line %d: bec id %d out of range [1,%d]\n", __FUNCTION__, line_num, bec, DEF_MAX_NB_OF_BEC ); 
				return D_RetCode_Err_Wrong_Param;
			}
			if( (ret = BecParams_Parse( &(params->Bec_Params[bec]), line_num )) != D_RetCode_Sucsess )
			{
				fprintf( stderr, "%s: BecParams_Parse failed for bec %d with %d\n", __FUNCTION__, bec, ret );
				return ret;
			}
		}
		else if( ( strcmp( argv[0], "Ti" ) == 0 ) || ( strcmp( argv[0], "MVT_Ti" ) == 0 ) || ( strcmp( argv[0], "FTT_Ti" ) == 0 ) )
		{
			// Read TI parameters only in Standalone and Expert modes 
			if( params->RunMode != Clas12 )
			{
				bec = atoi( argv[1] );
				if( (bec < 0) || (DEF_MAX_NB_OF_BEC < bec) )
				{
					fprintf( stderr, "%s: line %d: ti id %d out of range [1,%d]\n", __FUNCTION__, line_num, bec, DEF_MAX_NB_OF_BEC ); 
					return D_RetCode_Err_Wrong_Param;
				}
				if( (ret = TiParams_Parse( &(params->Ti_Params[bec]), line_num )) != D_RetCode_Sucsess )
				{
					fprintf( stderr, "%s: TiParams_Parse failed for ti %d with %d\n", __FUNCTION__, bec, ret );
					return ret;
				}
			}
		}
		else if( ( strcmp( argv[0], "Beu" ) == 0 ) || ( strcmp( argv[0], "MVT_Beu" ) == 0 ) || ( strcmp( argv[0], "FTT_Beu" ) == 0 ) )
		{
			if( (ret = BeuSspConfCol_Parse( &(params->BeuSspConf_Col), line_num )) != D_RetCode_Sucsess )
			{
				fprintf( stderr, "%s: BeuSspConfCol_Parse failed with %d\n", __FUNCTION__, ret );
				return ret;
			}
		}
		else if( ( strcmp( argv[0], "Feu" ) == 0 ) || ( strcmp( argv[0], "MVT_Feu" ) == 0 ) || ( strcmp( argv[0], "FTT_Feu" ) == 0 ) )
		{
			if( (ret = FeuParamsCol_Parse( &(params->FeuParams_Col), line_num )) != D_RetCode_Sucsess )
			{
				fprintf( stderr, "%s: FeuParamsCol_Parse failed with %d\n", __FUNCTION__, ret );
				return ret;
			}
		}
	} // if( argc > 0 )

	// All went fine
	return D_RetCode_Sucsess;
}
Пример #2
0
// Fill the SysParams structure from an ASCII file
int SysParams_Fread( SysParams *params, FILE *fptr )
{
	char line[LINE_SIZE];
	int line_num;
	int bec;
	int ret;

	// Check for Null pointer
	if( params == (SysParams *)NULL )
	{
		fprintf( stderr, "%s: params=0\n", __FUNCTION__ );
		return D_RetCode_Err_Null_Pointer;
	}
	if( fptr == (FILE *)NULL )
	{
		fprintf( stderr, "%s: fptr=0\n", __FUNCTION__ );
		return D_RetCode_Err_Null_Pointer;
	}

	// Process parameter file
	line_num = 0;
	while( fgets( line, LINE_SIZE, fptr ) != NULL )
	{
		/* parse the line */
		parse_line(line);
		line_num++;
		if( argc > 0 )
		{
			if( strcmp( argv[0], "Sys" ) == 0 )
			{
				// Common system parameters
				if( strcmp( argv[1], "Name" ) == 0 )
					sprintf( params->Name, "%s", argv[2]);
				else if( strcmp( argv[1], "RunMode" ) == 0 )
				{
					if( strcmp( argv[2], "Standalone" ) == 0 )
						params->RunMode = Standalone;
					else if( strcmp( argv[2], "Clas12" ) == 0 )
						params->RunMode = Clas12;
					else if( strcmp( argv[2], "Expert" ) == 0 )
						params->RunMode = Expert;
					else if( strcmp( argv[2], "Undefined" ) == 0 )
					{
						params->RunMode = SysModUdef;
						fprintf( stderr, "%s: line %d: Sys RunMode explicitly set to Undefined\n", __FUNCTION__, line_num ); 
						return D_RetCode_Err_Wrong_Param;
					}
					else
					{
						params->RunMode = SysModUdef;
						fprintf( stderr, "%s: line %d: attempt to set unknown Sys RunMode %s\n", __FUNCTION__, line_num, argv[2] ); 
						return D_RetCode_Err_Wrong_Param;
					}
				}
				else if( strcmp( argv[1], "ClkMode" ) == 0 )
				{
					if( strcmp( argv[2], "Smp48_Rd48" ) == 0 )
						params->ClkMode = Smp48_Rd48;
					else if( strcmp( argv[2], "Smp44_Rd44" ) == 0 )
						params->ClkMode = Smp44_Rd44;
					else if( strcmp( argv[2], "Smp40_Rd40" ) == 0 )
						params->ClkMode = Smp40_Rd40;
					else if( strcmp( argv[2], "Smp36_Rd36" ) == 0 )
						params->ClkMode = Smp36_Rd36;
					else if( strcmp( argv[2], "Smp32_Rd32" ) == 0 )
						params->ClkMode = Smp32_Rd32;
					else if( strcmp( argv[2], "Smp24_Rd48" ) == 0 )
						params->ClkMode = Smp24_Rd48;
					else if( strcmp( argv[2], "SysClkUdef" ) == 0 )
					{
						params->ClkMode = SysClkUdef;
						fprintf( stderr, "%s: line %d: Sys ClkMode explicitly set to Undefined\n", __FUNCTION__, line_num ); 
						return D_RetCode_Err_Wrong_Param;
					}
					else
					{
						params->ClkMode = SysClkUdef;
						fprintf( stderr, "%s: line %d: attempt to set unknown Sys ClkMode %s\n", __FUNCTION__, line_num, argv[2] ); 
						return D_RetCode_Err_Wrong_Param;
					}
				}
				else if( strcmp( argv[1], "SparseSmp" ) == 0 )
				{
					params->SparseSmp = atoi( argv[2] );
					// Check the parameter: has to be derived from FeuConfigParams.h
					if( (params->SparseSmp < 0) || (1 < params->SparseSmp) )
					{
						params->SparseSmp = 0;
						fprintf( stderr, "%s: line %d: attempt to set unsupported SparseSmp %s; must be in [0,1]\n", __FUNCTION__, line_num, argv[2] ); 
						return D_RetCode_Err_Wrong_Param;
					}
				}
				else if( strcmp( argv[1], "NbOfSmpPerEvt" ) == 0 )
				{
					params->NbOfSmpPerEvt = atoi( argv[2] );
					// Check the parameter: has to be derived from FeuConfigParams.h
					if( (params->NbOfSmpPerEvt < 1) || (256 < params->NbOfSmpPerEvt) )
					{
						params->NbOfSmpPerEvt = 0;
						fprintf( stderr, "%s: line %d: attempt to set unsupported NbOfSmpPerEvt %s; must be in [1,256]\n", __FUNCTION__, line_num, argv[2] ); 
						return D_RetCode_Err_Wrong_Param;
					}
				}
				else if( strcmp( argv[1], "NbOfEvtPerBlk" ) == 0 )
				{
					params->NbOfEvtPerBlk = atoi( argv[2] );
					// Check the parameter: has to be derived from BeuConfigParams.h
					if( (params->NbOfEvtPerBlk < 1) || (256 < params->NbOfEvtPerBlk) )
					{
						params->NbOfEvtPerBlk = 0;
						fprintf( stderr, "%s: line %d: attempt to set unsupported NbOfEvtPerBlk %s; must be in [1,256]\n", __FUNCTION__, line_num, argv[2] ); 
						return D_RetCode_Err_Wrong_Param;
					}
				}
				else if( strcmp( argv[1], "BlockPrescale" ) == 0 )
				{
					params->BlockPrescale = atoi( argv[2] );
					if( (params->BlockPrescale < 0) )
					{
						params->BlockPrescale = 0;
						fprintf( stderr, "%s: line %d: attempt to set negative BlockPrescale %s; must be positive\n", __FUNCTION__, line_num, argv[2] ); 
						return D_RetCode_Err_Wrong_Param;
					}
				}
				else
				{
					fprintf( stderr, "%s: line %d: Unknown or empty keywod for Sys entry %s\n", __FUNCTION__, line_num, argv[1] ); 
					return D_RetCode_Err_Wrong_Param;
				}
			}			
			else if( strcmp( argv[0], "Bec" ) == 0 )
			{
				bec = atoi( argv[1] );
				if( (bec < 1) || (DEF_MAX_NB_OF_BEC < bec) )
				{
					fprintf( stderr, "%s: line %d: bec id %d out of range [1,%d]\n", __FUNCTION__, line_num, bec, DEF_MAX_NB_OF_BEC ); 
					return D_RetCode_Err_Wrong_Param;
				}
				if( (ret = BecParams_Parse( &(params->Bec_Params[bec]), line_num )) != D_RetCode_Sucsess )
				{
					fprintf( stderr, "%s: BecParams_Parse failed for bec %d with %d\n", __FUNCTION__, bec, ret );
					return ret;
				}
			}
			else if( strcmp( argv[0], "Ti" ) == 0 )
			{
				bec = atoi( argv[1] );
				if( (bec < 0) || (DEF_MAX_NB_OF_BEC < bec) )
				{
					fprintf( stderr, "%s: line %d: ti id %d out of range [1,%d]\n", __FUNCTION__, line_num, bec, DEF_MAX_NB_OF_BEC ); 
					return D_RetCode_Err_Wrong_Param;
				}
				if( (ret = TiParams_Parse( &(params->Ti_Params[bec]), line_num )) != D_RetCode_Sucsess )
				{
					fprintf( stderr, "%s: TiParams_Parse failed for ti %d with %d\n", __FUNCTION__, bec, ret );
					return ret;
				}
			}
			else if( strcmp( argv[0], "Beu" ) == 0 )
			{
				if( (ret = BeuSspConfCol_Parse( &(params->BeuSspConf_Col), line_num )) != D_RetCode_Sucsess )
				{
					fprintf( stderr, "%s: BeuSspConfCol_Parse failed with %d\n", __FUNCTION__, ret );
					return ret;
				}
			}
			else if( strcmp( argv[0], "Feu" ) == 0 )
			{
				if( (ret = FeuParamsCol_Parse( &(params->FeuParams_Col), line_num )) != D_RetCode_Sucsess )
				{
					fprintf( stderr, "%s: FeuParamsCol_Parse failed with %d\n", __FUNCTION__, ret );
					return ret;
				}
			}
		} // if( argc > 0 )
	} // while( fgets( line, LINE_SIZE, fptr ) != NULL )

	// All went fine
	return D_RetCode_Sucsess;
}