General Purpose Geodetic Library
SgTask.cpp
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of Space Geodetic Library. The library is used by
4  * nuSolve, a part of CALC/SOLVE system, and designed to make analysis of
5  * geodetic VLBI observations.
6  * Copyright (C) 2010-2020 Sergei Bolotin.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #include <SgTask.h>
24 
25 
26 #include <SgLogger.h>
27 #include <SgVlbiSession.h>
28 
29 
30 
31 /*=======================================================================================================
32 *
33 * METHODS:
34 *
35 *======================================================================================================*/
36 //
37 // static first:
38 const QString SgTask::className()
39 {
40  return "SgTask";
41 };
42 
43 
44 // A destructor:
46 {
47  // SgTask is an owner of them, so delete the pointers:
48  // sessionInfos:
49  for (SessionInfosByName_it i=sessionsByName_.begin(); i!=sessionsByName_.end(); ++i)
50  delete i.value();
51  sessionsByName_.clear();
52  // stationInfos:
53  for (StationsByName_it i=stationsByName_.begin(); i!=stationsByName_.end(); ++i)
54  delete i.value();
55  stationsByName_.clear();
56  // baselineInfos:
57  for (BaselinesByName_it i=baselinesByName_.begin(); i!=baselinesByName_.end(); ++i)
58  delete i.value();
59  baselinesByName_.clear();
60  // sourceInfos:
61  for (SourcesByName_it i=sourcesByName_.begin(); i!=sourcesByName_.end(); ++i)
62  delete i.value();
63  sourcesByName_.clear();
64 };
65 
66 
67 
68 //
70 {
71  // check for NULLs:
72  if (!sInfo)
73  {
75  ": addSession(SgVlbiSessionInfo*, SgVlbiSession*): sInfo is NULL");
76  return;
77  };
78  if (!sInfo)
79  {
81  ": addSession(SgVlbiSessionInfo*, SgVlbiSession*): session is NULL");
82  return;
83  };
84 
85  // check for duplicates:
86  if (sessionsByName_.contains(sInfo->getName()))
87  {
89  ": addSession(SgVlbiSessionInfo*, SgVlbiSession*): session " + sInfo->getName() +
90  " already in the task " + name_);
91  return;
92  };
93 
94  // add a session to the container:
95  sessionsByName_.insert(sInfo->getName(), new SgVlbiSessionInfo(*sInfo));
96 
97  // update statistics per object:
98  // stations:
99  for (QMap<QString, SgVlbiStationInfo*>::iterator i=session->stationsByName().begin();
100  i!=session->stationsByName().end(); ++i)
101  {
102  SgVlbiStationInfo* stationInfo = NULL;
103  if (stationsByName_.contains(i.key()))
104  {
105  stationInfo = stationsByName_.value(i.key());
106  stationInfo->incNumTotal(DT_DELAY, i.value()->numTotal(DT_DELAY));
107  }
108  else
109  {
110  stationInfo = new SgVlbiStationInfo(stationsByName_.size(),
111  i.value()->getKey(), i.value()->getAka());
112  stationInfo->incNumTotal(DT_DELAY, i.value()->numTotal(DT_DELAY));
113  stationsByName_.insert(stationInfo->getKey(), stationInfo);
114  };
115  };
116  // sources:
117  for (QMap<QString, SgVlbiSourceInfo*>::iterator i=session->sourcesByName().begin();
118  i!=session->sourcesByName().end(); ++i)
119  {
120  SgVlbiSourceInfo* sourceInfo = NULL;
121  if (sourcesByName_.contains(i.key()))
122  {
123  sourceInfo = sourcesByName_.value(i.key());
124  sourceInfo->incNumTotal(DT_DELAY, i.value()->numTotal(DT_DELAY));
125  }
126  else
127  {
128  sourceInfo = new SgVlbiSourceInfo(sourcesByName_.size(),
129  i.value()->getKey(), i.value()->getAka());
130  sourceInfo->incNumTotal(DT_DELAY, i.value()->numTotal(DT_DELAY));
131  sourcesByName_.insert(sourceInfo->getKey(), sourceInfo);
132  };
133  };
134  // baselines:
135  for (QMap<QString, SgVlbiBaselineInfo*>::iterator i=session->baselinesByName().begin();
136  i!=session->baselinesByName().end(); ++i)
137  {
138  SgVlbiBaselineInfo* baselineInfo = NULL;
139  if (baselinesByName_.contains(i.key()))
140  {
141  baselineInfo = baselinesByName_.value(i.key());
142  baselineInfo->incNumTotal(DT_DELAY, i.value()->numTotal(DT_DELAY));
143  }
144  else
145  {
146  baselineInfo = new SgVlbiBaselineInfo(baselinesByName_.size(),
147  i.value()->getKey(), i.value()->getAka());
148  baselineInfo->incNumTotal(DT_DELAY, i.value()->numTotal(DT_DELAY));
149  baselinesByName_.insert(baselineInfo->getKey(), baselineInfo);
150  };
151  };
152  //
153 };
154 
155 
156 
157 //
159 {
160  // check for NULLs:
161  if (!sInfo)
162  {
164  ": removeSession(SgVlbiSessionInfo*, SgVlbiSession*): sInfo is NULL");
165  return;
166  };
167  if (!sInfo)
168  {
170  ": removeSession(SgVlbiSessionInfo*, SgVlbiSession*): session is NULL");
171  return;
172  };
173 
174  // check for duplicates:
175  if (!sessionsByName_.contains(sInfo->getName()))
176  {
178  ": removeSession(SgVlbiSessionInfo*, SgVlbiSession*): session " + sInfo->getName() +
179  " is not a part of the task " + name_);
180  return;
181  };
182 
183  // update statistics per object:
184  // stations:
185  for (QMap<QString, SgVlbiStationInfo*>::iterator i=session->stationsByName().begin();
186  i!=session->stationsByName().end(); ++i)
187  {
188  SgVlbiStationInfo* stationInfo = NULL;
189  if (stationsByName_.contains(i.key()))
190  {
191  stationInfo = stationsByName_.value(i.key());
192  stationInfo->decNumTotal(DT_DELAY, i.value()->numTotal(DT_DELAY));
193  if (stationInfo->numTotal(DT_DELAY)<0) // sometimes it could happen,correct it:
194  {
196  ": removeSession(SgVlbiSessionInfo*, SgVlbiSession*): the station " +
197  stationInfo->getKey() + " has got num of total obs. less than zero, fixed it");
198 // stationInfo->setNumTotal(DT_DELAY, 0);
199  };
200  if (stationInfo->numTotal(DT_DELAY)==0) // remove the object from the task:
201  {
202  stationsByName_.remove(stationInfo->getKey());
203  delete stationInfo;
204  };
205  }
206  else
208  ": removeSession(SgVlbiSessionInfo*, SgVlbiSession*): cannot remove the station " +
209  i.key() + " from the container; the task is " + name_);
210  };
211  // sources:
212  for (QMap<QString, SgVlbiSourceInfo*>::iterator i=session->sourcesByName().begin();
213  i!=session->sourcesByName().end(); ++i)
214  {
215  SgVlbiSourceInfo* sourceInfo = NULL;
216  if (sourcesByName_.contains(i.key()))
217  {
218  sourceInfo = sourcesByName_.value(i.key());
219  sourceInfo->decNumTotal(DT_DELAY, i.value()->numTotal(DT_DELAY));
220  if (sourceInfo->numTotal(DT_DELAY) < 0) // sometimes it could happen,correct it:
221  {
223  ": removeSession(SgVlbiSessionInfo*, SgVlbiSession*): the source " +
224  sourceInfo->getKey() + " has got num of total obs. less than zero, fixed it");
225 // sourceInfo->setTotalNum(0);
226  };
227  if (sourceInfo->numTotal(DT_DELAY) == 0) // remove the object from the task:
228  {
229  sourcesByName_.remove(sourceInfo->getKey());
230  delete sourceInfo;
231  };
232  }
233  else
235  ": removeSession(SgVlbiSessionInfo*, SgVlbiSession*): cannot remove the source " +
236  i.key() + " from the container; the task is " + name_);
237  };
238  // baselines:
239  for (QMap<QString, SgVlbiBaselineInfo*>::iterator i=session->baselinesByName().begin();
240  i!=session->baselinesByName().end(); ++i)
241  {
242  SgVlbiBaselineInfo* baselineInfo = NULL;
243  if (baselinesByName_.contains(i.key()))
244  {
245  baselineInfo = baselinesByName_.value(i.key());
246  baselineInfo->decNumTotal(DT_DELAY, i.value()->numTotal(DT_DELAY));
247  if (baselineInfo->numTotal(DT_DELAY) < 0) // sometimes it could happen,correct it:
248  {
250  ": removeSession(SgVlbiSessionInfo*, SgVlbiSession*): the baseline " +
251  baselineInfo->getKey() + " has got num of total obs. less than zero, fixed it");
252 // baselineInfo->setTotalNum(0);
253  };
254  if (baselineInfo->numTotal(DT_DELAY) == 0) // remove the object from the task:
255  {
256  baselinesByName_.remove(baselineInfo->getKey());
257  delete baselineInfo;
258  };
259  }
260  else
262  ": removeSession(SgVlbiSessionInfo*, SgVlbiSession*): cannot remove the baseline " +
263  i.key() + " from the container; the task is " + name_);
264  };
265 
266  // remove a sessionInfo from the container and delete it:
267  delete sessionsByName_.take(sInfo->getName());
268  //
269 };
270 
271 
272 
273 
274 /*=======================================================================================================
275 *
276 * FRIENDS:
277 *
278 *======================================================================================================*/
279 //
280 
281 
282 
283 /*=====================================================================================================*/
284 //
285 // aux functions:
286 //
287 
288 
289 // i/o:
290 
291 
292 /*=====================================================================================================*/
293 //
294 // constants:
295 //
296 
297 
298 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
QMap< QString, SgVlbiBaselineInfo * >::iterator BaselinesByName_it
QMap< QString, SgVlbiSessionInfo * >::iterator SessionInfosByName_it
QMap< QString, SgVlbiSourceInfo * >::iterator SourcesByName_it
QMap< QString, SgVlbiStationInfo * >::iterator StationsByName_it
@ DT_DELAY
Definition: SgWrmsable.h:44
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
void incNumTotal(DataType, int=1)
Definition: SgObjectInfo.h:519
void decNumTotal(DataType, int=1)
Definition: SgObjectInfo.h:527
const QString & getKey() const
Definition: SgObjectInfo.h:319
int numTotal(DataType dType) const
Definition: SgObjectInfo.h:343
QString name_
Definition: SgTask.h:146
void removeSession(SgVlbiSessionInfo *, SgVlbiSession *)
Definition: SgTask.cpp:158
BaselinesByName baselinesByName_
Definition: SgTask.h:154
void addSession(SgVlbiSessionInfo *, SgVlbiSession *)
Definition: SgTask.cpp:69
SourcesByName sourcesByName_
Definition: SgTask.h:155
static const QString className()
Definition: SgTask.cpp:38
StationsByName stationsByName_
Definition: SgTask.h:153
SessionInfosByName sessionsByName_
Definition: SgTask.h:152
~SgTask()
Definition: SgTask.cpp:45
const QString & getName() const
QMap< QString, SgVlbiStationInfo * > & stationsByName()
QMap< QString, SgVlbiSourceInfo * > & sourcesByName()
QMap< QString, SgVlbiBaselineInfo * > & baselinesByName()