1 /* Copyright (c) 2010-2016. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/jedule/jedule.hpp"
8 #include "simgrid/s4u/NetZone.hpp"
9 #include "xbt/asserts.h"
11 #if SIMGRID_HAVE_JEDULE
15 Event::Event(std::string name, double start_time, double end_time, std::string type)
16 : name(name), start_time(start_time), end_time(end_time), type(type)
18 this->resource_subsets = new std::vector<jed_subset_t>();
23 if (not this->resource_subsets->empty()) {
24 for (auto const& subset : *this->resource_subsets)
26 delete this->resource_subsets;
30 void Event::addResources(std::vector<sg_host_t> *host_selection)
32 get_resource_selection_by_hosts(this->resource_subsets, host_selection);
35 void Event::addCharacteristic(char *characteristic)
37 xbt_assert( characteristic != nullptr );
38 this->characteristics_list.push_back(characteristic);
41 void Event::addInfo(char* key, char *value) {
42 xbt_assert((key != nullptr) && value != nullptr);
43 this->info_map.insert({key, value});
46 void Event::print(FILE *jed_file)
48 fprintf(jed_file, " <event>\n");
49 fprintf(jed_file, " <prop key=\"name\" value=\"%s\" />\n", this->name.c_str());
50 fprintf(jed_file, " <prop key=\"start\" value=\"%g\" />\n", this->start_time);
51 fprintf(jed_file, " <prop key=\"end\" value=\"%g\" />\n", this->end_time);
52 fprintf(jed_file, " <prop key=\"type\" value=\"%s\" />\n", this->type.c_str());
54 xbt_assert(not this->resource_subsets->empty());
55 fprintf(jed_file, " <res_util>\n");
56 for (auto const& subset : *this->resource_subsets) {
57 fprintf(jed_file, " <select resources=\"");
58 fprintf(jed_file, "%s", subset->parent->getHierarchyAsString().c_str());
59 fprintf(jed_file, ".[%d-%d]", subset->start_idx, subset->start_idx + subset->nres-1);
60 fprintf(jed_file, "\" />\n");
62 fprintf(jed_file, " </res_util>\n");
64 if (not this->characteristics_list.empty()) {
65 fprintf(jed_file, " <characteristics>\n");
66 for (auto const& ch : this->characteristics_list)
67 fprintf(jed_file, " <characteristic name=\"%s\" />\n", ch);
68 fprintf(jed_file, " </characteristics>\n");
71 if (not this->info_map.empty()) {
72 fprintf(jed_file, " <info>\n");
73 for (auto const& elm : this->info_map)
74 fprintf(jed_file, " <prop key=\"%s\" value=\"%s\" />\n",elm.first,elm.second);
75 fprintf(jed_file, " </info>\n");
78 fprintf(jed_file, " </event>\n");