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 #include <QtCore/QRegularExpression>
34 
35 
36 
37 #include <SgConstants.h>
38 #include <SgDbhImage.h>
39 #include <SgGuiPiaReport.h>
40 #include <SgGuiPlotter.h>
41 #include <SgGuiTaskConfig.h>
42 #include <SgLogger.h>
43 #include <SgMJD.h>
44 #include <SgParameterCfg.h>
46 #include <SgSolutionReporter.h>
47 #include <SgTaskManager.h>
48 #include <SgVgosDb.h>
49 #include <SgVlbiBand.h>
50 #include <SgVlbiNetworkId.h>
51 #include <SgVlbiObservation.h>
52 
53 
54 
55 
56 
57 
58 /*=======================================================================================================
59 *
60 * METHODS:
61 *
62 *======================================================================================================*/
63 NsSessionHandler::NsSessionHandler(const QString& fileName, const QString& fileNameAux,
66  : fileName_(fileName),
67  fileNameAux_(fileNameAux),
68  path2DbhFiles_(""),
69  dbhImageByKey_(),
70  dbhNameByKey_(),
71  dbhPathByKey_(),
72  path2VdbFiles_(""),
73  vdbWrapperFileName_(""),
74  path2VdaFiles_("")
75 {
76  oType_ = oType;
77  session_ = NULL;
78  reporter_ = NULL;
79  vgosDb_ = NULL;
80 
81  // make a copy:
82  config_ = new SgTaskConfig(*config);
84  //
85  //
86  initData();
87 };
88 
89 
90 
91 //
93  : fileName_(""),
94  fileNameAux_(""),
95  path2DbhFiles_(""),
96  dbhImageByKey_(),
97  dbhNameByKey_(),
98  dbhPathByKey_(),
99  path2VdbFiles_(""),
100  vdbWrapperFileName_("")
101 {
103  session_ = NULL;
104  reporter_ = NULL;
105  vgosDb_ = NULL;
106 
107  // make a copy:
108  config_ = new SgTaskConfig(*config);
110  //
111  initData();
112 };
113 
114 
115 
116 //
118 {
119  //
120  isImportOk_ = false;
122  // overwrite the saved set up:
127  //
128  // create the session and set up its config:
129  session_ = new SgVlbiSession;
135  //
137  //
138  activeBand_ = 0;
139  //
140 };
141 
142 
143 
144 //
146 {
147  //
148  dbhNameByKey_.clear();
149  dbhPathByKey_.clear();
150  for (QMap<QString, SgDbhImage*>::iterator it=dbhImageByKey_.begin(); it!=dbhImageByKey_.end(); ++it)
151  delete it.value();
152  dbhImageByKey_.clear();
153  //
154  if (vgosDb_)
155  {
156  delete vgosDb_;
157  vgosDb_ = NULL;
158  };
159  //
160  if (reporter_)
161  {
162  delete reporter_;
163  reporter_ = NULL;
164  };
165  //
166  if (session_)
167  {
168  delete session_;
169  session_ = NULL;
170  };
171  config = *config_;
172  delete config_;
173  config_ = NULL;
174 
175  delete parametersDescriptor_;
176  parametersDescriptor_ = NULL;
177 };
178 
179 
180 
181 //
182 bool NsSessionHandler::importSession(bool guiExpected)
183 {
184  isImportOk_ = false;
186  //
188  {
191  else
193  }
195  {
197  }
199  {
201  };
202  //
203  if ((oType_==SgVlbiSessionInfo::OT_DBH && dbhNameByKey_.size()==0) ||
206  )
207  {
209  "::importSession(): cannot find anything associated with the name \"" + fileName_ +
210  "\". Please, check and do it again.");
211  return false;
212  };
213  //
214  // read the files:
216  isImportOk_ = initSessionFromDbh(guiExpected);
218  isImportOk_ = initSessionFromOdb(guiExpected);
220  isImportOk_ = initSessionFromVda(guiExpected);
221  //
222  return isImportOk_;
223 };
224 
225 
226 
227 //
229 {
230  bool isOk(false);
231  //
233  {
235  "::performPia(): the automatic analysis is disabled by the command line argument");
236  return isOk;
237  };
238 
239  if (isImportOk_)
240  {
241 
242  isOk = session_->doPostReadActions();
243 
244  };
245  //
246  return isOk;
247 };
248 
249 
250 
251 //
252 //
254 {
255  session_->process(true, false);
256 };
257 
258 
259 
260 //
262 {
264 };
265 
266 
267 
268 //
270 {
272 };
273 
274 
276 {
277  activeBand_ = idx;
279 };
280 
281 
282 
283 
284 //
286 {
287  //
288  bool isOk(false);
290  {
292  isOk = exportDataIntoDbh();
293  else if (oType_ == SgVlbiSessionInfo::OT_VDB)
294  isOk = exportDataIntoVgosDb();
295  else if (oType_ == SgVlbiSessionInfo::OT_AGV) // export data in vgosDb format:
296  isOk = exportDataIntoVgosDa();
297  //
298  if (isOk &&
300  generateReport();
301  };
302  //
303  return isOk;
304 };
305 
306 
307 
308 //
309 // Sets up elements of dbhNameByKey_ map in a catalog-aware mode:
310 void NsSessionHandler::setupCatsDbhFileNames(const QString& fName, const QString& fName2)
311 {
312  QString fileName(fName);
313  QString fileName2(fName2);
314  QTextStream s;
315  QFile f;
316  QString baseName; // "YYMMMDD" part of databese's file name
317  QString currentBand; // "S", "X", ...
318  QString baseNetID; // "A", "E", ...
319  QString currentVersion; // e.g., "V001"
320  QString str1, str2;
321  QString key;
322  int version, v, l;
323  bool isOk;
324 
325  // user's input, can contain $-char at the begin:
326  if (fileName.at(0) == '$')
327  fileName = fileName.mid(1);
328  l = fileName.length();
329  if (fileName2.size()>0 && fileName2.at(0) == '$')
330  fileName2 = fileName2.mid(1);
331 
332  if (l==9)
333  {
334  // find out the first available version of the file:
335  v = 1;
336  while (inquireCat(fileName, ++v, str1, str2) != 0 && v<70)
337  ;
338  v--;
339  if (v==69)
340  {
342  "::setupCatsDbhFileNames(): the file " + fileName + " does not exist in the catalog");
343  return;
344  };
345  // find out the latest version of the file:
346  while (inquireCat(fileName, ++v, str1, str2) == 0)
347  ;
348  v--;
349  if (v<3)
350  {
352  "::setupCatsDbhFileNames(): the file " + fileName + " does not exist in the catalog");
353  return;
354  };
355  fileName += QString("").sprintf("_V%03d", v);
356  l += 5;
357  }
358  else if (!(fileName.mid(l-5, 2) == "_V")) // is it full name?
359  {
361  "::setupCatsDbhFileNames(): the file " + fileName + " is not a standard database name, "
362  "expecting: YYMMMDDBC_Vxxx");
363  return;
364  };
365 
366  baseName = fileName.mid(l-14, 7);
367  currentBand = fileName.mid(l-7, 1);
368  baseNetID = fileName.mid(l-6, 1);
369  currentVersion = fileName.mid(l-4, 4);
370  version = currentVersion.mid(1).toInt(&isOk);
371  if (!isOk)
372  {
374  "::setupCatsDbhFileNames(): cannot determine proper DBH version for the file " + fileName);
375  return;
376  };
377 
378  // enquire about user provided database:
379  if (inquireCat(baseName + currentBand + baseNetID, version, str1, str2) != 0)
380  {
382  "::setupCatsDbhFileNames(): got an error on the request to " +
383  setup.catnuGetDbInfo() + ": " + str1);
384  return;
385  };
386  // set up path to databases:
387  l = str2.lastIndexOf("/");
388  path2DbhFiles_ = str2.left(l+1);
389  dbhNameByKey_[currentBand] = str2.mid(l+1);
390  dbhPathByKey_[currentBand] = path2DbhFiles_;
391  //
392  //
393  if (setup.getHave2AutoloadAllBands() && fileName2 != "/dev/null")
394  {
395  l = fileName2.size();
396  if (l >= 9) // user explicitly provided a filename of the second database:
397  {
398  isOk = true;
399  if (l==9) // no version info:
400  {
401  // find out the first available version of the file:
402  v = 1;
403  while (inquireCat(fileName2, ++v, str1, str2) != 0 && v<70)
404  ;
405  v--;
406  if (v==69)
407  {
409  "::setupCatsDbhFileNames(): cannot find the second file " + fileName2 + " in the catalog");
410  isOk = false;
411  };
412  // find out the latest version of the file:
413  while (inquireCat(fileName2, ++v, str1, str2) == 0)
414  ;
415  v--;
416  if (v<2)
417  {
419  "::setupCatsDbhFileNames(): cannot find the second file " + fileName2 + " in the catalog");
420  isOk = false;
421  };
422  fileName2 += QString("").sprintf("_V%03d", v);
423  l += 5;
424  }
425  else
426  v = fileName2.mid(l-3, 3).toInt(&isOk);
427  //
428  if (isOk)
429  {
430  isOk = inquireCat(fileName2, v, str1, str2) == 0;
431  //
432  QString aBand("");
433  aBand = fileName2.mid(l-7, 1);
434  l = str2.lastIndexOf("/");
435  path2DbhFiles_ = str2.left(l+1);
436  dbhNameByKey_[aBand] = str2.mid(l+1);
437  dbhPathByKey_[aBand] = path2DbhFiles_;
439  "::setupCatsDbhFileNames(): the second database file " + fileName2 +
440  " has been found in the catalog, band=[" + currentBand + "], version=" +
441  QString("").setNum(v));
442  };
443  }
444  else // guess a file name of the second database:
445  {
446  // find a database with opposite band:
447  v = version;
448  isOk = false;
449  if (currentBand == "X")
450  {
451  key = "S";
452  while (v>1 && !isOk)
453  isOk = inquireCat(baseName + key + baseNetID, v--, str1, str2) == 0;
454  }
455  else
456  {
457  key = "X";
458  while (v<31 && !isOk) // ver 30 -- is it enouhg?
459  isOk = inquireCat(baseName + key + baseNetID, v++, str1, str2) == 0;
460  };
461  if (isOk)
462  {
463  l = str2.lastIndexOf("/");
464  dbhNameByKey_[key] = str2.mid(l+1);
465  dbhPathByKey_[key] = str2.left(l+1);
466  }
467  else
469  "::setupCatsDbhFileNames(): cannot find an opposite band, " + key + ", : " + str1);
470  };
471  };
472  //
473  // check if it is possible to submit a next version database:
474  if (inquireCat(baseName + (currentBand=="S"?"X":currentBand) + baseNetID, version+1, str1, str2) == 0)
475  {
477  {
480  "::setupCatsDbhFileNames(): a database with the next version already exists in the catalog");
481  };
482  };
483 };
484 
485 
486 
487 //
488 // Sets up elements of dbhNameByKey_ map in a standalone (non catalog) mode:
489 void NsSessionHandler::setupDogsDbhFileNames(const QString& fileName)
490 {
491  QString baseName; // "YYMMMDD" part of databese's file name
492  QString currentBand; // "S", "X", ...
493  QString baseNetID; // "A", "E", ...
494  QString currentVersion; // e.g., "V001"
495  QString str;
496  int l = fileName.length();
497  QString key;
498 
499  if (fileName.mid(l-5, 2) == "_V") // ok, we asuming it is standard IVS naming convention:
500  {
501  //
502  currentBand = fileName.mid(l-7, 1);
503  baseNetID = fileName.mid(l-6, 1);
504  currentVersion = fileName.mid(l-4, 4);
505 
506  l = fileName.lastIndexOf("/");
507  // we figure out it from the fileName:
508  if (fileName.at(0) == '/') // user provided absolute path:
509  {
510  path2DbhFiles_ = fileName.left(l+1);
511  str = fileName.mid(l+1);
512  }
513  else
514  {
515  path2DbhFiles_ = setup.getPath2DbhFiles() + "/" + fileName.left(l+1);
516  str = fileName.mid(l+1);
517  };
518  //
519  baseName = str.left(7);
520  QDir dir(path2DbhFiles_);
521  QStringList nameFilters;
523  nameFilters << baseName + "?" + baseNetID + "*";
524  else
525  nameFilters << baseName + currentBand + baseNetID + "*";
526  QStringList nameList = dir.entryList(nameFilters,
527  QDir::Files | QDir::Readable, QDir::Name | QDir::IgnoreCase);
528  if (!nameList.size())
529  {
530  // ??
531  };
532  for (int i=0; i<nameList.size(); i++)
533  {
534  l = nameList.at(i).length();
535  if (l==14)
536  {
537  key = nameList.at(i).mid(l-7, 1);
538  if (key == currentBand && !dbhNameByKey_.contains(key))
539  dbhNameByKey_[key] = str;
540  else
541  {
542  if (!dbhNameByKey_.contains(key))
543  dbhNameByKey_[key] = nameList.at(i);
544  else if (nameList.at(i).mid(l-4, 4) <= currentVersion)
545  dbhNameByKey_[key] = nameList.at(i);
546  };
547  };
548  };
549  }
550  else // perhaps, it is new naming convention, pass it as is:
551  dbhNameByKey_["A"] = fileName;
552 };
553 
554 
555 
556 //
557 // Sets up path to and name of the wrapper file of vgosDb data tree:
558 void NsSessionHandler::setupVgosDbFileNames(const QString& inpt)
559 {
560  QString sessionName("");
561  int version(0);
562 
563  bool isOk;
564 //QRegExp reWrapperFileName(".*\\.(wrp|wrap)$", Qt::CaseInsensitive);
565 //QRegExp reDatabaseName("^[0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2}$");
566 //QRegExp reDatabaseVersionName("^[0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2}_V[0-9]{3}$");
567 //QRegExp rePath2Database("(.*)([0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2})/?$");
568 
569  QRegularExpression reWrapperFileName(".*\\.(wrp|wrap)$",
570  QRegularExpression::CaseInsensitiveOption);
571  QRegularExpression reOldDbName("^(\\d{2}[A-Z]{3}\\d{2}[A-Z0-9]{1,2}).*");
572  QRegularExpression reNewDbName("^(\\d{8})-([\\S]{2,12}).*");
573 
574  QRegularExpression rePath2DatabaseV1("(.*)/(\\d{2}[A-Z]{3}\\d{2}[A-Z0-9]{1,2})/?$");
575  QRegularExpression rePath2DatabaseV2("(.*)/(\\d{8}-[\\S]{2,12})/?$");
576 
577  //
578  // ok, this is a wrapper file name:
579  if (reWrapperFileName.match(inpt).hasMatch())
580  {
583  sessionName, version);
584  if (isOk)
586  "::setupVgosDbFileNames(): got a session " + sessionName + " of version " +
587  QString("").setNum(version) + " from \"" + path2VdbFiles_ + "\":\"" +
588  vdbWrapperFileName_ + "\"");
589  else
591  "::setupVgosDbFileNames(): cannot figure out a session from the input \"" + inpt + "\"");
592  }
593  // a database or a database with version:
594  else if ( reOldDbName.match(inpt).hasMatch() ||
595  reNewDbName.match(inpt).hasMatch() )
596  {
599  path2VdbFiles_, vdbWrapperFileName_, sessionName, version);
600  if (isOk)
602  "::setupVgosDbFileNames(): got a wrapper file \"" + vdbWrapperFileName_ +
603  "\" from \"" + path2VdbFiles_ + "\" for the session " + sessionName +
604  " of version " + QString("").setNum(version));
605  else
607  "::setupVgosDbFileNames(): cannot figure out a wrapper file from the input \"" + inpt + "\"");
608  }
609  else if (rePath2DatabaseV1.match(inpt).hasMatch() ||
610  rePath2DatabaseV2.match(inpt).hasMatch() )
611  {
612  // a directory with a database:
613  QDir dir(inpt);
614  if (dir.exists())
615  {
616  QRegularExpressionMatch match=rePath2DatabaseV1.match(inpt);
617  if (!match.hasMatch())
618  match=rePath2DatabaseV2.match(inpt);
619  QString sDir(match.captured(2));
620  QString sPath(match.captured(1));
621 
623  path2VdbFiles_, vdbWrapperFileName_, sessionName, version, true);
624  if (isOk)
626  "::setupVgosDbFileNames(): got a wrapper file \"" + vdbWrapperFileName_ +
627  "\" from \"" + path2VdbFiles_ + "\" for the session " + sessionName +
628  " of version " + QString("").setNum(version));
629  else
631  "::setupVgosDbFileNames(): cannot figure out a wrapper file from the directory \"" +
632  inpt + "\"");
633  }
634  else
636  "::setupVgosDbFileNames(): the directory \"" + inpt + "\" does not exist");
637  }
638  else
639  {
641  "::setupVgosDbFileNames(): cannot guess input data from \"" + inpt + "\"");
642  };
643 };
644 
645 
646 
647 //
648 void NsSessionHandler::setupVgosDaFileNames(const QString& /*input*/)
649 {
650  // just a file name:
651  QFile file(fileName_);
652  if (file.exists())
653  return;
654  QString str(setup.getPath2VgosDaFiles() + "/" + fileName_);
655  file.setFileName(str);
656  // if a user provided .vda suffix:
657  if (file.exists())
658  {
659  fileName_ = str;
660  return;
661  };
662  // if a user provided just a database name:
663  str += ".vda";
664  file.setFileName(str);
665  if (file.exists())
666  fileName_ = str;
667 };
668 
669 
670 
671 // functions:
673 {
674  SgDbhStream dbhStream;
675  QFile dbhFile;
676  SgDbhImage *dbhImage;
677  QString path;
678 
679  for (QMap<QString, QString>::const_iterator i=dbhNameByKey_.constBegin();
680  i!=dbhNameByKey_.constEnd(); ++i)
681  {
682  path = dbhPathByKey_.contains(i.key()) ? dbhPathByKey_[i.key()] : path2DbhFiles_;
683  dbhImage = new SgDbhImage;
684  dbhFile.setFileName(path + i.value());
686  "::initSessionFromDbh(): reading file " + i.value() + " in the directory \"" +
687  path + "\"", true);
688 
689  dbhFile.open(QIODevice::ReadOnly);
690  dbhStream.setDevice(&dbhFile);
691  dbhStream >> *dbhImage;
692  dbhStream.setDevice(NULL);
693  dbhFile.close();
694  dbhImageByKey_[i.key()] = dbhImage;
695  };
696 
699  "::initSessionFromDbh(): absorbing data from the set of DBH images", true);
701  guiExpected);
702 };
703 
704 
705 
706 
707 //
709 {
710  bool isOk;
714  "::initSessionFromOdb(): parsing of wrapper file " + vdbWrapperFileName_ +
715  (isOk?" complete":" failed"));
716 
718 
720  {
722  "::initSessionFromOdb(): the session " + session_->getSessionCode() + " (" + session_->getName() +
723  ") has been imported from " + path2VdbFiles_);
724  return true;
725  };
727  "::initSessionFromOdb(): reading of the session " + session_->getSessionCode() +
728  " (" + session_->getName() + ") failed");
729  return false;
730 };
731 
732 
733 
734 //
735 bool NsSessionHandler::initSessionFromVda(bool /*guiExpected*/)
736 {
737  SgIdentities ids;
739 
741 
743  {
745  "::initSessionFromVda(): the session " + session_->getSessionCode() + " (" + session_->getName() +
746  ") has been imported from " + fileName_);
747  return true;
748  };
750  "::initSessionFromVda(): reading data from vgosDa file \"" + fileName_ + "\" failed");
751  return false;
752 };
753 
754 
755 
756 //
758 {
759  if (!canSave())
760  {
763  ": exportDataIntoDbh(): saving data in DBH format has been canceled");
764  return false;
765  };
766  //
768  "::exportDataIntoDbh(): saving data in DBH format");
769 
770  if (!session_)
771  {
774  "::exportDataIntoDbh(): the session pointer is NULL");
775  return false;
776  }
778  SgVlbiBand *primaryBand=session_->primaryBand();
779  if (!primaryBand)
780  {
783  "::exportDataIntoDbh(): the primary band pointer is NULL");
784  return false;
785  };
786  SgDbhImage *dbhImage=dbhImageByKey_[primaryBand->getKey()];
787  if (!dbhImage)
788  {
791  "::exportDataIntoDbh(): the dbhImage pointer is NULL");
792  return false;
793  };
794 
795  bool have2NotifyCatalog(setup.getHave2UpdateCatalog());
796  bool isNewChain(false);
797  // determine a name of the output file:
798  QString sessionFileName, dbhFileName;
800  {
801  // QString alterCode(networkSuffix=="U"?"1":"8");
802  QString alterCode(session_->getNetworkSuffix()=="U"?"1":"7");
803  dbhImage->alterCode(alterCode);
804  session_->setNetworkSuffix(alterCode);
805  isNewChain = true;
806  };
807 
808  sessionFileName = session_->getName() + QString().sprintf("_V%03d", dbhImage->currentVersion());
809  dbhFileName = path2DbhFiles_ + sessionFileName;
810  // check for existing file:
811  if (QFile::exists(dbhFileName))
812  {
813  if (have2NotifyCatalog) // notify a user about refusing to save:
814  {
817  "::exportDataIntoDbh(): the file " + dbhFileName + " is already exist; remove it and try again");
818  return false;
819  };
820  // alternate the name and save the data:
821  QString suffix="_" + SgMJD::currentMJD().toString(SgMJD::F_INTERNAL);
822  dbhFileName += suffix;
824  "::exportDataIntoDbh(): the new version file is already exist; the name is altered to " +
825  sessionFileName + suffix);
826  };
827  // adjust data:
828  session_->putDataIntoDbhImage(dbhImage);
829 
830  // before writing, verify catalog:
831  if (have2NotifyCatalog)
832  {
833  QString str1, str2;
834  if (inquireCat(session_->getName(), dbhImage->currentVersion(), str1, str2) == 0)
835  {
838  "::exportDataIntoDbh(): the new version already exists in the catalog, remove it from the "
839  "catalog and try again");
840  return false;
841  };
842  };
843  //
844  // write into the file:
845  SgDbhStream dbhStream;
846  QFile dbhFile(dbhFileName);
847  dbhFile.open(QIODevice::WriteOnly);
848  dbhStream.setDevice(&dbhFile);
849  dbhStream << *dbhImage;
850  dbhStream.setDevice(NULL);
851  dbhFile.close();
853  "::exportDataIntoDbh(): the " + primaryBand->getKey() + "-band of the session " +
854  session_->getName() + " has been saved into the file " + dbhFileName);
855 
856  if (have2NotifyCatalog)
857  {
858  QString str1;
859  if (notifyCat(dbhFileName, isNewChain, str1) != 0)
860  {
863  "::exportDataIntoDbh(): updating the catalog has failed; error: " + str1);
864  return false;
865  }
866  else
868  "::exportDataIntoDbh(): the catalog has been updated successfuly");
869  };
870  //
871  saveStatus_ = SS_OK;
872  return true;
873 };
874 
875 
876 
877 //
879 {
880  if (!canSave())
881  {
884  ": exportDataIntoVgosDb(): exporting of data into vgosDb tree has been canceled");
885  return false;
886  };
887  //
888  bool isOk;
889 
890  // data were imported in vgosDb format:
891  if (vgosDb_)
892  {
893  if ((isOk=session_->putDataIntoVgosDb(vgosDb_)))
894  saveStatus_ = SS_OK;
895  else
897  }
898  // data were imported in another format:
899  else
900  {
901  QString dir2Save("");
902  QDir dir;
903  if (output.size()) // for vgosDb output is a directory name:
904  {
905  dir2Save = output;
907  "::exportDataIntoVgosDb(): gpt a user specified path: \"" + dir2Save + "\"");
908  }
909  else
910  dir2Save = setup.path2(setup.getPath2VgosDbFiles()) + "/" +
911  QString("").sprintf("%04d", session_->getTStart().calcYear()) + "/" + session_->getName();
912 
915  "::exportDataIntoVgosDb(): vgosDb object has been created");
916 
919  "::exportDataIntoVgosDb(): the vgosDb object has been prepared to save the new session in "
920  "vgosDb format");
921  //
922  // check if a dir (or a file) exists, adjust the name:
923  if (dir.exists(dir2Save))
924  {
925  SgMJD epoch=SgMJD::currentMJD();
926  dir2Save += "-" + epoch.toString(SgMJD::F_yyyymmdd);
928  "::exportDataIntoVgosDb(): the output path has been adjusted to \"" + dir2Save + "\"");
929  if (dir.exists(dir2Save))
930  {
931  epoch = SgMJD::currentMJD();
932  dir2Save = setup.path2(setup.getPath2VgosDbFiles()) + "/" +
933  QString("").sprintf("%04d", session_->getTStart().calcYear()) + "/" + session_->getName() +
934  "-" + epoch.toString(SgMJD::F_SOLVE_SPLFL_LONG);
936  "::exportDataIntoVgosDb(): the output path has been readjusted to \"" + dir2Save + "\"");
937  };
938  };
939  vgosDb_->setPath2RootDir(dir2Save);
941  "::exportDataIntoVgosDb(): the path was set to " + vgosDb_->getPath2RootDir());
942 
945  "::exportDataIntoVgosDb(): export of data into vgosDb tree has been " + (isOk?"complete":"failed"));
946 
947  delete vgosDb_;
948  vgosDb_ = NULL;
950  "::exportDataIntoVgosDb(): vgosDb object has been destroyed.");
951  };
952 
954  "::exportDataIntoVgosDb(): exporting of data into vgosDb tree has been" +
955  (isOk?" complete":" failed"));
956 
957  return isOk;
958 };
959 
960 
961 
962 //
963 int NsSessionHandler::inquireCat(const QString& databaseName, int version,
964  QString& str1, QString& str2)
965 {
966  int rc;
967  QTextStream s;
968  QFile f;
969  QString execStr;
970  QString tmpFileName("/tmp/nuSolve-Catalog.");
971  QString complain;
972  tmpFileName += SgMJD::currentMJD().toString(SgMJD::F_INTERNAL);
973 
974  execStr = setup.getPath2CatNuInterfaceExec() + "/" + setup.catnuGetDbInfo() + " " +
975  databaseName + " " + QString("").setNum(version) + " " + tmpFileName;
976  rc = system(qPrintable(execStr));
977  if (rc!=0) // complain
978  {
979  complain = "An error occured executing the system call [" + execStr + "]; RC is " +
980  QString("").setNum(rc);
982  "::inquireCat(): " + complain, true);
983  return -2;
984  };
985  f.setFileName(tmpFileName);
986  f.open(QIODevice::ReadOnly);
987  s.setDevice(&f);
988  str1 = s.readLine();
989  if (str1 != "0 success")
990  {
991  f.close();
992  f.remove();
993  str2 = "";
994  return -1;
995  };
996  str2 = s.readLine();
997  if (str2.length() < 14)
999  "::inquireCat(): the length of the received string, " + str2 +
1000  ", is less than a properly formed database name");
1001  s.setDevice(NULL);
1002  f.close();
1003  f.remove();
1004  return 0;
1005 };
1006 
1007 
1008 
1009 //
1010 int NsSessionHandler::notifyCat(const QString& fileName, bool isNew, QString& str1)
1011 {
1012  int rc;
1013  QTextStream s;
1014  QFile f;
1015  QString execStr;
1016  QString tmpFileName("/tmp/nuSolve-Catalog.");
1017  QString complain;
1018  QString descriptionOfKey("1234"), descriptionOfEntry("");
1019  tmpFileName += SgMJD::currentMJD().toString(SgMJD::F_INTERNAL);
1020 
1021  // put info in the comm.file:
1022  // for David:
1024  {
1025  if (isNew)
1026  descriptionOfKey = session_->primaryBand()->history().getFirstRecordFromUser();
1027  descriptionOfEntry = session_->primaryBand()->history().getFirstRecordFromUser();
1028  }
1029  else
1030  {
1031  // describe the key (if necessary):
1032  if (isNew)
1033  descriptionOfKey = session_->getOfficialName() + " | " +
1035  // describe the entry:
1036  descriptionOfEntry = session_->getOfficialName() + "/" + setup.identities().getAcAbbrevName() +
1038  (isNew?" alt. ":" update. ") + setup.identities().getUserName();
1039  };
1040  //
1041  // prepare the file:
1042  f.setFileName(tmpFileName);
1043  if (f.open(QIODevice::WriteOnly))
1044  {
1045  s.setDevice(&f);
1046  s << descriptionOfKey .left(36) << endl;
1047  s << descriptionOfEntry.left(80) << endl;
1048  s.setDevice(NULL);
1049  f.close();
1050  }
1051  else
1052  {
1054  "::notifyCat(): cannot open for writting the communication file");
1055  return -2;
1056  };
1057  //
1058  // form a string:
1059  execStr = setup.getPath2CatNuInterfaceExec() + "/" + setup.catnuSetDbInfo() + " " +
1060  fileName + " " + (isNew?"create":"update") + " " + tmpFileName;
1061 // std::cout << "calling string: [" << qPrintable(execStr) << "]\n";
1062  // and exec it:
1063  rc = system(qPrintable(execStr));
1064  if (rc!=0) // complain
1065  {
1066  complain = "An error occured executing the system call [" + execStr + "]; RC is " +
1067  QString("").setNum(rc);
1069  "::notifyCat(): " + complain, true);
1070  return -2;
1071  };
1072  // read results:
1073  f.setFileName(tmpFileName);
1074  if (f.open(QIODevice::ReadOnly))
1075  {
1076  s.setDevice(&f);
1077  str1 = s.readLine();
1078  s.setDevice(NULL);
1079  f.close();
1080  f.remove();
1081  if (str1 != "0 success")
1082  return -1;
1083  return 0;
1084  }
1085  else
1086  {
1088  "::notifyCat(): cannot open for reading the communication file");
1089  return -2;
1090  };
1091 };
1092 
1093 
1094 
1095 
1096 //
1098 {
1099  bool isOk(true);
1100  QString splflDirName=setup.path2(setup.getPath2SpoolFileOutput());
1101  QString obsStatDirName=setup.path2(setup.getPath2NotUsedObsFileOutput());
1102  QDir d(splflDirName);
1103  if (!d.exists())
1104  isOk = d.mkpath("./"); // Qt, wtf?
1105  if (!isOk)
1106  {
1108  "::generateReport(): cannot create directory \"" + splflDirName + "\"; report failed");
1109  return;
1110  };
1111  d.setPath(obsStatDirName);
1112  if (!d.exists())
1113  isOk = d.mkpath("./");
1114  if (!isOk)
1115  {
1117  "::generateReport(): cannot create directory \"" + obsStatDirName + "\"; saving report failed");
1118  return;
1119  };
1120  //
1121  // create the report:
1122  QString fileName("SPLF" + setup.identities().getUserDefaultInitials());
1124  reporter_->report2spoolFile(splflDirName, obsStatDirName, fileName, isExtended);
1126  "::generateReport(): spoolfile output has been saved in the " + fileName + " file");
1127  //
1128  // save it in a separate file (if necessary):
1130  {
1131  QString rptrDirName = setup.path2(setup.getPath2ReportOutput());
1132  d.setPath(rptrDirName);
1133  if (!d.exists())
1134  isOk = d.mkpath("./"); // Qt, wtf?
1135  if (!isOk)
1136  {
1138  "::generateReport(): cannot create directory " + rptrDirName + "; saving report failed");
1139  return;
1140  };
1141 
1142  QString str(session_->getName() + ".SFF");
1143  if (QFile::exists(rptrDirName + "/" + str) && !QFile(rptrDirName + "/" + str).remove())
1144  {
1146  "::generateReport(): cannot remove the file " + rptrDirName + "/" + str +
1147  "; saving report failed");
1148  return;
1149  };
1150  if (QFile::copy(splflDirName + "/" + fileName, rptrDirName + "/" + str))
1152  "::generateReport(): spoolfile output has been copied as " + rptrDirName + "/" + str +
1153  " file too");
1154  else
1156  "::generateReport(): copying of " + splflDirName + "/" + fileName + " as " + rptrDirName +
1157  "/" + str + " filed");
1158  };
1159 };
1160 
1161 
1162 
1163 
1164 //
1166 {
1167  bool isOk(true);
1168  QString splflDirName=setup.path2(setup.getPath2SpoolFileOutput());
1169  QString obsStatDirName=setup.path2(setup.getPath2NotUsedObsFileOutput());
1170  QDir d(splflDirName);
1171  if (!d.exists())
1172  isOk = d.mkpath("./"); // Qt, wtf?
1173  if (!isOk)
1174  {
1176  "::generateMyReport(): cannot create directory \"" + splflDirName + "\"; report failed");
1177  return;
1178  };
1179  d.setPath(obsStatDirName);
1180  if (!d.exists())
1181  isOk = d.mkpath("./");
1182  if (!isOk)
1183  {
1185  "::generateMyReport(): cannot create directory \"" + obsStatDirName + "\"; saving report failed");
1186  return;
1187  };
1188  //
1189  // create the report:
1190  QString fileName("Report." + session_->getName() + ".dat");
1192  reporter_->report2MyFile(splflDirName, fileName);
1194  "::generateMyReport(): report has been saved in the " + fileName + " file");
1195  //
1196 };
1197 
1198 
1199 
1200 //
1202 {
1203  QString outputDirName=setup.path2(setup.getPath2ReportOutput());
1204  QString dbName=session_->getName();
1205 
1206  if (dbName.at(0) == '$')
1207  dbName.remove(0, 1);
1208 
1209  outputDirName += "/" + dbName;
1210  reporter_->reportStochasticEstimations(outputDirName);
1212  "::generateReport4StcPars(): stochastic parameter estimaitons were saved in \"" + outputDirName +
1213  "\" direcory");
1214 };
1215 
1216 
1217 
1218 //
1220 {
1221  QString outputDirName=setup.path2(setup.getPath2ReportOutput());
1222  QString dbName=session_->getName();
1223 
1224  if (dbName.at(0) == '$')
1225  dbName.remove(0, 1);
1226  outputDirName += "/" + dbName;
1227 
1228  if (reporter_->reportTotalZenithDelays(outputDirName))
1230  "::generateReport4Tzds(): total zenith delays were saved in \"" + outputDirName +
1231  "\" direcory");
1232  else
1234  "::generateReport4Tzds(): saving total zenith delays in \"" + outputDirName +
1235  "\" direcory has been failed");
1236 
1237 };
1238 
1239 
1240 
1241 //
1242 //
1244 {
1245  bool isOk(true);
1246  QString splflDirName=setup.path2(setup.getPath2SpoolFileOutput());
1247  QDir d(splflDirName);
1248  if (!d.exists())
1249  isOk = d.mkpath("./"); // Qt, wtf?
1250  if (!isOk)
1251  {
1253  "::generateAposterioriFiles(): cannot create directory " + splflDirName + "; report failed");
1254  return;
1255  };
1256  //
1257  // create the report:
1258  QString fileName(session_->getName());
1259  if (fileName.at(0) == '$')
1260  fileName.remove(0, 1);
1261  reporter_->report2aposterioriFiles(splflDirName, fileName);
1263  "::generateAposterioriFiles(): a posteriori files were saved with \"" + fileName + "\" basename");
1264  //
1265 };
1266 
1267 
1268 
1269 //
1271 {
1272  if (!canSave())
1273  {
1275  ": exportDataToNgs(): exporting of data into NGS card format has been canceled");
1276  return;
1277  };
1278  //
1279  QString dirName=setup.path2(setup.getPath2NgsOutput());
1280  bool isOk(true);
1281  // check for existance:
1282  QDir d(dirName);
1283  if (!d.exists())
1284  isOk = d.mkpath("./"); // Qt, wtf?
1285  if (isOk)
1286  {
1287  session_->exportDataIntoNgsFile(dirName);
1289  "::exportDataToNgs(): the session has been exported as NGS file in the directory " + dirName);
1290  }
1291  else
1293  "::exportDataToNgs(): cannot create directory " + dirName + "; NGS export failed");
1294 };
1295 
1296 
1297 
1298 //
1300 {
1301  if (!canSave())
1302  {
1304  ": exportDataIntoVgosDa(): saving data in vgosDa format has been canceled");
1305  return false;
1306  };
1307  //
1308  QString dir2Save("");
1309  QString file2Save("");
1310  QDir dir;
1311  if (output.size())
1312  {
1313  // first, check is it a direcory:
1314  dir.setPath(output);
1315  if (dir.exists())
1316  {
1317  dir2Save = output;
1318  }
1319  else
1320  {
1321  // split input name for directory and file parts:
1322  int idx=-1;
1323  if (-1 < (idx=output.lastIndexOf('/')))
1324  {
1325  dir2Save = output.left(idx);
1326  file2Save = output.mid(idx + 1);
1327  }
1328  else
1329  file2Save = output;
1330  };
1331  }
1332  else
1333  dir2Save = setup.path2(setup.getPath2VgosDaFiles());
1334  //
1335  //
1336  bool isOk(true);
1337  // check for existance:
1338  dir.setPath(dir2Save);
1339  if (!dir.exists())
1340  isOk = dir.mkpath("./"); // Qt, wtf?
1341  if (isOk)
1342  {
1343  if ((isOk=session_->putDataIntoAgvFile(dir2Save, file2Save, &setup.identities(), &nuSolveVersion)))
1345  "::exportDataIntoVgosDa(): the session has been saved as an vgosDa file in the directory \"" +
1346  dir2Save + "\"");
1347  else
1349  "::exportDataIntoVgosDa(): export data in a vgosDa file failed; directory to store: \"" +
1350  dir2Save + "\", file to store: \"" + file2Save + "\"");
1351  }
1352  else
1354  "::exportDataIntoVgosDa(): cannot create directory " + dir2Save +
1355  "; storing data in vgosDa format has failed");
1356  return isOk;
1357 };
1358 
1359 
1360 
1361 //
1362 void NsSessionHandler::addUserComment(const QString& comment)
1363 {
1364  reporter_->addUserComment(comment);
1365 };
1366 /*=====================================================================================================*/
1367 
1368 
1369 
1370 
1371 
1372 
1373 
1374 
1375 
1376 
1377 
1378 /*=====================================================================================================*/
SgVersion nuSolveVersion("nuSolve", 0, 8, 2, "Dark Hollow Falls (rc2)", SgMJD(2023, 4, 3, 10, 59))
SgLogger * logger
Definition: SgLogger.cpp:231
SgVersion libraryVersion("SgLib", 0, 8, 2, "Compton Peak (rc2)", SgMJD(2023, 4, 3, 10, 59))
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:1008
static SgMJD currentMJD()
Definition: SgMJD.cpp:119
int calcYear() const
Definition: SgMJD.cpp:205
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:318
bool init(const QString path, const QString fileName)
Definition: SgVgosDb.cpp:538
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)
SgVersion * driverVersion
Definition: l2aVersion.cpp:31
NsSetup setup
Definition: nuSolve.cpp:61
SgTaskConfig config
Definition: nuSolve.cpp:59
SgParametersDescriptor parametersDescriptor
Definition: nuSolve.cpp:60