MsPASS C++ API  2.4.1.dev4+g92330b7a
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
Public Member Functions | List of all members
mspass::utility::ProcessManager Class Reference

Manager for process-level algorithm and job identifiers. More...

#include <ProcessManager.h>

Public Member Functions

 ProcessManager ()
 
 ProcessManager (std::string fname)
 
AlgorithmDefinition algorithm (const std::string name, const size_t instance=0) const
 
std::string jobname () const
 
std::string jobid () const
 
std::string new_newid ()
 Get a new UUID to define unique job run.
 

Detailed Description

Manager for process-level algorithm and job identifiers.

Constructor & Destructor Documentation

◆ ProcessManager() [1/2]

mspass::utility::ProcessManager::ProcessManager ( )

Construct a default process manager.

10: jobnm() { job_uuid = gen(); };

◆ ProcessManager() [2/2]

mspass::utility::ProcessManager::ProcessManager ( std::string  fname)

Construct from a serialized process-manager file.

11 {
12 const string base_error("ProcessManager file constructor: ");
13 try {
14 job_uuid = gen();
15 ifstream ifs;
16 ifs.open(fname.c_str(), std::ifstream::in);
17 if (!ifs.is_open())
18 throw MsPASSError(base_error + "fopen failed for file=" + fname,
19 ErrorSeverity::Fatal);
20 /* job names needs to be the first line */
21 ifs >> jobnm;
22 /* Now we loop over lines with algorithm name and and idstring */
23 char inp[128];
24 while (ifs.getline(inp, 128)) {
25 map<string, vector<AlgorithmDefinition>>::iterator aptr;
26 stringstream ss(inp);
27 string algnm, idin, inptyp, outtyp;
28 ss >> algnm;
29 ss >> idin;
30 ss >> inptyp;
31 ss >> outtyp;
32 AlgorithmDefinition thisalg(algnm, inptyp, outtyp, idin);
33 aptr = algs.find(algnm);
34 if (aptr == algs.end()) {
35 vector<AlgorithmDefinition> temp;
36 temp.push_back(thisalg);
37 algs.insert(pair<string, vector<AlgorithmDefinition>>(algnm, temp));
38 } else {
39 aptr->second.push_back(thisalg);
40 }
41 }
42 } catch (...) {
43 throw;
44 };
45};

Member Function Documentation

◆ algorithm()

AlgorithmDefinition mspass::utility::ProcessManager::algorithm ( const std::string  name,
const size_t  instance = 0 
) const

Return an algorithm definition by name and instance number.

47 {
48 size_t i;
49 map<string, vector<AlgorithmDefinition>>::const_iterator aptr;
50 aptr = algs.find(name);
51 if (aptr == algs.end()) {
52 /* If the name is not registered the map we don't want this
53 method to throw an error. Instead we return the name with
54 the id field set to UNDEFINED*/
55 return AlgorithmDefinition(name, "UNDEFINED", "UNDEFINED", "UNDEFINED");
56 } else {
57 i = instance;
58 if (instance >= (aptr->second.size())) {
59 cerr << "ProcessManager::algorithm(Warning): "
60 << "algorithm=" << name
61 << " was defined but requested instance=" << instance
62 << " exceeds number of defined instances=" << aptr->second.size()
63 << endl
64 << "Set to id for instance=" << aptr->second.size() - 1 << endl
65 << "History data may be invalid" << endl;
66 i = aptr->second.size() - 1;
67 }
68 }
69 return aptr->second[i];
70}

◆ jobid()

std::string mspass::utility::ProcessManager::jobid ( ) const
inline

Return the job UUID as a string.

134{ return boost::uuids::to_string(job_uuid); };

◆ jobname()

std::string mspass::utility::ProcessManager::jobname ( ) const
inline

Return the job name.

132{ return jobnm; };

◆ new_newid()

std::string mspass::utility::ProcessManager::new_newid ( )
inline

Get a new UUID to define unique job run.

MsPASS data objects are tagged with a UUID to properly handle processing history. Procedures can call his method to get a uuid based on boost's random_generator. We keep the generator in this object because web conversations suggest construction of random_generator is expensive in time and needs to not be done at the object level.

Returns
new uuid definign this job in string form.
146 {
147 boost::uuids::uuid id;
148 id = gen();
149 return boost::uuids::to_string(id);
150 }

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