DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::tool::graph::segregated_graph_write Class Reference

#include <segregate.hpp>

Public Member Functions

 segregated_graph_write (std::string const &ofn_prefix, size_t const minc=0, size_t const maxc=0)
 
int operator() (gtool const &) const
 

Private Attributes

std::string const this_dest_prefix
 
size_t const this_min_component_size
 
size_t const this_max_component_size
 

Detailed Description

Definition at line 21 of file segregate.hpp.

Constructor & Destructor Documentation

◆ segregated_graph_write()

dbe::tool::graph::segregated_graph_write::segregated_graph_write ( std::string const & ofn_prefix,
size_t const minc = 0,
size_t const maxc = 0 )

Construct an object from the filename prefix ,the mininimum and maximum size components to be included in the output. Separate files are generated for it component

Parameters
ofnis an std::string of the filename prefix
mincis the minimum size for a component to be considered
maxcis the maximum sized component to be included in the output

Definition at line 26 of file segregate.cpp.

Member Function Documentation

◆ operator()()

int dbe::tool::graph::segregated_graph_write::operator() ( gtool const & tool) const

Definition at line 36 of file segregate.cpp.

37{
38 typedef long unsigned int t_int;
39 gtool::t_graph const & G = tool.getgraph();
40 std::vector<t_int> compindices ( boost::num_vertices ( G ) );
41 t_int total_connected = boost::connected_components ( G, &compindices[0] );
42
43 std::vector<gtool::t_graph> components ( total_connected );
44 std::vector<gtool::t_registry> component_registries ( total_connected );
45
46 // Build the components as seperate graphs
47 for ( t_int vector_i = 0; vector_i != compindices.size(); ++vector_i )
48 {
49 t_int component_j = compindices[vector_i];
50 std::string const & oname = boost::get ( &gtool::vertex_label::uid, G ) [vector_i];
51 std::string const & cname = boost::get ( &gtool::vertex_label::cname, G ) [vector_i];
53 components[component_j],
55 { oname, cname } ),
56 component_registries[component_j] );
57 }
58
59 // from the graphs built output only those that are within the range specified
60
61 int max_punits = GTOOL_MAX_THREADS;
62
63 typedef std::future<void> t_futuwrite;
64 std::vector<std::future<void>> punits;
65
66 unsigned long long int c = 0;
67
68 for ( auto const & g : components )
69 {
70 size_t const component_size = g.vertex_set().size();
71
72 if ( component_size > this_min_component_size
73 and component_size < this_max_component_size )
74 {
75 if ( --max_punits )
76 {
77 std::string output_file
78 { this_dest_prefix + std::string ( "_" ) + std::to_string ( ++c ) + std::string ( ".dot" ) };
79
80 try
81 {
82 punits.push_back ( std::async ( std::launch::async, graph::write, g, output_file ) );
83 }
84 catch ( std::system_error const & e )
85 {
86 if ( e.code() == std::errc::resource_unavailable_try_again )
87 {
88
89 ERROR (
90 "Could not launch another thread", e.what(), "for file:", output_file,
91 "try to launch in deferred" );
92
93 punits.push_back (
94 std::async ( std::launch::deferred, graph::write, g, output_file ) );
95
96 WARN (
97 "File write policy change", "Program execution correction", " for file:",
98 output_file, " launched in deferred" );
99
100 }
101 else
102 {
103 throw e;
104 }
105 }
106 }
107 else
108 {
109 // The standard dictates ( C++11 ) that wait is called on the destructor
110 // and the futures launched are either async or defered, which puts them
111 // always in a valid state. All that is needed to do is clear the vector
112 // of futures to initiate calling the destructors.
113 punits.clear();
114 max_punits = GTOOL_MAX_THREADS;
115 }
116 }
117 }
118
119 return EXIT_SUCCESS;
120}
static configobject::tref get(dbe::cokey const &desc)
static t_vertex add_object_and_friends(t_graph &, tref const &, t_registry &registry)
Definition gtool.cpp:161
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, vertex_label > t_graph
Definition gtool.hpp:50
#define ERROR(...)
Definition messenger.hpp:88
#define WARN(...)
Definition messenger.hpp:80
void write(gtool::t_graph const &, std::string const &)
Definition gtool.cpp:221
#define GTOOL_MAX_THREADS
Definition segregate.cpp:17

Member Data Documentation

◆ this_dest_prefix

std::string const dbe::tool::graph::segregated_graph_write::this_dest_prefix
private

Definition at line 38 of file segregate.hpp.

◆ this_max_component_size

size_t const dbe::tool::graph::segregated_graph_write::this_max_component_size
private

Definition at line 40 of file segregate.hpp.

◆ this_min_component_size

size_t const dbe::tool::graph::segregated_graph_write::this_min_component_size
private

Definition at line 39 of file segregate.hpp.


The documentation for this class was generated from the following files: