Changeset 1348


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

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r1347 r1348  
    11                                                                  -*-*- END -*-*-
    2  2002/06/03: Thomas Bretz
     2 2002/06/05: Thomas Bretz
     3
     4   * mbase/MWriteAsciiFile.[h,cc]:
     5     - changed the code completely to support rules (data chains), too.
     6       the interface stayed the same.
     7
     8   * mdata/MDataChain.cc, mhist/MHMatrix.cc:
     9     - added math.h for alpha compilers
     10
     11   * mbase/MParContainer.h:
     12     - changes IsReadyToSave to const
     13
     14   * mdata/MData.[h,cc]:
     15     - added AsciiWrite
     16
     17   * mdata/MDataChain.[h,cc], mdata/MDataList.[h,cc], mdata/MDataValue.h:
     18     - added IsReadyToSave
     19
     20   * mdata/MDataMember.[h,cc]:
     21     - added a new constructor
     22     - added IsReadyToSave
     23
     24
     25
     26 2002/06/04: Thomas Bretz
    327
    428   * mhist/MHCompProb.[h,cc]:
     
    1034   * mhist/Makefile:
    1135     - added -I../mmc
     36
     37   * mbase/Makefile:
     38     - added -I../mdata
    1239
    1340   * mhist/MHHadroness.cc:
  • 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
  • trunk/MagicSoft/Mars/mdata/MData.cc

    r1304 r1348  
    4848#include "MData.h"
    4949
     50#include <ostream.h>
     51
    5052ClassImp(MData);
     53
     54Bool_t MData::AsciiWrite(ostream &out) const
     55{
     56    out << GetValue() << " ";
     57    return kTRUE;
     58}
     59
  • trunk/MagicSoft/Mars/mdata/MData.h

    r1338 r1348  
    2323    Double_t operator()() { return GetValue(); }
    2424
     25    Bool_t AsciiWrite(ostream &out) const;
     26
    2527    ClassDef(MData, 0) // A Base class for a generalized value
    2628};
  • trunk/MagicSoft/Mars/mdata/MDataChain.cc

    r1339 r1348  
    8181#include "MDataChain.h"
    8282
     83#include <math.h>         // fabs on Alpha
    8384#include <ctype.h>        // isalnum, ...
    8485#include <stdlib.h>       // strtod, ...
     
    131132{
    132133    return fMember ? fMember->PreProcess(pList) : kFALSE;
     134}
     135
     136// --------------------------------------------------------------------------
     137//
     138// Checks whether at least one member has the ready-to-save flag.
     139//
     140Bool_t MDataChain::IsReadyToSave() const
     141{
     142    *fLog << all << "fM=" << fMember << "/" << (int)fMember->IsReadyToSave() << " " << endl;
     143    return fMember ? fMember->IsReadyToSave() : kFALSE;
    133144}
    134145
  • trunk/MagicSoft/Mars/mdata/MDataChain.h

    r1338 r1348  
    5858
    5959    Bool_t IsValid() const { return fMember ? kTRUE : kFALSE; }
     60    Bool_t IsReadyToSave() const;
    6061
    6162    void Print(Option_t *opt = "") const;
  • trunk/MagicSoft/Mars/mdata/MDataList.cc

    r1338 r1348  
    142142// --------------------------------------------------------------------------
    143143//
     144// Checks whether at least one member has the ready-to-save flag.
     145//
     146Bool_t MDataList::IsReadyToSave() const
     147{
     148    TIter Next(&fMembers);
     149
     150    MData *data = NULL;
     151
     152    while ((data=(MData*)Next()))
     153        if (data->IsReadyToSave())
     154            return kTRUE;
     155
     156    return kFALSE;
     157}
     158
     159// --------------------------------------------------------------------------
     160//
    144161// If you want to add a new member to the list call this function with the
    145162// pointer to the member to be added.
  • trunk/MagicSoft/Mars/mdata/MDataList.h

    r1305 r1348  
    4141
    4242    Bool_t IsValid() const { return fMembers.GetSize() ? kTRUE : kFALSE; }
     43    Bool_t IsReadyToSave() const;
    4344
    4445    Double_t GetValue() const;
  • trunk/MagicSoft/Mars/mdata/MDataMember.cc

    r1334 r1348  
    5959    fObject = obj;
    6060    fCall   = call;
     61}
     62
     63// --------------------------------------------------------------------------
     64//
     65//  obj is a pointer to the instance of your class from which the data
     66//  should be requested. TMethodCall (s. root dox) is a pointer
     67//  to a TMethodCall object which should be the getter function for
     68//  the data you want to get.
     69//
     70MDataMember::MDataMember(MParContainer *obj, const TString call)
     71{
     72    fObject = obj;
     73    fCall   = obj->GetterMethod(call);
    6174}
    6275
     
    134147// --------------------------------------------------------------------------
    135148//
     149// Returns the ready-to-save flag of the data member container
     150//
     151Bool_t MDataMember::IsReadyToSave() const
     152{
     153    return IsValid() ? fObject->IsReadyToSave() : kFALSE;
     154}
     155
     156// --------------------------------------------------------------------------
     157//
    136158// Print the name of the data member without an CR.
    137159//
  • trunk/MagicSoft/Mars/mdata/MDataMember.h

    r1305 r1348  
    2424    }
    2525    MDataMember(MParContainer *obj, TMethodCall *call);
     26    MDataMember(MParContainer *obj, const TString call);
    2627
    2728    Double_t GetValue() const;
     
    2930
    3031    Bool_t IsValid() const { return fCall ? kTRUE : kFALSE; }
     32    Bool_t IsReadyToSave() const;
    3133
    3234    void Print(Option_t *opt = "") const;
  • trunk/MagicSoft/Mars/mdata/MDataValue.h

    r1305 r1348  
    2626
    2727    Bool_t IsValid() const { return kTRUE; }
     28    Bool_t IsReadyToSave() const { return kFALSE; }
    2829
    2930    void Print(Option_t *opt = "") const;
  • trunk/MagicSoft/Mars/mhist/MHMatrix.cc

    r1345 r1348  
    4545#include "MHMatrix.h"
    4646
     47#include <math.h>     // fabs on Alpha
     48
    4749#include <TList.h>
    4850#include <TArrayD.h>
Note: See TracChangeset for help on using the changeset viewer.