コード例 #1
0
ファイル: SharedMemory.cpp プロジェクト: RadicalZephyr/bwdi
 //----------------------- EXPORT TO PROCESS --------------------------
 SharedMemory::Export SharedMemory::exportToProcess(RemoteProcess &target, bool readOnly) const
 {
   HANDLE targetProcessHandle = target.getHandle();
   HANDLE exportHandle;
   BOOL success = DuplicateHandle(
     GetCurrentProcess(),        // source process handle
     this->mappingObjectHandle,  // source handle
     targetProcessHandle,        // target process handle
     &exportHandle,              // out: target handle
     NULL,                       // access
     false,                      // inherit
     readOnly ? PAGE_READONLY : DUPLICATE_SAME_ACCESS);
   if(!success)
   {
     throw GeneralException(__FUNCTION__ ": failed export SharedMemory");
   }
   Export exportObject;
   exportObject.bufferSize = this->bufferSize;
   exportObject.targetProcessMappingObjectHandle = exportHandle;
   exportObject.readOnly = readOnly;
   return exportObject;
 }
コード例 #2
0
AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
{
	//Arguments from stack
	StringType property = eval(words);
	AnyType selector = eval(words);
	AnyType value = eval(words);

	Simulation * sim = m->GetSimulation();
	unsigned char * partsBlock = (unsigned char*)&sim->parts[0];

	int returnValue = 0;

	FormatType propertyFormat;
	int propertyOffset = GetPropertyOffset(property.Value(), propertyFormat);

	if(propertyOffset==-1)
		throw GeneralException("Invalid property");

	//Selector
	int newValue;
	float newValuef;
	if (value.GetType() == TypeNumber)
	{
		newValue = newValuef = ((NumberType)value).Value();
	}
	else if (value.GetType() == TypeFloat)
	{
		newValue = newValuef = ((FloatType)value).Value();
	}
	else if(value.GetType() == TypeString)
	{
		if (property.Value() == "temp")
		{
			std::string newString = ((StringType)value).Value();
			if (newString.at(newString.length()-1) == 'C')
				newValuef = atof(newString.substr(0, newString.length()-1).c_str())+273.15;
			else if (newString.at(newString.length()-1) == 'F')
				newValuef = (atof(newString.substr(0, newString.length()-1).c_str())-32.0f)*5/9+273.15f;
			else
				throw GeneralException("Invalid value for assignment");
		}
		else
		{
			newValue = GetParticleType(((StringType)value).Value());
			if (newValue < 0 || newValue >= PT_NUM)
			{
				// TODO: add element CAKE to invalidate this
				if (!strcasecmp(((StringType)value).Value().c_str(),"cake"))
					throw GeneralException("Cake is a lie, not an element");
				throw GeneralException("Invalid element");
			}
		}
	}
	else
		throw GeneralException("Invalid value for assignment");
	if (property.Value() == "type" && (newValue < 0 || newValue >= PT_NUM || !sim->elements[newValue].Enabled))
		throw GeneralException("Invalid element");

	if(selector.GetType() == TypePoint || selector.GetType() == TypeNumber)
	{
		int partIndex = -1;
		if(selector.GetType() == TypePoint)
		{
			ui::Point tempPoint = ((PointType)selector).Value();
			if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES)
				throw GeneralException("Invalid position");

		}
		else
			partIndex = ((NumberType)selector).Value();
		if(partIndex<0 || partIndex>NPART || sim->parts[partIndex].type==0)
			throw GeneralException("Invalid particle");

		switch(propertyFormat)
		{
		case FormatInt:
			*((int*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
			break;
		case FormatFloat:
			*((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValuef;
			break;
		}
		returnValue = 1;
	}
	else if(selector.GetType() == TypeString && ((StringType)selector).Value() == "all")
	{
		switch(propertyFormat)
		{
		case FormatInt:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type)
					{
						returnValue++;
						*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		case FormatFloat:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type)
					{
						returnValue++;
						*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValuef;
					}
			}
			break;
		}
	}
	else if(selector.GetType() == TypeString || selector.GetType() == TypeNumber)
	{
		int type;
		if(selector.GetType() == TypeNumber)
			type = ((NumberType)selector).Value();
		else if(selector.GetType() == TypeString)
			type = GetParticleType(((StringType)selector).Value());

		if(type<0 || type>=PT_NUM)
			throw GeneralException("Invalid particle type");
		if(type==0)
			throw GeneralException("Cannot set properties of particles that do not exist");
		std::cout << propertyOffset << std::endl;
		switch(propertyFormat)
		{
		case FormatInt:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type == type)
					{
						returnValue++;
						*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		case FormatFloat:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type == type)
					{
						returnValue++;
						*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValuef;
					}
			}
			break;
		}
	}
	else
		throw GeneralException("Invalid selector");
	return NumberType(returnValue);
}
コード例 #3
0
AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
{
	//Arguments from stack
	StringType property = eval(words);
	AnyType selector = eval(words);
	AnyType value = eval(words);

	Simulation * sim = m->GetSimulation();
	unsigned char * partsBlock = (unsigned char*)&sim->parts[0];

	int returnValue = 0;

	FormatType propertyFormat;
	int propertyOffset = GetPropertyOffset(property.Value(), propertyFormat);

	if(propertyOffset==-1)
		throw GeneralException("Invalid property");

	//Selector
	int newValue;
	if(value.GetType() == TypeNumber)
		newValue = ((NumberType)value).Value();
	else if(value.GetType() == TypeString)
	{
		newValue = GetParticleType(((StringType)value).Value());
		if (newValue < 0 || newValue >= PT_NUM)
			throw GeneralException("Invalid element");
	}
	else
		throw GeneralException("Invalid value for assignment");
	if (property.Value() == "type" && (newValue < 0 || newValue >= PT_NUM))
		throw GeneralException("Invalid element");

	if(selector.GetType() == TypePoint || selector.GetType() == TypeNumber)
	{
		int partIndex = -1;
		if(selector.GetType() == TypePoint)
		{
			ui::Point tempPoint = ((PointType)selector).Value();
			if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES)
				throw GeneralException("Invalid position");

		}
		else
			partIndex = ((NumberType)selector).Value();
		if(partIndex<0 || partIndex>NPART || sim->parts[partIndex].type==0)
			throw GeneralException("Invalid particle");

		switch(propertyFormat)
		{
		case FormatInt:
			*((int*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
			break;
		case FormatFloat:
			*((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
			break;
		}
		returnValue = 1;
	}
	else if(selector.GetType() == TypeString && ((StringType)selector).Value() == "all")
	{
		switch(propertyFormat)
		{
		case FormatInt:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type)
					{
						returnValue++;
						*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		case FormatFloat:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type)
					{
						returnValue++;
						*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		}
	}
	else if(selector.GetType() == TypeString || selector.GetType() == TypeNumber)
	{
		int type;
		if(selector.GetType() == TypeNumber)
			type = ((NumberType)selector).Value();
		else if(selector.GetType() == TypeString)
			type = GetParticleType(((StringType)selector).Value());

		if(type<0 || type>=PT_NUM)
			throw GeneralException("Invalid particle type");
		std::cout << propertyOffset << std::endl;
		switch(propertyFormat)
		{
		case FormatInt:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type == type)
					{
						returnValue++;
						*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		case FormatFloat:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type == type)
					{
						returnValue++;
						*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		}
	}
	else
		throw GeneralException("Invalid selector");
	return NumberType(returnValue);
}
コード例 #4
0
ファイル: Globals.cpp プロジェクト: gottardo7/pixie_scan
Globals::Globals() {
    clockInSeconds_ = -1;
    adcClockInSeconds_ = -1;
    filterClockInSeconds_ = -1;
    eventInSeconds_ = -1;
    energyContraction_ = 1.0;
    hasReject_ = false;
    revision_ = "None";
    numTraces_  = 16;

    try {
        pugi::xml_document doc;
        pugi::xml_parse_result result = doc.load_file("Config.xml");

        std::stringstream ss;
        if (!result) {
            ss << "Globals : error parsing file " << "Config.xml";
            ss << " : " << result.description();
            throw GeneralException(ss.str());
        }

        Messenger m;
        pugi::xml_node description =
            doc.child("Configuration").child("Description");
        std::string desc_text = description.text().get();
        m.detail("Experiment: " + desc_text);

        m.start("Loading global parameters");
        pugi::xml_node global = doc.child("Configuration").child("Global");
        for (pugi::xml_node_iterator it = global.begin();
                                    it != global.end(); ++it) {
            if (std::string(it->name()).compare("Revision") == 0) {
                revision_ = it->attribute("version").as_string();
                ss << "Revision: " << revision_;
                m.detail(ss.str());
                ss.str("");

                if (revision_ == "A") {
                    clockInSeconds_ = 10e-9;
                    adcClockInSeconds_ = 10e-9;
                    filterClockInSeconds_ = 10e-9;
                    maxWords_ = IO_BUFFER_LENGTH;
                } else if (revision_ == "D") {
                    clockInSeconds_ = 10e-9;
                    adcClockInSeconds_ = 10e-9;
                    filterClockInSeconds_ = 10e-9;
                    maxWords_ = EXTERNAL_FIFO_LENGTH;
                } else if (revision_ == "F" || revision_ == "DF") {
                    clockInSeconds_ = 8e-9;
                    adcClockInSeconds_ = 4e-9;
                    filterClockInSeconds_ = 8e-9;
                    maxWords_ = EXTERNAL_FIFO_LENGTH;
                } else {
                    throw GeneralException("Globals: unknown revision version "
                                           + revision_);
                }

            } else if (std::string(it->name()).compare("EventWidth") == 0) {

                std::string units = it->attribute("unit").as_string("None");
                double value = it->attribute("value").as_double(-1);

                if (units == "ns")
                    value *= 1e-9;
                else if (units == "us")
                    value *= 1e-6;
                else if (units == "ms")
                    value *= 1e-3;
                else if (units == "s")
                    value *= 1.0;
                else
                    throw GeneralException("Globals: unknown units " + units);

                eventInSeconds_ = value;
                eventWidth_ = (int)(eventInSeconds_ / clockInSeconds_);
                ss << "Event width: " << eventInSeconds_ * 1e6
                   << " us" << ", i.e. " << eventWidth_
                   << " pixie16 clock tics.";
                m.detail(ss.str());
                ss.str("");
            } else if (std::string(it->name()).compare("EnergyContraction") == 0) {
                energyContraction_ = it->attribute("value").as_double(1);
            } else if (std::string(it->name()).compare("Path") == 0) {
                configPath_ =  it->text().get();
                m.detail("Path to other configuration files: " + configPath_);
            } else if (std::string(it->name()).compare("NumOfTraces") == 0) {
                numTraces_ =  it->attribute("value").as_uint();
            } else
                WarnOfUnknownParameter(m, it);
        }

        unsigned int power2 = 1;
        unsigned int maxDammSize = 16384;
        while (power2 < numTraces_ && power2 < maxDammSize) {
            power2 *= 2;
        }
        ss << "Number of traces set to " << power2 << " ("
           << numTraces_ << ")";
        m.detail(ss.str());
        ss.str("");
        numTraces_ = power2;

        m.detail("Loading rejection regions");
        pugi::xml_node reject = doc.child("Configuration").child("Reject");
        for (pugi::xml_node time = reject.child("Time"); time;
            time = time.next_sibling("Time")) {
            int start = time.attribute("start").as_int(-1);
            int end = time.attribute("end").as_int(-1);

            std::stringstream ss;
            if (start < 0 || end < 0 || start > end) {
                ss << "Globals: incomplete or wrong rejection region "
                <<  "declaration: " << start << ", " << end;
                throw GeneralException(ss.str());
            }

            ss << "Rejection region: " << start << " to " << end << " s";
            m.detail(ss.str(), 1);
            std::pair<int, int> region(start, end);
            reject_.push_back(region);
        }

        if (reject_.size() > 0) {
            hasReject_ = true;
        }

        pugi::xml_node timing = doc.child("Configuration").child("Timing");

        for(pugi::xml_node_iterator it = timing.child("Physical").begin();
            it != timing.child("Physical").end(); ++it) {
            if(std::string(it->name()).compare("NeutronMass") == 0)
                neutronMass_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SpeedOfLight") == 0)
                speedOfLight_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SpeedOfLightSmall") == 0)
                speedOfLightSmall_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SpeedOfLightBig") == 0)
                speedOfLightBig_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SpeedOfLightMedium") == 0)
                speedOfLightMedium_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SmallLength") == 0)
                smallLength_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("MediumLength") == 0)
                mediumLength_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("BigLength") == 0)
                bigLength_ = it->attribute("value").as_double();
            else
                WarnOfUnknownParameter(m, it);
        }

        for(pugi::xml_node_iterator it = timing.child("Trace").begin();
            it != timing.child("Trace").end(); ++it) {
            if(std::string(it->name()).compare("WaveformRange") == 0) {
                waveformRange_.first =
                    it->child("Low").attribute("value").as_int(5);
                waveformRange_.second =
                    it->child("High").attribute("value").as_int(10);
            } else if(std::string(it->name()).compare("SiPmtWaveformRange") == 0) {
                siPmtWaveformRange_.first =
                    it->child("Low").attribute("value").as_int(5);
                siPmtWaveformRange_.second =
                    it->child("High").attribute("value").as_int(5);
            } else if(std::string(it->name()).compare("LaBr3WaveformRange") == 0) {
                labr3WaveformRange_.first =
                    it->child("Low").attribute("value").as_int(10);
                labr3WaveformRange_.second =
                    it->child("High").attribute("value").as_int(15);
            } else if(std::string(it->name()).compare("DiscriminationStart") == 0)
                discriminationStart_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("TrapezoidalWalk") == 0)
                trapezoidalWalk_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("TraceDelay") == 0)
                traceDelay_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("TraceLength") == 0)
                traceLength_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("QdcCompression") == 0)
                qdcCompression_ = it->attribute("value").as_double();
            else
                WarnOfUnknownParameter(m, it);
        }

        for(pugi::xml_node_iterator it = timing.child("Fitting").begin();
            it != timing.child("Fitting").end(); ++it) {
            if(std::string(it->name()).compare("SigmaBaselineThresh") == 0)
                sigmaBaselineThresh_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SiPmtSigmaBaselineThresh") == 0)
                siPmtSigmaBaselineThresh_ = it->attribute("value").as_double();
            else if (std::string(it->name()).compare("Vandle") == 0) {
                smallVandlePars_.first =
                    it->child("Small").child("Beta").attribute("value").as_double();
                smallVandlePars_.second =
                    it->child("Small").child("Gamma").attribute("value").as_double();
                mediumVandlePars_.first =
                    it->child("Medium").child("Beta").attribute("value").as_double();
                mediumVandlePars_.second =
                    it->child("Medium").child("Gamma").attribute("value").as_double();
                bigVandlePars_.first =
                    it->child("Big").child("Beta").attribute("value").as_double();
                bigVandlePars_.second =
                    it->child("Big").child("Gamma").attribute("value").as_double();
                tvandlePars_.first =
                    it->child("TeenyVandle").child("Beta").attribute("value").as_double();
                tvandlePars_.second =
                    it->child("TeenyVandle").child("Gamma").attribute("value").as_double();
            }else if (std::string(it->name()).compare("SingleBeta") == 0) {
                singleBetaPars_.first =
                    it->child("Beta").attribute("value").as_double();
                singleBetaPars_.second =
                    it->child("Gamma").attribute("value").as_double();
            }else if(std::string(it->name()).compare("DoubleBeta") == 0) {
                doubleBetaPars_.first = 0.0;
                doubleBetaPars_.second =
                    it->child("Gamma").attribute("value").as_double();
            }else if (std::string(it->name()).compare("Pulser") == 0) {
                pulserPars_.first =
                    it->child("Beta").attribute("value").as_double();
                pulserPars_.second =
                    it->child("Gamma").attribute("value").as_double();
            }else if (std::string(it->name()).compare("Liquid") == 0) {
                liquidScintPars_.first =
                    it->child("Beta").attribute("value").as_double();
                liquidScintPars_.second =
                    it->child("Gamma").attribute("value").as_double();
            }else if (std::string(it->name()).compare("LaBr3") == 0) {
                labr3_r6231_100Pars_.first =
                    it->child("r6231_100").child("Beta").attribute("value").as_double(0);
                labr3_r6231_100Pars_.second =
                    it->child("r6231_100").child("Gamma").attribute("value").as_double(0);
                labr3_r7724_100Pars_.first =
                    it->child("r7724_100").child("Beta").attribute("value").as_double(0);
                labr3_r7724_100Pars_.second =
                    it->child("r7724_100").child("Gamma").attribute("value").as_double(0);
            }else
                WarnOfUnknownParameter(m, it);
        }

        SanityCheck();
    } catch (std::exception &e) {
        std::cout << "Exception caught at Globals" << std::endl;
        std::cout << "\t" << e.what() << std::endl;
        exit(EXIT_FAILURE);
    }
}