MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / getMeasureInfo

Method getMeasureInfo

src/cli/MeasureManager.cpp:385–557  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383}
384
385openstudio::measure::OSMeasureInfo MeasureManager::getMeasureInfo(const openstudio::path& measureDirPath, const BCLMeasure& measure,
386 const openstudio::path& osmOrIdfPath, const boost::optional<model::Model>& model_,
387 const boost::optional<Workspace>& workspace_) {
388
389 if (!m_measures.contains(measureDirPath)) {
390 LOG_AND_THROW("Measure isn't recorded in m_measures, that should NOT happen");
391 }
392 auto& bclMeasureInfo = m_measures.at(measureDirPath);
393 auto it2 = bclMeasureInfo.measureInfos.find(osmOrIdfPath);
394 if (it2 != bclMeasureInfo.measureInfos.end()) {
395 fmt::print("Using cached OSMeasureInfo for '{}', '{}'\n", measureDirPath.generic_string(), osmOrIdfPath.generic_string());
396 return it2->second;
397 }
398
399 auto scriptPath_ = measure.primaryScriptPath();
400 if (!scriptPath_) {
401 throw std::runtime_error(
402 fmt::format("Unable to locate primary Ruby script path for BCLMeasure '{}' located at '{}'", measure.name(), measureDirPath.generic_string()));
403 }
404
405 auto getOrCreateModel = [this, &model_, &osmOrIdfPath]() -> openstudio::model::Model {
406 if (model_) {
407 // model should already have been cloned in the endpoint, so no need to do it twice
408 return *model_; // _->clone(true).cast<openstudio::model::Model>();
409 } else if (!osmOrIdfPath.empty()) {
410 // TODO: not sure we want to keep this here or not..
411 if (auto osmInfo_ = getModel(osmOrIdfPath)) {
412 return osmInfo_->model.clone().cast<openstudio::model::Model>();
413 } else {
414 LOG_AND_THROW("Failed to load the Model at " << osmOrIdfPath);
415 }
416 } else {
417 return {};
418 }
419 };
420
421 auto getOrCreateWorkspace = [this, &workspace_, &osmOrIdfPath]() -> openstudio::Workspace {
422 if (workspace_) {
423 return *workspace_; // ->clone(true);
424 } else if (!osmOrIdfPath.empty()) {
425 if (auto idfInfo_ = getIdf(osmOrIdfPath)) {
426 return idfInfo_->workspace.clone();
427 } else {
428 LOG_AND_THROW("Failed to load the Model at " << osmOrIdfPath);
429 }
430 } else {
431 return {openstudio::StrictnessLevel::Draft, openstudio::IddFileType::EnergyPlus};
432 }
433 };
434
435 ScriptEngineInstance* thisEngine = nullptr;
436 const MeasureLanguage measureLanguage = measure.measureLanguage();
437 if (measureLanguage == MeasureLanguage::Ruby) {
438 thisEngine = &rubyEngine;
439 } else if (measureLanguage == MeasureLanguage::Python) {
440 thisEngine = &pythonEngine;
441 }
442

Callers 2

compute_argumentsMethod · 0.80
executeMethod · 0.80

Calls 15

primaryScriptPathMethod · 0.80
measureLanguageMethod · 0.80
valueNameMethod · 0.80
findMethod · 0.45
endMethod · 0.45
nameMethod · 0.45
emptyMethod · 0.45
cloneMethod · 0.45
inferMeasureClassNameMethod · 0.45
loadMeasureMethod · 0.45
measureTypeMethod · 0.45
descriptionMethod · 0.45

Tested by

no test coverage detected