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 (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 HasChanged 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 |
|
---|
48 | ClassImp(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 | //
|
---|
57 | MWriteAsciiFile::MWriteAsciiFile(const char *filename, const char *contname,
|
---|
58 | const char *name, const char *title)
|
---|
59 | : fOut(NULL), fContainer(NULL)
|
---|
60 | {
|
---|
61 | *fName = name ? name : "MWriteAsciiFile";
|
---|
62 | *fTitle = title ? title : "Task to write one container to an ascii file";
|
---|
63 |
|
---|
64 | fNameFile = filename;
|
---|
65 | fNameContainer = contname;
|
---|
66 |
|
---|
67 | fOut = new ofstream(fNameFile);
|
---|
68 | }
|
---|
69 |
|
---|
70 | // --------------------------------------------------------------------------
|
---|
71 | //
|
---|
72 | // Specify a the name of the ascii output file 'filename' and a pointer to
|
---|
73 | // the container you want to write.
|
---|
74 | //
|
---|
75 | MWriteAsciiFile::MWriteAsciiFile(const char *filename, MParContainer *cont,
|
---|
76 | const char *name, const char *title)
|
---|
77 | : fOut(NULL), fContainer(cont)
|
---|
78 | {
|
---|
79 | *fName = name ? name : "MWriteAsciiFile";
|
---|
80 | *fTitle = title ? title : "Task to write one container to an ascii file";
|
---|
81 |
|
---|
82 | fNameFile = filename;
|
---|
83 | fNameContainer = cont->GetName();
|
---|
84 |
|
---|
85 | fOut = new ofstream(fNameFile);
|
---|
86 | }
|
---|
87 |
|
---|
88 | // --------------------------------------------------------------------------
|
---|
89 | //
|
---|
90 | // Destructor. Delete the output file if necessary (it is closed
|
---|
91 | // automatically by its destructor.
|
---|
92 | //
|
---|
93 | MWriteAsciiFile::~MWriteAsciiFile()
|
---|
94 | {
|
---|
95 | delete fOut;
|
---|
96 | }
|
---|
97 |
|
---|
98 | // --------------------------------------------------------------------------
|
---|
99 | //
|
---|
100 | // Check if our container is ready for writing. If so write it.
|
---|
101 | //
|
---|
102 | void MWriteAsciiFile::CheckAndWrite() const
|
---|
103 | {
|
---|
104 | if (fContainer->HasChanged())
|
---|
105 | fContainer->AsciiWrite(*fOut);
|
---|
106 | }
|
---|
107 |
|
---|
108 | // --------------------------------------------------------------------------
|
---|
109 | //
|
---|
110 | // Return open state of the file
|
---|
111 | //
|
---|
112 | Bool_t MWriteAsciiFile::IsFileOpen() const
|
---|
113 | {
|
---|
114 | return (bool)(*fOut);
|
---|
115 | }
|
---|
116 |
|
---|
117 | // --------------------------------------------------------------------------
|
---|
118 | //
|
---|
119 | // If the container is yet unknown and the name of it is known only, try
|
---|
120 | // to get the container from the parameter list.
|
---|
121 | //
|
---|
122 | Bool_t MWriteAsciiFile::GetContainer(MParList *pList)
|
---|
123 | {
|
---|
124 | //
|
---|
125 | // Try to find the container which should be stored.
|
---|
126 | //
|
---|
127 | if (fContainer)
|
---|
128 | return kTRUE;
|
---|
129 |
|
---|
130 | fContainer = (MParContainer*)pList->FindObject(fNameContainer);
|
---|
131 | if (fContainer)
|
---|
132 | return kTRUE;
|
---|
133 |
|
---|
134 | *fLog << dbginf << "Cannot find parameter container '" << fContainer << "'." << endl;
|
---|
135 | return kFALSE;
|
---|
136 | }
|
---|