| 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, 6/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MWriteFile
|
|---|
| 28 | //
|
|---|
| 29 | // This is a base class for writing tasks. If you want to implement
|
|---|
| 30 | // writing out parameter containers in a new file format, this is a good
|
|---|
| 31 | // starting point.
|
|---|
| 32 | // The class defines a generalized interface between writing out data in
|
|---|
| 33 | // an eventloop and your file format.
|
|---|
| 34 | //
|
|---|
| 35 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 36 | #include "MWriteFile.h"
|
|---|
| 37 |
|
|---|
| 38 | #include <fstream>
|
|---|
| 39 |
|
|---|
| 40 | #include "MLog.h"
|
|---|
| 41 | #include "MLogManip.h"
|
|---|
| 42 |
|
|---|
| 43 | #include "MParList.h"
|
|---|
| 44 |
|
|---|
| 45 | ClassImp(MWriteFile);
|
|---|
| 46 |
|
|---|
| 47 | using namespace std;
|
|---|
| 48 |
|
|---|
| 49 | // --------------------------------------------------------------------------
|
|---|
| 50 | //
|
|---|
| 51 | // Tries to open the given output file.
|
|---|
| 52 | // The derived class should retrieve needed containers from the parameter
|
|---|
| 53 | // list.
|
|---|
| 54 | // instance of the container which should be written.
|
|---|
| 55 | // If the container has already the HasChanged flag it is immediatly written
|
|---|
| 56 | // to the output file.
|
|---|
| 57 | //
|
|---|
| 58 | Int_t MWriteFile::PreProcess(MParList *pList)
|
|---|
| 59 | {
|
|---|
| 60 | //
|
|---|
| 61 | // test whether file is now open or not
|
|---|
| 62 | //
|
|---|
| 63 | if (!IsFileOpen())
|
|---|
| 64 | {
|
|---|
| 65 | *fLog << err << dbginf << "Cannot open file '" << GetFileName() << "'" << endl;
|
|---|
| 66 | return kFALSE;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | *fLog << inf << "File '" << GetFileName() << "' open for writing." << endl;
|
|---|
| 70 |
|
|---|
| 71 | //
|
|---|
| 72 | // Get the containers (pointers) from the parameter list you want to write
|
|---|
| 73 | //
|
|---|
| 74 | if (!GetContainer(pList))
|
|---|
| 75 | return kFALSE;
|
|---|
| 76 |
|
|---|
| 77 | //
|
|---|
| 78 | // write the container if it is already in changed state
|
|---|
| 79 | //
|
|---|
| 80 | return CheckAndWrite();
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | // --------------------------------------------------------------------------
|
|---|
| 84 | //
|
|---|
| 85 | // Checks if the SetReadyToSave flag of the output container is set. If it
|
|---|
| 86 | // is set the container should be written to the output.
|
|---|
| 87 | //
|
|---|
| 88 | Bool_t MWriteFile::ReInit(MParList *pList)
|
|---|
| 89 | {
|
|---|
| 90 | return CheckAndWrite();
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | // --------------------------------------------------------------------------
|
|---|
| 94 | //
|
|---|
| 95 | // Checks if the SetReadyToSave flag of the output container is set. If it is
|
|---|
| 96 | // set the container should be written to the output.
|
|---|
| 97 | //
|
|---|
| 98 | Int_t MWriteFile::Process()
|
|---|
| 99 | {
|
|---|
| 100 | return CheckAndWrite();
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | // --------------------------------------------------------------------------
|
|---|
| 104 | //
|
|---|
| 105 | // Checks if the SetReadyToSave flag of the output container is set. If it is
|
|---|
| 106 | // set the container should be written to the output.
|
|---|
| 107 | //
|
|---|
| 108 | Int_t MWriteFile::PostProcess()
|
|---|
| 109 | {
|
|---|
| 110 | //
|
|---|
| 111 | // check if the container changed state is set
|
|---|
| 112 | //
|
|---|
| 113 | return CheckAndWrite();
|
|---|
| 114 | }
|
|---|