Changeset 1176


Ignore:
Timestamp:
01/14/02 17:56:43 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc

    r1080 r1176  
    4848ClassImp(MWriteAsciiFile);
    4949
     50void MWriteAsciiFile::Init(const char *filename, const char *name, const char *title)
     51{
     52    fName  = name  ? name  : "MWriteAsciiFile";
     53    fTitle = title ? title : "Task to write one container to an ascii file";
     54
     55    fNameFile = filename;
     56
     57    fOut = new ofstream(fNameFile);
     58}
     59
    5060// --------------------------------------------------------------------------
    5161//
     
    6171MWriteAsciiFile::MWriteAsciiFile(const char *filename, const char *contname,
    6272                                 const char *name, const char *title)
    63     : fOut(NULL), fContainer(NULL)
    6473{
    65     fName  = name  ? name  : "MWriteAsciiFile";
    66     fTitle = title ? title : "Task to write one container to an ascii file";
     74    Init(filename, name, title);
    6775
    68     fNameFile      = filename;
    69     fNameContainer = contname;
    70 
    71     fOut = new ofstream(fNameFile);
     76    AddContainer(contname);
    7277}
    7378
     
    8590MWriteAsciiFile::MWriteAsciiFile(const char *filename, MParContainer *cont,
    8691                                 const char *name, const char *title)
    87     : fOut(NULL), fContainer(cont)
    8892{
    89     fName  = name  ? name  : "MWriteAsciiFile";
    90     fTitle = title ? title : "Task to write one container to an ascii file";
     93    Init(filename, name, title);
    9194
    92     fNameFile      = filename;
    93     fNameContainer = cont->GetName();
    94 
    95     fOut = new ofstream(fNameFile);
     95    AddContainer(cont);
    9696}
    9797
     
    103103MWriteAsciiFile::~MWriteAsciiFile()
    104104{
     105    fContNames.SetOwner();
     106
    105107    delete fOut;
    106108}
     
    112114void MWriteAsciiFile::CheckAndWrite() const
    113115{
    114     if (fContainer->IsReadyToSave())
    115         fContainer->AsciiWrite(*fOut);
     116    Bool_t written = kFALSE;
     117
     118    MParContainer *cont = NULL;
     119
     120    TIter Next(&fContainer);
     121
     122    while ((cont=(MParContainer*)Next()))
     123    {
     124        if (!cont->IsReadyToSave())
     125            continue;
     126
     127        cont->AsciiWrite(*fOut);
     128        *fOut << " ";
     129        written = kTRUE;
     130    }
     131
     132    if (written)
     133        *fOut << endl;
    116134}
    117135
     
    132150Bool_t MWriteAsciiFile::GetContainer(MParList *pList)
    133151{
    134     //
    135     // Try to find the container which should be stored.
    136     //
    137     if (fContainer)
    138         return kTRUE;
     152    TObject *obj = NULL;
    139153
    140     fContainer = (MParContainer*)pList->FindObject(fNameContainer);
    141     if (fContainer)
    142         return kTRUE;
     154    TIter Next(&fContNames);
    143155
    144     *fLog << err << dbginf << "Cannot find parameter container '" << fContainer << "'." << endl;
    145     return kFALSE;
     156    while ((obj=Next()))
     157    {
     158        const char *name = obj->GetName();
     159
     160        MParContainer *cont = (MParContainer*)pList->FindObject(name);
     161        if (!cont)
     162        {
     163            *fLog << err << dbginf << "Cannot find parameter container '" << name << "'." << endl;
     164            return kFALSE;
     165        }
     166
     167        if (!cont->InheritsFrom(MParContainer::Class()))
     168        {
     169            *fLog << err << dbginf << "'" << name << "' doesn't inherit from MParContainer." << endl;
     170            return kFALSE;
     171
     172        }
     173
     174        AddContainer(cont);
     175    }
     176
     177    return kTRUE;
    146178}
     179
     180// --------------------------------------------------------------------------
     181//
     182//
     183void MWriteAsciiFile::AddContainer(const char *cname)
     184{
     185    TNamed *named = new TNamed(cname, "");
     186    fContNames.AddLast(named);
     187}
     188
     189// --------------------------------------------------------------------------
     190//
     191//
     192void MWriteAsciiFile::AddContainer(MParContainer *cont)
     193{
     194    fContainer.AddLast(cont);
     195}
     196
  • trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h

    r1014 r1176  
    44#ifndef MARS_MWriteFile
    55#include "MWriteFile.h"
     6#endif
     7#ifndef ROOT_TObjArray
     8#include <TObjArray.h>
    69#endif
    710
     
    1114    ofstream *fOut;
    1215
     16    TObjArray fContNames;
     17    TObjArray fContainer;
     18
    1319    TString fNameFile;
    14     TString fNameContainer;
    15 
    16     MParContainer *fContainer;
    1720
    1821    virtual void   CheckAndWrite() const;
     
    2124    virtual const char *GetFileName() const { return fNameFile; }
    2225
     26    void Init(const char *filename, const char *name, const char *title);
    2327
    2428public:
    2529    MWriteAsciiFile(const char *filename, const char *contname,
    2630                    const char *name=NULL, const char *title=NULL);
    27     MWriteAsciiFile(const char *filename, MParContainer *cont,
     31    MWriteAsciiFile(const char *filename, MParContainer *cont=NULL,
    2832                    const char *name=NULL, const char *title=NULL);
    2933    ~MWriteAsciiFile();
     34
     35    void AddContainer(const char *cname);
     36    void AddContainer(MParContainer *cont);
    3037
    3138    ClassDef(MWriteAsciiFile, 0) // Class to write one container to an ascii file
Note: See TracChangeset for help on using the changeset viewer.