29 : moutput(), minput(), msetvalue(), mtasks(ws) {}
38 moutput(
std::move(output)),
39 minput(
std::move(input)),
47 : ws(workspace.weak_from_this()),
71 const auto i2 = MdMap.find(methodname);
73 Index
id = i2->second;
99 "Agendas must share workspace"
109 auto mi = AgendaMap.find(
mname);
115 if (mi == AgendaMap.end()) {
120 const AgRecord& this_data = agenda_data[mi->second];
126 for (Index i = 0; i < this_data.
Out().
nelem(); ++i) {
128 Index this_wsv = this_data.
Out()[i];
132 os <<
"The agenda " <<
mname <<
" must generate the output WSV "
134 <<
"but it does not. It only generates:\n";
137 throw runtime_error(os.str());
143 for (Index i = 0; i < this_data.
In().
nelem(); ++i) {
145 Index this_wsv = this_data.
In()[i];
149 os <<
"The agenda " <<
mname <<
" must use the input WSV "
151 <<
"but it does not. It only uses:\n";
154 throw runtime_error(os.str());
172This check is usually done by AgendaSet or AgendaAppend.
174There are three possible causes for this:
175 1) Custom agenda: You're trying to execute an agenda that has been
176 created manually. This is not allowed. You have to use one of
177 the predefined agendas and execute that one.
178 2) Developer error: If you have written code that modifies an Agenda
179 directly (changing its name or altering its method list), it's up
180 to you to call Agenda::check in your code after your modifications.
181 3) Workspace mismatch: All Agendas live on the workspace and can only
182 be executed by the workspace, or a child of the workspace, that
183 was originally connected to the workspace.
198 const Index wsv_id_verbosity = ws_in.
WsvMap_ptr->at(
"verbosity");
202 *(
static_cast<Verbosity*
>(ws_in[wsv_id_verbosity].
get()));
212 aout1 <<
"Executing " <<
name() <<
"\n"
216 for (Index i = 0; i <
mml.
nelem(); ++i) {
218 *
static_cast<Verbosity*
>(ws_in[wsv_id_verbosity].
get());
230 out3 <<
"- " + mdd.
Name() +
"\n";
232 out1 <<
"- " + mdd.
Name() +
"\n";
238 for (Index s = 0; s <
v.nelem(); ++s) {
239 if ((s !=
v.nelem() - 1 || !mdd.
SetMethod()) &&
242 "Method " + mdd.
Name() +
243 " needs input variable: " + (*ws_in.
wsv_data_ptr)[
v[s]].Name());
250 for (Index s = 0; s <
v.nelem(); ++s)
252 throw runtime_error(
"Method " + mdd.
Name() +
253 " needs input variable: " +
260 }
catch (
const std::bad_alloc& x) {
264 os <<
"Memory allocation error in method: " << mdd.
Name() <<
'\n'
265 <<
"For memory intensive jobs it could help to limit the\n"
266 <<
"number of threads with the -n option.\n"
269 throw runtime_error(os.str());
270 }
catch (
const std::exception& x) {
274 os <<
"Run-time error in method: " << mdd.
Name() <<
'\n' << x.what();
276 throw runtime_error(os.str());
282 ws_in.
pop(wsv_id_verbosity);
300 set<Index> outs2push;
303 const Index WsmAgendaExecuteIndex = MdMap.find(
"AgendaExecute")->second;
304 const Index WsmAgendaExecuteExclIndex =
305 MdMap.find(
"AgendaExecuteExclusive")->second;
306 const Index WsmDeleteIndex = MdMap.find(
"Delete")->second;
307 const Index WsvAgendaGroupIndex = WsvGroupMap.find(
"Agenda")->second;
309 for (
auto & method :
mml) {
316 souts.insert(gouts.begin(), gouts.end());
320 inputs.insert(gins.begin(), gins.end());
326 if (method.Id() == WsmDeleteIndex) {
327 souts.insert(gins.begin(), gins.end());
334 if (method.Id() == WsmAgendaExecuteIndex ||
335 method.Id() == WsmAgendaExecuteExclIndex) {
336 for (Index j = 0; j < md_data[method.Id()].GInType().
nelem(); j++) {
337 if (md_data[method.Id()].GInType()[j] == WsvAgendaGroupIndex) {
338 const String& agenda_name = (*
workspace()->wsv_data_ptr)[gins[j]].Name();
339 const auto agenda_it =
340 AgendaMap.find(agenda_name);
342 if (agenda_it == AgendaMap.end()) {
344 os <<
"Manual execution of the agenda \"" << agenda_name
345 <<
"\" is not supported.";
346 throw std::runtime_error(os.str());
348 const ArrayOfIndex& agouts = agenda_data[agenda_it->second].Out();
349 souts.insert(agouts.begin(), agouts.end());
350 const ArrayOfIndex& agins = agenda_data[agenda_it->second].In();
351 inputs.insert(agins.begin(), agins.end());
357 outputs.insert(souts.begin(), souts.end());
362 set_intersection(souts.begin(),
366 insert_iterator<set<Index> >(outs2dup, outs2dup.begin()));
369 const ArrayOfIndex& mdinout = md_data[method.Id()].InOut();
372 for (Index j = 0; j < mdinout.
nelem(); j++) {
373 inputs.insert(output[mdinout[j]]);
378 set_difference(outputs.begin(),
382 insert_iterator<set<Index> >(outs2push, outs2push.begin()));
391 saout.insert(aout.begin(), aout.end());
392 sain.insert(ain.begin(), ain.end());
400 set<Index> outs2push_without_agenda_input;
406 insert_iterator<set<Index> >(outs2push_without_agenda_input,
407 outs2push_without_agenda_input.begin()));
411 outs2push_without_agenda_input.begin(),
412 outs2push_without_agenda_input.end(),
420 set<Index> outs2dup_without_agenda_input;
426 insert_iterator<set<Index> >(outs2dup_without_agenda_input,
427 outs2dup_without_agenda_input.begin()));
431 outs2dup_without_agenda_input.begin(),
432 outs2dup_without_agenda_input.end(),
441 set<Index> saout_only;
443 set_difference(saout.begin(),
447 insert_iterator<set<Index> >(saout_only, saout_only.begin()));
450 set_intersection(outs2dup.begin(),
454 insert_iterator<ArrayOfIndex>(
455 agenda_only_out_wsm_in, agenda_only_out_wsm_in.begin()));
461 set<Index> sain_only;
463 set_difference(sain.begin(),
467 insert_iterator<set<Index> >(sain_only, sain_only.begin()));
470 set_intersection(outs2push.begin(),
474 insert_iterator<ArrayOfIndex>(
475 agenda_only_in_wsm_out, agenda_only_in_wsm_out.begin()));
479 out3 <<
" [Agenda::pushpop] : " <<
name() <<
"\n";
480 out3 <<
" [Agenda::pushpop] - # Funcs in Ag : " <<
mml.
nelem() <<
"\n";
481 out3 <<
" [Agenda::pushpop] - AgOut : ";
484 out3 <<
" [Agenda::pushpop] - AgIn : ";
487 out3 <<
" [Agenda::pushpop] - All WSM output: ";
490 out3 <<
" [Agenda::pushpop] - All WSM input : ";
493 out3 <<
" [Agenda::pushpop] - Output WSVs push : ";
496 out3 <<
" [Agenda::pushpop] - Output WSVs dup : ";
499 out3 <<
" [Agenda::pushpop] - Ag inp dup : ";
502 out3 <<
" [Agenda::pushpop] - Ag out dup : ";
524 const Index WsmAgendaExecuteIndex = MdMap.find(
"AgendaExecute")->second;
525 const Index WsmAgendaExecuteExclIndex =
526 MdMap.find(
"AgendaExecuteExclusive")->second;
533 const Index WsvAgendaGroupIndex = WsvGroupMap.find(
"Agenda")->second;
536 for (Index i = 0; i <
nelem(); ++i) {
545 for (Index j = 0; j < input.
nelem(); ++j) {
546 if (var == input[j])
return true;
553 for (Index j = 0; j < mdinout.
nelem(); j++) {
554 if (var == output[mdinout[j]])
return true;
560 if (this_method.
Id() == WsmAgendaExecuteIndex ||
561 this_method.
Id() == WsmAgendaExecuteExclIndex) {
562 for (Index j = 0; j < md_data[this_method.
Id()].GInType().nelem();
564 if (md_data[this_method.
Id()].GInType()[j] == WsvAgendaGroupIndex) {
566 const auto agenda_it =
567 AgendaMap.find(agenda_name);
569 if (agenda_it == AgendaMap.end()) {
571 os <<
"Manual execution of the agenda \"" << agenda_name
572 <<
"\" is not supported.";
573 throw std::runtime_error(os.str());
575 const ArrayOfIndex& agins = agenda_data[agenda_it->second].In();
576 for (Index k = 0; k < agins.
nelem(); ++k) {
577 if (var == agins[k])
return true;
606 const Index WsmAgendaExecuteIndex = MdMap.find(
"AgendaExecute")->second;
607 const Index WsmAgendaExecuteExclIndex =
608 MdMap.find(
"AgendaExecuteExclusive")->second;
611 const Index WsvAgendaGroupIndex = WsvGroupMap.find(
"Agenda")->second;
614 for (Index i = 0; i <
nelem(); ++i) {
623 for (Index j = 0; j < output.
nelem(); ++j) {
624 if (var == output[j])
return true;
630 if (this_method.
Id() == WsmAgendaExecuteIndex ||
631 this_method.
Id() == WsmAgendaExecuteExclIndex) {
632 for (Index j = 0; j < md_data[this_method.
Id()].GInType().nelem();
634 if (md_data[this_method.
Id()].GInType()[j] == WsvAgendaGroupIndex) {
635 const String& agenda_name =
636 (*
workspace()->wsv_data_ptr)[this_method.
In()[j]].Name();
637 const auto agenda_it =
638 AgendaMap.find(agenda_name);
640 if (agenda_it == AgendaMap.end()) {
642 os <<
"Manual execution of the agenda \"" << agenda_name
643 <<
"\" is not supported.";
644 throw std::runtime_error(os.str());
646 const ArrayOfIndex& agouts = agenda_data[agenda_it->second].Out();
647 for (Index k = 0; k < agouts.
nelem(); k++)
648 if (agouts[k] == var)
return true;
694 for (
auto it =
mml.begin();
695 !found && it !=
mml.end();
697 if (md_data[it->Id()].Name() == methodname) found =
true;
720 for (Index i = 0; i <
mml.
nelem(); ++i) {
722 mml[i].print(os, indent);
767 "This agenda does not contain a valid Workspace.\n"
768 "The workspace might have gotten deleted, or\n"
769 "you're accessing a default-constructed agenda.");
822 os << indent << tmd.
Name();
831 for (Index i = 0; i <
Out().
nelem(); ++i) {
840 for (Index i = 0; i <
In().
nelem(); ++i) {
855 os << indent <<
"}\n";
877 for (
auto k = ginonly.begin(); k < ginonly.end(); ++k)
880 k = ginonly.erase(k) - 1;
907 for (
auto& ag : agendas) out.push_back(ag.deepcopy_if(ws));
915 return ws_out.
wsvs(ws_in.
wsvs(vars));
938 for (
auto& method :
mml) out.
mml.push_back(method.deepcopy_if(
workspace));
952 if (
auto agenda_it = AgendaMap.find(
name());
953 agenda_it != AgendaMap.end()) {
954 const AgRecord& agr = agenda_data[agenda_it->second];
962 ws = x.shared_from_this();
963 for (
auto& mr:
mml) {
976 for (
auto&
b:
a)
b.set_workspace(x);
ArrayOfIndex make_same_wsvs(Workspace &ws_out, const Workspace &ws_in, const ArrayOfIndex &vars)
ArrayOfAgenda deepcopy_if(Workspace &ws, const ArrayOfAgenda &agendas)
Same as Agenda member method but for an entire array.
ostream & operator<<(ostream &os, const Agenda &a)
Output operator for Agenda.
Declarations for agendas.
void PrintWsvNames(OutputStream &outstream, const Workspace &ws, const Container &container)
Print list of WSV names to output stream.
Declarations for AgRecord, storing lookup information for one agenda.
The global header file for ARTS.
Header file for helper functions for OpenMP.
void(* getaways[])(Workspace &, const MRecord &)
Lookup information for one agenda.
const ArrayOfIndex & Out() const
const ArrayOfIndex & In() const
bool mchecked
Flag indicating that the agenda was checked for consistency.
bool has_same_origin(const Workspace &ws2) const
void print(ostream &os, const String &indent) const
Print an agenda.
std::weak_ptr< Workspace > ws
void append(const String &methodname, const TokVal &keywordvalue)
Appends methods to an agenda.
String name() const
Agenda name.
void execute(Workspace &ws_in) const
Execute an agenda.
bool has_method(const String &methodname) const
Check if method is in Agenda.
void set_workspace(Workspace &x)
bool is_output(Index var) const
Check if given variable is agenda output.
bool main_agenda
Is set to true if this is the main agenda.
void set_methods(const Array< MRecord > &ml)
void check(Workspace &ws_in, const Verbosity &verbosity)
Checks consistency of an agenda.
bool is_input(Workspace &ws_in, Index var) const
Check if given variable is agenda input.
Agenda & operator=(const Agenda &x)
std::pair< ArrayOfIndex, ArrayOfIndex > get_global_inout() const
Get index lists of global input and output variables from agenda_data of this agenda.
void set_outputs_to_push_and_dup(const Verbosity &verbosity)
Retrieve indexes of all input and output WSVs.
void push_back(const MRecord &n)
Append a new method to end of list.
Agenda deepcopy_if(Workspace &) const
Creates a deep copy of the agenda if necessary (i.e., different workspace)!
void resize(Index n)
Resize the method list.
ArrayOfIndex moutput_push
std::shared_ptr< Workspace > workspace() const
void set_name(const String &nname)
Set agenda name.
bool is_main_agenda() const
Index nelem() const
Return the number of agenda elements.
Index nelem() const ARTS_NOEXCEPT
Agenda mtasks
An agenda, which can be given in the controlfile instead of keywords.
const ArrayOfIndex & In() const
ArrayOfIndex minput
Input workspace variables.
void set_workspace(Workspace &x)
MRecord & operator=(const MRecord &x)
Assignment operator for MRecord.
const Agenda & Tasks() const
void print(ostream &os, const String &indent) const
Print an MRecord.
bool minternal
Flag if this method is called internally by the engine.
MRecord deepcopy_if(Workspace &) const
Creates a deep copy of the method if necessary (i.e., different workspace)!
ArrayOfIndex moutput
Output workspace variables.
void ginput_only(ArrayOfIndex &ginonly) const
Get list of generic input only WSVs.
bool isInternal() const
Indicates the origin of this method.
const ArrayOfIndex & Out() const
TokVal msetvalue
Keyword value for Set methods.
All information for one workspace method.
const String & Name() const
const ArrayOfIndex & GOutType() const
const ArrayOfIndex & InOut() const
const ArrayOfIndex & GInType() const
bool holdsArrayOfAgenda() const
void set_main_agenda(bool main_agenda)
std::shared_ptr< wsv_data_type > wsv_data_ptr
void pop(Index i)
Remove the topmost WSV from its stack.
T * get(const char *name)
Retrieve a value ptr if it exist (FIXME: C++20 allows const char* as template argument)
bool is_initialized(Index i) const
Checks existence of the given WSV.
wsv_data_type wsvs(const ArrayOfIndex &) const
Workspace * original_workspace
void duplicate(Index i)
Duplicate WSV.
std::shared_ptr< WsvMap_type > WsvMap_ptr
Helper macros for debugging.
#define ARTS_ASSERT(condition,...)
#define ARTS_USER_ERROR_IF(condition,...)
Declarations having to do with the four output streams.
Declaration of the class MdRecord.
const Array< MdRecord > md_data
Lookup information for workspace methods.
const map< String, Index > MdMap
The map associated with md_data.
const Array< AgRecord > agenda_data
The lookup information for the agendas.
const map< String, Index > WsvGroupMap
The map associated with wsv_groups.
map< String, Index > AgendaMap
The map associated with agenda_data.
This file contains the Workspace class.