hepnos-ls.cpp 1.24 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5
#include <iostream>
#include <hepnos.hpp>

void navigate_subrun(int level, hepnos::SubRun& sr) {
    for(int i=0; i < level; i++) std::cout << " ";
Matthieu Dorier's avatar
Matthieu Dorier committed
6
    std::cout << "| [S] " << sr.number() << std::endl;
Matthieu Dorier's avatar
Matthieu Dorier committed
7 8
    for(auto& e : sr) {
        for(int i=0; i < level+1; i++) std::cout << " ";
Matthieu Dorier's avatar
Matthieu Dorier committed
9
        std::cout << "| [E] " << e.number() << std::endl;
Matthieu Dorier's avatar
Matthieu Dorier committed
10 11 12 13 14
    }
}

void navigate_run(int level, hepnos::Run& r) {
    for(int i=0; i < level; i++) std::cout << " ";
Matthieu Dorier's avatar
Matthieu Dorier committed
15
    std::cout << "| [R] " << r.number() << std::endl;
Matthieu Dorier's avatar
Matthieu Dorier committed
16 17 18 19 20 21 22
    for(auto& sr : r) {
        navigate_subrun(level+1, sr);
    }
}

void navigate_dataset(int level, hepnos::DataSet& ds) {
    for(int i=0; i < level; i++) std::cout << " ";
Matthieu Dorier's avatar
Matthieu Dorier committed
23
    std::cout << "| [D] " << ds.name() << std::endl;
Matthieu Dorier's avatar
Matthieu Dorier committed
24 25 26
    for(auto& sub_ds : ds) {
        navigate_dataset(level+1, sub_ds);
    }
27 28
    for(auto it = ds.runs().begin(); it != ds.runs().end(); it++) {
        navigate_run(level+1, *it);
Matthieu Dorier's avatar
Matthieu Dorier committed
29 30 31 32 33 34 35 36 37 38
    }
}

int main(int argc, char* argv[])
{
    if(argc != 2 ) {
        std::cerr << "Usage: " << argv[0] << " <connection.yaml>" << std::endl;
        exit(-1);
    }

Matthieu Dorier's avatar
Matthieu Dorier committed
39
    hepnos::DataStore datastore = hepnos::DataStore::connect(std::string(argv[1]));
40
    for(auto& ds : datastore.root()) {
Matthieu Dorier's avatar
Matthieu Dorier committed
41 42 43 44 45
        navigate_dataset(0, ds);
    }

    return 0;
}