示例#1
0
void Profiler::shutDown()
{
	std::ofstream outStream(filename);

	//Write Catergory headers
	for(unsigned int i = 0; i < numUsedCategories; i ++)
	{
		outStream << categories[i].name;
		outStream << getDelimiter(i);

	}

	//Account for last frame if they added entries
	int numActualFrames = frameIndex;
	if(categoryIndex == numUsedCategories)
		numActualFrames++;

	for(int frame = 0; frame < numActualFrames; frame++)
	{
		for(unsigned int cat = 0; cat < numUsedCategories; cat++)
		{
			outStream << categories[cat].samples[frame];
			outStream << getDelimiter(cat);

		}
	}
}
示例#2
0
// append an ascii-version of FastExtract into cachewa.qryText_
void FastExtract::generateCacheKey(CacheWA &cwa) const
{
  RelExpr::generateCacheKeyNode(cwa);

  char buf[40];
  cwa += " targType_ ";
  str_itoa(getTargetType(), buf);
  cwa += buf;

  cwa += " targName_ ";
  cwa += getTargetName();

  cwa += " delim_ ";
  cwa += getDelimiter();

  cwa += " isAppend_ ";
  cwa += isAppend() ? "1" : "0";

  cwa += " includeHeader_ ";
  cwa += includeHeader() ? "1" : "0";

  cwa += " cType_ ";
  str_itoa(getCompressionType(), buf);
  cwa += buf;

  cwa += " nullString_ ";
  cwa += getNullString();

  cwa += " recSep_ ";
  cwa += getRecordSeparator();

  generateCacheKeyForKids(cwa);
}
示例#3
0
std::string Strings::getDelimitedText() const
{
	std::string result;
	std::string line;
	int count = getCount();
	char quoteChar = getQuoteChar();
	char delimiter = getDelimiter();

	if (count == 1 && getString(0).empty())
		return std::string(getQuoteChar(), 2);

	std::string delimiters;
	for (int i = 1; i <= 32; i++)
		delimiters += (char)i;
	delimiters += quoteChar;
	delimiters += delimiter;

	for (int i = 0; i < count; i++)
	{
		line = getString(i);
		if (line.find_first_of(delimiters) != std::string::npos)
			line = getQuotedStr((char*)line.c_str(), quoteChar);

		if (i > 0) result += delimiter;
		result += line;
	}

	return result;
}
示例#4
0
	void Profiler::writeFrame(uint frameNumber) const
	{
		for(uint category = 0; category < numUsedCategories; category++)
		{
			outStream << categories[category].samples[frameNumber];
			outStream << getDelimiter(category);
		}
	}
示例#5
0
int parse_arguments(int argc, char** argv, FILE** streams, int* streamsCount, char* delim, int* split_bytes) {
	FILE* stream = stdin;
	int argIndex = 1;

	*streamsCount = 0;
	*split_bytes = -1;

	while (argc > argIndex) {
		/* got some arguments. check them */
		if (strcmp(argv[argIndex], "-d") == 0) {
			/* -d [DELIMITER_TYPE = W] */
			argIndex++;

			/* check that we have more args to parse */
			/* and that the next one isn't an option argument */
			if (argc > argIndex && argv[argIndex][0] != '-') {
				/* got a delimiter_type. set it */
				*delim = getDelimiter(argv[argIndex++], split_bytes);
			}
		} else if (strcmp(argv[argIndex], "-i") == 0) {
			/* -i FILE */
			argIndex++;
		
			if (argc > argIndex) {
				/* got file name */
				stream = fopen(argv[argIndex], "r");	
				argIndex++;
			} else {
				/* didn't receive a filename after -i! exit with an error */
				printf("-i should be followed with a filename to open.");
				return 1;
			}	
		} else {
			/* [FILE1], [FILE2], [FILE3]... */
			streams[(*streamsCount)++] = fopen(argv[argIndex], "r");
			argIndex++;
		}
	}

	if (streamsCount == 0) {
		/* no stream was selected. add the default or given -i stream to the party */
		streams[0] = stream;
		(*streamsCount)++;
	}

	return 0;
}
示例#6
0
	void Profiler::writeData() const
	{
		outStream.open(fileName, std::ios::trunc);

		//Write category headers
		for(uint i=0;i< numUsedCategories; i++)
		{
			outStream << categories[i].name;
			outStream << getDelimiter(i);
		}

		//Account for last frame if they added entries


		uint endIndex;
		uint startIndex;
		if(wrapped())
		{
			endIndex = frameIndex % MAX_FRAME_SAMPLES;
			startIndex = (endIndex + 1) % MAX_FRAME_SAMPLES;
			while(startIndex != endIndex)
			{
				writeFrame(startIndex);
				startIndex = (startIndex + 1) % MAX_FRAME_SAMPLES;
			}
			if(currentFrameComplete())
			{
				writeFrame(startIndex);
			}
		}
		else
		{
			uint numActualFrames = frameIndex;
			if(currentFrameComplete())
			{
				numActualFrames++;
			}
			startIndex = 0;
			endIndex = numActualFrames;
			while(startIndex < endIndex)
			{
				writeFrame(startIndex++);
			}
		}
		outStream.close();
	}
示例#7
0
void Strings::setDelimitedText(const char* value)
{
	AutoUpdater autoUpdater(*this);

	char quoteChar = getQuoteChar();
	char delimiter = getDelimiter();
	const char* curPtr = value;
	std::string line;

	clear();
	while (*curPtr >= 1 && *curPtr <= 32)
		curPtr++;

	while (*curPtr != '\0')
	{
		if (*curPtr == quoteChar)
			line = extractQuotedStr(curPtr, quoteChar);
		else
		{
			const char* p = curPtr;
			while (*curPtr > 32 && *curPtr != delimiter)
				curPtr++;
			line.assign(p, curPtr - p);
		}

		add(line.c_str());

		while (*curPtr >= 1 && *curPtr <= 32)
			curPtr++;

		if (*curPtr == delimiter)
		{
			const char* p = curPtr;
			p++;
			if (*p == '\0')
				add("");

			do curPtr++; while (*curPtr >= 1 && *curPtr <= 32);
		}
	}
}
示例#8
0
void M680X_printInst(MCInst *MI, SStream *O, void *PrinterInfo)
{
	m680x_info *info = (m680x_info *)PrinterInfo;
	cs_m680x *m680x = &info->m680x;
	cs_detail *detail = MI->flat_insn->detail;
	int suppress_operands = 0;
	const char *delimiter = getDelimiter(info, m680x);
	int i;

	if (detail != NULL)
		memcpy(&detail->m680x, m680x, sizeof(cs_m680x));

	if (info->insn == M680X_INS_INVLD || info->insn == M680X_INS_ILLGL) {
		if (m680x->op_count)
			SStream_concat(O, "fcb $%02x", m680x->operands[0].imm);
		else
			SStream_concat(O, "fcb $<unknown>");

		return;
	}

	printInstructionName(MI->csh, O, info->insn);
	SStream_concat(O, " ");

	if ((m680x->flags & M680X_FIRST_OP_IN_MNEM) != 0)
		suppress_operands++;

	if ((m680x->flags & M680X_SECOND_OP_IN_MNEM) != 0)
		suppress_operands++;

	for (i  = 0; i < m680x->op_count; ++i) {
		if (i >= suppress_operands) {
			printOperand(MI, O, info, &m680x->operands[i]);

			if ((i + 1) != m680x->op_count)
				SStream_concat(O, delimiter);
		}
	}
}
示例#9
0
void pairSaveWindow::doUpdate()
{
    if( _recording && _intervalCounter%_ui->spb_ticks->value() == 0 )
    {
        _fileStream.open( _fileName.toStdString().c_str(), std::ios_base::app );

        if( !_fileStream.is_open() )
        {
            _ui->lbl_status->setText( "ERROR!" );
            _ui->lbl_status->setStyleSheet( STYLE_ERROR );
            emit newError( this->windowTitle() + ": unable to open file!" );
            return;
        }

        _fileStream << _x << getDelimiter().toStdString() << _y << std::endl;
        _fileStream.close();

        _dataRecorded = true;
        _savedCounter++;
        _ui->lbl_numSaved->setText( QString::number( _savedCounter ) );
        _intervalCounter = 0;
    }
    _intervalCounter++;
}
示例#10
0
short
PhysicalFastExtract::codeGen(Generator *generator)
{
  short result = 0;
  Space *space = generator->getSpace();
  CmpContext *cmpContext = generator->currentCmpContext();

  const ULng32 downQueueMaxSize = getDefault(GEN_FE_SIZE_DOWN);
  const ULng32 upQueueMaxSize = getDefault(GEN_FE_SIZE_UP);


  const ULng32 defaultBufferSize = getDefault(GEN_FE_BUFFER_SIZE);
  const ULng32 outputBufferSize = defaultBufferSize;
  const ULng32 requestBufferSize = defaultBufferSize;
  const ULng32 replyBufferSize = defaultBufferSize;
  const ULng32 numOutputBuffers = getDefault(GEN_FE_NUM_BUFFERS);

  // used in runtime stats
  Cardinality estimatedRowCount = (Cardinality)
                       (getInputCardinality() * getEstRowsUsed()).getValue();

  Int32 numChildren = getArity();
  ex_cri_desc * givenDesc = generator->getCriDesc(Generator::DOWN);
  ComTdb * childTdb = (ComTdb*) new (space) ComTdb();
  ExplainTuple *firstExplainTuple = 0;

  // Allocate a new map table for this child.
  //
  MapTable *localMapTable = generator->appendAtEnd();
  generator->setCriDesc(givenDesc, Generator::DOWN);
  child(0)->codeGen(generator);
  childTdb = (ComTdb *)(generator->getGenObj());
  firstExplainTuple = generator->getExplainTuple();

  ComTdbFastExtract *newTdb = NULL;
  char * targetName = NULL;
  char * hiveTableName = NULL;
  char * delimiter = NULL;
  char * header = NULL;
  char * nullString = NULL;
  char * recordSeparator = NULL;
  char * hdfsHostName = NULL;
  Int32 hdfsPortNum = getHdfsPort();

  char * newDelimiter = (char *)getDelimiter().data();
  char specChar = '0';
  if (!isHiveInsert() && isSpecialChar(newDelimiter, specChar))
  {
    newDelimiter = new (cmpContext->statementHeap()) char[2];
    newDelimiter[0] = specChar;
    newDelimiter[1] = '\0';
  }

  char * newRecordSep = (char *)getRecordSeparator().data();
  specChar = '0';
  if (!isHiveInsert() && isSpecialChar(newRecordSep, specChar))
  {
    newRecordSep = new (cmpContext->statementHeap()) char[2];
    newRecordSep[0] = specChar;
    newRecordSep[1] = '\0';
  }

  targetName = AllocStringInSpace(*space, (char *)getTargetName().data());
  hdfsHostName = AllocStringInSpace(*space, (char *)getHdfsHostName().data());
  hiveTableName = AllocStringInSpace(*space, (char *)getHiveTableName().data());
  delimiter = AllocStringInSpace(*space,  newDelimiter);
  header = AllocStringInSpace(*space, (char *)getHeader().data());
  nullString = AllocStringInSpace(*space, (char *)getNullString().data());
  recordSeparator = AllocStringInSpace(*space, newRecordSep);

   result = ft_codegen(generator,
                       *this,              // RelExpr &relExpr
                       newTdb,             // ComTdbUdr *&newTdb
                       estimatedRowCount,
                       targetName,
                       hdfsHostName,
                       hdfsPortNum,
                       hiveTableName,
                       delimiter,
                       header,
                       nullString,
                       recordSeparator,
                       downQueueMaxSize,
                       upQueueMaxSize,
                       outputBufferSize,
                       requestBufferSize,
                       replyBufferSize,
                       numOutputBuffers,
                       childTdb,
                       isSequenceFile());

  if (!generator->explainDisabled())
  {
    generator->setExplainTuple(addExplainInfo(newTdb, firstExplainTuple, 0, generator));
  }

  if (getTargetType() == FILE)
    newTdb->setTargetFile(1);
  else if (getTargetType() == SOCKET)
    newTdb->setTargetSocket(1);
  else
  GenAssert(0, "Unexpected Fast Extract target type")

  if (isAppend())
    newTdb->setIsAppend(1);
  if (this->includeHeader())
    newTdb->setIncludeHeader(1);

  if (isHiveInsert())
  {
    newTdb->setIsHiveInsert(1);
    newTdb->setIncludeHeader(0);
    setOverwriteHiveTable( getOverwriteHiveTable());
  }
  else
  {
    if (includeHeader())
      newTdb->setIncludeHeader(1);
  }
  if (getCompressionType() != NONE)
  {
    if (getCompressionType() == LZO)
      newTdb->setCompressLZO(1);
    else
    GenAssert(0, "Unexpected Fast Extract compression type")
  }
     if((ActiveSchemaDB()->getDefaults()).getToken(FAST_EXTRACT_DIAGS) == DF_ON)
    	 newTdb->setPrintDiags(1);

  return result;
}
示例#11
0
ExplainTuple *PhysicalFastExtract::addSpecificExplainInfo(ExplainTupleMaster *explainTuple, ComTdb *tdb,
    Generator *generator)
{

  NAString description = "Target_type: ";
  if (getTargetType() == FILE)
  {
    if (isHiveInsert())
      description += "hive table";
    else
      description += "file";
  }
  else if (getTargetType() == SOCKET)
    description += "socket";
  else
    description += "none";
  if (isHiveInsert())
  {

    NAString str = getTargetName();
    size_t colonIndex = str.index(":", 1,0,NAString::ignoreCase);
    while (colonIndex !=  NA_NPOS)
    {
      str = str.replace(colonIndex, 1, "_", 1);
      colonIndex = str.index(":", 1,0,NAString::ignoreCase);
    }

    description += " location: ";
    description += str;
  }


  if (isHiveInsert())
  {
    description += " table_name: ";
    description += getHiveTableName();
  }
  else
  {
    description += " target_name: ";
    description += getTargetName();
  }
  description += " delimiter: ";
  description += getDelimiter();

  if (isAppend())
    description += " append: yes";
  if ( !isHiveInsert() && includeHeader())
  {
    description += " header: ";
    description += getHeader();
  }
  if (getCompressionType() != NONE)
  {
    description += " compression_type: ";
    if (getCompressionType() == LZO)
      description += "LZO";
    else
      description += "error";
  }

  description += " null_string: ";
  description += getNullString();

  description += " record_separator: ";
  description += getRecordSeparator();


  explainTuple->setDescription(description);
  if (isHiveInsert())
    explainTuple->setTableName(getHiveTableName());

  return explainTuple;
}
示例#12
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
FloatArrayType::Pointer AngleFileLoader::loadData()
{
  FloatArrayType::Pointer angles = FloatArrayType::NullPointer();

  // Make sure the input file variable is not empty
  if (m_InputFile.size() == 0)
  {
    setErrorMessage("Input File Path is empty");
    setErrorCode(-1);
    return angles;
  }

  QFileInfo fi(getInputFile());

  // Make sure the file exists on disk
  if (fi.exists() == false)
  {
    setErrorMessage("Input File does not exist at path");
    setErrorCode(-2);
    return angles;
  }

  // Make sure we have a valid angle representation
  if(m_AngleRepresentation != EulerAngles
      && m_AngleRepresentation != QuaternionAngles
      && m_AngleRepresentation != RodriguezAngles)
  {
    setErrorMessage("The Angle representation was not set to anything known to this code");
    setErrorCode(-3);
    return angles;
  }


  // The format of the file is quite simple. Comment lines start with a "#" symbol
  // The only Key-Value pair we are looking for is 'Angle Count' which will have
  // the total number of angles that will be read

  int numOrients = 0;
  QByteArray buf;

  // Open the file and read the first line
  QFile reader(getInputFile());
  if (!reader.open(QIODevice::ReadOnly | QIODevice::Text))
  {
    QString msg = QObject::tr("Angle file could not be opened: %1").arg(getInputFile());
    setErrorCode(-100);
    setErrorMessage(msg);
    return angles;
  }

  bool ok = false;
  buf = reader.readLine();
  while(buf[0] == '#')
  {
    buf = reader.readLine();
  }
  buf = buf.trimmed();

  //Split the next line into a pair of tokens delimited by the ":" character
  QList<QByteArray> tokens = buf.split(':');
  if(tokens.count() != 2)
  {
    QString msg = QObject::tr("Proper Header was not detected. The file should have a single header line of 'Angle Count:XXXX'");
    setErrorCode(-101);
    setErrorMessage(msg);
    return angles;
  }

  if(tokens[0].toStdString().compare("Angle Count") != 0)
  {
    QString msg = QObject::tr("Proper Header was not detected. The file should have a single header line of 'Angle Count:XXXX'");
    setErrorCode(-102);
    setErrorMessage(msg);
    return angles;
  }
  numOrients = tokens[1].toInt(&ok, 10);

  // Allocate enough for the angles
  QVector<size_t> dims(1, 5);
  angles = FloatArrayType::CreateArray(numOrients, dims, "EulerAngles_From_File");

  for(int i = 0; i < numOrients; i++)
  {
    float weight = 0.0f;
    float sigma = 1.0f;
    buf = reader.readLine();
    // Skip any lines that start with a '#' character
    if(buf[0] == '#') { continue; }
    buf = buf.trimmed();

    // Remove multiple Delimiters if wanted by the user.
    if (m_IgnoreMultipleDelimiters == true)
    {
      buf = buf.simplified();
    }
    tokens = buf.split( *(getDelimiter().toLatin1().data()));

    FOrientArrayType euler(3);
    if (m_AngleRepresentation == EulerAngles)
    {
      euler[0] = tokens[0].toFloat(&ok);
      euler[1] = tokens[1].toFloat(&ok);
      euler[2] = tokens[2].toFloat(&ok);
      weight = tokens[3].toFloat(&ok);
      sigma = tokens[4].toFloat(&ok);
    }
    else if (m_AngleRepresentation == QuaternionAngles)
    {
      FOrientArrayType quat(4);
      quat[0] = tokens[0].toFloat(&ok);
      quat[1] = tokens[1].toFloat(&ok);
      quat[2] = tokens[2].toFloat(&ok);
      quat[3] = tokens[3].toFloat(&ok);
      FOrientTransformsType::qu2eu(quat, euler);
      weight = tokens[4].toFloat(&ok);
      sigma = tokens[5].toFloat(&ok);
    }
    else if (m_AngleRepresentation == RodriguezAngles)
    {
      FOrientArrayType rod(4, 0.0);
      rod[0] = tokens[0].toFloat(&ok);
      rod[1] = tokens[1].toFloat(&ok);
      rod[2] = tokens[2].toFloat(&ok);
      FOrientTransformsType::ro2eu(rod, euler);
      weight = tokens[3].toFloat(&ok);
      sigma = tokens[4].toFloat(&ok);
    }

    // Values in File are in Radians and the user wants them in Degrees
    if (m_FileAnglesInDegrees == false && m_OutputAnglesInDegrees == true)
    {
      euler[0] = euler[0] * SIMPLib::Constants::k_RadToDeg;
      euler[1] = euler[1] * SIMPLib::Constants::k_RadToDeg;
      euler[2] = euler[2] * SIMPLib::Constants::k_RadToDeg;
    }
    // Values are in Degrees but user wants them in Radians
    else if (m_FileAnglesInDegrees == true && m_OutputAnglesInDegrees == false)
    {
      euler[0] = euler[0] * SIMPLib::Constants::k_DegToRad;
      euler[1] = euler[1] * SIMPLib::Constants::k_DegToRad;
      euler[2] = euler[2] * SIMPLib::Constants::k_DegToRad;
    }

    // Store the values into our array
    angles->setComponent(i, 0, euler[0]);
    angles->setComponent(i, 1, euler[1]);
    angles->setComponent(i, 2, euler[2]);
    angles->setComponent(i, 3, weight);
    angles->setComponent(i, 4, sigma);
    //   qDebug() << "reading line: " << i ;
  }



  return angles;
}