Exemplo n.º 1
0
//
// Preparing drives for selected grunts.
//
void Manager::Prepare_Disks(int target)
{
	int i, loop_start, loop_finish;

	if (target == ALL_WORKERS) {
		// Preparing all grunts at the same time.  This requires a great
		// amount of coordination on the part of Iometer to ensure that the
		// grunts do not prepare the same drives.
		for (i = 0; i < grunt_count; i++) {
			if (!grunts[i]->Prepare_Disks()) {
				// Send failure message back to Iometer.
				msg.data = 0;
				if (IsBigEndian()) {
					(void)reorder(msg);
				}
				prt->Send(&msg);
				return;
			}
		}
		loop_start = 0;
		loop_finish = grunt_count;
	} else {
		// Preparing a single grunt.
		if (!grunts[target]->Prepare_Disks()) {
			// Send failure message back to Iometer.
			msg.data = 0;
			if (IsBigEndian()) {
				(void)reorder(msg);
			}
			prt->Send(&msg);
			return;
		}

		loop_start = target;
		loop_finish = loop_start + 1;
	}

	// Peek to see if the prepare was be canceled by the user.
	for (i = loop_start; i < loop_finish; i++) {
		while (grunts[i]->not_ready) {
			if (prt->Peek()) {
				prt->Receive(&msg);
				if (IsBigEndian()) {
					(void)reorder(msg);
				}
				Process_Message();
			} else {
				Sleep(LONG_DELAY);
			}
		}
		grunts[i]->grunt_state = TestIdle;
	}
	// Send a message back to Iometer to indicate that we're done preparing.
	msg.data = 1;		// indicates success
	if (IsBigEndian()) {
		(void)reorder(msg);
	}
	prt->Send(&msg);
}
Exemplo n.º 2
0
//
// Signalling to stop testing.
//
void Manager::Stop_Test(int target)
{
	if (target == ALL_WORKERS) {
		for (int i = 0; i < grunt_count; i++) {
			grunts[i]->Stop_Test();
		}
	} else {
		grunts[target]->Stop_Test();
	}

	cout << "Stopping..." << endl << flush;

	if (target == ALL_WORKERS) {
		for (int i = 0; i < grunt_count; i++) {
			grunts[i]->Wait_For_Stop();
		}
	} else {
		grunts[target]->Wait_For_Stop();
	}

	cout << "   Stopped." << endl << flush;

	// Reply that test has stopped.
	if (IsBigEndian()) {
		(void)reorder(msg);
	}
	prt->Send(&msg);

#if defined(IOMTR_OS_LINUX) || defined(IOMTR_OS_SOLARIS)
	if (do_syslog) {
		syslog(LOG_INFO, "I/O Stopped");
	}
#endif
}
Exemplo n.º 3
0
status_t
ArchitectureX8664::GetReturnAddressLocation(StackFrame* frame,
	target_size_t valueSize, ValueLocation*& _location)
{
	// for the calling conventions currently in use on Haiku,
	// the x86-64 rules for how values are returned are as follows:
	//
	// - 64 bit or smaller values are returned in RAX.
	// - > 64 bit values are returned on the stack.
	ValueLocation* location = new(std::nothrow) ValueLocation(
		IsBigEndian());
	if (location == NULL)
		return B_NO_MEMORY;
	BReference<ValueLocation> locationReference(location,
		true);

	if (valueSize <= 8) {
		ValuePieceLocation piece;
		piece.SetSize(valueSize);
		piece.SetToRegister(X86_64_REGISTER_RAX);
		if (!location->AddPiece(piece))
			return B_NO_MEMORY;
	} else {
		ValuePieceLocation piece;
		CpuStateX8664* state = dynamic_cast<CpuStateX8664*>(frame->GetCpuState());
		piece.SetToMemory(state->IntRegisterValue(X86_64_REGISTER_RAX));
		piece.SetSize(valueSize);
		if (!location->AddPiece(piece))
			return B_NO_MEMORY;
	}

	_location = locationReference.Detach();
	return B_OK;
}
Exemplo n.º 4
0
bool KlamptToROS(const Meshing::PointCloud3D& kpc,sensor_msgs::PointCloud2& pc)
{
  pc.is_bigendian = IsBigEndian();
  pc.height = 1;
  pc.width = kpc.points.size();
  pc.point_step = 4*(3+kpc.propertyNames.size());
  pc.row_step = pc.width*pc.point_step;
  pc.fields.resize(3+kpc.propertyNames.size());
  pc.fields[0].name = "x";
  pc.fields[1].name = "y";
  pc.fields[2].name = "z";
  for(size_t i=0;i<kpc.propertyNames.size();i++)
    pc.fields[3+i].name = kpc.propertyNames[i];
  for(size_t i=0;i<pc.fields.size();i++) {
    pc.fields[0].datatype = sensor_msgs::PointField::FLOAT32;
    pc.fields[0].offset = i*4;
    pc.fields[0].count = 1;
  }
  int ofs = 0;
  pc.data.resize(pc.row_step);
  for(size_t i=0;i<kpc.points.size();i++) {
    *(float*)&pc.data[ofs] = kpc.points[i].x; ofs += 4;
    *(float*)&pc.data[ofs] = kpc.points[i].y; ofs += 4;
    *(float*)&pc.data[ofs] = kpc.points[i].z; ofs += 4;
    for(size_t j=0;j<kpc.propertyNames.size();j++) {
      *(float*)&pc.data[ofs] = kpc.properties[i][j]; ofs += 4;
    }
  }
  return true;
}
Exemplo n.º 5
0
//
// Signalling all threads to begin performing I/O.
//
void Manager::Begin_IO(int target)
{
	msg.data = TRUE;
	cout << "Beginning to perform I/O..." << endl << flush;

#if defined(IOMTR_OS_LINUX) || defined(IOMTR_OS_SOLARIS)
	if (do_syslog) {
		syslog(LOG_INFO, "Beginning to perform I/O...");
	}
#endif

	if (target == ALL_WORKERS) {
		for (int i = 0; i < grunt_count; i++) {
			grunts[i]->Begin_IO();
			if (grunts[i]->critical_error)
				msg.data = FALSE;
		}
	} else {
		grunts[target]->Begin_IO();
		if (grunts[target]->critical_error)
			msg.data = FALSE;
	}
#ifdef _DEBUG
	cout << "   Performing I/O." << endl << flush;
#endif

	// Reply that I/O has started.
	if (IsBigEndian()) {
		(void)reorder(msg);
	}
	prt->Send(&msg);
}
Exemplo n.º 6
0
//
// Stopping recording of test results.
//
void Manager::Record_Off( int target )
{
	// Get performance data for end of test.
	Get_Performance( WHOLE_TEST_PERF, LAST_SNAPSHOT );
	Get_Performance( LAST_UPDATE_PERF, LAST_SNAPSHOT );

	if ( target == ALL_WORKERS )
	{
		for ( int i = 0; i < grunt_count; i++ )
		{
			grunts[i]->Record_Off();
		}
	}
	else
	{
		grunts[target]->Record_Off();
	}
	cout << "   Stopped." << endl << flush;

	record = FALSE;		// No workers are recording data.
	#if _DEBUG
		cout << "Recording stopped." << endl << flush;
	#endif
	if( IsBigEndian() )
	{
		(void) reorder(msg);
	}
	prt->Send( &msg );
}
Exemplo n.º 7
0
//
// Signalling all threads to begin performing I/O.
//
void Manager::Begin_IO( int target )
{
	msg.data = TRUE;
	cout << "Beginning to perform I/O..." << endl << flush;

	if ( target == ALL_WORKERS )
	{
		for ( int i = 0; i < grunt_count; i++ )
		{
			grunts[i]->Begin_IO();
			if ( grunts[i]->critical_error )
				msg.data = FALSE;
		}
	}
	else
	{
		grunts[target]->Begin_IO();
		if ( grunts[target]->critical_error )
			msg.data = FALSE;
	}
	#if _DEBUG
		cout << "   Performing I/O." << endl << flush;
	#endif

	// Reply that I/O has started.
	if( IsBigEndian() )
	{
		(void) reorder(msg);
	}
	prt->Send( &msg );
}
Exemplo n.º 8
0
uint32_t SwapEndianIfBig(uint32_t x) {
  if (IsBigEndian()) {
    return SwapEndian(x);
  } else {
    return x;
  }
}
Exemplo n.º 9
0
int AFMConn::WriteInt(int val)
{
	char buf[4];
	char* p = (char*)&val;

	if(1 == IsBigEndian())
	{
		buf[0]=p[0];
		buf[1]=p[1];
		buf[2]=p[2];
		buf[3]=p[3];		
	}
	else
	{		
		buf[0]=p[3];
		buf[1]=p[2];
		buf[2]=p[1];
		buf[3]=p[0];
	}
	
	int len = Send(buf, 4);
	if(len == -1)
	{
		printf("Conn WriteInt-1!!!!\n");
		return -1;
	}
	printf("Conn WriteInt retlen%d, %x\n",len, *((int*)buf));
	return val;
}
Exemplo n.º 10
0
/**
 * SPHSaverへのセーブ
 * @param filename セーブファイル名
 * @retval true  セーブ成功
 * @retval false セーブ失敗
 */
bool SPHSaver::Save(const char* filename){
    // @todo { double precision. }

    SphHeaderTop headerTop;
    SphHeaderSingle headerSingle;

    assert(m_volumeData->Component() == 1 || m_volumeData->Component() == 3);

    headerTop.svType = m_volumeData->Component() == 1 ? 1 : 2;
    headerTop.dType = 1; // float

    headerSingle.size[0] = static_cast<int>(m_volumeData->Width());
    headerSingle.size[1] = static_cast<int>(m_volumeData->Height());
    headerSingle.size[2] = static_cast<int>(m_volumeData->Depth());
    headerSingle.org[0]   = 0.0f;
    headerSingle.org[1]   = 0.0f;
    headerSingle.org[2]   = 0.0f;
    headerSingle.pitch[0] = 1.0f;
    headerSingle.pitch[1] = 1.0f;
    headerSingle.pitch[2] = 1.0f;
    headerSingle.step = 0;
    headerSingle.time = 0.0f;

    SphData sph(headerTop, headerSingle, m_volumeData->Buffer()->GetBuffer());

    std::string fname(filename);
    bool byteSwap = IsBigEndian();
    bool ret = SaveSphFile(&sph, fname, byteSwap);

	return ret;
}
Exemplo n.º 11
0
char GetEndianValue(void)
{
  if ( IsBigEndian() )
    return(1);

  return(0);
}
Exemplo n.º 12
0
//
// Manager runs assuming Iometer control.  Returns TRUE if Dynamo should
// continue to run, otherwise FALSE.
//
BOOL Manager::Run()
{
	while (TRUE)		// Receive loop.
	{
#ifdef _DEBUG
		cout << "in while loop : Manager::Run() " << endl;
#endif
		if ( prt->Receive( &msg ) == PORT_ERROR )
		{
			// Error receiving data message, stop running.
			cout << "Error receiving message." << endl << flush;
			return FALSE;
		}
		else
		{
			if( IsBigEndian() )
			{
				(void) reorder(msg);
			}
			// Continue to process messages until manager indicates stopping.
			if ( !Process_Message() )
				return FALSE;

			// On a reset, stop then restart running the manager.
			if ( msg.purpose == RESET )
				return TRUE;
		}
	}
}
Exemplo n.º 13
0
int IsSameEndian(int file)
{
  int system;

  system = IsBigEndian();

  if ( system == file )
    return(1);

  return(0);
}
Exemplo n.º 14
0
CLwoWriter::CLwoWriter(CFile* pFile, const fs::path& fileName):
m_curLayer(0)
{
	CLwoFile* pLwoFile = static_cast<CLwoFile*>(pFile);
	OBJ_ASSERT(pLwoFile);

	m_pLwoFile = pLwoFile;

	m_fileName = fileName;

	m_bWriteBinary = true;

	IsBigEndian(); // Make the base class call this instead
}
Exemplo n.º 15
0
short rotate2b(short var) {
  typedef union {
    short int i;
    char b[2];
  } int_um;

  if( IsBigEndian() == _true ) {
    int_um *ptr;
    char hilf;
    ptr = (int_um *) &var;
    hilf = ptr->b[0];
    ptr->b[0] = ptr->b[1];
    ptr->b[1] = hilf;
  }
  return var;
}
Exemplo n.º 16
0
/*******************************************************************
 * Changes byte construction if dbf is used on another platform
 * than Little Endian. dBASE databases are written in Little Endian
 * format.
 *******************************************************************/
unsigned int
rotate4b(u_int32_t var) {
	u_int32_t old, tmp;
	if(IsBigEndian() == _true) {
		tmp = old = var;
		// change Byte 4 with Byte 1
		tmp>>=24;
		var<<=24;
		var^=tmp;
		// change Byte 3 with Byte 2
		tmp=old;
		tmp<<=8;
		old>>=8;
		tmp &= 0x00FF0000;
		old &= 0x0000FF00;
		tmp |= old;
		var |= tmp;
	}
Exemplo n.º 17
0
//
// Starting a new grunt worker.  Sending a message back to Iometer indicating 
// the number of workers actually created.
//
void Manager::Add_Workers( int count )
{
	msg.data = 0;

	#if _DEBUG 
		cout << "Adding " << count << " new worker(s)." << endl << flush;
	#endif

	for ( int i = 0; i < count; i++ )
	{
		// Create a new grunt.
		if ( !(grunts[grunt_count] = new Grunt) )
			break;

		// Assign grunt to manager's data buffer by default.
		grunts[grunt_count]->read_data = data;
		grunts[grunt_count]->write_data = data;
		grunt_count++;
		msg.data++;
	}

	// See if we successfully create all workers requested.
	if ( msg.data != count )
	{
		// Failed to create all workers.
		while ( msg.data )
		{
			Remove_Workers( grunt_count-- );
			msg.data--;
		}
	}

#if _DEBUG
	cout << msg.data << " worker(s) are created." << endl;
#endif

	if( IsBigEndian() )
	{
		(void) reorder(msg);
	}
	
	prt->Send( &msg );
}
Exemplo n.º 18
0
int RPCClient::ReadInt()
{
	char buf[4];
	int val=0;	
	int len = Receive(buf, 4);
	
	if(len == -1)
		return -1;

	if(1 == IsBigEndian())
	{		
		val = *((int*)buf);		
	}
	else
	{	
		char* p = (char*)&val;
		p[0]=buf[3];
		p[1]=buf[2];
		p[2]=buf[1];
		p[3]=buf[0];
	}
	return val;
}
Exemplo n.º 19
0
int AFMConn::ReadInt()
{
	char buf[4];
	int val=0;
	int len = Receive(buf, 4);
	printf("Conn ReadInt ret len %d, buffer %x\n", len, *((int*)buf));
	if(len == -1)
		return -1;

	if(1 == IsBigEndian())
	{
		val = *(int*)buf;		
	}
	else
	{
		char* p = (char*)&val;
		p[0]=buf[3];
		p[1]=buf[2];
		p[2]=buf[1];
		p[3]=buf[0];
	}
	return val;
}
Exemplo n.º 20
0
int
main(int, char **)
{
	printf("IsBigEndian: %s\n", (IsBigEndian()) ? "yes" : "no");
	printf("IsBigEndian2: %s\n", (IsBigEndian2()) ? "yes" : "no");

	printDouble(1.0);
	printDouble(0.0);
	printDouble(12345.6789);
	ReconstructDouble(12345.6789);
	ReconstructDouble(123401234.567891234);
	double val = 123401234.567891234;

	printInt(1);
	printInt(0x10000);

	printf("Swap test\n");
	printDouble(val);
	DoSwap(val);
	printDouble(val);
	
	return 0;
}
Exemplo n.º 21
0
//
// Signalling to stop testing.
//
void Manager::Stop_Test( int target )
{
	if ( target == ALL_WORKERS )
	{
		for ( int i = 0; i < grunt_count; i++ )
		{
			grunts[i]->Stop_Test();
		}
	}
	else
	{
		grunts[target]->Stop_Test();
	}

	cout << "Stopping..." << endl << flush;

	if ( target == ALL_WORKERS )
	{
		for ( int i = 0; i < grunt_count; i++ )
		{
			grunts[i]->Wait_For_Stop();
		}
	}
	else
	{
		grunts[target]->Wait_For_Stop();
	}

	cout << "   Stopped." << endl << flush;

	// Reply that test has stopped.
	if( IsBigEndian() )
	{
		(void) reorder(msg);
	}
	prt->Send( &msg );
}
Exemplo n.º 22
0
int CDECL main(int argc, char *argv[])
{
	Manager *manager;
	char iometer[MAX_NETWORK_NAME];
	int error = 0;
	// struct dynamo_param param; //move up to global scope

#if defined(IOMTR_OS_LINUX)
	struct aioinit aioDefaults;

	memset(&aioDefaults, 0, sizeof(aioDefaults));
	aioDefaults.aio_threads = 32;
	aio_init(&aioDefaults);
	kstatfd = InitIoctlInterface();
#if defined(IOMTR_CPU_XSCALE)
	if ((ccntfd = InitCCNTInterface()) < 0) {
		exit(1);
	}
#endif
#endif

	Banner();

#if !defined(DO_NOT_PARSE_BEFORE_MANAGER)
	// In order to allow command line parameters to influence default values of
	// the Manager class members, we need to parse parameters before instantiating
	// the Manager, but to do this, we need to:

	// Setup local storage -- could just be in the global param structure???
	char blkdevlist[MAX_TARGETS][MAX_NAME];
	char manager_name[MAX_WORKER_NAME];
	char network_name[MAX_NETWORK_NAME];
	char exclude_filesys[MAX_EXCLUDE_FILESYS];

	// Init the local storage to match the original code
	iometer[0] = 0;
	manager_name[0] = 0;
	exclude_filesys[0] = 0;
	network_name[0] = 0;

	// Setup the param structure to defaults and to point to buffers above
	param.iometer = iometer;
	param.manager_name = manager_name;
	param.manager_computer_name = network_name;
	param.manager_exclude_fs = exclude_filesys;
	param.blkdevlist = &blkdevlist;
	param.login_port_number = 0;
	param.cpu_affinity = 0; // not specified or default
	param.timer_type = TIMER_UNDEFINED; // use the default
	param.disk_control = RAWDISK_VIEW_NOPART; // do not show raw disks with partitions

	// The manager's GetVersionString method is not available yet since it does not exist, 
	// so we do away with the variable and have ParseParam rely directly on the source of 
	// the strings in ioversion.h. Not too clean but functional...
	// g_pVersionStringWithDebug = NULL; // not needed

	// Parse params and then instantiate the manager next...
	ParseParam(argc, argv, &param);
#endif

	manager = new Manager;

#if !defined(DO_NOT_PARSE_BEFORE_MANAGER)
	// Restore the param globals retrieved above back to the manager
	// since the manager buffers were not available prior to the parse call.
	memcpy(manager->manager_name, manager_name, sizeof(manager_name));
	memcpy(manager->prt->network_name, network_name, sizeof(network_name));
	memcpy(manager->exclude_filesys, exclude_filesys, sizeof(exclude_filesys));
	memcpy(manager->blkdevlist, blkdevlist, sizeof(blkdevlist));
#else // defined(DO_NOT_PARSE_BEFORE_MANAGER) // the original code
	iometer[0] = 0;
	manager->manager_name[0] = 0;
	manager->exclude_filesys[0] = 0;

	//provide a temporary global ptr to the version string for Syntax() to use
	g_pVersionStringWithDebug = manager->GetVersionString(TRUE);

	param.iometer = iometer;
	param.manager_name = manager->manager_name;
	param.manager_computer_name = manager->prt->network_name;
	param.manager_exclude_fs = manager->exclude_filesys;
	param.blkdevlist = &manager->blkdevlist;
	param.login_port_number = 0;
	param.cpu_affinity = 0; // not specified or default
	param.timer_type = TIMER_UNDEFINED; // use the default
	param.disk_control = RAWDISK_VIEW_NOPART; // do not show raw disks with partitions

	ParseParam(argc, argv, &param);

	g_pVersionStringWithDebug = NULL;	//should use manager object after this...
#endif

	iomtr_set_cpu_affinity(param.cpu_affinity);

	// If there were command line parameters, indicate that they were recognized.
	if (iometer[0] || manager->manager_name[0]) {
		cout << "\nCommand line parameter(s):" << endl;

		if (iometer[0]) {
			cout << "   Looking for Iometer on \"" << iometer << "\"" << endl;
		}
		if (manager->manager_name[0]) {
			cout << "   New manager name is \"" << manager->manager_name << "\"" << endl;
		}
	}
	if (manager->exclude_filesys[0]) {
		cout << "\nExcluding the following filesystem types:" << endl;
		cout << "   \"" << manager->exclude_filesys << "\"" << endl;
	} else {
		strcpy(manager->exclude_filesys, DEFAULT_EXCLUDE_FILESYS);
	}
	// cout << endl;

#if defined(IOMTR_OSFAMILY_UNIX)
#if defined(IOMTR_OS_LINUX) || defined(IOMTR_OS_OSX)
	signal(SIGALRM, SIG_IGN);
#elif defined(IOMTR_OS_SOLARIS)
	sigignore(SIGALRM);
#else
#warning ===> WARNING: You have to do some coding here to get the port done!
#endif

	// Initialize the lock on UNIX platforms.
	if (pthread_mutex_init(&lock_mt, NULL)) {
		cout << "unable to init the lock" << endl;
		error = 1;
		goto CleanUp;
		//exit(1);
	}
	// Block SIGPIPE signal. Needed to ensure that Network worker
	// threads don't exit due to a broken pipe signal.
	sigset_t sigset;

	sigemptyset(&sigset);
	sigaddset(&sigset, SIGPIPE);
	if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0) {
		cout << "sigprocmask() call failed." << endl;
		cout << "dynamo could be unstable" << endl;
	}
	//
	// the number of file descriptors a process may create can be a small value like 64.
	//
	struct rlimit rlimitp;

	if (getrlimit(RLIMIT_NOFILE, &rlimitp) < 0) {
		cout << "error " << errno << " trying to get rlimit (# file descriptors)" << endl;
	} else {
		// it succeeded. We leave out atleast 25 file descriptors for non-targets
		// and compare with the hard limit.
		unsigned int targets = MAX_TARGETS + 25;

		if (rlimitp.rlim_max < targets) {
			cout << "Only " << rlimitp.rlim_max << " file descriptors available" << endl;
			rlimitp.rlim_cur = rlimitp.rlim_max;
		} else {
			// set the soft limit to the required value.
			rlimitp.rlim_cur = targets;
		}
		if (setrlimit(RLIMIT_NOFILE, &rlimitp) < 0) {
			cout << "error " << errno << " trying to set rlimit (# file descriptors)" << endl;
		}
	}

	// Check for super-user permissions. If not super-user, we
	// cannot get many of the info from the kernel.
	if (getuid() || geteuid()) {
		cout << "Dynamo not running as super-user." << endl;
		cout << "       All available disks might not be reported " << endl;
		cout << "       Cannot get TCP statistics from the kernel " << endl;
	}
#ifdef IOMTR_SETTING_OVERRIDE_FS
	// No command line args specifies destructive testing. Check to see if there
	// are any environment variables specifying the same. We need to warn the user.
	if (getenv("IOMTR_SETTING_OVERRIDE_FS") != NULL) {
		cout << "       ************ WARNING **************" << endl;
		cout << "       dynamo running in Destructive mode." << endl;
		cout << "         (overriding the not mounted fs)" << endl;
		cout << "       ************ WARNING **************" << endl;
	}
#endif				// IOMTR_SETTING_OVERRIDE_FS
#endif				// IOMTR_OSFAMILY_UNIX
#if defined(IOMTR_OSFAMILY_NETWARE)
	// Initialize the lock on NetWare platforms.
	if (pthread_mutex_init(&lock_mt, NULL)) {
		cout << "unable to init the lock" << endl;
		error = 1;
		goto CleanUp;
		//exit(1);
	}
#endif

#if defined(IOMTR_OSFAMILY_WINDOWS)
	// IOmeter/Dynamo now utilizes Windows UAC for privilege elevation,
	// but on version of Windows in which that is not supported we
	// match the UNIX output above.

	BOOL bReturned;
	SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
	PSID AdminGroup; 

	bReturned = AllocateAndInitializeSid(
		&NtAuthority,
		2,
		SECURITY_BUILTIN_DOMAIN_RID,
		DOMAIN_ALIAS_RID_ADMINS,
		0, 0, 0, 0, 0, 0,
		&AdminGroup); 

	if(bReturned) 
	{
		CheckTokenMembership( NULL, AdminGroup, &bReturned);

		if (!bReturned)
		{
			cout << "Dynamo not running as an administrator." << endl;
			cout << "       All available disks might not be reported " << endl;
			cout << endl;
		} 
		FreeSid(AdminGroup); 
	}
#endif

	// Ensure, that the endian type of the CPU is detectable
	if ((IsBigEndian() != 0) && (IsBigEndian() != 1)) {
		cout << "===> ERROR: Endian type of the CPU couldn't be detected." << endl;
		cout << "     [main() in " << __FILE__ << " line " << __LINE__ << "]" << endl;
		error = 1;
		goto CleanUp;
		//exit(1);
	}
	// Entering infinite loop to allow Dynamo to run multiple tests.  Outer while loop allows
	// Dynamo to be reset from Iometer.  If everything works smoothly, resets should be rare.
	while (TRUE) {
		// Initializing worker and logging into Iometer director.
		if (!manager->Login(iometer, param.login_port_number))
			break;

		// Manager will continue to run until an error, or stopped by Iometer.
		if (!manager->Run())
			break;	// Stop running when the manager is done.
	}
	cout << "Ending execution." << endl;
	Sleep(1000);

#if defined(IOMTR_OS_LINUX)
	CleanupIoctlInterface(kstatfd);
#if defined(IOMTR_CPU_XSCALE)
	CleanupCCNTInterface(ccntfd);
#endif
#endif

	//return (0);

CleanUp:
	if (manager) delete manager;
	if (error) exit(error);
	return (0);
}
Exemplo n.º 23
0
int ImageBase::readHDF5(size_t select_img)
{
    bool isStack = false;

    H5infoProvider provider = getProvider(fhdf5); // Provider name

    int errCode = 0;

    hid_t dataset;    /* Dataset and datatype identifiers */
    hid_t filespace;
    hsize_t dims[4]; // We are not going to support more than 4 dimensions, at this moment.
    hsize_t nobjEman;
    hid_t cparms;
    int rank;

    String dsname = filename.getBlockName();
    
    // Setting default dataset name
    if (dsname.empty())
    {
        dsname = provider.second;

        switch (provider.first)
        {
        case EMAN: // Images in stack are stored in separated groups
            hid_t grpid;
            grpid = H5Gopen(fhdf5,"/MDF/images/", H5P_DEFAULT);
            /*herr_t err = */
            H5Gget_num_objs(grpid, &nobjEman);
            dsname = formatString(dsname.c_str(), IMG_INDEX(select_img));
            H5Gclose(grpid);
            break;
        default:
        	break;
        }
    }
    else
    {
        switch (provider.first)
        {
        case EMAN: // Images in stack are stored in separated groups
            nobjEman=1;
            break;
        default:
            break;
        }
    }

    dataset = H5Dopen2(fhdf5, dsname.c_str(), H5P_DEFAULT);

    if( dataset < 0)
        REPORT_ERROR(ERR_IO_NOTEXIST, formatString("readHDF5: Dataset '%s' not found",dsname.c_str()));

    cparms = H5Dget_create_plist(dataset); /* Get properties handle first. */

    // Get dataset rank and dimension.
    filespace = H5Dget_space(dataset);    /* Get filespace handle first. */
    //    rank      = H5Sget_simple_extent_ndims(filespace);
    rank  = H5Sget_simple_extent_dims(filespace, dims, NULL);

    // Offset only set when it is possible to access to data directly
    offset = (H5D_CONTIGUOUS == H5Pget_layout(cparms))? H5Dget_offset(dataset) : 0;


    //    status = H5Dread(dataset, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm_out);

    hid_t h5datatype = H5Dget_type(dataset);

    // Reading byte order
    switch(H5Tget_order(h5datatype))
    {
    case H5T_ORDER_ERROR:
        REPORT_ERROR(ERR_IO, "readHDF5: error reading endianness.");
        break;
    case H5T_ORDER_LE:
        swap = IsBigEndian();
        break;
    case H5T_ORDER_BE:
        swap = IsLittleEndian();
        break;
    default:
        REPORT_ERROR(ERR_IO, "readHDF5: unknown endianness type, maybe mixed types.");
        break;
    }

    DataType datatype = datatypeH5(h5datatype);
    MDMainHeader.setValue(MDL_DATATYPE,(int) datatype);

    // Setting isStack depending on provider
    switch (provider.first)
    {
    case MISTRAL: // rank 3 arrays are stacks
        isStack = true;
        break;
        //    case EMAN: // Images in stack are stored in separated groups
    default:
    	break;
    }


    ArrayDim aDim;
    size_t nDimFile;
    aDim.xdim = dims[rank-1];
    aDim.ydim = (rank>1)?dims[rank-2]:1;
    aDim.zdim = (rank>3 || (rank==3 && !isStack))?dims[rank-3]:1;
    if ( provider.first == EMAN )
        nDimFile = nobjEman;
    else
        nDimFile = ( rank<3 || !isStack )?1:dims[0] ;

    if (select_img > nDimFile)
        REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS, formatString("readHDF5 (%s): Image number %lu exceeds stack size %lu", filename.c_str(), select_img, nDimFile));

    aDim.ndim = replaceNsize = (select_img == ALL_IMAGES)? nDimFile :1 ;
    setDimensions(aDim);

    //Read header only
    if(dataMode == HEADER || (dataMode == _HEADER_ALL && aDim.ndim > 1))
        return errCode;


    // EMAN stores each image in a separate dataset
    if ( provider.first == EMAN )
        select_img = 1;

    size_t   imgStart = IMG_INDEX(select_img);
    size_t   imgEnd = (select_img != ALL_IMAGES) ? imgStart + 1 : aDim.ndim;



    MD.clear();
    MD.resize(imgEnd - imgStart,MDL::emptyHeader);

    if (dataMode < DATA)   // Don't read  data if not necessary but read the header
        return errCode;

    if ( H5Pget_layout(cparms) == H5D_CONTIGUOUS ) //We can read it directly
        readData(fimg, select_img, datatype, 0);
    else // We read it by hyperslabs
    {
        // Allocate memory for image data (Assume xdim, ydim, zdim and ndim are already set
        //if memory already allocated use it (no resize allowed)
        mdaBase->coreAllocateReuse();

        hid_t       memspace;

        hsize_t offset[4]; // Hyperslab offset in the file
        hsize_t  count[4]; // Size of the hyperslab in the file

        // Define the offset and count of the hyperslab to be read.

        switch (rank)
        {
        case 4:
            count[0] = 1;
        case 3:
            //            if (stack)
            count[rank-3] = aDim.zdim;
            offset[rank-2]  = 0;
        case 2:
            count[rank-2]  = aDim.ydim;
            offset[rank-2]  = 0;
            break;
        }
        count[rank-1]  = aDim.xdim;
        offset[rank-1]  = 0;

        aDim.xdim = dims[rank-1];
        aDim.ydim = (rank>1)?dims[rank-2]:1;
        aDim.zdim = (rank == 4)?dims[1]:1;
        // size_t nDimFile = (rank>2)?dims[0]:1 ;

        // Define the memory space to read a hyperslab.
        memspace = H5Screate_simple(rank,count,NULL);

        size_t data = (size_t) this->mdaBase->getArrayPointer();
        size_t pad = aDim.zyxdim*gettypesize(myT());


        for (size_t idx = imgStart, imN = 0; idx < imgEnd; ++idx, ++imN)
        {

            // Set the offset of the hyperslab to be read
            offset[0] = idx;

            if ( H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
                                     count, NULL) < 0 )
                REPORT_ERROR(ERR_IO_NOREAD, formatString("readHDF5: Error selecting hyperslab %d from filename %s",
                             imgStart, filename.c_str()));

            //            movePointerTo(ALL_SLICES,imN);
            // Read
            if ( H5Dread(dataset, H5Datatype(myT()), memspace, filespace,
                         H5P_DEFAULT, (void*)(data + pad*imN)) < 0 )
                REPORT_ERROR(ERR_IO_NOREAD,formatString("readHDF5: Error reading hyperslab %d from filename %s",
                                                        imgStart, filename.c_str()));
        }
        H5Sclose(memspace);
    }

    H5Pclose(cparms);
    H5Sclose(filespace);
    H5Dclose(dataset);

    return errCode;
}
Exemplo n.º 24
0
/** TIA Reader
  * @ingroup TIA
*/
int ImageBase::readTIA(int select_img,bool isStack)
{
    TIAhead * header = new TIAhead;

    xmippFREAD(&header->endianess, sizeof(short int), 1, fimg, swap );

    // Set Endianess
    if (header->endianess == 18761)
        swap = 0;
    else
        swap = 1;
    if (IsBigEndian())
        swap = !swap;

    xmippFREAD(&header->SeriesID, sizeof(short int), 1, fimg, swap );
    xmippFREAD(&header->SeriesVersion, sizeof(short int), 1, fimg, swap);
    xmippFREAD(&header->DATA_TYPE_ID, sizeof(int), 1, fimg, swap);
    xmippFREAD(&header->TagTypeID, sizeof(int), 1, fimg, swap );
    xmippFREAD(&header->TotalNumberElements, sizeof(int), 1, fimg, swap );
    xmippFREAD(&header->NUMBER_IMAGES, sizeof(int), 1, fimg, swap );
    xmippFREAD(&header->OFFSET_ARRAY_OFFSET, sizeof(int), 1, fimg, swap );
    xmippFREAD(&header->numberdimensions, sizeof(int), 1, fimg, swap );

    // Check data type
    if (header->DATA_TYPE_ID != 16674)
        REPORT_ERROR(ERR_TYPE_INCORRECT, "ERROR: readTIA only processes images in real space");

    fseek(fimg, header->OFFSET_ARRAY_OFFSET, SEEK_SET);
    header->pDATA_OFFSET = (int *) askMemory(header->NUMBER_IMAGES * sizeof(int));
    xmippFREAD(header->pDATA_OFFSET, sizeof(int), header->NUMBER_IMAGES, fimg, swap);

    TIAdataHead* dataHeaders = new TIAdataHead [header->NUMBER_IMAGES];

    // Read all the image headers
    for (int i = 0; i < header->NUMBER_IMAGES; i++)
    {
        fseek(fimg, header->pDATA_OFFSET[i], SEEK_SET);
        xmippFREAD(&(dataHeaders[i].CalibrationOffsetX), sizeof(double), 1, fimg, swap);
        xmippFREAD(&dataHeaders[i].PIXEL_WIDTH, sizeof(double), 1, fimg, swap);
        xmippFREAD(&dataHeaders[i].CalibrationElementX, sizeof(int), 1, fimg, swap);
        xmippFREAD(&dataHeaders[i].CalibrationOffsetY, sizeof(double), 1, fimg, swap);
        xmippFREAD(&dataHeaders[i].PIXEL_HEIGHT, sizeof(double), 1, fimg, swap);
        xmippFREAD(&dataHeaders[i].CalibrationElementY, sizeof(int), 1, fimg, swap);
        xmippFREAD(&dataHeaders[i].DATA_TYPE, sizeof(short int), 1, fimg, swap);
        xmippFREAD(&dataHeaders[i].IMAGE_WIDTH, sizeof(int), 1, fimg, swap);
        xmippFREAD(&dataHeaders[i].IMAGE_HEIGHT, sizeof(int), 1, fimg, swap);
    }

    int _xDim,_yDim;
    size_t _nDim;

    size_t   imgStart = IMG_INDEX(select_img);
    size_t   imgEnd = (select_img != ALL_IMAGES) ? imgStart + 1 : header->NUMBER_IMAGES;

    if (select_img >  header->NUMBER_IMAGES)
        REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS, formatString("readTIA: Image number %lu exceeds stack size %lu", select_img, header->NUMBER_IMAGES));
    else if (select_img == ALL_IMAGES)
    {
        for (int i = 1; i < header->NUMBER_IMAGES; i++)    // Check images dimensions. Need to be the same
        {
            if (dataHeaders[0].IMAGE_HEIGHT != dataHeaders[i].IMAGE_HEIGHT || \
                dataHeaders[0].IMAGE_WIDTH != dataHeaders[i].IMAGE_WIDTH  || \
                dataHeaders[0].DATA_TYPE != dataHeaders[i].DATA_TYPE)
                REPORT_ERROR(ERR_IMG_NOREAD, "readTIA: images in TIA file with different dimensions and data types are not supported");
        }
        _xDim = dataHeaders[0].IMAGE_WIDTH;
        _yDim = dataHeaders[0].IMAGE_HEIGHT;
        _nDim = (size_t) header->NUMBER_IMAGES;
    }
    else
    {
        _xDim = dataHeaders[imgStart].IMAGE_WIDTH;
        _yDim = dataHeaders[imgStart].IMAGE_HEIGHT;
        _nDim = 1;
    }

    // Map the parameters
    setDimensions(_xDim, _yDim, 1, _nDim);

    DataType datatype;
    //    dataHeaders[0].isSigned = false;
    int tiaDT;
    tiaDT = dataHeaders[imgStart].DATA_TYPE;
    offset = header->pDATA_OFFSET[imgStart] + TIAdataSIZE;

    switch ( tiaDT )
    {
    case 1:
        datatype = DT_UChar;
        break;
    case 2:
        datatype = DT_UShort;
        //        datatype = DT_Short;
        break;
    case 3:
        datatype = DT_UInt;
        break;
    case 4:
        datatype = DT_SChar;
        break;
    case 5:
        datatype = DT_Short;
        //        dataHeaders[0].isSigned = true;
        break;
    case 6:
        datatype = DT_Int;
        break;
    case 7:
        datatype = DT_Float;
        break;
    case 8:
        datatype = DT_Double;
        break;
    case 9:
        datatype = DT_CFloat;
        break;
    case 10:
        datatype = DT_CDouble;
        break;
    default:
        datatype = DT_Unknown;
        break;
    }

    MDMainHeader.setValue(MDL_SAMPLINGRATE_X,(double)dataHeaders[0].PIXEL_WIDTH);
    MDMainHeader.setValue(MDL_SAMPLINGRATE_Y,(double)dataHeaders[0].PIXEL_HEIGHT);
    MDMainHeader.setValue(MDL_DATATYPE,(int)datatype);

    if (dataMode == HEADER || (dataMode == _HEADER_ALL && _nDim > 1)) // Stop reading if not necessary
    {
        delete header;
        return 0;
    }

    MD.clear();
    MD.resize(imgEnd - imgStart,MDL::emptyHeader);
    double aux;
    for ( size_t i = 0; i < imgEnd - imgStart; ++i )
    {
        if (dataMode == _HEADER_ALL || dataMode == _DATA_ALL)
        {
            if(MDMainHeader.getValue(MDL_SAMPLINGRATE_X,aux))
            {
                MD[i].setValue(MDL_SHIFT_X, dataHeaders[i].CalibrationOffsetX/aux);
                aux = ROUND(dataHeaders[i].CalibrationElementX - \
                            dataHeaders[i].CalibrationOffsetX/aux - _xDim/2);
                MD[i].setValue(MDL_ORIGIN_X, aux);
            }
            if(MDMainHeader.getValue(MDL_SAMPLINGRATE_Y,aux))
            {
                MD[i].setValue(MDL_SHIFT_Y, dataHeaders[i].CalibrationOffsetY/aux);
                aux = ROUND(dataHeaders[i].CalibrationElementY - \
                            dataHeaders[i].CalibrationOffsetY/aux -_yDim/2);
                MD[i].setValue(MDL_ORIGIN_Y, aux);
            }
        }
    }

    delete header;

    if( dataMode < DATA )
        return 0;

    size_t pad = TIAdataSIZE;
    readData(fimg, select_img, datatype, pad);

    return(0);
}
Exemplo n.º 25
0
int CDECL main( int argc, char *argv[] )
{
	Manager	manager;
	char	iometer[MAX_NETWORK_NAME];
	struct dynamo_param param;

#if defined(IOMTR_OS_LINUX)
	struct aioinit aioDefaults;

	memset(&aioDefaults, 0, sizeof(aioDefaults));
	aioDefaults.aio_threads = 2;
	aioDefaults.aio_threads = 2;
	aio_init(&aioDefaults);
	kstatfd = InitIoctlInterface();
	procstatstyle = DetectProcStatStyle();
	if (kstatfd < 0 && procstatstyle == -1) {
		cerr << "IoMeter can not get correct status information" << endl;
		exit(1);
	}
#if defined(IOMTR_CPU_XSCALE)
	if ((ccntfd = InitCCNTInterface()) < 0) {
		exit(1);
	}
#endif
#endif

	iometer[0]                 = 0;
	manager.manager_name[0]    = 0;
	manager.exclude_filesys[0] = 0;

	//provide a temporary global ptr to the version string for Syntax() to use
	g_pVersionStringWithDebug = manager.GetVersionString(TRUE);
	
	param.iometer 		    = iometer;
	param.manager_name 	    = manager.manager_name;
	param.manager_computer_name = manager.prt->network_name;
	param.manager_exclude_fs    = manager.exclude_filesys;
	param.blkdevlist 	    = &manager.blkdevlist;
	
	ParseParam(argc, argv, &param);

	g_pVersionStringWithDebug = NULL;	//should use manager object after this...

	iomtr_set_cpu_affinity(param.cpu_affinity);

	// If there were command line parameters, indicate that they were recognized.
	if ( iometer[0] || manager.manager_name[0] )
	{
		cout << "\nCommand line parameter(s):" << endl;

		if ( iometer[0] ) {
			cout << "   Looking for Iometer on \"" << iometer << "\"" << endl;
		}
		if ( manager.manager_name[0] ) {
			cout << "   New manager name is \"" << manager.manager_name << "\"" << endl;
		}
	}
	if ( manager.exclude_filesys[0] )
        {
      		cout << "\nExcluding the following filesystem types:" << endl;
        	cout << "   \"" << manager.exclude_filesys << "\"" << endl;
        }
        else
        {
        	strcpy(manager.exclude_filesys, DEFAULT_EXCLUDE_FILESYS);
        }
	cout << endl;

#if defined(IOMTR_OSFAMILY_UNIX)
 #if defined(IOMTR_OS_LINUX)
	signal(SIGALRM, SIG_IGN);
 #elif defined(IOMTR_OS_SOLARIS)
	sigignore(SIGALRM);
 #else
  #warning ===> WARNING: You have to do some coding here to get the port done!
 #endif 

	// Initialize the lock on UNIX platforms.
	if (pthread_mutex_init(&lock_mt, NULL))
	{
		cout <<"unable to init the lock" << endl;
		exit(1);
	}

	// Block SIGPIPE signal. Needed to ensure that Network worker
	// threads don't exit due to a broken pipe signal.
	sigset_t sigset;
	sigemptyset(&sigset);
	sigaddset(&sigset, SIGPIPE);
	if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0)
	{
		cout << "sigprocmask() call failed." << endl;
		cout << "dynamo could be unstable" << endl;
	}

	//
	// the number of file descriptors a process may create can be a small value like 64.
	//
	struct rlimit rlimitp;
	if (getrlimit(RLIMIT_NOFILE, &rlimitp) < 0)
	{
		cout << "error " << errno << " trying to get rlimit (# file descriptors)" << endl;
	}
	else
	{
		// it succeeded. We leave out atleast 25 file descriptors for non-targets
		// and compare with the hard limit.
		unsigned int targets = MAX_TARGETS + 25;
		if ( rlimitp.rlim_max < targets )
		{
			cout << "Only " << rlimitp.rlim_max << " file descriptors available" << endl;
			rlimitp.rlim_cur = rlimitp.rlim_max;
		}
		else
		{
			// set the soft limit to the required value.
			rlimitp.rlim_cur = targets;
		}
		if (setrlimit(RLIMIT_NOFILE, &rlimitp) < 0)
		{
			cout << "error " << errno << " trying to set rlimit (# file descriptors)" << endl;
		}
	}

	// Check for super-user permissions. If not super-user, we
	// cannot get many of the info from the kernel.
	if (getuid() || geteuid())
	{
		cout << "Dynamo not running as super-user." << endl;
		cout << "       All available disks might not be reported " << endl;
		cout << "       Cannot get TCP statistics from the kernel " << endl;
	}

#ifdef IOMTR_SETTING_OVERRIDE_FS
	// No command line args specifies destructive testing. Check to see if there
	// are any environment variables specifying the same. We need to warn the user.
	if (getenv("IOMTR_SETTING_OVERRIDE_FS") != NULL)
	{
		cout << "       ************ WARNING **************" << endl;
		cout << "       dynamo running in Destructive mode." << endl;
		cout << "         (overriding the not mounted fs)"   << endl;		
		cout << "       ************ WARNING **************" << endl;
	}
#endif // IOMTR_SETTING_OVERRIDE_FS
#endif // IOMTR_OSFAMILY_UNIX
#if defined(IOMTR_OSFAMILY_NETWARE)
	// Initialize the lock on NetWare platforms.
	if (pthread_mutex_init(&lock_mt, NULL))
	{
		cout <<"unable to init the lock" << endl;
		exit(1);
	}
#endif

	// Ensure, that the endian type of the CPU is detectable
	if ( (IsBigEndian() != 0) && (IsBigEndian() != 1) )
	{
		cout << "===> ERROR: Endian type of the CPU couldn't be detected." << endl;
		cout << "     [main() in " << __FILE__ << " line " << __LINE__ << "]" << endl;
		exit(1);
	}

	// Entering infinite loop to allow Dynamo to run multiple tests.  Outer while loop allows
	// Dynamo to be reset from Iometer.  If everything works smoothly, resets should be rare.
	while (TRUE)
	{
		// Initializing worker and logging into Iometer director.
		if ( !manager.Login( iometer ) )
			break;

		// Manager will continue to run until an error, or stopped by Iometer.
		if ( !manager.Run() )
			break;		// Stop running when the manager is done.
	}
	cout << "Ending execution." << endl;
	Sleep( 1000 );

#if defined(IOMTR_OS_LINUX)
	CleanupIoctlInterface(kstatfd);
#if defined(IOMTR_CPU_XSCALE)
	CleanupCCNTInterface(ccntfd);
#endif
#endif
	return(0);
}
Exemplo n.º 26
0
int main(int argc, char* argv[])
{
	int ret=0;
	int fHandle;
	psd_context * context=NULL;

	ret = IsBigEndian();
	if (!ret)
		printf("we are using little endian, psd image file stream byte order is big endian! need convert\n");
	else
		printf("we are using big endian\n");
	
	if (argc == 1)
	{
		printfHelp();
		return 0;
	}

	if (!strcmp(argv[1],"psd2bmp"))
	{
		Psd2Bmp("..\\..\\pic\\tianye_all.psd","..\\..\\pic\\tianye_all.bmp");
		Psd2Bmp("..\\..\\pic\\tianye_new.psd","..\\..\\pic\\tianye_new.jpg");
		Psd2Png("..\\..\\pic\\tianye_all.psd","..\\..\\pic\\tianye_all.png");
	}
	else if (!strcmp(argv[1],"merge"))
	{
		MergeTwoPngFile("..\\..\\pic\\bg.png","..\\..\\pic\\tianye.png","..\\..\\pic\\merge.png",180);
	}
	else if (!strcmp(argv[1],"bmp2psd"))
	{
		//CreateDemoPsdFile("..\\..\\pic\\tianye_new.psd","..\\..\\pic\\tianye.png");
		fHandle = PsdNewFile("..\\..\\pic\\tianye_1.psd","..\\..\\pic\\tianye.bmp");
		printf("new one psd file, ret=%d\n",fHandle);
		if (ret>=0)
		{
			ret = PsdNewLayer(fHandle,"..\\..\\pic\\ms12.png",0,0,1,200);
//			ret = PsdNewLayer(fHandle,"..\\..\\pic\\ms12.png",200,200,2,200);
//			PsdSetLayerDirection(fHandle,1,RIGHT90);
//			PsdSetLayerDirection(fHandle,1,LEFT90);
			//PsdSetLayerBrightness(fHandle,1,-0);
			//PsdSetLayerContrast(fHandle,1,-50);
			PsdSaveFile(fHandle);
			PsdCloseFile(fHandle);		//must close firstly before load again...
		}

//		Psd2Bmp("..\\..\\pic\\tianye_new.psd","..\\..\\pic\\tianye_new_tmp.bmp");
		Psd2Png("..\\..\\pic\\tianye_1.psd","..\\..\\pic\\tianye_1_tmp.png");
		//pngzoom("..\\..\\pic\\tianye_new_tmp.png",50);

	}
	else if (!strcmp(argv[1],"psd2psd"))
	{
		//fHandle = PsdLoadFile("..\\..\\pic\\tianye_1.psd");	//tianye_1.psd has two layers already
		fHandle = PsdNewFile("..\\..\\pic\\tianye_1.psd","..\\..\\pic\\tianye.bmp");
		if (fHandle>=0)
		{
			//ret = PsdNewLayer(fHandle,"..\\..\\pic\\ms12.png",200,200,2,200);
			ret = PsdCreateLayer(fHandle,"..\\..\\pic\\ms12.png",200,200,100,200,2,200);
			ret = PsdSaveFile(fHandle);
			ret = PsdCloseFile(fHandle);
			Psd2Png("..\\..\\pic\\tianye_1.psd","..\\..\\pic\\tianye_1.png");
		}
		else
		{
			printf("fail to load psd file. ret=%d\n",ret);
		}		
	}
	else if (!strcmp(argv[1],"bmp2bmp"))
	{
		ret = bmp2bmp("..\\..\\pic\\tianye.bmp","..\\..\\pic\\tianye_tmp.bmp");
		if (ret>=0)
		{
			printf("bmp convert to bmp successfully!\n");
		}
	}		
	else if (!strcmp(argv[1],"jpg2bmp"))
	{
		//ret = jpg2bmp("..\\..\\pic\\testimg.jpg","..\\..\\pic\\testimg.bmp");
		ret = jpg2bmp("..\\..\\pic\\puke.jpg","..\\..\\pic\\puke_tmp.bmp");
		if (ret>=0)
		{
			printf("jpg convert to bmp successfully!\n");
		}
	}	
	else if (!strcmp(argv[1],"bmp2jpg"))
	{
		ret = bmp2jpg("..\\..\\pic\\tianye.bmp","..\\..\\pic\\tianye.jpg");
		if (ret>=0)
		{
			printf("bmp convert to jpg successfully!\n");
		}
	}
	else if (!strcmp(argv[1],"png2bmp"))
	{
		//ret = png2bmp("..\\..\\pic\\mxp.png","..\\..\\pic\\mxp_tmp.bmp");
		ret = png2bmp("..\\..\\pic\\ms12.png","..\\..\\pic\\ms12_tmp.bmp");

//		ret = png2bmp("..\\..\\pic\\lisa.png","..\\..\\pic\\lisa_tmp.bmp");		//can NOT load lisa.png into RAM
		if (ret>=0)
		{
			printf("png convert to bmp successfully!\n");
		}
	}	
	else if (!strcmp(argv[1],"bmp2png"))
	{
		ret = bmp2png("..\\..\\pic\\Bliss.bmp","..\\..\\pic\\Bliss.png");
		if (!ret)
		{
			printf("bmp convert to png successfully!\n");
		}
	}		
	else if (!strcmp(argv[1],"pngcrop"))
	{
		ret = bmp2png("..\\..\\pic\\Bliss.bmp","..\\..\\pic\\Bliss.png");
		//ret = pngzoom("..\\..\\pic\\Bliss.png",100);
		ret=pngcrop("..\\..\\pic\\Bliss.png",600,400);
	}		

	else
		;

	return 0;
}
Exemplo n.º 27
0
bool FourierBSDFTable::Read(const std::string &filename,
                            FourierBSDFTable *bsdfTable) {
    bsdfTable->mu = bsdfTable->cdf = bsdfTable->a = nullptr;
    bsdfTable->aOffset = bsdfTable->m = nullptr;

    FILE *f = fopen(filename.c_str(), "rb");

    if (!f) {
        Error("Unable to open tabulated BSDF file \"%s\"", filename.c_str());
        return false;
    }

    auto read32 = [&](void *target, size_t count) -> bool {
        if (fread(target, sizeof(int), count, f) != count) return false;
        if (IsBigEndian()) {
            int32_t *tmp = (int32_t *)target;
            for (size_t i = 0; i < count; ++i) {
#if defined(__GNUC__)
                tmp[i] = __builtin_bswap32(tmp[i]);
#else
                tmp[i] = _byteswap_ulong(tmp[i]);
#endif
            }
        }
        return true;
    };
    auto readfloat = [&](Float *target, size_t count) -> bool {
        if (sizeof(*target) == sizeof(float)) return read32(target, count);

        std::unique_ptr<float[]> buf(new float[count]);
        bool ret = read32(buf.get(), count);
        for (size_t i = 0; i < count; ++i) target[i] = buf[i];
        return ret;
    };

    const char header_exp[8] = {'S', 'C', 'A', 'T', 'F', 'U', 'N', '\x01'};
    char header[8];
    std::unique_ptr<int[]> offsetAndLength;

    if (fread(header, 1, 8, f) != 8 || memcmp(header, header_exp, 8) != 0)
        goto fail;

    int flags, nCoeffs, nBases, unused[4];

    if (!read32(&flags, 1) || !read32(&bsdfTable->nMu, 1) ||
        !read32(&nCoeffs, 1) || !read32(&bsdfTable->mMax, 1) ||
        !read32(&bsdfTable->nChannels, 1) || !read32(&nBases, 1) ||
        !read32(unused, 3) || !readfloat(&bsdfTable->eta, 1) ||
        !read32(&unused, 4))
        goto fail;

    /* Only a subset of BSDF files are supported for simplicity, in particular:
       monochromatic and
       RGB files with uniform (i.e. non-textured) material properties */
    if (flags != 1 ||
        (bsdfTable->nChannels != 1 && bsdfTable->nChannels != 3) || nBases != 1)
        goto fail;

    bsdfTable->mu = new Float[bsdfTable->nMu];
    bsdfTable->cdf = new Float[bsdfTable->nMu * bsdfTable->nMu];
    bsdfTable->a0 = new Float[bsdfTable->nMu * bsdfTable->nMu];
    offsetAndLength.reset(new int[bsdfTable->nMu * bsdfTable->nMu * 2]);
    bsdfTable->aOffset = new int[bsdfTable->nMu * bsdfTable->nMu];
    bsdfTable->m = new int[bsdfTable->nMu * bsdfTable->nMu];
    bsdfTable->a = new Float[nCoeffs];

    if (!readfloat(bsdfTable->mu, bsdfTable->nMu) ||
        !readfloat(bsdfTable->cdf, bsdfTable->nMu * bsdfTable->nMu) ||
        !read32(offsetAndLength.get(), bsdfTable->nMu * bsdfTable->nMu * 2) ||
        !readfloat(bsdfTable->a, nCoeffs))
        goto fail;

    for (int i = 0; i < bsdfTable->nMu * bsdfTable->nMu; ++i) {
        int offset = offsetAndLength[2 * i],
            length = offsetAndLength[2 * i + 1];

        bsdfTable->aOffset[i] = offset;
        bsdfTable->m[i] = length;

        bsdfTable->a0[i] = length > 0 ? bsdfTable->a[offset] : (Float)0;
    }

    bsdfTable->recip = new Float[bsdfTable->mMax];
    for (int i = 0; i < bsdfTable->mMax; ++i)
        bsdfTable->recip[i] = 1 / (Float)i;

    fclose(f);
    return true;
fail:
    fclose(f);
    Error(
        "Tabulated BSDF file \"%s\" has an incompatible file format or "
        "version.",
        filename.c_str());
    return false;
}
Exemplo n.º 28
0
//
// Processing messages from Iometer based on their purpose and
// returns TRUE if the manager can process additional messages.
//
BOOL Manager::Process_Message()
{
	switch ( msg.purpose )
	{
	case ADD_WORKERS:
#ifdef _DETAILS
		cout << "in Process_Message() : ADD_WORKERS" << endl;
#endif
		Add_Workers( msg.data );
		break;

	// Signaling to reset all workers
	case RESET:
		// Remove all workers.
#ifdef _DETAILS
		cout << "in Process_Message() : RESET" << endl;
#endif
		Remove_Workers( ALL_WORKERS );
		prt->Disconnect();
		break;
	// Received call to end program or thread execution.
	case EXIT:
#ifdef _DETAILS
		cout << "in Process_Message() : EXIT" << endl;
#endif
		Remove_Workers( msg.data );
		return ( msg.data != MANAGER );

	// Preparing drives for access.
	case PREP_DISKS:
#ifdef _DETAILS
		cout << "in Process_Message() : PREP_DISKS" << endl;
#endif
		Prepare_Disks( msg.data );
		break;
	// Signalling to stop disk preparation.
	case STOP_PREPARE:
#ifdef _DETAILS
		cout << "in Process_Message() : STOP_PREPARE" << endl;
#endif
		Stop_Prepare( msg.data );
		break;
	
	// Reporting all targets accessible by this manager.
	case REPORT_TARGETS:
#ifdef _DETAILS
		cout << "in Process_Message() : REPORT_TARGETS" << endl;
#endif
		data_msg.count = Report_Disks( data_msg.data.targets );
		if( IsBigEndian() )
		{
			(void) reorder(data_msg, DATA_MESSAGE_TARGET_SPEC, SEND);
		}
		prt->Send( &data_msg, DATA_MESSAGE_SIZE );

		data_msg.count = Report_TCP( data_msg.data.targets );
		if( IsBigEndian() )
		{
			(void) reorder(data_msg, DATA_MESSAGE_TARGET_SPEC, SEND);
		}
		prt->Send( &data_msg, DATA_MESSAGE_SIZE );

		data_msg.count = Report_VIs( data_msg.data.targets );
		if( IsBigEndian() )
		{
			(void) reorder(data_msg, DATA_MESSAGE_TARGET_SPEC, SEND);
		}
		prt->Send( &data_msg, DATA_MESSAGE_SIZE );
		break;
	// Setting targets for a given grunt and reporting back.
	case SET_TARGETS:
#ifdef _DETAILS
		cout << "in Process_Message() : SET_TARGETS" << endl;
#endif
		prt->Receive( &data_msg, DATA_MESSAGE_SIZE );
		if( IsBigEndian() )
		{
			(void) reorder(data_msg, DATA_MESSAGE_TARGET_SPEC, RECV);
		}
		msg.data = Set_Targets( msg.data, data_msg.count, 
			data_msg.data.targets );
		// Send back success/failure indication along with additional error
		// information or target settings (such as TCP port).
		if( IsBigEndian() )
		{
			(void) reorder(msg);
		}
		prt->Send( &msg );
		if( IsBigEndian() )
		{
			(void) reorder(data_msg, DATA_MESSAGE_TARGET_SPEC, SEND);
		}
		prt->Send( &data_msg, DATA_MESSAGE_SIZE );
		break;

	// Setting access specifications for next test.
	case SET_ACCESS:
#ifdef _DETAILS
		cout << "in Process_Message() : SET_ACCESS" << endl;
#endif
		prt->Receive( &data_msg, DATA_MESSAGE_SIZE );
		if( IsBigEndian() )
		{
			(void) reorder(data_msg, DATA_MESSAGE_TEST_SPEC, RECV);
		}
		msg.data = (int)Set_Access( msg.data, &(data_msg.data.spec) );
		if( IsBigEndian() )
		{
			(void) reorder(msg);
		}
		prt->Send( &msg );	// notify Iometer of success
		break;

	// Signalling start of test.
	case START:
#ifdef _DETAILS
		cout << "in Process_Message() : START" << endl;
#endif
		Start_Test( msg.data );
		break;
	// Beginning to perform I/O.
	case BEGIN_IO:
#ifdef _DETAILS
		cout << "in Process_Message() : BEGIN_IO" << endl;
#endif
		Begin_IO( msg.data );
		break;
	// Beginning recording of test results.
	case RECORD_ON:
#ifdef _DETAILS
		cout << "in Process_Message() : RECORD_ON" << endl;
#endif
		Record_On( msg.data );
		break;
	// Stopping recording of test results.
	case RECORD_OFF:
#ifdef _DETAILS
		cout << "in Process_Message() : RECORD_OFF" << endl;
#endif
		Record_Off( msg.data );
		break;
	// Signalling to stop testing.
	case STOP:
#ifdef _DETAILS
		cout << "in Process_Message() : STOP" << endl;
#endif
		Stop_Test( msg.data );
		break;

	// Reporting results of whole test to Iometer.
	case REPORT_RESULTS:
#ifdef _DETAILS
		cout << "in Process_Message() : REPORT_RESULTS" << endl;
#endif
		Report_Results( WHOLE_TEST_PERF );
		break;

	// Reporting results since last update to Iometer.
	case REPORT_UPDATE:
#ifdef _DETAILS
		cout << "in Process_Message() : REPORT_UPDATE" << endl;
#endif
		Report_Results( LAST_UPDATE_PERF );
		break;

	default:
		cout << "*** Unknown purpose found in message." << endl << flush;
		return FALSE;
	}
	return TRUE;
}
Exemplo n.º 29
0
//
// Logging into Iometer.  Returns success.
//
BOOL Manager::Login( char* port_name )
{
	Port			*login_port;
	Message			msg, reply;
	Data_Message	data_msg;
	size_t			name_size = MAX_NETWORK_NAME;
	int				year, month, day;

	// Creating login messages that include the machine name and Dynamo version.
	// The version number is included in two places for backward compatibility.
	msg.purpose = LOGIN;
	strcpy(data_msg.data.manager_info.version, m_pVersionStringWithDebug);
#ifdef _DEBUG
	cout << "dynamo version: " << data_msg.data.manager_info.version << endl;
#endif
	sscanf( data_msg.data.manager_info.version, "%d.%d.%d", &year, &month, &day );
	msg.data = (year * 10000) + (month * 100) + day;

	if ( manager_name[0] != '\0' )
	{
		if ( strlen(manager_name) > MAX_NETWORK_NAME )
		{
			cout << "*** Specified manager name cannot be more than "
				 << MAX_NETWORK_NAME << " characters" << endl;
			exit(1);
		}

		strcpy( data_msg.data.manager_info.names[0], manager_name );
		name_size = strlen(manager_name);
	}
	else
	{
#if defined(IOMTR_OS_LINUX) || defined(IOMTR_OS_SOLARIS) 
		// This will not work correctly if hostname length > MAX_NETWORK_NAME
		if (gethostname(manager_name, name_size) < 0)
		{
			cout << "*** Exiting... gethostname() returned error " << errno << endl;
			exit(1);
		}
		name_size = strlen(data_msg.data.manager_info.names[0]);
#elif defined(IOMTR_OS_WIN32) || defined(IOMTR_OS_WIN64)
		GetComputerName( manager_name, (LPDWORD)&name_size );
#else
 #warning ===> WARNING: You have to do some coding here to get the port done!
#endif
		strcpy(data_msg.data.manager_info.names[0], manager_name);
	}
	strcpy( data_msg.data.manager_info.names[1], prt->network_name );
	data_msg.data.manager_info.port_number     = prt->network_port;
	data_msg.data.manager_info.processor_speed = perf_data[WHOLE_TEST_PERF].processor_speed;
	data_msg.data.manager_info.processors      = perf_data[WHOLE_TEST_PERF].processor_count;

#if defined(IOMTR_CPU_SPARC)
 #if defined(IOMTR_OS_SOLARIS)
	// Calculate processor_speed_to_nsecs for use in rdtsc.c
	// Note that this works only for MHz CPUs. For GHz CPUs the divisor will change.
	processor_speed_to_nsecs = (double)perf_data[WHOLE_TEST_PERF].processor_speed / 1000000000; 
 #else
  #warning ===> WARNING: You have to do some coding here to get the port done!
 #endif
#endif

	// Sending login request message.
	cout << "Sending login request..." << endl;
	cout << "   " << data_msg.data.manager_info.names[0] << endl;
	cout << "   " << data_msg.data.manager_info.names[1] 
		 << " (port " << data_msg.data.manager_info.port_number << ")" << endl;

	if ( prt->type == PORT_TYPE_TCP )
	{
		login_port = new PortTCP;

		if ( !login_port->Connect( port_name ) )
		{
			cout << "*** Could not create TCP/IP port to connect with Iometer!" << endl;
			return FALSE;
		}
	}
	else
	{
		cout << "*** Invalid port type in Manager::Login()" << endl;
		return FALSE;
	}

	if( IsBigEndian() )
	{
		(void)reorder(msg);
		(void)reorder(data_msg, DATA_MESSAGE_MANAGER_INFO, SEND);
	}
	login_port->Send( &msg );
	login_port->Send( &data_msg, DATA_MESSAGE_SIZE );

	// wait to receive reply to login request, then get the incoming message...
	if ( login_port->Receive( &reply ) == PORT_ERROR )
	{
		cout << endl << "*** Unable to receive a reply from Iometer" << endl;
		return FALSE;
	}

	if( IsBigEndian() )
	{
		(void)reorder(reply);
	}

	// Delete login port because we don't need it anymore.
	delete  login_port;

	// process the login reply message from Iometer
	switch (reply.data)
	{
		case WRONG_VERSION:
			cout << endl << "*** Incorrect version of Dynamo for this Iometer" << endl;
			return FALSE;

		case LOGIN_OK:
			//
			// Waiting for login to be accepted.
			if ( prt->Accept() )
				cout << "   Login accepted." << endl << flush;
			return TRUE;
		default:
			cout << endl << "*** Bad login status reply received - don't know what to do" << endl;
			return FALSE;
	}
}
Exemplo n.º 30
0
//
// Gathering results from all threads and reporting them back to Iometer.
//
void Manager::Report_Results( int which_perf )
{
	if ( (which_perf < 0) || (which_perf >= MAX_PERF) )
		return;

	// Shortcut pointers to where results are stored.
	Worker_Results	*worker_results;

	// If recording, update the ending results for the system performance.
	if ( record )
	{
		Get_Performance( which_perf, LAST_SNAPSHOT );
	}

	// Copy the current system results into a message.
	memcpy( (void*) &data_msg.data.manager_results, (void*) 
		&(manager_performance[which_perf]), sizeof( Manager_Results ) );
	if( IsBigEndian() )
	{
		(void) reorder(data_msg, DATA_MESSAGE_MANAGER_RESULTS, SEND);
	}
	prt->Send( &data_msg, DATA_MESSAGE_SIZE );

	// Sending back a result message for each worker thread.  Using multiple
	// messages keeps the message size down to a reasonable limit.
	worker_results = &(data_msg.data.worker_results);
	for ( int g = 0; g < grunt_count; g++ )
	{
		// Only send results for grunts that are running.
		if ( grunts[g]->target_count && !grunts[g]->idle )
		{
			#if _DEBUG
				cout << "Reporting results for grunt " << g << " ...";
			#endif
			// Copying worker's results into the message.
			memcpy( (void*) worker_results, (void*) &(grunts[g]->worker_performance), 
				sizeof( Worker_Results ) );
			worker_results->target_results.count = grunts[g]->target_count;

			// If recording, update the ending results for the worker's drive performance.
			if ( grunts[g]->grunt_state == TestRecording )
			{
				worker_results->time[LAST_SNAPSHOT] = rdtsc();
			}

			if ( which_perf == LAST_UPDATE_PERF )
			{
				// Subtract previous update's results from current results to give 
				// results since last update.

				Raw_Result	*target_result;
				Raw_Result	*prev_target_result;
				int i;

				worker_results->time[FIRST_SNAPSHOT] = 
					grunts[g]->prev_worker_performance.time[LAST_SNAPSHOT];

				for ( i = 0; i < worker_results->target_results.count; i++ )
				{
					target_result = &(worker_results->target_results.result[i]);
					prev_target_result
						= &(grunts[g]->prev_worker_performance.target_results.result[i]);

					// Subtract current result from each counter.
					target_result->bytes_read
						-= prev_target_result->bytes_read;
					target_result->bytes_written
						-= prev_target_result->bytes_written;
					target_result->read_count
						-= prev_target_result->read_count;
					target_result->write_count
						-= prev_target_result->write_count;
					target_result->transaction_count
						-= prev_target_result->transaction_count;
					target_result->connection_count
						-= prev_target_result->connection_count;
					target_result->read_errors
						-= prev_target_result->read_errors;
					target_result->write_errors
						-= prev_target_result->write_errors;
					target_result->read_latency_sum
						-= prev_target_result->read_latency_sum;
					target_result->write_latency_sum
						-= prev_target_result->write_latency_sum;
					target_result->transaction_latency_sum
						-= prev_target_result->transaction_latency_sum;
					target_result->connection_latency_sum
						-= prev_target_result->connection_latency_sum;
					target_result->counter_time
						-= prev_target_result->counter_time;

					// Use values from prev_worker_performance for "max_" values.
					target_result->max_raw_read_latency
						= prev_target_result->max_raw_read_latency;
					target_result->max_raw_write_latency
						= prev_target_result->max_raw_write_latency;
					target_result->max_raw_transaction_latency
						= prev_target_result->max_raw_transaction_latency;
					target_result->max_raw_connection_latency
						= prev_target_result->max_raw_connection_latency;
				}

				// Store away a copy of the current results for next time.
				memcpy( &(grunts[g]->prev_worker_performance), &(grunts[g]->worker_performance), 
					sizeof( Worker_Results ) );

				// Record time of last update.
				grunts[g]->prev_worker_performance.time[LAST_SNAPSHOT] = rdtsc();

				// Clear "max_" values in prev_worker_performance.
				for ( i = 0; i < worker_results->target_results.count; i++ )
				{
					Raw_Result *prev_target_result
						= &(grunts[g]->prev_worker_performance.target_results.result[i]);

					prev_target_result->max_raw_read_latency = 0;
					prev_target_result->max_raw_write_latency = 0;
					prev_target_result->max_raw_transaction_latency = 0;
					prev_target_result->max_raw_connection_latency = 0;
				}
			}

			// Sending results to Iometer.
			if( IsBigEndian() )
			{
				(void) reorder(data_msg, DATA_MESSAGE_WORKER_RESULTS, SEND);
			}
			prt->Send( &data_msg, DATA_MESSAGE_SIZE );
			#if _DEBUG
				cout << "sent." << endl;
			#endif
		}
	}

	if ( record && (which_perf == LAST_UPDATE_PERF) )
	{
		// Store current performance counters as baseline for next update.
		Get_Performance( LAST_UPDATE_PERF, FIRST_SNAPSHOT );
	}

	#if _DEBUG
		cout << "   Finished reporting results." << endl;
	#endif
}