source: trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc@ 1080

Last change on this file since 1080 was 1080, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 5.0 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 06/2001 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MWriteAsciiFile //
28// //
29// If you want to store a single container into an Ascii file you have //
30// to use this class. You must know the name of the file you wanne write //
31// (you should know it) and the name of the container you want to write. //
32// This can be the name of the class or a given name, which identifies //
33// the container in a parameter container list (MParList). //
34// The container is writte to the ascii file if its ReadyToSave flag is //
35// set (MParContainer) //
36// //
37/////////////////////////////////////////////////////////////////////////////
38
39#include "MWriteAsciiFile.h"
40
41#include <fstream.h>
42
43#include "MLog.h"
44#include "MLogManip.h"
45
46#include "MParList.h"
47
48ClassImp(MWriteAsciiFile);
49
50// --------------------------------------------------------------------------
51//
52// Specify the name of the ascii output file 'filename' and the name
53// of the container you want to write. (Normally this is the name
54// of the class (eg. MHillas) but it can also be a different name which
55// identifies the container in the parameter list.
56// Because you cannot write more than one container there is no Add-function
57// like in MWriteRootFile.
58//
59// For Example: MWriteAsciiFile("file.txt", "MHillas");
60//
61MWriteAsciiFile::MWriteAsciiFile(const char *filename, const char *contname,
62 const char *name, const char *title)
63 : fOut(NULL), fContainer(NULL)
64{
65 fName = name ? name : "MWriteAsciiFile";
66 fTitle = title ? title : "Task to write one container to an ascii file";
67
68 fNameFile = filename;
69 fNameContainer = contname;
70
71 fOut = new ofstream(fNameFile);
72}
73
74// --------------------------------------------------------------------------
75//
76// Specify a the name of the ascii output file 'filename' and a pointer to
77// the container you want to write.
78// Because you cannot write more than one container there is no Add-function
79// like in MWriteRootFile.
80//
81// For Example: MHillas hillas;
82// MWriteAsciiFile("file.txt", &hillas);
83//
84//
85MWriteAsciiFile::MWriteAsciiFile(const char *filename, MParContainer *cont,
86 const char *name, const char *title)
87 : fOut(NULL), fContainer(cont)
88{
89 fName = name ? name : "MWriteAsciiFile";
90 fTitle = title ? title : "Task to write one container to an ascii file";
91
92 fNameFile = filename;
93 fNameContainer = cont->GetName();
94
95 fOut = new ofstream(fNameFile);
96}
97
98// --------------------------------------------------------------------------
99//
100// Destructor. Delete the output file if necessary (it is closed
101// automatically by its destructor.
102//
103MWriteAsciiFile::~MWriteAsciiFile()
104{
105 delete fOut;
106}
107
108// --------------------------------------------------------------------------
109//
110// Check if our container is ready for writing. If so write it.
111//
112void MWriteAsciiFile::CheckAndWrite() const
113{
114 if (fContainer->IsReadyToSave())
115 fContainer->AsciiWrite(*fOut);
116}
117
118// --------------------------------------------------------------------------
119//
120// Return open state of the file
121//
122Bool_t MWriteAsciiFile::IsFileOpen() const
123{
124 return (bool)(*fOut);
125}
126
127// --------------------------------------------------------------------------
128//
129// If the container is yet unknown and the name of it is known only, try
130// to get the container from the parameter list.
131//
132Bool_t MWriteAsciiFile::GetContainer(MParList *pList)
133{
134 //
135 // Try to find the container which should be stored.
136 //
137 if (fContainer)
138 return kTRUE;
139
140 fContainer = (MParContainer*)pList->FindObject(fNameContainer);
141 if (fContainer)
142 return kTRUE;
143
144 *fLog << err << dbginf << "Cannot find parameter container '" << fContainer << "'." << endl;
145 return kFALSE;
146}
Note: See TracBrowser for help on using the repository browser.