Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ file(COPY ${CMAKE_SOURCE_DIR}/lattice_files/
add_library(yaml_c_wrapper SHARED src/yaml_c_wrapper.cpp)
target_link_libraries(yaml_c_wrapper PUBLIC yaml-cpp)

add_executable(example_read_write examples/example_read_write.cpp)
target_link_libraries(example_read_write yaml_c_wrapper yaml-cpp)
add_executable(example_rw examples/example_rw.cpp)
target_link_libraries(example_rw yaml_c_wrapper yaml-cpp)

add_executable(get_lattices src/get_lattices.cpp)
target_link_libraries(get_lattices yaml_c_wrapper yaml-cpp)
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ repeat
YAML::Nodes are values that act like pointers, so editing a node will cause the tree the node is
contained in to reflect the changes.

Lattice files should be placed in the `lattice_files/` directory.

## Usage
In pals-cpp, run

Expand All @@ -20,12 +22,22 @@ cmake --build build
This builds `libyaml_c_wrapper.dylib`, a shared object library that can be used
by other languages.

It also builds an executable using yaml_reader.cpp containing examples for how
It also builds an executable at build/example_rw containing examples for how
to use the library to read lattice files, perform basic manipulations, and write
to other lattice files. To see the output, navigate to the directory `build` and run

The program `get_lattices` will create a struct containing three lattices:
- `original` is a map containing the base lattice as well as any lattices included
in the base lattice.
- `included` is the base lattice but with all included files substituted in.
- `expanded` is the base lattice after lattice expansion has been performed.
Specify the lattice file with the first argument to the function. On default,
the lattice specified by the last `use` statement will be used, and if no `use`
statement exists, the lattice lattice in the file will be used. An optional flag
`-lat lattice_name` can be used to specify the lattice to expand, which has greatest
priority. For example, in the build directory, run
```console
./yaml_reader
./get_lattices ex.pals.yaml -lat lat2
```

It will also build the tests.
Expand Down
File renamed without changes.
71 changes: 0 additions & 71 deletions examples/yaml_reader.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion lattice_files/ex.pals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
direction: -1
- a_subline: # Item a_subline is repeated three times
repeat: 3
- include: "include.pals.yaml"
- include: "../lattice_files/include.pals.yaml"
- a_subline:
kind: BeamLine
line:
Expand Down
2 changes: 1 addition & 1 deletion lattice_files/include.pals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
- first: 1
- second: 2
- third: 3
- include: "include2.pals.yaml"
- include: "../lattice_files/include2.pals.yaml"
10 changes: 5 additions & 5 deletions src/get_lattices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
#include <cstring>

int main(int argc, char* argv[]) {
std::string file_name = "ex.pals.yaml";
const char* file_name = "../lattice_files/ex.pals.yaml";
const char* lattice_name = "";
if (argc >= 1) {
file_name = argv[0];
}
if (argc >= 2) {
file_name = argv[1];
}
if (argc >= 3) {
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-lat") == 0) {
lattice_name = argv[i+1];
}
}
}

struct lattices lat = get_lattices("ex.pals.yaml", lattice_name);
struct lattices lat = get_lattices(file_name, lattice_name);
std::cout << "Printing original lattice information: " << std::endl;
std::cout << yaml_to_string(lat.original) << std::endl << "\n\n";

Expand Down
12 changes: 9 additions & 3 deletions src/yaml_c_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ std::vector<YAML::Node> search_kind(YAML::Node root,
return search(root, condition_wrapper);
}

// /* `node` should be a Lattice or Beamline. For each element in the line,
// add the map {parent, `node`.}*/
// void add_parents(YAML::Node node) {

// }

/*
Recursively loops through the node to record all the lattices and beamlines and
their corresponding parameters.
Expand Down Expand Up @@ -113,7 +119,7 @@ void add_to_original(YAML::Node original, std::string filename) {
if (!original[filename]) {
YAML::Node node = YAML::Node(YAML::NodeType::Map);
node["path"] = "";
node["info"] = YAML::LoadFile("../lattice_files/" + filename);
node["info"] = YAML::LoadFile(filename);
original[filename] = node;
}
}
Expand Down Expand Up @@ -158,7 +164,7 @@ YAML::Node original_lattice(std::string filename) {
Constructs the included lattice.
*/
YAML::Node included_lattice(std::string filename) {
YAML::Node included = YAML::LoadFile("../lattice_files/" + filename);
YAML::Node included = YAML::LoadFile(filename);
std::vector<YAML::Node> include_files =
search(included,
[](YAML::Node node) { return node.IsMap() && node["include"]; });
Expand Down Expand Up @@ -328,7 +334,7 @@ statement will be expanded.
that occurs latest in the file will be expanded.
*/
YAML::Node expanded_lattice(std::string filename, std::string lattice_name) {
YAML::Node root = YAML::LoadFile("../lattice_files/" + filename);
YAML::Node root = YAML::LoadFile(filename);
root = included_lattice(filename);
std::map<std::string, YAML::Node>* elements_map = get_dict(root);

Expand Down
Loading