General Purpose Geodetic Library
NsSessionHandler.cpp
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of nuSolve. nuSolve is a part of CALC/SOLVE system
4  * and is designed to perform data analyis of a geodetic VLBI session.
5  * Copyright (C) 2010-2020 Sergei Bolotin.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #include "NsSessionHandler.h"
23 #include "nuSolve.h"
24 
25 #include <iostream>
26 #include <stdlib.h>
27 
28 
29 
30 #include <QtCore/QDataStream>
31 #include <QtCore/QDir>
32 #include <QtCore/QFile>
33 
34 
35 
36 #include <SgConstants.h>
37 #include <SgDbhImage.h>
38 #include <SgGuiPiaReport.h>
39 #include <SgGuiPlotter.h>
40 #include <SgGuiTaskConfig.h>
41 #include <SgLogger.h>
42 #include <SgMJD.h>
43 #include <SgParameterCfg.h>
45 #include <SgSolutionReporter.h>
46 #include <SgTaskManager.h>
47 #include <SgVgosDb.h>
48 #include <SgVlbiBand.h>
49 #include <SgVlbiNetworkId.h>
50 #include <SgVlbiObservation.h>
51 
52 
53 
54 
55 
56 
57 /*=======================================================================================================
58 *
59 * METHODS:
60 *
61 *======================================================================================================*/
62 NsSessionHandler::NsSessionHandler(const QString& fileName, const QString& fileNameAux,
65  : fileName_(fileName),
66  fileNameAux_(fileNameAux),
67  path2DbhFiles_(""),
68  dbhImageByKey_(),
69  dbhNameByKey_(),
70  dbhPathByKey_(),
71  path2VdbFiles_(""),
72  vdbWrapperFileName_(""),
73  path2VdaFiles_("")
74 {
75  oType_ = oType;
76  session_ = NULL;
77  reporter_ = NULL;
78  vgosDb_ = NULL;
79 
80  // make a copy:
81  config_ = new SgTaskConfig(*config);
83  //
84  //
85  initData();
86 };
87 
88 
89 
90 //
92  : fileName_(""),
93  fileNameAux_(""),
94  path2DbhFiles_(""),
95  dbhImageByKey_(),
96  dbhNameByKey_(),
97  dbhPathByKey_(),
98  path2VdbFiles_(""),
99  vdbWrapperFileName_("")
100 {
102  session_ = NULL;
103  reporter_ = NULL;
104  vgosDb_ = NULL;
105 
106  // make a copy:
107  config_ = new SgTaskConfig(*config);
109  //
110  initData();
111 };
112 
113 
114 
115 //
117 {
118  //
119  isImportOk_ = false;
121  // overwrite the saved set up:
126  //
127  // create the session and set up its config:
128  session_ = new SgVlbiSession;
134  //
136  //
137  activeBand_ = 0;
138  //
139 };
140 
141 
142 
143 //
145 {
146  //
147  dbhNameByKey_.clear();
148  dbhPathByKey_.clear();
149  for (QMap<QString, SgDbhImage*>::iterator it=dbhImageByKey_.begin(); it!=dbhImageByKey_.end(); ++it)
150  delete it.value();
151  dbhImageByKey_.clear();
152  //
153  if (vgosDb_)
154  {
155  delete vgosDb_;
156  vgosDb_ = NULL;
157  };
158  //
159  if (reporter_)
160  {
161  delete reporter_;
162  reporter_ = NULL;
163  };
164  //
165  if (session_)
166  {
167  delete session_;
168  session_ = NULL;
169  };
170  config = *config_;
171  delete config_;
172  config_ = NULL;
173 
174  delete parametersDescriptor_;
175  parametersDescriptor_ = NULL;
176 };
177 
178 
179 
180 //
181 bool NsSessionHandler::importSession(bool guiExpected)
182 {
183  isImportOk_ = false;
185  //
187  {
190  else
192  }
194  {
196  }
198  {
200  };
201  //
202  if ((oType_==SgVlbiSessionInfo::OT_DBH && dbhNameByKey_.size()==0) ||
205  )
206  {
208  "::importSession(): cannot find anything associated with the name \"" + fileName_ +
209  "\". Please, check and do it again.");
210  return false;
211  };
212  //
213  // read the files:
215  isImportOk_ = initSessionFromDbh(guiExpected);
217  isImportOk_ = initSessionFromOdb(guiExpected);
219  isImportOk_ = initSessionFromVda(guiExpected);
220  //
221  return isImportOk_;
222 };
223 
224 
225 
226 //
228 {
229  bool isOk(false);
230  //
232  {
234  "::performPia(): the automatic analysis is disabled by the command line argument");
235  return isOk;
236  };
237 
238  if (isImportOk_)
239  {
240 
241  isOk = session_->doPostReadActions();
242 
243  };
244  //
245  return isOk;
246 };
247 
248 
249 
250 //
251 //
253 {
254  session_->process(true, false);
255 };
256 
257 
258 
259 //
261 {
263 };
264 
265 
266 
267 //
269 {
271 };
272 
273 
275 {
276  activeBand_ = idx;
278 };
279 
280 
281 
282 
283 //
285 {
286  //
287  bool isOk(false);
289  {
291  isOk = exportDataIntoDbh();
292  else if (oType_ == SgVlbiSessionInfo::OT_VDB)
293  isOk = exportDataIntoVgosDb();
294  else if (oType_ == SgVlbiSessionInfo::OT_AGV) // export data in vgosDb format:
295  isOk = exportDataIntoVgosDa();
296  //
297  if (isOk &&
299  generateReport();
300  };
301  //
302  return isOk;
303 };
304 
305 
306 
307 //
308 // Sets up elements of dbhNameByKey_ map in a catalog-aware mode:
309 void NsSessionHandler::setupCatsDbhFileNames(const QString& fName, const QString& fName2)
310 {
311  QString fileName(fName);
312  QString fileName2(fName2);
313  QTextStream s;
314  QFile f;
315  QString baseName; // "YYMMMDD" part of databese's file name
316  QString currentBand; // "S", "X", ...
317  QString baseNetID; // "A", "E", ...
318  QString currentVersion; // e.g., "V001"
319  QString str1, str2;
320  QString key;
321  int version, v, l;
322  bool isOk;
323 
324  // user's input, can contain $-char at the begin:
325  if (fileName.at(0) == '$')
326  fileName = fileName.mid(1);
327  l = fileName.length();
328  if (fileName2.size()>0 && fileName2.at(0) == '$')
329  fileName2 = fileName2.mid(1);
330 
331  if (l==9)
332  {
333  // find out the first available version of the file:
334  v = 1;
335  while (inquireCat(fileName, ++v, str1, str2) != 0 && v<70)
336  ;
337  v--;
338  if (v==69)
339  {
341  "::setupCatsDbhFileNames(): the file " + fileName + " does not exist in the catalog");
342  return;
343  };
344  // find out the latest version of the file:
345  while (inquireCat(fileName, ++v, str1, str2) == 0)
346  ;
347  v--;
348  if (v<3)
349  {
351  "::setupCatsDbhFileNames(): the file " + fileName + " does not exist in the catalog");
352  return;
353  };
354  fileName += QString("").sprintf("_V%03d", v);
355  l += 5;
356  }
357  else if (!(fileName.mid(l-5, 2) == "_V")) // is it full name?
358  {
360  "::setupCatsDbhFileNames(): the file " + fileName + " is not a standard database name, "
361  "expecting: YYMMMDDBC_Vxxx");
362  return;
363  };
364 
365  baseName = fileName.mid(l-14, 7);
366  currentBand = fileName.mid(l-7, 1);
367  baseNetID = fileName.mid(l-6, 1);
368  currentVersion = fileName.mid(l-4, 4);
369  version = currentVersion.mid(1).toInt(&isOk);
370  if (!isOk)
371  {
373  "::setupCatsDbhFileNames(): cannot determine proper DBH version for the file " + fileName);
374  return;
375  };
376 
377  // enquire about user provided database:
378  if (inquireCat(baseName + currentBand + baseNetID, version, str1, str2) != 0)
379  {
381  "::setupCatsDbhFileNames(): got an error on the request to " +
382  setup.catnuGetDbInfo() + ": " + str1);
383  return;
384  };
385  // set up path to databases:
386  l = str2.lastIndexOf("/");
387  path2DbhFiles_ = str2.left(l+1);
388  dbhNameByKey_[currentBand] = str2.mid(l+1);
389  dbhPathByKey_[currentBand] = path2DbhFiles_;
390  //
391  //
392  if (setup.getHave2AutoloadAllBands() && fileName2 != "/dev/null")
393  {
394  l = fileName2.size();
395  if (l >= 9) // user explicitly provided a filename of the second database:
396  {
397  isOk = true;
398  if (l==9) // no version info:
399  {
400  // find out the first available version of the file:
401  v = 1;
402  while (inquireCat(fileName2, ++v, str1, str2) != 0 && v<70)
403  ;
404  v--;
405  if (v==69)
406  {
408  "::setupCatsDbhFileNames(): cannot find the second file " + fileName2 + " in the catalog");
409  isOk = false;
410  };
411  // find out the latest version of the file:
412  while (inquireCat(fileName2, ++v, str1, str2) == 0)
413  ;
414  v--;
415  if (v<2)
416  {
418  "::setupCatsDbhFileNames(): cannot find the second file " + fileName2 + " in the catalog");
419  isOk = false;
420  };
421  fileName2 += QString("").sprintf("_V%03d", v);
422  l += 5;
423  }
424  else
425  v = fileName2.mid(l-3, 3).toInt(&isOk);
426  //
427  if (isOk)
428  {
429  isOk = inquireCat(fileName2, v, str1, str2) == 0;
430  //
431  QString aBand("");
432  aBand = fileName2.mid(l-7, 1);
433  l = str2.lastIndexOf("/");
434  path2DbhFiles_ = str2.left(l+1);
435  dbhNameByKey_[aBand] = str2.mid(l+1);
436  dbhPathByKey_[aBand] = path2DbhFiles_;
438  "::setupCatsDbhFileNames(): the second database file " + fileName2 +
439  " has been found in the catalog, band=[" + currentBand + "], version=" +
440  QString("").setNum(v));
441  };
442  }
443  else // guess a file name of the second database:
444  {
445  // find a database with opposite band:
446  v = version;
447  isOk = false;
448  if (currentBand == "X")
449  {
450  key = "S";
451  while (v>1 && !isOk)
452  isOk = inquireCat(baseName + key + baseNetID, v--, str1, str2) == 0;
453  }
454  else
455  {
456  key = "X";
457  while (v<31 && !isOk) // ver 30 -- is it enouhg?
458  isOk = inquireCat(baseName + key + baseNetID, v++, str1, str2) == 0;
459  };
460  if (isOk)
461  {
462  l = str2.lastIndexOf("/");
463  dbhNameByKey_[key] = str2.mid(l+1);
464  dbhPathByKey_[key] = str2.left(l+1);
465  }
466  else
468  "::setupCatsDbhFileNames(): cannot find an opposite band, " + key + ", : " + str1);
469  };
470  };
471  //
472  // check if it is possible to submit a next version database:
473  if (inquireCat(baseName + (currentBand=="S"?"X":currentBand) + baseNetID, version+1, str1, str2) == 0)
474  {
476  {
479  "::setupCatsDbhFileNames(): a database with the next version already exists in the catalog");
480  };
481  };
482 };
483 
484 
485 
486 //
487 // Sets up elements of dbhNameByKey_ map in a standalone (non catalog) mode:
488 void NsSessionHandler::setupDogsDbhFileNames(const QString& fileName)
489 {
490  QString baseName; // "YYMMMDD" part of databese's file name
491  QString currentBand; // "S", "X", ...
492  QString baseNetID; // "A", "E", ...
493  QString currentVersion; // e.g., "V001"
494  QString str;
495  int l = fileName.length();
496  QString key;
497 
498  if (fileName.mid(l-5, 2) == "_V") // ok, we asuming it is standard IVS naming convention:
499  {
500  //
501  currentBand = fileName.mid(l-7, 1);
502  baseNetID = fileName.mid(l-6, 1);
503  currentVersion = fileName.mid(l-4, 4);
504 
505  l = fileName.lastIndexOf("/");
506  // we figure out it from the fileName:
507  if (fileName.at(0) == '/') // user provided absolute path:
508  {
509  path2DbhFiles_ = fileName.left(l+1);
510  str = fileName.mid(l+1);
511  }
512  else
513  {
514  path2DbhFiles_ = setup.getPath2DbhFiles() + "/" + fileName.left(l+1);
515  str = fileName.mid(l+1);
516  };
517  //
518  baseName = str.left(7);
519  QDir dir(path2DbhFiles_);
520  QStringList nameFilters;
522  nameFilters << baseName + "?" + baseNetID + "*";
523  else
524  nameFilters << baseName + currentBand + baseNetID + "*";
525  QStringList nameList = dir.entryList(nameFilters,
526  QDir::Files | QDir::Readable, QDir::Name | QDir::IgnoreCase);
527  if (!nameList.size())
528  {
529  // ??
530  };
531  for (int i=0; i<nameList.size(); i++)
532  {
533  l = nameList.at(i).length();
534  if (l==14)
535  {
536  key = nameList.at(i).mid(l-7, 1);
537  if (key == currentBand && !dbhNameByKey_.contains(key))
538  dbhNameByKey_[key] = str;
539  else
540  {
541  if (!dbhNameByKey_.contains(key))
542  dbhNameByKey_[key] = nameList.at(i);
543  else if (nameList.at(i).mid(l-4, 4) <= currentVersion)
544  dbhNameByKey_[key] = nameList.at(i);
545  };
546  };
547  };
548  }
549  else // perhaps, it is new naming convention, pass it as is:
550  dbhNameByKey_["A"] = fileName;
551 };
552 
553 
554 
555 //
556 // Sets up path to and name of the wrapper file of vgosDb data tree:
557 void NsSessionHandler::setupVgosDbFileNames(const QString& inpt)
558 {
559  QString sessionName("");
560  int version(0);
561 
562  bool isOk;
563  QRegExp reWrapperFileName(".*\\.(wrp|wrap)$", Qt::CaseInsensitive);
564  QRegExp reDatabaseName("^[0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2}$");
565  QRegExp reDatabaseVersionName("^[0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2}_V[0-9]{3}$");
566  QRegExp rePath2Database("(.*)([0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2})/?$");
567  //
568  // ok, this is a wrapper file name:
569  if (reWrapperFileName.indexIn(inpt) != -1)
570  {
573  sessionName, version);
574  if (isOk)
576  "::setupVgosDbFileNames(): got a session " + sessionName + " of version " +
577  QString("").setNum(version) + " from \"" + path2VdbFiles_ + "\":\"" +
578  vdbWrapperFileName_ + "\"");
579  else
581  "::setupVgosDbFileNames(): cannot figure out a session from the input \"" + inpt + "\"");
582  }
583  // a database or a database with version:
584  else if (reDatabaseName.exactMatch(inpt) || reDatabaseVersionName.exactMatch(inpt))
585  {
588  path2VdbFiles_, vdbWrapperFileName_, sessionName, version);
589  if (isOk)
591  "::setupVgosDbFileNames(): got a wrapper file \"" + vdbWrapperFileName_ +
592  "\" from \"" + path2VdbFiles_ + "\" for the session " + sessionName +
593  " of version " + QString("").setNum(version));
594  else
596  "::setupVgosDbFileNames(): cannot figure out a wrapper file from the input \"" + inpt + "\"");
597  }
598  else if (-1 < rePath2Database.indexIn(inpt))
599  {
600  // could be a directory with a database:
601  QDir dir(inpt);
602  if (dir.exists())
603  {
604  if (rePath2Database.indexIn(dir.canonicalPath()) == -1)
605  {
607  "::setupVgosDbFileNames(): converting input \"" + inpt + "\" to the absolute path \"" +
608  dir.canonicalPath() + "\" has failed");
609  return;
610  };
611  QString sDir(rePath2Database.cap(2));
612  QString sPath(rePath2Database.cap(1));
613 
615  path2VdbFiles_, vdbWrapperFileName_, sessionName, version, true);
616  if (isOk)
618  "::setupVgosDbFileNames(): got a wrapper file \"" + vdbWrapperFileName_ +
619  "\" from \"" + path2VdbFiles_ + "\" for the session " + sessionName +
620  " of version " + QString("").setNum(version));
621  else
623  "::setupVgosDbFileNames(): cannot figure out a wrapper file from the directory \"" +
624  inpt + "\"");
625  }
626  else
628  "::setupVgosDbFileNames(): the directory \"" + inpt + "\" does not exist");
629  }
630  else
632  "::setupVgosDbFileNames(): cannot guess input data from \"" + inpt + "\"");
633 };
634 
635 
636 
637 //
638 void NsSessionHandler::setupVgosDaFileNames(const QString& /*input*/)
639 {
640  // just a file name:
641  QFile file(fileName_);
642  if (file.exists())
643  return;
644  QString str(setup.getPath2VgosDaFiles() + "/" + fileName_);
645  file.setFileName(str);
646  // if a user provided .vda suffix:
647  if (file.exists())
648  {
649  fileName_ = str;
650  return;
651  };
652  // if a user provided just a database name:
653  str += ".vda";
654  file.setFileName(str);
655  if (file.exists())
656  fileName_ = str;
657 };
658 
659 
660 
661 // functions:
663 {
664  SgDbhStream dbhStream;
665  QFile dbhFile;
666  SgDbhImage *dbhImage;
667  QString path;
668 
669  for (QMap<QString, QString>::const_iterator i=dbhNameByKey_.constBegin();
670  i!=dbhNameByKey_.constEnd(); ++i)
671  {
672  path = dbhPathByKey_.contains(i.key()) ? dbhPathByKey_[i.key()] : path2DbhFiles_;
673  dbhImage = new SgDbhImage;
674  dbhFile.setFileName(path + i.value());
676  "::initSessionFromDbh(): reading file " + i.value() + " in the directory \"" +
677  path + "\"", true);
678 
679  dbhFile.open(QIODevice::ReadOnly);
680  dbhStream.setDevice(&dbhFile);
681  dbhStream >> *dbhImage;
682  dbhStream.setDevice(NULL);
683  dbhFile.close();
684  dbhImageByKey_[i.key()] = dbhImage;
685  };
686 
689  "::initSessionFromDbh(): absorbing data from the set of DBH images", true);
691  guiExpected);
692 };
693 
694 
695 
696 
697 //
699 {
700  bool isOk;
704  "::initSessionFromOdb(): parsing of wrapper file " + vdbWrapperFileName_ +
705  (isOk?" complete":" failed"));
706 
708 
710  {
712  "::initSessionFromOdb(): the session " + session_->getSessionCode() + " (" + session_->getName() +
713  ") has been imported from " + path2VdbFiles_);
714  return true;
715  };
717  "::initSessionFromOdb(): reading of the session " + session_->getSessionCode() +
718  " (" + session_->getName() + ") failed");
719  return false;
720 };
721 
722 
723 
724 //
725 bool NsSessionHandler::initSessionFromVda(bool /*guiExpected*/)
726 {
727  SgIdentities ids;
729 
731 
733  {
735  "::initSessionFromVda(): the session " + session_->getSessionCode() + " (" + session_->getName() +
736  ") has been imported from " + fileName_);
737  return true;
738  };
740  "::initSessionFromVda(): reading data from vgosDa file \"" + fileName_ + "\" failed");
741  return false;
742 };
743 
744 
745 
746 //
748 {
749  if (!canSave())
750  {
753  ": exportDataIntoDbh(): saving data in DBH format has been canceled");
754  return false;
755  };
756  //
758  "::exportDataIntoDbh(): saving data in DBH format");
759 
760  if (!session_)
761  {
764  "::exportDataIntoDbh(): the session pointer is NULL");
765  return false;
766  }
768  SgVlbiBand *primaryBand=session_->primaryBand();
769  if (!primaryBand)
770  {
773  "::exportDataIntoDbh(): the primary band pointer is NULL");
774  return false;
775  };
776  SgDbhImage *dbhImage=dbhImageByKey_[primaryBand->getKey()];
777  if (!dbhImage)
778  {
781  "::exportDataIntoDbh(): the dbhImage pointer is NULL");
782  return false;
783  };
784 
785  bool have2NotifyCatalog(setup.getHave2UpdateCatalog());
786  bool isNewChain(false);
787  // determine a name of the output file:
788  QString sessionFileName, dbhFileName;
790  {
791  // QString alterCode(networkSuffix=="U"?"1":"8");
792  QString alterCode(session_->getNetworkSuffix()=="U"?"1":"7");
793  dbhImage->alterCode(alterCode);
794  session_->setNetworkSuffix(alterCode);
795  isNewChain = true;
796  };
797 
798  sessionFileName = session_->nickName() + QString().sprintf("_V%03d", dbhImage->currentVersion());
799  dbhFileName = path2DbhFiles_ + sessionFileName;
800  // check for existing file:
801  if (QFile::exists(dbhFileName))
802  {
803  if (have2NotifyCatalog) // notify a user about refusing to save:
804  {
807  "::exportDataIntoDbh(): the file " + dbhFileName + " is already exist; remove it and try again");
808  return false;
809  };
810  // alternate the name and save the data:
811  QString suffix="_" + SgMJD::currentMJD().toString(SgMJD::F_INTERNAL);
812  dbhFileName += suffix;
814  "::exportDataIntoDbh(): the new version file is already exist; the name is altered to " +
815  sessionFileName + suffix);
816  };
817  // adjust data:
818  session_->putDataIntoDbhImage(dbhImage);
819 
820  // before writing, verify catalog:
821  if (have2NotifyCatalog)
822  {
823  QString str1, str2;
824  if (inquireCat(session_->nickName(), dbhImage->currentVersion(), str1, str2) == 0)
825  {
828  "::exportDataIntoDbh(): the new version already exists in the catalog, remove it from the "
829  "catalog and try again");
830  return false;
831  };
832  };
833  //
834  // write into the file:
835  SgDbhStream dbhStream;
836  QFile dbhFile(dbhFileName);
837  dbhFile.open(QIODevice::WriteOnly);
838  dbhStream.setDevice(&dbhFile);
839  dbhStream << *dbhImage;
840  dbhStream.setDevice(NULL);
841  dbhFile.close();
843  "::exportDataIntoDbh(): the " + primaryBand->getKey() + "-band of the session " +
844  session_->getName() + " has been saved into the file " + dbhFileName);
845 
846  if (have2NotifyCatalog)
847  {
848  QString str1;
849  if (notifyCat(dbhFileName, isNewChain, str1) != 0)
850  {
853  "::exportDataIntoDbh(): updating the catalog has failed; error: " + str1);
854  return false;
855  }
856  else
858  "::exportDataIntoDbh(): the catalog has been updated successfuly");
859  };
860  //
861  saveStatus_ = SS_OK;
862  return true;
863 };
864 
865 
866 
867 //
869 {
870  if (!canSave())
871  {
874  ": exportDataIntoVgosDb(): exporting of data into vgosDb tree has been canceled");
875  return false;
876  };
877  //
878  bool isOk;
879 
880  // data were imported in vgosDb format:
881  if (vgosDb_)
882  {
883  if ((isOk=session_->putDataIntoVgosDb(vgosDb_)))
884  saveStatus_ = SS_OK;
885  else
887  }
888  // data were imported in another format:
889  else
890  {
891  QString dir2Save("");
892  QDir dir;
893  if (output.size()) // for vgosDb output is a directory name:
894  {
895  dir2Save = output;
897  "::exportDataIntoVgosDb(): gpt a user specified path: \"" + dir2Save + "\"");
898  }
899  else
900  dir2Save = setup.path2(setup.getPath2VgosDbFiles()) + "/" +
901  QString("").sprintf("%04d", session_->getTStart().calcYear()) + "/" + session_->getName();
902 
905  "::exportDataIntoVgosDb(): vgosDb object has been created");
906 
909  "::exportDataIntoVgosDb(): the vgosDb object has been prepared to save the new session in "
910  "vgosDb format");
911  //
912  // check if a dir (or a file) exists, adjust the name:
913  if (dir.exists(dir2Save))
914  {
915  SgMJD epoch=SgMJD::currentMJD();
916  dir2Save += "-" + epoch.toString(SgMJD::F_yyyymmdd);
918  "::exportDataIntoVgosDb(): the output path has been adjusted to \"" + dir2Save + "\"");
919  if (dir.exists(dir2Save))
920  {
921  epoch = SgMJD::currentMJD();
922  dir2Save = setup.path2(setup.getPath2VgosDbFiles()) + "/" +
923  QString("").sprintf("%04d", session_->getTStart().calcYear()) + "/" + session_->getName() +
924  "-" + epoch.toString(SgMJD::F_SOLVE_SPLFL_LONG);
926  "::exportDataIntoVgosDb(): the output path has been readjusted to \"" + dir2Save + "\"");
927  };
928  };
929  vgosDb_->setPath2RootDir(dir2Save);
931  "::exportDataIntoVgosDb(): the path was set to " + vgosDb_->getPath2RootDir());
932 
935  "::exportDataIntoVgosDb(): export of data into vgosDb tree has been " + (isOk?"complete":"failed"));
936 
937  delete vgosDb_;
938  vgosDb_ = NULL;
940  "::exportDataIntoVgosDb(): vgosDb object has been destroyed.");
941  };
942 
944  "::exportDataIntoVgosDb(): exporting of data into vgosDb tree has been" +
945  (isOk?" complete":" failed"));
946 
947  return isOk;
948 };
949 
950 
951 
952 //
953 int NsSessionHandler::inquireCat(const QString& databaseName, int version,
954  QString& str1, QString& str2)
955 {
956  int rc;
957  QTextStream s;
958  QFile f;
959  QString execStr;
960  QString tmpFileName("/tmp/nuSolve-Catalog.");
961  QString complain;
962  tmpFileName += SgMJD::currentMJD().toString(SgMJD::F_INTERNAL);
963 
964  execStr = setup.getPath2CatNuInterfaceExec() + "/" + setup.catnuGetDbInfo() + " " +
965  databaseName + " " + QString("").setNum(version) + " " + tmpFileName;
966  rc = system(qPrintable(execStr));
967  if (rc!=0) // complain
968  {
969  complain = "An error occured executing the system call [" + execStr + "]; RC is " +
970  QString("").setNum(rc);
972  "::inquireCat(): " + complain, true);
973  return -2;
974  };
975  f.setFileName(tmpFileName);
976  f.open(QIODevice::ReadOnly);
977  s.setDevice(&f);
978  str1 = s.readLine();
979  if (str1 != "0 success")
980  {
981  f.close();
982  f.remove();
983  str2 = "";
984  return -1;
985  };
986  str2 = s.readLine();
987  if (str2.length() < 14)
989  "::inquireCat(): the length of the received string, " + str2 +
990  ", is less than a properly formed database name");
991  s.setDevice(NULL);
992  f.close();
993  f.remove();
994  return 0;
995 };
996 
997 
998 
999 //
1000 int NsSessionHandler::notifyCat(const QString& fileName, bool isNew, QString& str1)
1001 {
1002  int rc;
1003  QTextStream s;
1004  QFile f;
1005  QString execStr;
1006  QString tmpFileName("/tmp/nuSolve-Catalog.");
1007  QString complain;
1008  QString descriptionOfKey("1234"), descriptionOfEntry("");
1009  tmpFileName += SgMJD::currentMJD().toString(SgMJD::F_INTERNAL);
1010 
1011  // put info in the comm.file:
1012  // for David:
1014  {
1015  if (isNew)
1016  descriptionOfKey = session_->primaryBand()->history().getFirstRecordFromUser();
1017  descriptionOfEntry = session_->primaryBand()->history().getFirstRecordFromUser();
1018  }
1019  else
1020  {
1021  // describe the key (if necessary):
1022  if (isNew)
1023  descriptionOfKey = session_->getOfficialName() + " | " +
1025  // describe the entry:
1026  descriptionOfEntry = session_->getOfficialName() + "/" + setup.identities().getAcAbbrevName() +
1028  (isNew?" alt. ":" update. ") + setup.identities().getUserName();
1029  };
1030  //
1031  // prepare the file:
1032  f.setFileName(tmpFileName);
1033  if (f.open(QIODevice::WriteOnly))
1034  {
1035  s.setDevice(&f);
1036  s << descriptionOfKey .left(36) << endl;
1037  s << descriptionOfEntry.left(80) << endl;
1038  s.setDevice(NULL);
1039  f.close();
1040  }
1041  else
1042  {
1044  "::notifyCat(): cannot open for writting the communication file");
1045  return -2;
1046  };
1047  //
1048  // form a string:
1049  execStr = setup.getPath2CatNuInterfaceExec() + "/" + setup.catnuSetDbInfo() + " " +
1050  fileName + " " + (isNew?"create":"update") + " " + tmpFileName;
1051 // std::cout << "calling string: [" << qPrintable(execStr) << "]\n";
1052  // and exec it:
1053  rc = system(qPrintable(execStr));
1054  if (rc!=0) // complain
1055  {
1056  complain = "An error occured executing the system call [" + execStr + "]; RC is " +
1057  QString("").setNum(rc);
1059  "::notifyCat(): " + complain, true);
1060  return -2;
1061  };
1062  // read results:
1063  f.setFileName(tmpFileName);
1064  if (f.open(QIODevice::ReadOnly))
1065  {
1066  s.setDevice(&f);
1067  str1 = s.readLine();
1068  s.setDevice(NULL);
1069  f.close();
1070  f.remove();
1071  if (str1 != "0 success")
1072  return -1;
1073  return 0;
1074  }
1075  else
1076  {
1078  "::notifyCat(): cannot open for reading the communication file");
1079  return -2;
1080  };
1081 };
1082 
1083 
1084 
1085 
1086 //
1088 {
1089  bool isOk(true);
1090  QString splflDirName=setup.path2(setup.getPath2SpoolFileOutput());
1091  QString obsStatDirName=setup.path2(setup.getPath2NotUsedObsFileOutput());
1092  QDir d(splflDirName);
1093  if (!d.exists())
1094  isOk = d.mkpath("./"); // Qt, wtf?
1095  if (!isOk)
1096  {
1098  "::generateReport(): cannot create directory \"" + splflDirName + "\"; report failed");
1099  return;
1100  };
1101  d.setPath(obsStatDirName);
1102  if (!d.exists())
1103  isOk = d.mkpath("./");
1104  if (!isOk)
1105  {
1107  "::generateReport(): cannot create directory \"" + obsStatDirName + "\"; saving report failed");
1108  return;
1109  };
1110  //
1111  // create the report:
1112  QString fileName("SPLF" + setup.identities().getUserDefaultInitials());
1114  reporter_->report2spoolFile(splflDirName, obsStatDirName, fileName, isExtended);
1116  "::generateReport(): spoolfile output has been saved in the " + fileName + " file");
1117  //
1118  // save it in a separate file (if necessary):
1120  {
1121  QString rptrDirName = setup.path2(setup.getPath2ReportOutput());
1122  d.setPath(rptrDirName);
1123  if (!d.exists())
1124  isOk = d.mkpath("./"); // Qt, wtf?
1125  if (!isOk)
1126  {
1128  "::generateReport(): cannot create directory " + rptrDirName + "; saving report failed");
1129  return;
1130  };
1131 
1132  QString str(session_->nickName() + ".SFF");
1133  if (QFile::exists(rptrDirName + "/" + str) && !QFile(rptrDirName + "/" + str).remove())
1134  {
1136  "::generateReport(): cannot remove the file " + rptrDirName + "/" + str +
1137  "; saving report failed");
1138  return;
1139  };
1140  if (QFile::copy(splflDirName + "/" + fileName, rptrDirName + "/" + str))
1142  "::generateReport(): spoolfile output has been copied as " + rptrDirName + "/" + str +
1143  " file too");
1144  else
1146  "::generateReport(): copying of " + splflDirName + "/" + fileName + " as " + rptrDirName +
1147  "/" + str + " filed");
1148  };
1149 };
1150 
1151 
1152 
1153 
1154 //
1156 {
1157  bool isOk(true);
1158  QString splflDirName=setup.path2(setup.getPath2SpoolFileOutput());
1159  QString obsStatDirName=setup.path2(setup.getPath2NotUsedObsFileOutput());
1160  QDir d(splflDirName);
1161  if (!d.exists())
1162  isOk = d.mkpath("./"); // Qt, wtf?
1163  if (!isOk)
1164  {
1166  "::generateMyReport(): cannot create directory \"" + splflDirName + "\"; report failed");
1167  return;
1168  };
1169  d.setPath(obsStatDirName);
1170  if (!d.exists())
1171  isOk = d.mkpath("./");
1172  if (!isOk)
1173  {
1175  "::generateMyReport(): cannot create directory \"" + obsStatDirName + "\"; saving report failed");
1176  return;
1177  };
1178  //
1179  // create the report:
1180  QString fileName("Report." + session_->getName() + ".dat");
1182  reporter_->report2MyFile(splflDirName, fileName);
1184  "::generateMyReport(): report has been saved in the " + fileName + " file");
1185  //
1186 };
1187 
1188 
1189 
1190 //
1192 {
1193  QString outputDirName=setup.path2(setup.getPath2ReportOutput());
1194  QString dbName=session_->getName();
1195 
1196  if (dbName.at(0) == '$')
1197  dbName.remove(0, 1);
1198 
1199  outputDirName += "/" + dbName;
1200  reporter_->reportStochasticEstimations(outputDirName);
1202  "::generateReport4StcPars(): stochastic parameter estimaitons were saved in \"" + outputDirName +
1203  "\" direcory");
1204 };
1205 
1206 
1207 
1208 //
1210 {
1211  QString outputDirName=setup.path2(setup.getPath2ReportOutput());
1212  QString dbName=session_->getName();
1213 
1214  if (dbName.at(0) == '$')
1215  dbName.remove(0, 1);
1216  outputDirName += "/" + dbName;
1217 
1218  if (reporter_->reportTotalZenithDelays(outputDirName))
1220  "::generateReport4Tzds(): total zenith delays were saved in \"" + outputDirName +
1221  "\" direcory");
1222  else
1224  "::generateReport4Tzds(): saving total zenith delays in \"" + outputDirName +
1225  "\" direcory has been failed");
1226 
1227 };
1228 
1229 
1230 
1231 //
1232 //
1234 {
1235  bool isOk(true);
1236  QString splflDirName=setup.path2(setup.getPath2SpoolFileOutput());
1237  QDir d(splflDirName);
1238  if (!d.exists())
1239  isOk = d.mkpath("./"); // Qt, wtf?
1240  if (!isOk)
1241  {
1243  "::generateAposterioriFiles(): cannot create directory " + splflDirName + "; report failed");
1244  return;
1245  };
1246  //
1247  // create the report:
1248  QString fileName(session_->getName());
1249  if (fileName.at(0) == '$')
1250  fileName.remove(0, 1);
1251  reporter_->report2aposterioriFiles(splflDirName, fileName);
1253  "::generateAposterioriFiles(): a posteriori files were saved with \"" + fileName + "\" basename");
1254  //
1255 };
1256 
1257 
1258 
1259 //
1261 {
1262  if (!canSave())
1263  {
1265  ": exportDataToNgs(): exporting of data into NGS card format has been canceled");
1266  return;
1267  };
1268  //
1269  QString dirName=setup.path2(setup.getPath2NgsOutput());
1270  bool isOk(true);
1271  // check for existance:
1272  QDir d(dirName);
1273  if (!d.exists())
1274  isOk = d.mkpath("./"); // Qt, wtf?
1275  if (isOk)
1276  {
1277  session_->exportDataIntoNgsFile(dirName);
1279  "::exportDataToNgs(): the session has been exported as NGS file in the directory " + dirName);
1280  }
1281  else
1283  "::exportDataToNgs(): cannot create directory " + dirName + "; NGS export failed");
1284 };
1285 
1286 
1287 
1288 //
1290 {
1291  if (!canSave())
1292  {
1294  ": exportDataIntoVgosDa(): saving data in vgosDa format has been canceled");
1295  return false;
1296  };
1297  //
1298  QString dir2Save("");
1299  QString file2Save("");
1300  QDir dir;
1301  if (output.size())
1302  {
1303  // first, check is it a direcory:
1304  dir.setPath(output);
1305  if (dir.exists())
1306  {
1307  dir2Save = output;
1308  }
1309  else
1310  {
1311  // split input name for directory and file parts:
1312  int idx=-1;
1313  if (-1 < (idx=output.lastIndexOf('/')))
1314  {
1315  dir2Save = output.left(idx);
1316  file2Save = output.mid(idx + 1);
1317  }
1318  else
1319  file2Save = output;
1320  };
1321  }
1322  else
1323  dir2Save = setup.path2(setup.getPath2VgosDaFiles());
1324  //
1325  //
1326  bool isOk(true);
1327  // check for existance:
1328  dir.setPath(dir2Save);
1329  if (!dir.exists())
1330  isOk = dir.mkpath("./"); // Qt, wtf?
1331  if (isOk)
1332  {
1333  session_->putDataIntoAgvFile(dir2Save, file2Save, &setup.identities(), &nuSolveVersion);
1335  "::exportDataIntoVgosDa(): the session has been saved as an vgosDa file in the directory \"" +
1336  dir2Save + "\"");
1337  }
1338  else
1340  "::exportDataIntoVgosDa(): cannot create directory " + dir2Save +
1341  "; storing data in vgosDa format has failed");
1342  return isOk;
1343 };
1344 
1345 
1346 
1347 //
1348 void NsSessionHandler::addUserComment(const QString& comment)
1349 {
1350  reporter_->addUserComment(comment);
1351 };
1352 /*=====================================================================================================*/
1353 
1354 
1355 
1356 
1357 
1358 
1359 
1360 
1361 
1362 
1363 
1364 /*=====================================================================================================*/
SgVersion nuSolveVersion("nuSolve", 0, 7, 5, "Carroll Creek (rc)", SgMJD(2022, 2, 18, 17, 34))
SgLogger * logger
Definition: SgLogger.cpp:231
SgVersion libraryVersion("SgLib", 0, 7, 5, "Tuscarora (rc1)", SgMJD(2022, 2, 18, 17, 34))
const SgParametersDescriptor * parametersDescriptor() const
void setupVgosDaFileNames(const QString &fileName)
SgSolutionReporter * reporter_
int inquireCat(const QString &, int, QString &, QString &)
void generateReport(bool isExtended=false)
QMap< QString, SgDbhImage * > dbhImageByKey_
bool importSession(bool guiExpected)
bool exportDataIntoVgosDb(QString output=QString(""))
bool initSessionFromDbh(bool guiExpected)
void addUserComment(const QString &comment)
bool initSessionFromOdb(bool guiExpected)
void setupDogsDbhFileNames(const QString &fileName)
QMap< QString, QString > dbhNameByKey_
QMap< QString, QString > dbhPathByKey_
SgVlbiSessionInfo::OriginType oType_
void setupCatsDbhFileNames(const QString &fName, const QString &fName2)
int notifyCat(const QString &, bool, QString &)
SgParametersDescriptor * parametersDescriptor_
QString className() const
bool exportDataIntoVgosDa(QString output=QString(""))
SgTaskConfig * config_
bool initSessionFromVda(bool guiExpected)
void changeActiveBand(int idx)
SgVlbiSession * session_
NsSessionHandler(const QString &fileName, const QString &fileNameAux, SgTaskConfig *, SgParametersDescriptor *, SgVlbiSessionInfo::OriginType)
virtual bool canSave()
SaveStatus saveStatus_
void setupVgosDbFileNames(const QString &fileName)
const QString & catnuGetDbInfo() const
Definition: NsSetup.h:992
QString path2(const QString &) const
Definition: NsSetup.h:1008
bool getHave2SkipAutomaticProcessing() const
Definition: NsSetup.h:686
const QString & getPath2ReportOutput() const
Definition: NsSetup.h:470
const QString & getPath2CatNuInterfaceExec() const
Definition: NsSetup.h:414
const QString & getPath2MasterFiles() const
Definition: NsSetup.h:446
const QString & getPath2SpoolFileOutput() const
Definition: NsSetup.h:454
bool getHave2AutoloadAllBands() const
Definition: NsSetup.h:638
bool getHave2MaskSessionCode() const
Definition: NsSetup.h:534
SgIdentities & identities()
Definition: NsSetup.h:566
bool getHave2KeepSpoolFileReports() const
Definition: NsSetup.h:542
bool getHave2LoadImmatureSession() const
Definition: NsSetup.h:550
const QString & getPath2APrioriFiles() const
Definition: NsSetup.h:438
const QString & getPath2VgosDaFiles() const
Definition: NsSetup.h:87
bool getHave2UpdateCatalog() const
Definition: NsSetup.h:526
const QString & getPath2DbhFiles() const
Definition: NsSetup.h:422
const QString & getPath2VgosDbFiles() const
Definition: NsSetup.h:430
const QString & getPath2NgsOutput() const
Definition: NsSetup.h:478
const QString & getPath2NotUsedObsFileOutput() const
Definition: NsSetup.h:462
const QString & catnuSetDbInfo() const
Definition: NsSetup.h:1000
bool isAttr(uint a) const
Definition: SgAttribute.h:226
void addAttr(uint a)
Definition: SgAttribute.h:202
int currentVersion() const
Definition: SgDbhImage.h:331
void alterCode(const QString &c)
Definition: SgDbhImage.h:247
const QString & getAcAbbrevName() const
Definition: SgIdentities.h:247
const QString & getAcAbbName() const
Definition: SgIdentities.h:255
const QString & getUserDefaultInitials() const
Definition: SgIdentities.h:231
const QString & getUserName() const
Definition: SgIdentities.h:215
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
@ IO_TXT
Definition: SgLogger.h:65
@ IO_DBH
Definition: SgLogger.h:67
@ REPORT
Definition: SgLogger.h:95
@ PREPROC
Definition: SgLogger.h:98
@ SESSION
Definition: SgLogger.h:77
Definition: SgMJD.h:59
@ F_SOLVE_SPLFL_LONG
Another version from spoolfile format: 12/01/20 00:02.
Definition: SgMJD.h:78
@ F_yyyymmdd
Date in digits: 2010 04 02.
Definition: SgMJD.h:89
@ F_INTERNAL
Digits, date and time: 20100402.71.
Definition: SgMJD.h:72
QString toString(Format format=F_Verbose) const
Definition: SgMJD.cpp:1007
static SgMJD currentMJD()
Definition: SgMJD.cpp:118
int calcYear() const
Definition: SgMJD.cpp:204
const QString & getKey() const
Definition: SgObjectInfo.h:319
bool reportTotalZenithDelays(const QString &path)
void report2aposterioriFiles(const QString &path, const QString &fileNameBase)
void report2MyFile(const QString &path, const QString &fileName)
void addUserComment(const QString &coment)
void setPath2APrioriFiles(const QString &path)
void report2spoolFile(const QString &path, const QString &path2obsStatus, const QString &fileName, bool=false)
void reportStochasticEstimations(const QString &path)
void setDoWeightCorrection(bool)
void setActiveBandIdx(int)
void setUseDelayType(VlbiDelayType)
void setOpAction(OutliersProcessingAction)
const QString & getSoftwareName() const
Definition: SgVersion.h:254
void setPath2RootDir(const QString &path)
Definition: SgVgosDb.h:316
bool init(const QString path, const QString fileName)
Definition: SgVgosDb.cpp:533
const QString & getPath2RootDir() const
Definition: SgVgosDb.h:272
SgVlbiHistory & history()
Definition: SgVlbiBand.h:360
const QString & getFirstRecordFromUser() const
const QString & getName() const
const SgMJD & getTStart() const
@ OT_DBH
observations are from database files provided by correlators;
@ OT_AGV
observations are in AGV format;
@ OT_VDB
observations are from vgosDb data tree;
@ OT_UNKNOWN
unknown (=all others) source of import;
@ Attr_PRE_PROCESSED
the observations has been prepared for analysis;
@ Attr_FF_AUTOPROCESSED
automatic data processing performed successfully;
const QString & getOfficialName() const
void setNetworkSuffix(const QString &suffix)
const QString & getNetworkSuffix() const
const QString & getSessionCode() const
void setOriginType(OriginType type)
SgVlbiBand * primaryBand()
bool getDataFromVgosDb(SgVgosDb *vgosDb, bool have2LoadImmatureSession, bool guiExpected)
bool getDataFromDbhImages(QMap< QString, SgDbhImage * > &images, bool have2LoadImmatureSession, bool guiExpected)
void calculateIonoCorrections(const SgTaskConfig *)
void setParametersDescriptor(SgParametersDescriptor *parametersDescriptor)
bool exportDataIntoNgsFile(const QString &fileName)
void process(bool haveProcessAllBands, bool interactWithGui)
static bool guessSessionByWrapperFileName(const QString &inputArg, const QString &path2VgosDb, QString &path2wrapperFile, QString &wrapperFileName, QString &sessionName, int &version)
bool putDataIntoAgvFile(const QString &dirName, const QString &fileName, SgIdentities *ids, SgVersion *driverVersion)
bool putDataIntoDbhImage(SgDbhImage *image)
bool getDataFromAgvFile(const QString &fileName, SgIdentities *ids, SgVersion *driverVersion)
static bool guessWrapperFileNameBySession(const QString &inputArg, const QString &path2VgosDb, const QString &acAbbName, QString &path2wrapperFile, QString &wrapperFileName, QString &sessionName, int &version, bool noYears=false)
void zerofyIonoCorrections(const SgTaskConfig *)
void setPath2Masterfile(const QString &)
void setPath2APrioriFiles(const QString &)
bool putDataIntoVgosDb(SgVgosDb *vgosDb)
void setConfig(SgTaskConfig *cfg)
QString nickName()
SgVersion * driverVersion
Definition: l2aVersion.cpp:31
NsSetup setup
Definition: nuSolve.cpp:61
SgTaskConfig config
Definition: nuSolve.cpp:59
SgParametersDescriptor parametersDescriptor
Definition: nuSolve.cpp:60