Simpatico  v1.10
tools/analyzers/Analyzer.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "Analyzer.h"
9 #include <tools/processor/Processor.h>
10 #include <util/misc/FileMaster.h>
11 #include <util/global.h>
12 
13 namespace Tools
14 {
15 
16  using namespace Util;
17 
18  /*
19  * Constructor.
20  */
22  : ParamComposite(),
23  outputFileName_(),
24  configurationPtr_(&configuration),
25  fileMasterPtr_(0),
26  interval_(1),
27  ownsFileMaster_(false)
28  {}
29 
30  /*
31  * Constructor.
32  */
34  : ParamComposite(),
35  outputFileName_(),
36  configurationPtr_(&processor),
37  fileMasterPtr_(&processor.fileMaster()),
38  interval_(1),
39  ownsFileMaster_(false)
40  {}
41 
42  /*
43  * Constructor.
44  */
46  : ParamComposite(),
47  outputFileName_(),
48  configurationPtr_(&configuration),
49  fileMasterPtr_(&fileMaster),
50  interval_(1),
51  ownsFileMaster_(false)
52  {}
53 
54  /*
55  * Destructor.
56  */
58  {
59  if (fileMasterPtr_) {
60  if (ownsFileMaster_) {
61  delete fileMasterPtr_;
62  }
63  }
64  }
65 
66  /*
67  * Read the interval from parameter file, with error checking.
68  */
69  void Analyzer::readInterval(std::istream &in)
70  {
71 
72  // Read interval value (inherited from Interval)
73  read<long>(in, "interval", interval_);
74 
75  // Check that interval has a nonzero, positive value
76  if (interval_ == 0) {
77  UTIL_THROW("interval_ == 0");
78  }
79  if (interval_ < 0) {
80  UTIL_THROW("interval_ < 0");
81  }
82 
83  }
84 
85  /*
86  * Read output file name and open output file.
87  */
88  void Analyzer::readOutputFileName(std::istream &in)
89  { read<std::string>(in, "outputFileName", outputFileName_); }
90 
91  /*
92  * Get the outputFileName string with an added suffix
93  */
94  std::string Analyzer::outputFileName(const std::string& suffix) const
95  {
96  std::string filename = outputFileName_;
97  filename += suffix;
98  return filename;
99  }
100 
101  /*
102  * Get an associated FileMaster by reference.
103  */
105  {
106  if (fileMasterPtr_ == 0) {
107  fileMasterPtr_ = new FileMaster();
108  ownsFileMaster_ = true;
109  }
110  return *fileMasterPtr_;
111  }
112 
113 }
void readOutputFileName(std::istream &in)
Read outputFileName from file.
A post-processor for analyzing outputs of MD simulations.
Definition: Processor.h:30
virtual ~Analyzer()
Destructor.
File containing preprocessor macros for error handling.
An instantaneous molecular dynamics configuration.
Definition: Configuration.h:40
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Utility classes for scientific computation.
Definition: accumulators.mod:1
Configuration & configuration()
Get the parent Configuration by reference.
Single-processor classes for pre- and post-processing MD trajectories.
void readInterval(std::istream &in)
Read parameter interval from file.
A FileMaster manages input and output files for a simulation.
Definition: FileMaster.h:142
FileMaster & fileMaster()
Get an associated FileMaster by reference.
An object that can read multiple parameters from file.
Analyzer(Configuration &configuration)
Constructor.
const std::string & outputFileName() const
Return outputFileName string.