Example #1
0
void DoMeasureShear(
    ConfigFile& params, ShearLog& log,
    const Image<double>& im, const Image<double>* weight_image,
    const Transformation& trans, 
    const InputCatalog& incat, const FittedPsf& fitpsf,
    std::auto_ptr<ShearCatalog>& shearcat)
{
    dbg<<"Starting MeasureShear script\n";

    bool isTiming = params.read("timing",false);
    timeval tp;
    double t1=0.,t2=0.;

    if (isTiming) {
        gettimeofday(&tp,0);
        t1 = tp.tv_sec + tp.tv_usec/1.e6;
    }

    // Create shear catalog
    shearcat.reset(new ShearCatalog(incat,trans,fitpsf,params));

    if (isTiming) {
        gettimeofday(&tp,0);
        t2 = tp.tv_sec + tp.tv_usec/1.e6;
        std::cout<<"Time: Create ShearCatalog = "<<t2-t1<<std::endl;
        t1 = t2;
    }

    // Measure shears and shapelet vectors
    int nShear = shearcat->measureShears(im,weight_image,log);

    if (isTiming) {
        gettimeofday(&tp,0);
        t2 = tp.tv_sec + tp.tv_usec/1.e6;
        std::cout<<"Time: Measure Shears = "<<t2-t1<<std::endl;
        std::cout<<"Rate: "<<(t2-t1)/shearcat->size()<<" s / gal\n";
        t1 = t2;
    }

    // Write results to file
    shearcat->write();

    if (isTiming) {
        gettimeofday(&tp,0);
        t2 = tp.tv_sec + tp.tv_usec/1.e6;
        std::cout<<"Time: Write ShearCatalog = "<<t2-t1<<std::endl;
        t1 = t2;
    }

    if (nShear == 0) {
        throw ProcessingException(
            "No successful shear measurements");
    }

    xdbg<<"Shear Log: \n"<<log<<std::endl;
}
Example #2
0
void HandleAddCommand(const CStringArray& saArgs)
{
	// get the active Compression Manager interface
	CComPtr<IUnknown> pCompressionRuleManagerUnk;
	HRESULT hr = ::GetActiveObject(CLSID_CompressionRuleManager, NULL, (IUnknown**) &pCompressionRuleManagerUnk);
	if (hr != S_OK)
	{
		throw ProcessingException(hr, IDS_ERROR_NORUNNINGIISXPRESS);				
	}	

	// get the rule manager
	CComQIPtr<ICompressionRuleManager> pCompressionRuleManager = pCompressionRuleManagerUnk;
	if (pCompressionRuleManager == NULL)
	{
		throw ProcessingException(E_NOINTERFACE, IDS_INTERNALERROR);
	}

	// get the never compress rules
	CComQIPtr<INeverCompressRules> pNeverCompressRules = pCompressionRuleManager;
	if (pNeverCompressRules == NULL)
	{
		throw ProcessingException(E_NOINTERFACE, IDS_INTERNALERROR);
	}

	if (saArgs.GetCount() >= 1 && saArgs[0].CompareNoCase(_T("extn")) == 0)
	{
		// keep track of the number of extensions added
		int nExtns = 0;

		// loop round the supplied extensions
		for (int i = 1; i < saArgs.GetCount(); i++)
		{
			const TCHAR* pszExtn = saArgs[i];

			_tprintf(_T("Adding '%s': "), pszExtn);

			hr = pNeverCompressRules->AddExtensionRule(CStringA(pszExtn), "", "", 0);

			if (hr == S_OK)
			{
				_tprintf(_T("OK\n"));
				nExtns++;
			}
			else
			{
				_tprintf(_T("FAILED\n"));
			}
		}

		_tprintf(_T("%sAdded %d extension(s)\n"), 
			saArgs.GetCount() > 1 ? _T("\n") : _T(""),
			nExtns);
	}
	else if (saArgs.GetCount() >= 1 && saArgs[0].CompareNoCase(_T("ct")) == 0)
	{
		// keep track of the number of content types added
		int nCTs = 0;

		// loop around the passed in content types
		for (int i = 1; i < saArgs.GetCount(); i++)
		{
			const TCHAR* pszContentType = saArgs[i];

			_tprintf(_T("Adding '%s': "), pszContentType);

			hr = pNeverCompressRules->AddContentTypeRule(CStringA(pszContentType), "", "", 0);

			if (hr == S_OK)
			{
				_tprintf(_T("OK\n"));
				nCTs++;
			}
			else
			{
				_tprintf(_T("FAILED\n"));
			}
		}

		_tprintf(_T("%sAdded %d content type(s)\n"), 
			saArgs.GetCount() > 1 ? _T("\n") : _T(""),
			nCTs);
	}
	else if (saArgs.GetCount() >= 1 && saArgs[0].CompareNoCase(_T("uri")) == 0)
	{
		// the user must supply the instance
		if (saArgs.GetCount() < 2)
		{			
			CString sMsg;
			sMsg.LoadString(IDS_ERROR_COMMANDLINEINCORRECT);		
			throw sMsg;
		}		

		// assume the arg is an instance number
		CString sInstance = saArgs[1];

		if (g_VerInfo.dwMajorVersion < 6)
		{
			// attempt to map the arg to an instance id
			MapServerNameToInstance(saArgs[1], sInstance);
		}
		else
		{
			CComPtr<IXMLDOMDocument> pDoc;
			if (CIIS7XMLConfigHelper::GetApplicationHostConfigDocument(&pDoc) == S_OK)
			{
				// attempt to map the arg to an instance id
				MapServerNameToInstance(pDoc, saArgs[1], sInstance);
			}
		}

		int nURIs = 0;

		// loop around the supplied URIs
		for (int i = 2; i < saArgs.GetCount(); i++)
		{
			const TCHAR* pszURI = saArgs[i];

			// the string must begin with a /
			if (pszURI[0] != '/')
			{
				CString sMsg;
				sMsg.LoadString(IDS_ERROR_BADURIFORMAT);		
				throw sMsg;
			}

			DWORD dwMode = RULEFLAGS_FOLDER_EXACTMATCH;

			_tprintf(_T("Adding '%s': "), pszURI);			

			CStringA sURI(pszURI);			
			int nURILength = sURI.GetLength();
			if (sURI.Compare("/*") == 0)
			{
				sURI = "/";
				dwMode = RULEFLAGS_FOLDER_WILDCARDMATCH;
			}
			else if (nURILength > 1 && 
				pszURI[nURILength - 2] == '/' &&
				pszURI[nURILength - 1] == '*')
			{
				// remove the /* from the end of the string and set the type as wildcard
				sURI = CString(sURI, nURILength - 2);
				dwMode = RULEFLAGS_FOLDER_WILDCARDMATCH;
			}

			hr = pNeverCompressRules->AddFolderRule(CStringA(sInstance), sURI, dwMode, 0);

			if (hr == S_OK)
			{
				_tprintf(_T("OK\n"));
				nURIs++;
			}
			else
			{
				_tprintf(_T("FAILED\n"));
			}
		}

		_tprintf(_T("%sAdded %d URI(s)\n"), 
			saArgs.GetCount() > 1 ? _T("\n") : _T(""),
			nURIs);
	}
	else if (saArgs.GetCount() >= 1 && saArgs[0].CompareNoCase(_T("ip")) == 0)
	{
		// keep track of the number of IPs added
		int nIPs = 0;

		// loop round the supplied IPs
		for (int i = 1; i < saArgs.GetCount(); i++)
		{
			const TCHAR* pszIP = saArgs[i];

			_tprintf(_T("Adding '%s': "), pszIP);

			hr = pNeverCompressRules->AddIPRule(CStringA(pszIP), 0);

			if (hr == S_OK)
			{
				_tprintf(_T("OK\n"));
				nIPs++;
			}
			else
			{
				_tprintf(_T("FAILED\n"));
			}
		}

		_tprintf(_T("%sAdded %d IP(s)\n"), 
			saArgs.GetCount() > 1 ? _T("\n") : _T(""),
			nIPs);
	}
	else if (saArgs.GetCount() >= 1 && saArgs[0].CompareNoCase(_T("file")) == 0)
	{
		CComQIPtr<IStaticFileRules> pStaticFileRules = pNeverCompressRules;
		if (pStaticFileRules != NULL)
		{
			// keep track of the number of files added
			int nFiles = 0;

			// loop round the supplied files
			for (int i = 1; i < saArgs.GetCount(); i++)
			{				
				const TCHAR* pszFilename = saArgs[i];

				_tprintf(_T("Adding '%s': "), pszFilename);

				hr = pStaticFileRules->AddFileRule(CStringA(pszFilename), 0, -1);

				// TODO: fix this problem in the server
				if (hr == S_OK)
				{
					hr = pStaticFileRules->SetFileRule(CStringA(pszFilename), 0, -1);
				}

				if (hr == S_OK)
				{
					_tprintf(_T("OK\n"));
					nFiles++;
				}
				else
				{
					_tprintf(_T("FAILED\n"));
				}
			}

			_tprintf(_T("%sAdded %d files\n"), 
				saArgs.GetCount() > 1 ? _T("\n") : _T(""),
				nFiles);
		}
	}
	else
	{
		CString sMsg;
		sMsg.LoadString(IDS_ERROR_COMMANDLINEINCORRECT);		
		throw sMsg;
	}	
}
Example #3
0
void HandleListCommand(const CStringArray& saArgs)
{
	// get the active Compression Manager interface
	CComPtr<IUnknown> pCompressionRuleManagerUnk;
	HRESULT hr = ::GetActiveObject(CLSID_CompressionRuleManager, NULL, (IUnknown**) &pCompressionRuleManagerUnk);
	if (hr != S_OK)
	{
		throw ProcessingException(hr, IDS_ERROR_NORUNNINGIISXPRESS);				
	}	

	// get the rule manager
	CComQIPtr<ICompressionRuleManager> pCompressionRuleManager = pCompressionRuleManagerUnk;
	if (pCompressionRuleManager == NULL)
	{
		throw ProcessingException(E_NOINTERFACE, IDS_INTERNALERROR);
	}

	// get the never compress rules
	CComQIPtr<INeverCompressRules> pNeverCompressRules = pCompressionRuleManager;
	if (pNeverCompressRules == NULL)
	{
		throw ProcessingException(E_NOINTERFACE, IDS_INTERNALERROR);
	}

	if (saArgs.GetCount() == 1 && saArgs[0].CompareNoCase(_T("extn")) == 0)
	{
		CComPtr<IEnumExclusionRule> pExtnRules;
		hr = pNeverCompressRules->EnumExtensions(&pExtnRules);
		if (hr != S_OK || pExtnRules == NULL)
		{
			throw ProcessingException(hr, IDS_ERROR_UNABLETOENUMEXTNS);
		}

		int nExtns = 0;
		ULONG nFetched = 0;
		ExclusionRuleInfo RuleInfo;
		while (pExtnRules->Next(1, &RuleInfo, &nFetched) == S_OK)
		{
			if (nExtns == 0)
			{
				_tprintf(_T("Extensions:\n"));
			}

			_tprintf(_T(" %ls\n"), RuleInfo.bsRule);
			nExtns++;
		}

		_tprintf(_T("%sFound %d excluded extension(s)\n"), 
			nExtns > 0 ? _T("\n") : _T(""),
			nExtns);
	}
	else if (saArgs.GetCount() == 1 && saArgs[0].CompareNoCase(_T("ct")) == 0)
	{
		CComPtr<IEnumExclusionRule> pCTRules;
		hr = pNeverCompressRules->EnumContentTypes(&pCTRules);
		if (hr != S_OK || pCTRules == NULL)
		{
			throw ProcessingException(hr, IDS_ERROR_UNABLETOENUMCTS);
		}

		int nCTs = 0;
		ULONG nFetched = 0;
		ExclusionRuleInfo RuleInfo;
		while (pCTRules->Next(1, &RuleInfo, &nFetched) == S_OK)
		{
			if (nCTs == 0)
			{
				_tprintf(_T("Content Types:\n"));
			}

			_tprintf(_T(" %ls\n"), RuleInfo.bsRule);
			nCTs++;
		}

		_tprintf(_T("%sFound %d excluded content type(s)\n"), 
			nCTs > 0 ? _T("\n") : _T(""),
			nCTs);
	}
	else if (saArgs.GetCount() == 1 && saArgs[0].CompareNoCase(_T("uri")) == 0)
	{
		CMap<CStringW, LPCWSTR, CString, LPCTSTR> Servers;		

		CComPtr<IEnumExclusionRule> pURIRules;
		hr = pNeverCompressRules->EnumFolders(&pURIRules);
		if (hr != S_OK || pURIRules == NULL)
		{
			throw ProcessingException(hr, IDS_ERROR_UNABLETOENUMURIS);
		}

		// for Vista we need to get the config document
		CComPtr<IXMLDOMDocument> pDoc;
		if (g_VerInfo.dwMajorVersion >= 6 && CIIS7XMLConfigHelper::GetApplicationHostConfigDocument(&pDoc) != S_OK)
		{
			// TODO: throw better error message
			throw ProcessingException(hr, IDS_ERROR_UNABLETOENUMURIS);
		}

		int nURIs = 0;
		ULONG nFetched = 0;
		ExclusionRuleInfo RuleInfo;
		while (pURIRules->Next(1, &RuleInfo, &nFetched) == S_OK)
		{						
			if (nURIs == 0)
			{
				_tprintf(_T("Web site/URI:\n"));
			}

			CString sInstance;

			// try to map the server name to an instance
			if (Servers.Lookup(RuleInfo.bsInstance, sInstance) == TRUE)
			{
				// we got a hit, do nothing
			}
			else if (g_VerInfo.dwMajorVersion < 6 && MapInstanceToServerName(RuleInfo.bsInstance, sInstance) == true)
			{
				// the mapping was a success, so store it
				Servers[sInstance] = RuleInfo.bsInstance;
			}
			else if (g_VerInfo.dwMajorVersion >= 6)
			{
				// for Vista we get the site node from the XML config file
				CComPtr<IXMLDOMNode> pSite;				
				if (CIIS7XMLConfigHelper::GetSiteNode(pDoc, RuleInfo.bsInstance, &pSite) == S_OK)
				{
					CAtlString sId;
					CAtlString sDesc;
					CAtlString sPhysicalPath;
					CAtlArray<CAtlString> Ports;
					CAtlArray<CAtlString> SecurePorts;

					if (CIIS7XMLConfigHelper::GetSiteInfo(pSite, sId, sDesc, sPhysicalPath, Ports, SecurePorts) == S_OK)
					{
						sInstance = sDesc;

						// the mapping was a success, so store it
						Servers[sInstance] = RuleInfo.bsInstance;
					}
				}
			}
			else
			{
				// use the raw instance number
				sInstance = RuleInfo.bsInstance;
			}

			_tprintf(_T(" %-24ls %ls%s\n"), 
				sInstance, 
				RuleInfo.bsRule,
				RuleInfo.dwFlags == RULEFLAGS_FOLDER_WILDCARDMATCH ? _T("/*") : _T(""));

			nURIs++;			
		}

		_tprintf(_T("%sFound %d excluded URIs(s)\n"), 
			nURIs > 0 ? _T("\n") : _T(""),
			nURIs);
	}
	else if (saArgs.GetCount() == 2 && saArgs[0].CompareNoCase(_T("uri")) == 0)
	{								
		CComPtr<IEnumExclusionRule> pURIRules;
		hr = pNeverCompressRules->EnumFolders(&pURIRules);
		if (hr != S_OK || pURIRules == NULL)
		{
			throw ProcessingException(hr, IDS_ERROR_UNABLETOENUMURIS);
		}

		// assume the arg is an instance number
		CString sInstance = saArgs[1];

		if (g_VerInfo.dwMajorVersion < 6)
		{
			// attempt to map the arg to an instance id
			MapServerNameToInstance(saArgs[1], sInstance);
		}
		else
		{
			CComPtr<IXMLDOMDocument> pDoc;
			if (CIIS7XMLConfigHelper::GetApplicationHostConfigDocument(&pDoc) == S_OK)
			{
				// attempt to map the arg to an instance id
				MapServerNameToInstance(pDoc, saArgs[1], sInstance);
			}
		}

		int nURIs = 0;
		ULONG nFetched = 0;
		ExclusionRuleInfo RuleInfo;
		while (pURIRules->Next(1, &RuleInfo, &nFetched) == S_OK)
		{	
			if (sInstance.CompareNoCase(RuleInfo.bsInstance) != 0)
				continue;

			if (nURIs == 0)
			{
				_tprintf(_T("URI:\n"));
			}

			_tprintf(_T(" %ls%s\n"), 				
				RuleInfo.bsRule,
				RuleInfo.dwFlags == RULEFLAGS_FOLDER_WILDCARDMATCH ? _T("/*") : _T(""));

			nURIs++;			
		}

		_tprintf(_T("%sFound %d excluded URIs(s)\n"), 
			nURIs > 0 ? _T("\n") : _T(""),
			nURIs);
	}
	else if (saArgs.GetCount() == 1 && saArgs[0].CompareNoCase(_T("ip")) == 0)
	{		
		CComPtr<IEnumExclusionRule> pIPRules;
		hr = pNeverCompressRules->EnumIPAddresses(&pIPRules);
		if (hr != S_OK || pIPRules == NULL)
		{
			throw ProcessingException(hr, IDS_ERROR_UNABLETOENUMIPS);
		}

		int nIPs = 0;
		ULONG nFetched = 0;
		ExclusionRuleInfo RuleInfo;
		while (pIPRules->Next(1, &RuleInfo, &nFetched) == S_OK)
		{
			if (nIPs == 0)
			{
				_tprintf(_T("IP Addresses:\n"));
			}

			_tprintf(_T(" %ls\n"), RuleInfo.bsRule);
			nIPs++;
		}

		_tprintf(_T("%sFound %d excluded IP(s)\n"), 
			nIPs > 0 ? _T("\n") : _T(""),
			nIPs);
	}
	else if (saArgs.GetCount() >= 1 && saArgs[0].CompareNoCase(_T("file")) == 0)
	{
		CComQIPtr<IStaticFileRules> pStaticFileRules = pNeverCompressRules;
		if (pStaticFileRules != NULL)
		{
			// loop round the supplied filepaths
			for (int i = 1; i < saArgs.GetCount(); i++)
			{
				const TCHAR* pszFilepath = saArgs[i];

				CComPtr<IEnumStaticFileInfo> pEnumFileInfo;
				HRESULT hr = pStaticFileRules->EnumByPath(CStringA(pszFilepath), &pEnumFileInfo);
				if (hr != S_OK)
					continue;

				if (i != 1)
				{
					_tprintf(_T("\n"));
				}

				_tprintf(_T("Path: %s\n"), pszFilepath);

				int nFiles = 0;

				while (1)
				{
					ULONG nFetched = 0;
					StaticFileInfo fileInfo;
					hr = pEnumFileInfo->Next(1, &fileInfo, &nFetched);
					if (hr != S_OK || nFetched != 1)
					{
						break;
					}

					// only show user excluded files
					if (fileInfo.nUserCompression == 0)
					{						
						wprintf(L" %s\n", fileInfo.bsFilename);						

						nFiles++;
					}

					::SysFreeString(fileInfo.bsPath);
					::SysFreeString(fileInfo.bsFilename);															
				}

				_tprintf(_T("Found %d excluded file(s)\n"), nFiles);
			}
		}
	}
	else
	{
		CString sMsg;
		sMsg.LoadString(IDS_ERROR_COMMANDLINEINCORRECT);		
		throw sMsg;
	}	
}
Example #4
0
void DoMeasurePsf(
    ConfigFile& params, PsfLog& log,
    const Image<double>& im, const Image<double>* weight_image,
    const Transformation& trans, 
    const StarCatalog& starcat,
    std::auto_ptr<PsfCatalog>& psfcat, std::auto_ptr<FittedPsf>& fitpsf,
    double& sigma_p)
{
    dbg<<"Starting MeasurePsf script\n";

    bool isTiming = params.read("timing",false);
    timeval tp;
    double t1=0.,t2=0.;

    if (isTiming) {
        gettimeofday(&tp,0);
        t1 = tp.tv_sec + tp.tv_usec/1.e6;
    }

    if (params.read("psf_skip_measurements",false)) {
        // Option to read existing PsfCatalog rather than remeasure.
        // (Useful if you only want to redo the fitting step.)
        psfcat.reset(new PsfCatalog(params));
        psfcat->read();

        if (isTiming) {
            gettimeofday(&tp,0);
            t2 = tp.tv_sec + tp.tv_usec/1.e6;
            std::cout<<"Time: Read PSFCatalog = "<<t2-t1<<std::endl;
            t1 = t2;
        }
    } else {
        // Create PsfCatalog from StarCatalog
        psfcat.reset(new PsfCatalog(starcat,params));

        if (isTiming) {
            gettimeofday(&tp,0);
            t2 = tp.tv_sec + tp.tv_usec/1.e6;
            std::cout<<"Time: Create PSFCatalog = "<<t2-t1<<std::endl;
            t1 = t2;
        }

        // Estimate the scale size to use for shapelet decompositions
        if (sigma_p == 0.)
            sigma_p = psfcat->estimateSigma(im,weight_image,trans);

        if (isTiming) {
            gettimeofday(&tp,0);
            t2 = tp.tv_sec + tp.tv_usec/1.e6;
            std::cout<<"Time: Estimate Sigma = "<<t2-t1<<std::endl;
            t1 = t2;
        }

        // Do the actual PSF measurements
        int npsf = psfcat->measurePsf(im,weight_image,trans,sigma_p,log);

        if (isTiming) {
            gettimeofday(&tp,0);
            t2 = tp.tv_sec + tp.tv_usec/1.e6;
            std::cout<<"Time: Measure PSF = "<<t2-t1<<std::endl;
            t1 = t2;
        }

        // Write PSF catalog to file
        psfcat->write();

        if (isTiming) {
            gettimeofday(&tp,0);
            t2 = tp.tv_sec + tp.tv_usec/1.e6;
            std::cout<<"Time: Write PSFCatalog = "<<t2-t1<<std::endl;
            t1 = t2;
        }

        if (npsf == 0) {
            throw ProcessingException(
                "No successful PSF measurements");
        }
    }


    // Fit the PSF with a polynomial:
    fitpsf.reset(new FittedPsf(*psfcat,params,log));

    if (isTiming) {
        gettimeofday(&tp,0);
        t2 = tp.tv_sec + tp.tv_usec/1.e6;
        std::cout<<"Time: Fit PSF = "<<t2-t1<<std::endl;
        t1 = t2;
    }

    // Write fitted psf to file
    fitpsf->write();

    // Re-write the PSF catalog, since the interpolation may have changed
    // the flags.
    // TODO: It may be worth having a new routine that just updates the 
    // flags.  More efficient, since don't need to re-write everything.
    psfcat->write();

    if (isTiming) {
        gettimeofday(&tp,0);
        t2 = tp.tv_sec + tp.tv_usec/1.e6;
        std::cout<<"Time: Write FittedPSF = "<<t2-t1<<std::endl;
        t1 = t2;
    }

    xdbg<<"PSF Log: \n"<<log<<std::endl;
}