casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SynthesisNormalizerMixin.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
2 //# SynthesisNormalizerMixin.h: Mixin for using SynthesisNormalizer class in
3 //# parallel imaging framework (ParallelImagerMixin)
4 //# Copyright (C) 2016
5 //# Associated Universities, Inc. Washington DC, USA.
6 //#
7 //# This library is free software; you can redistribute it and/or modify it
8 //# under the terms of the GNU Library General Public License as published by
9 //# the Free Software Foundation; either version 2 of the License, or (at your
10 //# option) any later version.
11 //#
12 //# This library is distributed in the hope that it will be useful, but WITHOUT
13 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 //# License for more details.
16 //#
17 //# You should have received a copy of the GNU Library General Public License
18 //# along with this library; if not, write to the Free Software Foundation,
19 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20 //#
21 //# Correspondence concerning AIPS++ should be addressed as follows:
22 //# Internet email: aips2-request@nrao.edu.
23 //# Postal address: AIPS++ Project Office
24 //# National Radio Astronomy Observatory
25 //# 520 Edgemont Road
26 //# Charlottesville, VA 22903-2475 USA
27 //#
28 #ifndef SYNTHESIS_NORMALIZER_MIXIN_H_
29 #define SYNTHESIS_NORMALIZER_MIXIN_H_
30 
33 #include <casa/OS/File.h>
34 #include <casa/OS/Directory.h>
35 #include <casa/OS/RegularFile.h>
36 #include <memory>
37 #include <algorithm>
38 #include <vector>
39 
40 namespace casa {
41 
46 template<class T>
48  : public T {
49 
50 private:
51  std::vector< std::shared_ptr<SynthesisNormalizer> > normalizers;
52 
53 protected:
54  void
55  setup_normalizer(MPI_Comm comm, std::vector<casacore::Record> &norm_pars) {
56  // Create all normalizer components on rank 0 of comm. TODO: Could we
57  // distribute normalizers in a round-robin fashion across processes in
58  // comm?
59 
61  if (T::effective_rank(comm) == 0)
62  for (auto pars : norm_pars) {
64  sn->setupNormalizer(pars);
65  normalizers.push_back(std::shared_ptr<SynthesisNormalizer>(sn));
66  // FIXME: check whether we're to remove any files or directories
67  // in addition to those provided in "partimagenames", i.e, those
68  // with file name extensions
69  //
70  // To ensure restarts work correctly, remove existing files.
71  if (pars.isDefined("partimagenames")) {
72  const std::vector<casacore::String> &part_names =
73  pars.asArrayString("partimagenames").tovector();
74  for (size_t p = 0; p < part_names.size(); ++p) {
75  casacore::File f(part_names[p]);
76  if (f.isDirectory(false))
78  else
80  }
81  }
82  }
83  };
84 
85  void
87  normalizers.clear();
88  };
89 
90 public:
91  void
93  for (auto sn : normalizers) {
94  sn->gatherImages(/*dopsf*/true, /*doresidual*/false,
95  /*density*/false);
96  sn->dividePSFByWeight();
97  }
98  };
99 
100  void
102  for (auto sn : normalizers) {
103  sn->divideModelByWeight();
104  sn->scatterModel();
105  }
106  };
107 
108  void
110  for (auto sn : normalizers) {
111  sn->gatherImages(/*dopsf*/false, /*doresidual*/true,
112  /*density*/false);
113  sn->divideResidualByWeight();
114  }
115  };
116 
117  void
119  for (auto sn : normalizers)
120  sn->multiplyModelByWeight();
121  };
122 
123  void
125  for (auto sn : normalizers) {
126  sn->gatherImages(/*dopsf*/false, /*doresidual*/false,
127  /*density*/true);
128  sn->scatterWeightDensity();
129  }
130  };
131 };
132 
133 } // namespace casa
134 
135 #endif // SYNTHESIS_NORMALIZER_MIXIN_H_
void setup_normalizer(MPI_Comm comm, std::vector< casacore::Record > &norm_pars)
int MPI_Comm
Definition: MPIGlue.h:59
void remove()
Remove the file.
void setupNormalizer(casacore::Record normpars)
Copy constructor and assignment operator.
Get information about, and manipulate directories.
Definition: Directory.h:87
Manipulate and get information about regular files.
Definition: RegularFile.h:91
Class to get file information and a base for other file classes.
Definition: File.h:101
Forward declarations.
void removeRecursive(Bool keepDir=False)
Remove the directory and its contents (recursively in all subdirectories).
Simple mixin class to put SynthesisNormalizer into ParallelImagerMixin framework. ...
std::vector< std::shared_ptr< SynthesisNormalizer > > normalizers
Bool isDirectory(Bool followSymLink=True) const
Check if the file is a directory.