Ignore:
Timestamp:
06/05/02 10:20:05 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MParContainer.h

    r1283 r1348  
    6464    virtual void   SetLogStream(MLog *lg) { fLog = lg; }
    6565    virtual void   Reset() { }
    66     virtual Bool_t IsReadyToSave()                   { return fReadyToSave; }
     66    virtual Bool_t IsReadyToSave() const             { return fReadyToSave; }
    6767    virtual void   SetReadyToSave(Bool_t flag=kTRUE) { fReadyToSave=flag; }
    6868
  • trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc

    r1337 r1348  
    5252#include <TClass.h>      // IsA
    5353#include <TMethodCall.h> // TMethodCall, AsciiWrite
    54 #include <TDataMember.h> // TDataMember, AsciiWrite
     54
     55#include "MDataList.h"   // MDataList
     56#include "MDataChain.h"  // MDataChain
     57#include "MDataValue.h"  // MDataValue
     58#include "MDataMember.h" // MDataMember
    5559
    5660#include "MLog.h"
     
    9296
    9397    if (contname)
    94         AddContainer(contname);
     98       AddContainer(contname);
    9599}
    96100
     
    122126MWriteAsciiFile::~MWriteAsciiFile()
    123127{
    124     fContNames.SetOwner();
    125     fMembers.SetOwner();
    126 
     128    fAutoDel.SetOwner();
    127129    delete fOut;
    128130}
     
    130132// --------------------------------------------------------------------------
    131133//
    132 // Check if the containers are ready for writing. If so write them.
    133 // The containers are written in one line, one after each other.
    134 // If not all containers are written (because of the IsReadyToSave-flag)
    135 // a warning message is print.
    136 //
    137 void MWriteAsciiFile::CheckAndWrite() const
    138 {
    139     Bool_t written = kFALSE;
    140 
    141     MParContainer *cont = NULL;
    142 
    143     Int_t num = fContainer.GetEntries();
    144 
    145     TIter NextCont(&fContainer);
    146     TIter NextMemb(&fMembers);
    147 
    148     while ((cont=(MParContainer*)NextCont()))
    149     {
    150         const MScale *memb = (MScale*)NextMemb();
    151 
    152         if (!cont->IsReadyToSave())
    153             continue;
    154 
    155         if (memb->GetTitle()[0]=='\0')
    156         {
    157             if (!cont->AsciiWrite(*fOut))
    158                 continue;
    159         }
    160         else
    161         {
    162             if (!cont->WriteDataMember(*fOut, memb->GetTitle(), memb->GetScale()))
    163                 continue;
    164         }
    165 
    166         written = kTRUE;
    167 
    168         num--;
    169     }
    170 
    171     if (!written)
     134// Return open state of the file
     135//
     136Bool_t MWriteAsciiFile::IsFileOpen() const
     137{
     138    return (bool)(*fOut);
     139}
     140
     141// --------------------------------------------------------------------------
     142//
     143// Add a rule to be written as a column to the ascii file.
     144// For more information about rules see MDataChain.
     145//
     146void MWriteAsciiFile::AddRule(const char *rule)
     147{
     148    MDataChain *chain = new MDataChain(rule);
     149    fList.Add(chain);
     150}
     151
     152// --------------------------------------------------------------------------
     153//
     154// Add another container (by pointer) to be written to the ascii file.
     155// The container will be output one after each other in one line.
     156// If you want to write only one data member of the container
     157// specify the name of the data member (eg. fAlpha) Make sure,
     158// that a "GetteMethod" for this data type exists (strip the f and
     159// replace it by Get)
     160// If you specify a single data member you can add a scale-factor which
     161// is (in case of the data member being a floating point value) multiplied
     162// with the data member value. This is usefull if you are want to
     163// change the scale (unit) of a data member for writing (eg.
     164// writing degrees for the hillas parameters instead of the internally
     165// used millimeters)
     166//
     167void MWriteAsciiFile::AddContainer(MParContainer *cont, const TString member, Double_t scale)
     168{
     169    if (member.IsNull())
     170    {
     171        fList.Add(cont);
    172172        return;
    173 
    174     *fOut << endl;
    175 
    176     if (num!=0)
    177         *fLog << warn << "Warning - given number of containers doesn't fit number of written containers." << endl;
    178 }
    179 
    180 // --------------------------------------------------------------------------
    181 //
    182 // Return open state of the file
    183 //
    184 Bool_t MWriteAsciiFile::IsFileOpen() const
    185 {
    186     return (bool)(*fOut);
    187 }
    188 
    189 // --------------------------------------------------------------------------
    190 //
    191 // Tries to get all containers from the ParList which were given by name
    192 // adds them to the list of pointers to the container which should be
    193 // written to the ascii file.
    194 //
    195 Bool_t MWriteAsciiFile::GetContainer(MParList *pList)
    196 {
    197     MScale *obj = NULL;
    198 
    199     TIter Next(&fContNames);
    200 
    201     while ((obj=(MScale*)Next()))
    202     {
    203         const char *name = obj->GetName();
    204 
    205         MParContainer *cont = (MParContainer*)pList->FindObject(name, "MParContainer");
    206         if (!cont)
    207         {
    208             *fLog << err << dbginf << "Cannot find parameter container '" << name << "'." << endl;
    209             return kFALSE;
    210         }
    211 
    212         AddContainer(cont, obj->GetTitle(), obj->GetScale());
    213     }
    214 
    215     return kTRUE;
     173    }
     174
     175    MData *data = new MDataMember(cont, member);
     176
     177    if (scale!=1)
     178    {
     179        MDataList  *list = new MDataList('*');
     180        MDataValue *val  = new MDataValue(scale);
     181
     182        list->SetOwner();
     183        list->AddToList(data);
     184        list->AddToList(val);
     185
     186        data = list;
     187    }
     188    fList.Add(data);
     189    fAutoDel.Add(data);
    216190}
    217191
     
    231205// used millimeters)
    232206//
    233 void MWriteAsciiFile::AddContainer(const char *cname, const char *member, Double_t scale)
    234 {
    235     MScale *name = new MScale(cname, member, scale);
    236     fContNames.AddLast(name);
    237 
    238     if (member && member[0])
    239         AddToBranchList(Form("%s.%s", cname, member));
    240 }
    241 
    242 // --------------------------------------------------------------------------
    243 //
    244 // Add another container (by pointer) to be written to the ascii file.
    245 // The container will be output one after each other in one line.
    246 // If you want to write only one data member of the container
    247 // specify the name of the data member (eg. fAlpha) Make sure,
    248 // that a "GetteMethod" for this data type exists (strip the f and
    249 // replace it by Get)
    250 // If you specify a single data member you can add a scale-factor which
    251 // is (in case of the data member being a floating point value) multiplied
    252 // with the data member value. This is usefull if you are want to
    253 // change the scale (unit) of a data member for writing (eg.
    254 // writing degrees for the hillas parameters instead of the internally
    255 // used millimeters)
    256 //
    257 void MWriteAsciiFile::AddContainer(MParContainer *cont, const char *member, Double_t scale)
    258 {
    259     fContainer.AddLast(cont);
    260 
    261     MScale *name = new MScale("", member, scale);
    262     fMembers.AddLast(name);
    263 }
    264 
    265 /*
    266 Bool_t MWriteAsciiFile::PreProcess(MParList *plist)
    267 {
    268     MDataChain *chain=NULL;
     207void MWriteAsciiFile::AddContainer(const TString cont, const TString member, Double_t scale)
     208{
     209    if (member.IsNull())
     210    {
     211        TNamed *name = new TNamed(cont, cont);
     212        fList.Add(name);
     213        fAutoDel.Add(name);
     214        return;
     215    }
     216
     217    MData *data = new MDataMember(Form("%s.%s", (const char*)cont, (const char*)member));
     218    if (scale!=1)
     219    {
     220        MDataList  *list = new MDataList('*');
     221        MDataValue *val  = new MDataValue(scale);
     222
     223        list->SetOwner();
     224        list->AddToList(data);
     225        list->AddToList(val);
     226
     227        data = list;
     228    }
     229    fList.Add(data);
     230    fAutoDel.Add(data);
     231}
     232
     233// --------------------------------------------------------------------------
     234//
     235// Tries to get all containers from the ParList which were given by name
     236// adds them to the list of pointers to the container which should be
     237// written to the ascii file.
     238//
     239Bool_t MWriteAsciiFile::GetContainer(MParList *plist)
     240{
     241    TObject *obj=NULL;
    269242
    270243    TIter Next(&fList);
    271     while (((MDataChain*)chain=Next()))
    272         if (!chain->PreProcess(plist))
     244    while ((obj=Next()))
     245    {
     246        //
     247        // MData is the highest class in the inheritance tree
     248        //
     249        if (obj->IsA()->InheritsFrom(MData::Class()))
     250        {
     251            if (!((MData*)obj)->PreProcess(plist))
     252                return kFALSE;
     253            continue;
     254        }
     255
     256        //
     257        // MParContainer is the next class in the inheritance tree
     258        //
     259        if (obj->IsA()->InheritsFrom(MParContainer::Class()))
     260            continue;
     261
     262        //
     263        // It is neither a MData nor a MParContainer, it must be a TNamed
     264        //
     265        TObject *o = plist->FindObject(obj->GetName());
     266        if (!o)
    273267            return kFALSE;
    274268
    275     return MWriteFile::PreProcess(plist);
    276 }
    277 
    278 void MWriteAsciiFile::Add(const char *rule)
    279 {
    280     MDataChain *chain = new MDataChain(rule);
    281     fList.Add(chain);
    282 }
    283 */
     269        fList[fList.IndexOf(obj)] = o;
     270    }
     271    return kTRUE;
     272}
     273
     274// --------------------------------------------------------------------------
     275//
     276// Check if the containers are ready for writing. If so write them.
     277// The containers are written in one line, one after each other.
     278// If not all containers are written (because of the IsReadyToSave-flag)
     279// a warning message is print.
     280//
     281void MWriteAsciiFile::CheckAndWrite() const
     282{
     283    Bool_t written = kFALSE;
     284
     285    MParContainer *obj = NULL;
     286
     287    Int_t num = fList.GetEntries();
     288
     289    *fLog << all << "CHECK&WRITE " << num << endl;
     290
     291    TIter Next(&fList);
     292    while ((obj=(MParContainer*)Next()))
     293    {
     294        *fLog << all << endl << obj->IsA()->GetName() << ": 0..." << flush;
     295
     296        if (!obj->IsReadyToSave())
     297            continue;
     298
     299        *fLog << all << "1..." << flush;
     300
     301        if (!obj->AsciiWrite(*fOut))
     302            continue;
     303
     304        *fLog << all << "2..." << flush;
     305
     306        written = kTRUE;
     307
     308        num--;
     309    }
     310
     311    if (!written)
     312        return;
     313
     314    *fOut << endl;
     315
     316    if (num!=0)
     317        *fLog << warn << "Warning - given number of objects doesn't fit number of written objects." << endl;
     318}
     319
  • trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h

    r1337 r1348  
    99#endif
    1010
     11class MData;
     12
    1113class MWriteAsciiFile : public MWriteFile
    1214{
    1315private:
    14     class MScale : public TNamed
    15     {
    16     private:
    17         Double_t fScale;
    18     public:
    19         MScale(const char *name, const char *title, Double_t scale)
    20             : TNamed(name, title), fScale(scale) {}
    21         Double_t GetScale() const { return fScale; }
    22     };
     16    ofstream *fOut;     //! ascii file
    2317
    24     ofstream *fOut;
     18    TString fNameFile;  // name of the ascii file
    2519
    26     TObjArray fContNames;
    27     TObjArray fContainer;
    28     TObjArray fMembers;
     20    TObjArray fList;    // list of rules and containers to be written
     21    TObjArray fAutoDel; //! List of object to be deleted in the destructor
    2922
    30     TString fNameFile;
    31 /*
    32     TList fList;
    33 */
    3423    virtual void   CheckAndWrite() const;
    3524    virtual Bool_t IsFileOpen() const;
     
    4635    ~MWriteAsciiFile();
    4736
    48     void AddContainer(const char *cname, const char *member="", Double_t scale=1);
    49     void AddContainer(MParContainer *cont, const char *member="", Double_t scale=1);
     37    void AddContainer(const TString cname, const TString member="", Double_t scale=1);
     38    void AddContainer(MParContainer *cont, const TString member="", Double_t scale=1);
    5039
    51     /*
    52      Bool_t PreProcess(MParList *plist);
    53      void Add(const char *rule);
    54      */
     40    void AddRule(const char *rule);
    5541
    5642    ClassDef(MWriteAsciiFile, 0) // Class to write one container to an ascii file
  • trunk/MagicSoft/Mars/mbase/Makefile

    r1346 r1348  
    2020# @endcode
    2121
    22 INCLUDES = -I. -I../mraw -I../MRawFormat -I../mmc
     22INCLUDES = -I. -I../mraw -I../MRawFormat -I../mmc -I../mdata
    2323
    2424# @code
Note: See TracChangeset for help on using the changeset viewer.