DABC (Data Acquisition Backbone Core)  2.9.9
dabc_xml.cxx
Go to the documentation of this file.
1 // $Id: dabc_xml.cxx 4722 2021-03-13 13:56:03Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #include "dabc/ConfigBase.h"
17 
18 #include <iostream>
19 #include <cstring>
20 #include <cstdlib>
21 #include <string>
22 
23 int main(int numc, char* args[])
24 {
25  const char* configuration = nullptr;
26  const char* workdir = nullptr;
27  unsigned configid = 0;
28 
29  if(numc > 1) configuration = args[1];
30 
31  dabc::ConfigBase cfg(configuration);
32  if (!cfg.IsOk() || (cfg.GetVersion()!=2)) return 7;
33 
34  int cnt = 2;
35  while (cnt<numc) {
36 
37  const char* arg = args[cnt++];
38 
39  if (strcmp(arg,"-id")==0) {
40  if (cnt < numc)
41  configid = std::stoul(args[cnt++]);
42  } else
43  if (strcmp(arg,"-workdir")==0) {
44  if (cnt < numc)
45  workdir = args[cnt++];
46  } else
47  if (strcmp(arg,"-number")==0) {
48  unsigned res = cfg.NumNodes();
49  if (res==0) return 5;
50  std::cout << res << std::endl;
51  std::cout.flush();
52  } else
53  if (strcmp(arg,"-mode") == 0) {
54  const char* kind = (cnt < numc) ? args[cnt++] : "start";
55  std::string res = cfg.SshArgs(configid, kind, configuration, workdir);
56  if (res.length()==0) return 7;
57  std::cout << res << std::endl;
58  std::cout.flush();
59  } else
60  if (strstr(arg,"-nodename")==arg) {
61  std::string name = cfg.NodeName(configid);
62  if (name.length() == 0) return 5;
63  std::cout << name << std::endl;
64  std::cout.flush();
65  } else
66  if (strstr(arg,"-contextname")==arg) {
67  std::string name = cfg.ContextName(configid);
68  if (name.length() == 0) return 5;
69  std::cout << name << std::endl;
70  std::cout.flush();
71  }
72  }
73 
74  return 0;
75 }
Base class to read configuration from xml file.
Definition: ConfigBase.h:104
int GetVersion() const
Definition: ConfigBase.h:179
std::string SshArgs(unsigned id=0, const char *skind="run", const char *topcfgfile=0, const char *topworkdir=0)
method used by run.sh script to produce command line
Definition: ConfigBase.cxx:529
std::string NodeName(unsigned id)
returns nodename of specified context
Definition: ConfigBase.cxx:349
bool IsOk() const
Definition: ConfigBase.h:177
std::string ContextName(unsigned id)
returns name of specified context
Definition: ConfigBase.cxx:379
unsigned NumNodes()
returns number of nodes in xml file
Definition: ConfigBase.cxx:334
int main(int numc, char *args[])
Definition: dabc_xml.cxx:23