예제 #1
0
ret_ CXMLLoaderActions::LoadNetworkVarialbe(const CData &Data,
											const DOMElement *pElement,
											CVariable *&pOV,
											const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return PARAMETER_NULL | PARAMETER_2;

	if (pOV)
		return PARAMETER_NOT_NULL | PARAMETER_3;
	
	if (!pPDU)
		return PARAMETER_NULL | PARAMETER_4;
#endif

	//
	auto_xerces_str wsGroupName	("group_name");
	auto_xerces_str wsFieldName	("field_name");
	auto_xerces_str wsIndex		("index");

	auto_xerces_str sGroupName	(pElement->getAttribute(wsGroupName));
	auto_xerces_str	sFieldName	(pElement->getAttribute(wsFieldName));
	auto_xerces_str sIndex		(pElement->getAttribute(wsIndex));

	ch_1 szName[VARIABLE_NAME_LENGTH * 2];

	memset(szName, 0, VARIABLE_NAME_LENGTH * 2);

	if (0 < strlen(sGroupName))
	{
		
		sprintf(szName, 
				"%s.%s", 
				(const ch_1 *)sGroupName, 
				(const ch_1 *)sFieldName);
	}
	else
	{
		sprintf(szName, "%s", (const ch_1 *)sFieldName);
	}

	CField *pField = null_v;

	if (SUCCESS != (((CPDUInfo *)pPDU)->GetField(szName, pField)))
		return XML_LOADER_ERROR;

	if (0 == strcmp(sIndex, SIGN_UNBOUNDED))
		pOV = new CVarNetwork(pField);
	else
		pOV = new CVarNetwork(pField, sIndex);

	return SUCCESS;
}
예제 #2
0
ret_ CXMLLoaderActions::LoadGroupVariable(const CData &Data,
										  const DOMElement *pElement,
										  CVariable *&pOV)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);

	if (pOV)
		return (PARAMETER_NOT_NULL | PARAMETER_3);
#endif
	auto_xerces_str wsGroupName	("group_name");
	auto_xerces_str wsFieldName	("field_name");
	auto_xerces_str wsIndex		("index");

	auto_xerces_str sGroupName	(pElement->getAttribute(wsGroupName));
	auto_xerces_str	sFieldName	(pElement->getAttribute(wsFieldName));
	auto_xerces_str sIndex		(pElement->getAttribute(wsIndex));

	ch_1 szName[VARIABLE_NAME_LENGTH * 2];
	const char *pszSubName = null_v;
	const char *pszIndexName = null_v;

	memset(szName, 0, VARIABLE_NAME_LENGTH * 2);

	if (0 < strlen(sFieldName))
	{
		sprintf(szName, 
				"%s.%s", 
				(const ch_1 *)sGroupName, 
				(const ch_1 *)sFieldName);
		pszSubName = sFieldName;
	}
	else
	{
		sprintf(szName, "%s", (const ch_1 *)sGroupName);
	}

	v_ *pV = Data.Value(szName);

	if (!pV)
		return XML_LOADER_ERROR; // There is no variable defined above

	if (0 != strcmp(sIndex, SIGN_UNBOUNDED))
		pszIndexName = sIndex;

	pOV = new CVarGroupDefined(sGroupName, pszSubName, pszIndexName);

	return SUCCESS;
}
예제 #3
0
RTWrite::~RTWrite()
{
	if (m_pFile != NULL)
	{
		fclose(m_pFile);
		sprintf(m_fileTemp, m_file, m_curFileChains, m_curFile);
		if (rename("temp.rt", m_fileTemp) != 0)
		{
			perror(m_fileTemp);
			exit(1);
		}
		printf("writing index before closing file...\n");
		printf("Covering %u - %u\n", m_prefixStart, (m_prefixStart + m_curFileChains - m_prefixStart));
		unsigned char index[11] = {0}; // [0 - 10]
		// The 5 byte prefix of the endingpoint [0 - 4]
		uint64 *prefix = (uint64 *)index;
		*prefix = m_curPrefix;	
		printf("value is %02x%02x%02x%02x%02x%02x%02x%02x (%llu)\n", index[0], index[1], index[2], index[3], index[4], index[5], index[6], index[7], m_curPrefix);
		int *iprefix;
		// The 4 bytes index where to look in the file for the chains [5 - 8]
		iprefix = (int*)&index[5];
		*iprefix = m_prefixStart;
		short *iprefixs = (short*)&index[9]; // The number of chains (2 bytes, max 65535 chains) with this prefix [9 - 10]
		*iprefixs = (short)(m_curFileChains - m_prefixStart);
		fwrite(&index, 1, 11, m_pFileIndex); // Position of these chains is: First chain: FILESTART + (iprefix * 8)
											 //								 Last chain:  FILESTART + (iprefix * 8) + (iprefixs * 8)
		
		std::string sIndex(m_fileTemp);
		sIndex.append(".index");
		if (rename("temp.rt.index", sIndex.c_str()) != 0)
		{
			perror(sIndex.c_str());
			exit(1);
		}
/*
		if(m_pFileCont != NULL)
			fclose(m_pFileCont);
			*/
	}
	if (m_file != NULL)
	{
		delete [] m_file;
	}
	if (m_fileTemp != NULL)
	{
		delete [] m_fileTemp;
	}
}
예제 #4
0
STDMETHODIMP CDocumentRiskLevel::get_Item(VARIANT vIndex, IDocumentRiskLevel** ppItem)
{
	try
	{
		_variant_t var(vIndex);
		DocumentRiskLevelImpl* pTheItem = 0;

		if (VT_BSTR == var.vt)
		{
			_bstr_t bstr(var.bstrVal, true);
			std::tstring sIndex((const TCHAR*)bstr);
			pTheItem = m_pRiskLevel->GetItem(sIndex);
		}
		else if(VT_I4 == vIndex.vt)
		{
			long index = vIndex.lVal;
			if(0 >= index)
				throw Workshare::ArgumentException(_T("vIndex"), _T("The index is one based"));

			pTheItem = m_pRiskLevel->GetItem(--index);
		}
		else if(VT_INT == vIndex.vt)
		{
			long index = static_cast<long>(vIndex.intVal);
			if(0 >= index)
				throw Workshare::ArgumentException(_T("vIndex"), _T("The index is one based"));

			pTheItem = m_pRiskLevel->GetItem(--index);
		}
		else
		{
			return E_INVALIDARG;
		}

		AddChildRiskLevel(pTheItem, ppItem);
	}
	catch(const Workshare::Exception& e)
	{
		return Error(e.Message, __uuidof(this), e.ErrorCode); 
	}
	catch(...)
	{
		return ProcessUnhandledException();
	}

	return S_OK;	
}
예제 #5
0
파일: ba81quad.cpp 프로젝트: mhunter1/rpf
void ba81NormalQuad::setup(double Qwidth, int Qpoints, double *means,
			   Eigen::MatrixXd &priCov, Eigen::VectorXd &sVar)
{
	quadGridSize = Qpoints;
	numSpecific = sVar.rows() * sVar.cols();
	primaryDims = priCov.rows();
	maxDims = primaryDims + (numSpecific? 1 : 0);
	maxAbilities = primaryDims + numSpecific;

	if (maxAbilities == 0) {
		setup0();
		return;
	}

	totalQuadPoints = 1;
	for (int dx=0; dx < maxDims; dx++) {
		totalQuadPoints *= quadGridSize;
	}

	if (int(Qpoint.size()) != quadGridSize) {
		Qpoint.clear();
		Qpoint.reserve(quadGridSize);
		double qgs = quadGridSize-1;
		for (int px=0; px < quadGridSize; ++px) {
			Qpoint.push_back(px * 2 * Qwidth / qgs - Qwidth);
		}
	}

	std::vector<double> tmpWherePrep(totalQuadPoints * maxDims);

	Eigen::VectorXi quad(maxDims);
	for (int qx=0; qx < totalQuadPoints; qx++) {
		double *wh = tmpWherePrep.data() + qx * maxDims;
		decodeLocation(qx, maxDims, quad.data());
		pointToWhere(quad.data(), wh, maxDims);
	}

	totalPrimaryPoints = totalQuadPoints;
	weightTableSize = totalQuadPoints;

	if (numSpecific) {
		totalPrimaryPoints /= quadGridSize;
		speQarea.resize(quadGridSize * numSpecific);
		weightTableSize *= numSpecific;
	}

	std::vector<double> tmpPriQarea;
	tmpPriQarea.reserve(totalPrimaryPoints);
	{
		Eigen::VectorXd where(primaryDims);
		for (int qx=0; qx < totalPrimaryPoints; qx++) {
			decodeLocation(qx, primaryDims, quad.data());
			pointToWhere(quad.data(), where.data(), primaryDims);
			double den = exp(dmvnorm(primaryDims, where.data(), means, priCov.data()));
			tmpPriQarea.push_back(den);
		}
	}

	std::vector<int> priOrder;
	priOrder.reserve(totalPrimaryPoints);
	for (int qx=0; qx < totalPrimaryPoints; qx++) {
		priOrder.push_back(qx);
	}
	if (0) {
		sortAreaHelper priCmp(tmpPriQarea);
		std::sort(priOrder.begin(), priOrder.end(), priCmp);
	}

	priQarea.clear();
	priQarea.reserve(totalPrimaryPoints);

	double totalArea = 0;
	for (int qx=0; qx < totalPrimaryPoints; qx++) {
		double den = tmpPriQarea[priOrder[qx]];
		priQarea.push_back(den);
		//double prevTotalArea = totalArea;
		totalArea += den;
		// if (totalArea == prevTotalArea) {
		// 	mxLog("%.4g / %.4g = %.4g", den, totalArea, den / totalArea);
		// }
	}

	for (int qx=0; qx < totalPrimaryPoints; qx++) {
		priQarea[qx] *= One;
		priQarea[qx] /= totalArea;
		//mxLog("%.5g,", priQarea[qx]);
	}

	for (int sgroup=0; sgroup < numSpecific; sgroup++) {
		totalArea = 0;
		double mean = means[primaryDims + sgroup];
		double var = sVar(sgroup);
		for (int qx=0; qx < quadGridSize; qx++) {
			double den = exp(dmvnorm(1, &Qpoint[qx], &mean, &var));
			speQarea[sIndex(sgroup, qx)] = den;
			totalArea += den;
		}
		for (int qx=0; qx < quadGridSize; qx++) {
			speQarea[sIndex(sgroup, qx)] /= totalArea;
		}
	}
	//pda(speQarea.data(), numSpecific, quadGridSize);

	for (int sx=0; sx < int(speQarea.size()); ++sx) {
		speQarea[sx] *= One;
	}
	//pda(speQarea.data(), numSpecific, quadGridSize);

	wherePrep.clear();
	wherePrep.reserve(totalQuadPoints * maxDims);

	if (numSpecific == 0) {
		for (int qx=0; qx < totalPrimaryPoints; qx++) {
			int sortq = priOrder[qx] * maxDims;
			for (int dx=0; dx < maxDims; ++dx) {
				wherePrep.push_back(tmpWherePrep[sortq + dx]);
			}
		}
	} else {
		for (int qx=0; qx < totalPrimaryPoints; ++qx) {
			int sortq = priOrder[qx] * quadGridSize;
			for (int sx=0; sx < quadGridSize; ++sx) {
				int base = (sortq + sx) * maxDims;
				for (int dx=0; dx < maxDims; ++dx) {
					wherePrep.push_back(tmpWherePrep[base + dx]);
				}
			}
		}
	}

	// recompute whereGram because the order might have changed
	whereGram.resize(triangleLoc1(maxDims), totalQuadPoints);

	for (int qx=0; qx < totalQuadPoints; qx++) {
		double *wh = wherePrep.data() + qx * maxDims;
		gramProduct(wh, maxDims, &whereGram.coeffRef(0, qx));
	}
}
예제 #6
0
void RTWrite::writeChain(RTChain *chain)
{
	bool bIndexWritten = false;
	if (m_pFile == NULL)
	{
		m_pFile = fopen("temp.rt", "wb");
		if (m_pFile == NULL)
		{
			perror(m_fileTemp);
			exit(1);
		}
		m_pFileIndex = fopen("temp.rt.index", "wb");
		if (m_pFileIndex == NULL)
		{
			perror(m_fileTemp);
			exit(1);
		}
		/*
		m_pFileCont = fopen("temp.rt.cont", "wb");
		if (m_pFileCont == NULL)
		{
			perror(m_fileTemp);
			exit(1);
		}*/
		
	}
//							int cp = 0;
//							if (cwc.GetIndex() == chain->endpt)
//							{
								if(chain->startpt == 0)
									return;
								if (m_prevEndpt >= chain->endpt && chain->endpt != 0)
								{
									fprintf(stderr, "**** Error writeChain() in %i: Tring to write unsorted data. %llu >= %llu****\n", m_curFileChains, m_prevEndpt, chain->endpt);
//									exit(1);
									return;
								}
#ifdef _WIN32
								if(chain->startpt > 0x0000FFFFFFFFFFFFI64)
#else
								if(chain->startpt > 0x0000FFFFFFFFFFFFllu)
#endif
								{
									fprintf(stderr, "**** Error writeChain() in %i: Startpoint is bigger than 6 bytes. (%llx) ****\n", m_curFileChains, chain->startpt);
//									exit(1);										
									return;
								}
#ifdef _WIN32
								if(chain->endpt > 0x00FFFFFFFFFFFFFFI64)
#else
								if(chain->endpt > 0x00FFFFFFFFFFFFFFllu)
#endif
								{
									fprintf(stderr, "**** Error writeChain() in %i: Endpoint is bigger than 7 bytes. (%llx) ****\n", m_curFileChains, chain->endpt);
//									exit(1);										
									return;
								}

								// Disable checkpoints in this version
//								cp = cp >> 24;
								fwrite(&chain->startpt, 1, 6, m_pFile); // Prefix increased to 6 bytes in this version
								fwrite(&chain->endpt, 1, 2, m_pFile);
								m_prevEndpt = chain->endpt;
//								fwrite(&cp, 1, 1, m_pFile);

								uint64 nPrefix = chain->endpt >> 16;
								if(nPrefix != m_curPrefix) // Next index. Write the current one down
								{		
									// nPrefix should NOT be smaller. If it is *something* is wrong
									if(nPrefix < m_curPrefix)
									{
										fprintf(stderr, "**** Error writeChain() in %i of file %i: Prefix is smaller than previous prefix. %llu < %llu**** \n", m_curFileChains, m_curFile, nPrefix, m_curPrefix);
										exit(1);									
									}
									unsigned char index[11] = {0}; // [0 - 10]
									// The 5 byte prefix of the endingpoint [0 - 4]
									uint64 *prefix = (uint64 *)index;
									*prefix = m_curPrefix;	
									int *iprefix;
									// The 4 bytes index where to look in the file for the chains [5 - 8]
									iprefix = (int*)&index[5]; 
									*iprefix = m_prefixStart;
									short *iprefixs = (short*)&index[9]; // The number of chains (2 bytes, max 65535 chains) with this prefix [9 - 10]
									*iprefixs = (short)(m_curFileChains - m_prefixStart);
									fwrite(&index, 1, 11, m_pFileIndex); // Position of these chains is: First chain: FILESTART + (iprefix * 8)
																		 //								 Last chain:  FILESTART + (iprefix * 8) + (iprefixs * 8)
									m_numIndexRows++;
//									fflush(m_pFileIndex);
									m_prefixStart = m_curFileChains;
									m_curPrefix = nPrefix; 
									bIndexWritten = true;
									/*fseek(m_pFileCont, 0, SEEK_SET);
									fwrite(m_curFileChains, 0, sizeof(int), m_pFileCont);
									fflush(m_curFileChains);
									*/
								}
								m_curFileChains++;
								//nChainNum++;
								//return 3;
//							}
/*							else
							{
//								nFailed++;
							}
*/	
/*	if (fwrite((void*)chain, 16, 1, m_pFile) != 1)
	{
		perror("temp.rt");
		exit(1);
	}*/
	if (m_curFileChains >= m_chainsPerFile)
	{
		fclose(m_pFile);
		m_pFile = NULL;
		sprintf(m_fileTemp, m_file, m_curFileChains, m_curFile);
		if (rename("temp.rt", m_fileTemp) != 0)
		{
			perror(m_fileTemp);
			exit(1);
		}

/*		if(bIndexWritten == false) // If we haven't written the index in this round, its time to do it before we close the file
		{*/
			printf("writing index before closing file...\n");
			printf("Covering %u - %u\n", m_prefixStart, (m_prefixStart + m_curFileChains - m_prefixStart));
			unsigned char index[11] = {0}; // [0 - 10]
			// The 5 byte prefix of the endingpoint [0 - 4]
			uint64 *prefix = (uint64 *)index;
			*prefix = m_curPrefix;	
			printf("value is %02x%02x%02x%02x%02x%02x%02x%02x (%llu)\n", index[0], index[1], index[2], index[3], index[4], index[5], index[6], index[7], m_curPrefix);
			int *iprefix;
			// The 4 bytes index where to look in the file for the chains [5 - 8]
			iprefix = (int*)&index[5];
			*iprefix = m_prefixStart;
			short *iprefixs = (short*)&index[9]; // The number of chains (2 bytes, max 65535 chains) with this prefix [9 - 10]
			*iprefixs = (short)(m_curFileChains - m_prefixStart);
			fwrite(&index, 1, 11, m_pFileIndex); // Position of these chains is: First chain: FILESTART + (iprefix * 8)
												 //								 Last chain:  FILESTART + (iprefix * 8) + (iprefixs * 8)
			m_numIndexRows++;
		/*	
		}
		else
		{
			printf("Index already written in this round.. skipping!\n");
		}
*/
		fclose(m_pFileIndex);
		std::string sIndex(m_fileTemp);
		sIndex.append(".index");
		printf("%s: %u index rows\n\n", sIndex.c_str(), m_numIndexRows);
		if (rename("temp.rt.index", sIndex.c_str()) != 0)
		{
			perror(m_fileTemp);
			exit(1);
		}


		m_curFile++;
		m_curFileChains = 0;
		m_prefixStart = 0;
		m_numIndexRows = 0;
	}
}