ARB
MP_mo_liste.cxx
Go to the documentation of this file.
1 // ============================================================= //
2 // //
3 // File : MP_mo_liste.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // ============================================================= //
10 
11 #include "MP_externs.hxx"
12 #include "MultiProbe.hxx"
13 
14 #include <aw_msg.hxx>
15 #include <arbdbt.h>
16 #include <client.h>
17 #include <servercntrl.h>
18 
19 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Methoden MO_Liste
20 
21 GBDATA *MO_Liste::gb_main = NULp;
22 
25 
26  laenge = 0;
27  mo_liste = NULp;
28  current = 0;
29  hashptr = NULp;
30  // Nach dem new muss die MO_Liste erst mit fill_all_bakts bzw fill_marked_bakts gefuellt werden
31 }
32 
34  if (mo_liste) {
35  for (int c = 0; c<current; ++c) {
36  delete mo_liste[c];
37  }
38  }
39  delete [] mo_liste;
40  if (hashptr) GBS_free_hash(hashptr);
41 }
42 
43 
46  mp_gl_struct mp_pd_gl;
47  {
48  const char *servername = NULp;
49  if (!(servername=arb_look_and_start_ptserver(AISC_MAGIC_NUMBER, ptserver_id, error))) {
50  ; // @@@ swap branches
51  }
52  else {
53  mp_assert(!error);
54 
55  mp_pd_gl.link = aisc_open(servername, mp_pd_gl.com, AISC_MAGIC_NUMBER, &error);
56  mp_pd_gl.locs.clear();
57  }
58  }
59 
60  if (!error && !mp_pd_gl.link) error = "Cannot contact PT server [1]";
61  if (!error && MP_init_local_com_struct(mp_pd_gl)) error = "Cannot contact PT server [2]";
62  if (!error && aisc_put(mp_pd_gl.link, PT_LOCS, mp_pd_gl.locs, NULp)) error = "Connection to PT_SERVER lost [3]";
63 
64  if (!error) {
65  bytestring bs = { NULp, 0 };
66  {
67  char *locs_error = NULp;
68  long nr_of_species;
69 
70  aisc_get(mp_pd_gl.link, PT_LOCS, mp_pd_gl.locs,
71  LOCS_MP_ALL_SPECIES_STRING, &bs,
72  LOCS_MP_COUNT_ALL_SPECIES, &nr_of_species,
73  LOCS_ERROR, &locs_error,
74  NULp);
75 
76  if (*locs_error) {
77  error = GBS_global_string("PTSERVER: %s", locs_error);
78  }
79 
80  laenge = nr_of_species;
81  free(locs_error);
82  }
83 
84  if (!error) {
85  mo_liste = new Bakt_Info*[laenge+2];
86  {
87  long j = 0;
88  while (j<laenge+2) {
89  mo_liste[j] = NULp;
90  j++;
91  }
92  }
93  current = 1; // ACHTUNG, CURRENT beginnt bei 1, da Hash bei 1 beginnt, d.h. Array[0] ist NULp
94 
95  // Initialisieren der Hashtabelle
96 
97  hashptr = GBS_create_hash(laenge + 1, GB_IGNORE_CASE);
98 
99  if (bs.data) {
100  char toksep[2];
101  toksep[0] = 1;
102  toksep[1] = 0;
103 
104  char *match_name = NULp;
105  match_name = strtok(bs.data, toksep);
107 
108  int i = 0;
109  while (match_name) {
110  i++;
111  if (!GBT_find_species(gb_main, match_name)) {
112  pt_server_different = true;
113  break; // abort
114  }
115  put_entry(match_name);
116  match_name = strtok(NULp, toksep);
117  }
118  delete match_name; // @@@ really allocated?
120  }
121  else {
122  error = "DB-query found no species";
123  }
124  }
125 
126  free(bs.data);
127  }
128 
129  if (mp_pd_gl.link) {
130  aisc_close(mp_pd_gl.link, mp_pd_gl.com);
131  }
132 
133  return error;
134 }
135 
136 
137 
139  long j = 0;
140  GBDATA *gb_species;
141 
142 
144  laenge = GBT_count_marked_species(gb_main); // laenge ist immer zuviel oder gleich der Anzahl wirklick markierter. weil pT-Server nur
145  // die Bakterien mit Sequenz zurueckliefert.
146 
147  if (!laenge) {
148  aw_message("Please mark some species!");
149  laenge = 1;
150  }
151  mo_liste = new Bakt_Info*[laenge+2];
152 
153  while (j<laenge+2) {
154  mo_liste[j] = NULp;
155  j++;
156  }
157  current = 1; // ACHTUNG, CURRENT beginnt bei 1, da Hash bei 1 beginnt, d.h. Array[0] ist NULp
158 
159  hashptr = GBS_create_hash(laenge, GB_IGNORE_CASE);
160 
161 
162  for (gb_species = GBT_first_marked_species(gb_main);
163  gb_species;
164  gb_species = GBT_next_marked_species(gb_species))
165  {
167  }
168 
170 
171  anz_elem_marked = laenge;
172 
173  return laenge;
174 }
175 
176 
177 
178 long MO_Liste::get_laenge() const {
179  return laenge;
180 }
181 
183  return current;
184 }
185 
186 long MO_Liste::put_entry(const char* name) {
187  // Pruefe: Gibts den Bakter schon in dieser Liste??
188  if (get_index_by_entry(name)) {
189  // wanns den Bakter scho gibt nicht eintragen
190  }
191  else {
192  mo_liste[current] = new Bakt_Info(name); // MEL koennte mit match_name zusammenhaengen
193  GBS_write_hash(hashptr, name, current);
194  current++;
195  }
196  return current;
197 }
198 
199 const char* MO_Liste::get_entry_by_index(long index) const {
200  if ((0<index) && (index < current))
201  return mo_liste[index]->get_name();
202  else
203  return NULp;
204 }
205 
206 long MO_Liste::get_index_by_entry(const char* key) {
207  return key ? GBS_read_hash(hashptr, key) : 0;
208 }
209 
211  return (0<index) && (index < current) ? mo_liste[index] : NULp;
212 }
213 
bool pt_server_different
Definition: MP_main.cxx:29
GBDATA * GBT_first_marked_species(GBDATA *gb_main)
Definition: aditem.cxx:113
T_PT_LOCS locs
Definition: mpdefs.h:51
long debug_get_current()
long GBS_write_hash(GB_HASH *hs, const char *key, long val)
Definition: adhash.cxx:454
Bakt_Info * get_bakt_info_by_index(long index)
int aisc_close(aisc_com *link, AISC_Object &object)
Definition: client.c:249
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
void GBS_free_hash(GB_HASH *hs)
Definition: adhash.cxx:538
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2494
positiontype fill_marked_bakts()
int aisc_put(aisc_com *link, int o_type, const AISC_Object &object,...)
Definition: client.c:539
GB_ERROR get_all_species(int ptserver_id)
Definition: MP_mo_liste.cxx:44
char * data
Definition: bytestring.h:16
int MP_init_local_com_struct(struct mp_gl_struct &mp_pd_gl)
Definition: MP_noclass.cxx:764
static void error(const char *msg)
Definition: mkptypes.cxx:96
long get_index_by_entry(const char *key)
GBDATA * GBT_next_marked_species(GBDATA *gb_species)
Definition: aditem.cxx:116
unsigned long positiontype
Definition: SoTl.hxx:42
const char * get_entry_by_index(long index) const
long get_laenge() const
GB_ERROR GB_pop_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2524
long GBT_count_marked_species(GBDATA *gb_main)
Definition: aditem.cxx:372
const char * arb_look_and_start_ptserver(int magic_number, int ptserver_id, GB_ERROR &error)
#define AISC_MAGIC_NUMBER
Definition: client_privat.h:51
aisc_com * aisc_open(const char *path, AISC_Object &main_obj, long magic, GB_ERROR *error)
Definition: client.c:205
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
const char * get_name()
Definition: MultiProbe.hxx:186
long put_entry(const char *name)
#define NULp
Definition: cxxforward.h:114
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:139
aisc_com * link
Definition: mpdefs.h:50
int aisc_get(aisc_com *link, int o_type, const AISC_Object &object,...)
Definition: client.c:266
#define mp_assert(cond)
Definition: mkptypes.cxx:32
GBDATA * gb_main
Definition: adname.cxx:32
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
Definition: aditem.cxx:459
T_PT_MAIN com
Definition: mpdefs.h:52
int anz_elem_marked
Definition: MP_main.cxx:27
long GBS_read_hash(const GB_HASH *hs, const char *key)
Definition: adhash.cxx:392
GB_HASH * GBS_create_hash(long estimated_elements, GB_CASE case_sens)
Definition: adhash.cxx:253