• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cyclus / cyclus / 15072701494

16 May 2025 04:08PM UTC coverage: 41.167% (+0.003%) from 41.164%
15072701494

push

github

web-flow
Merge pull request #1846 from gonuke/fix_schema

Fix ability to generate a master schema

22 of 32 new or added lines in 5 files covered. (68.75%)

26 existing lines in 5 files now uncovered.

51764 of 125743 relevant lines covered (41.17%)

17765.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.19
/src/xml_flat_loader.cc
1
#include "xml_flat_loader.h"
2

3
#include "agent.h"
4
#include "context.h"
5
#include "discovery.h"
6
#include "env.h"
7
#include "error.h"
8
#include "infile_tree.h"
9
#include "logger.h"
10
#include "recorder.h"
11
#include "timer.h"
12

13
namespace cyclus {
14

15
std::string BuildFlatMasterSchema(std::string schema_path, std::vector<AgentSpec> specs) {
4✔
16
  Timer ti;
4✔
17
  Recorder rec;
4✔
18
  Context ctx(&ti, &rec);
4✔
19

20
  std::stringstream schema("");
4✔
21
  LoadStringstreamFromFile(schema, schema_path);
12✔
22
  std::string master = schema.str();
23

24
  std::string subschemas;
25
  for (int i = 0; i < specs.size(); ++i) {
12✔
26
    Agent* m = DynamicModule::Make(&ctx, specs[i]);
8✔
27
    subschemas += "<element name=\"" + specs[i].alias() + "\">\n";
16✔
28
    subschemas += m->schema() + "\n";
16✔
29
    subschemas += "</element>\n";
30
    ctx.DelAgent(m);
8✔
31
  }
32

33
  // replace refs in master rng template file
34
  std::string search_str = std::string("@MODEL_SCHEMAS@");
4✔
35
  size_t pos = master.find(search_str);
36
  if (pos != std::string::npos) {
4✔
37
    master.replace(pos, search_str.size(), subschemas);
38
  }
39

40
  return master;
4✔
41
}
4✔
42

43
std::string BuildFlatMasterSchema(std::string schema_path, std::string infile) {
4✔
44

45
  std::vector<AgentSpec> specs = ParseSpecs(infile);
12✔
46

47
  return BuildFlatMasterSchema(schema_path, specs);
16✔
48

49
}
4✔
50

NEW
51
std::string BuildFlatMasterSchema(std::string schema_path) {
×
52

NEW
53
  std::vector<AgentSpec> specs = ParseSpecs(cyclus::DiscoverSpecsInCyclusPath());
×
54

NEW
55
  return BuildFlatMasterSchema(schema_path, specs);
×
56

NEW
57
}
×
58

59
std::string XMLFlatLoader::master_schema() {
4✔
60
  return BuildFlatMasterSchema(schema_path_, file_);
12✔
61
}
62

63
void XMLFlatLoader::LoadInitialAgents() {
4✔
64
  InfileTree xqe(*parser_);
4✔
65

66
  // create prototypes
67
  int num_protos = xqe.NMatches("/*/prototype");
4✔
68
  for (int i = 0; i < num_protos; i++) {
12✔
69
    InfileTree* qe = xqe.SubTree("/*/prototype", i);
8✔
70
    std::string prototype = qe->GetString("name");
8✔
71
    std::string alias = qe->SubTree("config")->GetElementName(0);
8✔
72
    AgentSpec spec = specs_[alias];
8✔
73

74
    Agent* agent = DynamicModule::Make(ctx_, spec);
8✔
75

76
    // call manually without agent impl injected to keep all Agent state in a
77
    // single, consolidated db table
78
    agent->Agent::InfileToDb(qe, DbInit(agent, true));
8✔
79

80
    agent->InfileToDb(qe, DbInit(agent));
8✔
81
    rec_->Flush();
8✔
82

83
    std::vector<Cond> conds;
84
    conds.push_back(Cond("SimId", "==", rec_->sim_id()));
24✔
85
    conds.push_back(Cond("AgentId", "==", agent->id()));
16✔
86
    conds.push_back(Cond("SimTime", "==", static_cast<int>(0)));
16✔
87
    CondInjector ci(b_, conds);
8✔
88
    PrefixInjector pi(&ci, "AgentState");
8✔
89

90
    // call manually without agent impl injected
91
    agent->Agent::InitFrom(&pi);
8✔
92

93
    pi = PrefixInjector(&ci, "AgentState" + spec.Sanitize());
24✔
94
    agent->InitFrom(&pi);
8✔
95
    ctx_->AddPrototype(prototype, agent);
24✔
96
  }
8✔
97

98
  // retrieve agent hierarchy and initial inventories
99
  int num_agents = xqe.NMatches("/*/agent");
8✔
100
  std::map<std::string, std::string> protos;  // map<name, prototype>
101
  std::map<std::string, std::string> parents;  // map<agent, parent>
102
  std::set<std::string> agents;  // set<agent_name>
103
  std::map<std::string, InfileTree*> invs;  // map<agent, qe>;
104
  for (int i = 0; i < num_agents; i++) {
12✔
105
    InfileTree* qe = xqe.SubTree("/*/agent", i);
8✔
106
    std::string name = qe->GetString("name");
8✔
107
    std::string proto = qe->GetString("prototype");
8✔
108
    std::string parent = OptionalQuery<std::string>(qe, "parent", "");
16✔
109
    protos[name] = proto;
8✔
110
    parents[name] = parent;
8✔
111
    invs[name] = qe;
8✔
112
    agents.insert(name);
113
  }
114

115
  // build agents starting at roots (no parent) down.
116
  std::map<std::string, Agent*> built;  // map<agent_name, agent_ptr>
117
  std::set<std::string>::iterator it = agents.begin();
118
  while (agents.size() > 0) {
12✔
119
    std::string name = *it;
120
    std::string proto = protos[name];
8✔
121
    std::string parent = parents[name];
8✔
122
    if (parent == "") {
8✔
123
      built[name] = BuildAgent(proto, NULL);
16✔
124
      ++it;
125
      agents.erase(name);
126
    } else if (built.count(parent) > 0) {
127
      built[name] = BuildAgent(proto, built[parent]);
×
128
      ++it;
129
      agents.erase(name);
130
    } else {
131
      ++it;
132
    }
133
    if (it == agents.end()) {
8✔
134
      it = agents.begin();
135
    }
136
  }
137
}
4✔
138

139
}  // namespace cyclus
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc