| 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 12/2000 (tbretz@uni-sw.gwdg.de)
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | // //
|
|---|
| 27 | // MParContainer //
|
|---|
| 28 | // //
|
|---|
| 29 | // The MParContainer class is the base class for all MARS parameter //
|
|---|
| 30 | // containers. At the moment it is almost the same than ROOT's TNamed. //
|
|---|
| 31 | // A TNamed contains the essential elements (name, title) //
|
|---|
| 32 | // to identify a derived object in lists like our MParList or MTaskList. //
|
|---|
| 33 | // The main difference is that the name and title isn't stored and read //
|
|---|
| 34 | // to and from root files ("//!") //
|
|---|
| 35 | // //
|
|---|
| 36 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 37 | #include "MParContainer.h"
|
|---|
| 38 |
|
|---|
| 39 | #include <TClass.h> // IsA
|
|---|
| 40 | #include <TROOT.h> // TROOT::Identlevel
|
|---|
| 41 | #include <TVirtualPad.h> // gPad
|
|---|
| 42 |
|
|---|
| 43 | #include "MLog.h"
|
|---|
| 44 |
|
|---|
| 45 | ClassImp(MParContainer);
|
|---|
| 46 |
|
|---|
| 47 | // --------------------------------------------------------------------------
|
|---|
| 48 | //
|
|---|
| 49 | // MParContainer copy ctor
|
|---|
| 50 | //
|
|---|
| 51 | MParContainer::MParContainer(const MParContainer &named)
|
|---|
| 52 | {
|
|---|
| 53 | *fName = *(named.fName);
|
|---|
| 54 | *fTitle = *(named.fTitle);
|
|---|
| 55 |
|
|---|
| 56 | fLog = named.fLog;
|
|---|
| 57 |
|
|---|
| 58 | fReadyToSave = named.fReadyToSave;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | // --------------------------------------------------------------------------
|
|---|
| 62 | //
|
|---|
| 63 | // MParContainer assignment operator.
|
|---|
| 64 | //
|
|---|
| 65 | MParContainer& MParContainer::operator=(const MParContainer& rhs)
|
|---|
| 66 | {
|
|---|
| 67 | if (this == &rhs)
|
|---|
| 68 | return *this;
|
|---|
| 69 |
|
|---|
| 70 | TObject::operator=(rhs);
|
|---|
| 71 |
|
|---|
| 72 | *fName = *(rhs.fName);
|
|---|
| 73 | *fTitle = *(rhs.fTitle);
|
|---|
| 74 |
|
|---|
| 75 | fLog = rhs.fLog;
|
|---|
| 76 | fReadyToSave = rhs.fReadyToSave;
|
|---|
| 77 |
|
|---|
| 78 | return *this;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | // --------------------------------------------------------------------------
|
|---|
| 82 | //
|
|---|
| 83 | // Compare two MParContainer objects. Returns 0 when equal, -1 when this is
|
|---|
| 84 | // smaller and +1 when bigger (like strcmp).
|
|---|
| 85 | //
|
|---|
| 86 | Int_t MParContainer::Compare(TObject *obj)
|
|---|
| 87 | {
|
|---|
| 88 | if (this == obj) return 0;
|
|---|
| 89 | return fName->CompareTo(obj->GetName());
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | // --------------------------------------------------------------------------
|
|---|
| 93 | //
|
|---|
| 94 | // Copy this to obj.
|
|---|
| 95 | //
|
|---|
| 96 | void MParContainer::Copy(TObject &obj)
|
|---|
| 97 | {
|
|---|
| 98 | MParContainer &cont = (MParContainer&)obj;
|
|---|
| 99 |
|
|---|
| 100 | TObject::Copy(obj);
|
|---|
| 101 |
|
|---|
| 102 | *cont.fName = *fName;
|
|---|
| 103 | *cont.fTitle = *fTitle;
|
|---|
| 104 |
|
|---|
| 105 | cont.fLog = fLog;
|
|---|
| 106 | cont.fReadyToSave = fReadyToSave;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | // --------------------------------------------------------------------------
|
|---|
| 110 | //
|
|---|
| 111 | // Encode MParContainer into output buffer.
|
|---|
| 112 | //
|
|---|
| 113 | void MParContainer::FillBuffer(char *&buffer)
|
|---|
| 114 | {
|
|---|
| 115 | fName->FillBuffer(buffer);
|
|---|
| 116 | fTitle->FillBuffer(buffer);
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | // --------------------------------------------------------------------------
|
|---|
| 120 | //
|
|---|
| 121 | // List MParContainer name and title.
|
|---|
| 122 | //
|
|---|
| 123 | void MParContainer::ls(Option_t *)
|
|---|
| 124 | {
|
|---|
| 125 | TROOT::IndentLevel();
|
|---|
| 126 | *fLog <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
|
|---|
| 127 | << Int_t(TestBit(kCanDelete)) << endl;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | // --------------------------------------------------------------------------
|
|---|
| 131 | //
|
|---|
| 132 | // Print MParContainer name and title.
|
|---|
| 133 | //
|
|---|
| 134 | void MParContainer::Print(Option_t *)
|
|---|
| 135 | {
|
|---|
| 136 | *fLog <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << endl;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | // --------------------------------------------------------------------------
|
|---|
| 140 | //
|
|---|
| 141 | // Change (i.e. set) the name of the MParContainer.
|
|---|
| 142 | // WARNING !!
|
|---|
| 143 | // If the object is a member of a THashTable, THashList container
|
|---|
| 144 | // The HashTable must be Rehashed after SetName
|
|---|
| 145 | // For example the list of objects in the current directory is a THashList
|
|---|
| 146 | //
|
|---|
| 147 | void MParContainer::SetName(const char *name)
|
|---|
| 148 | {
|
|---|
| 149 | *fName = name;
|
|---|
| 150 | if (gPad && TestBit(kMustCleanup)) gPad->Modified();
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | // --------------------------------------------------------------------------
|
|---|
| 154 | //
|
|---|
| 155 | // Change (i.e. set) all the MParContainer parameters (name and title).
|
|---|
| 156 | // See also WARNING in SetName
|
|---|
| 157 | //
|
|---|
| 158 | void MParContainer::SetObject(const char *name, const char *title)
|
|---|
| 159 | {
|
|---|
| 160 | *fName = name;
|
|---|
| 161 | *fTitle = title;
|
|---|
| 162 | if (gPad && TestBit(kMustCleanup)) gPad->Modified();
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | // --------------------------------------------------------------------------
|
|---|
| 166 | //
|
|---|
| 167 | // Change (i.e. set) the title of the MParContainer.
|
|---|
| 168 | //
|
|---|
| 169 | void MParContainer::SetTitle(const char *title)
|
|---|
| 170 | {
|
|---|
| 171 | *fTitle = title;
|
|---|
| 172 | if (gPad && TestBit(kMustCleanup)) gPad->Modified();
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | // --------------------------------------------------------------------------
|
|---|
| 176 | //
|
|---|
| 177 | // Return size of the MParContainer part of the TObject.
|
|---|
| 178 | //
|
|---|
| 179 | Int_t MParContainer::Sizeof() const
|
|---|
| 180 | {
|
|---|
| 181 | Int_t nbytes = fName->Sizeof() + fTitle->Sizeof();
|
|---|
| 182 | return nbytes;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | void MParContainer::AsciiRead(ifstream &fin)
|
|---|
| 186 | {
|
|---|
| 187 | *fLog << "To use the the ascii input of " << GetName();
|
|---|
| 188 | *fLog << " you have to overload " << GetName() << "::AsciiRead." << endl;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | void MParContainer::AsciiWrite(ofstream &fout) const
|
|---|
| 192 | {
|
|---|
| 193 | *fLog << "To use the the ascii output of " << GetName();
|
|---|
| 194 | *fLog << " you have to overload " << GetName() << "::AsciiWrite." << endl;
|
|---|
| 195 | }
|
|---|