| 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 <mailto: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 <fstream.h> // ofstream, AsciiWrite
|
|---|
| 40 |
|
|---|
| 41 | #include <TClass.h> // IsA
|
|---|
| 42 | #include <TROOT.h> // TROOT::Identlevel
|
|---|
| 43 | #include <TMethodCall.h> // TMethodCall, AsciiWrite
|
|---|
| 44 | #include <TDataMember.h> // TDataMember, AsciiWrite
|
|---|
| 45 | #include <TVirtualPad.h> // gPad
|
|---|
| 46 |
|
|---|
| 47 | #include "MLog.h"
|
|---|
| 48 | #include "MLogManip.h"
|
|---|
| 49 |
|
|---|
| 50 | ClassImp(MParContainer);
|
|---|
| 51 |
|
|---|
| 52 | // --------------------------------------------------------------------------
|
|---|
| 53 | //
|
|---|
| 54 | // MParContainer copy ctor
|
|---|
| 55 | //
|
|---|
| 56 | MParContainer::MParContainer(const MParContainer &named)
|
|---|
| 57 | {
|
|---|
| 58 | fName = named.fName;
|
|---|
| 59 | fTitle = named.fTitle;
|
|---|
| 60 |
|
|---|
| 61 | fLog = named.fLog;
|
|---|
| 62 |
|
|---|
| 63 | fReadyToSave = named.fReadyToSave;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | // --------------------------------------------------------------------------
|
|---|
| 67 | //
|
|---|
| 68 | // MParContainer assignment operator.
|
|---|
| 69 | //
|
|---|
| 70 | MParContainer& MParContainer::operator=(const MParContainer& rhs)
|
|---|
| 71 | {
|
|---|
| 72 | if (this == &rhs)
|
|---|
| 73 | return *this;
|
|---|
| 74 |
|
|---|
| 75 | TObject::operator=(rhs);
|
|---|
| 76 |
|
|---|
| 77 | fName = rhs.fName;
|
|---|
| 78 | fTitle = rhs.fTitle;
|
|---|
| 79 |
|
|---|
| 80 | fLog = rhs.fLog;
|
|---|
| 81 | fReadyToSave = rhs.fReadyToSave;
|
|---|
| 82 |
|
|---|
| 83 | return *this;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | // --------------------------------------------------------------------------
|
|---|
| 87 | //
|
|---|
| 88 | // Make a clone of an object using the Streamer facility.
|
|---|
| 89 | // If newname is specified, this will be the name of the new object
|
|---|
| 90 | //
|
|---|
| 91 | TObject *MParContainer::Clone(const char *newname) const
|
|---|
| 92 | {
|
|---|
| 93 |
|
|---|
| 94 | MParContainer *named = (MParContainer*)TObject::Clone();
|
|---|
| 95 | if (newname && strlen(newname)) named->SetName(newname);
|
|---|
| 96 | return named;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | // --------------------------------------------------------------------------
|
|---|
| 100 | //
|
|---|
| 101 | // Compare two MParContainer objects. Returns 0 when equal, -1 when this is
|
|---|
| 102 | // smaller and +1 when bigger (like strcmp).
|
|---|
| 103 | //
|
|---|
| 104 | Int_t MParContainer::Compare(const TObject *obj) const
|
|---|
| 105 | {
|
|---|
| 106 | if (this == obj) return 0;
|
|---|
| 107 | return fName.CompareTo(obj->GetName());
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | // --------------------------------------------------------------------------
|
|---|
| 111 | //
|
|---|
| 112 | // Copy this to obj.
|
|---|
| 113 | //
|
|---|
| 114 | void MParContainer::Copy(TObject &obj)
|
|---|
| 115 | {
|
|---|
| 116 | MParContainer &cont = (MParContainer&)obj;
|
|---|
| 117 |
|
|---|
| 118 | TObject::Copy(obj);
|
|---|
| 119 |
|
|---|
| 120 | cont.fName = fName;
|
|---|
| 121 | cont.fTitle = fTitle;
|
|---|
| 122 |
|
|---|
| 123 | cont.fLog = fLog;
|
|---|
| 124 | cont.fReadyToSave = fReadyToSave;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | // --------------------------------------------------------------------------
|
|---|
| 128 | //
|
|---|
| 129 | // Encode MParContainer into output buffer.
|
|---|
| 130 | //
|
|---|
| 131 | void MParContainer::FillBuffer(char *&buffer)
|
|---|
| 132 | {
|
|---|
| 133 | fName.FillBuffer(buffer);
|
|---|
| 134 | fTitle.FillBuffer(buffer);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | // --------------------------------------------------------------------------
|
|---|
| 138 | //
|
|---|
| 139 | // List MParContainer name and title.
|
|---|
| 140 | //
|
|---|
| 141 | void MParContainer::ls(Option_t *) const
|
|---|
| 142 | {
|
|---|
| 143 | TROOT::IndentLevel();
|
|---|
| 144 | *fLog << all << GetDescriptor() << " " << GetTitle() << ": kCanDelete=";
|
|---|
| 145 | *fLog << Int_t(TestBit(kCanDelete)) << endl;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | // --------------------------------------------------------------------------
|
|---|
| 149 | //
|
|---|
| 150 | // Print MParContainer name and title.
|
|---|
| 151 | //
|
|---|
| 152 | void MParContainer::Print(Option_t *) const
|
|---|
| 153 | {
|
|---|
| 154 | *fLog << all << GetDescriptor() << " " << GetTitle() << endl;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | // --------------------------------------------------------------------------
|
|---|
| 158 | //
|
|---|
| 159 | // Change (i.e. set) the name of the MParContainer.
|
|---|
| 160 | // WARNING !!
|
|---|
| 161 | // If the object is a member of a THashTable, THashList container
|
|---|
| 162 | // The HashTable must be Rehashed after SetName
|
|---|
| 163 | // For example the list of objects in the current directory is a THashList
|
|---|
| 164 | //
|
|---|
| 165 | void MParContainer::SetName(const char *name)
|
|---|
| 166 | {
|
|---|
| 167 | fName = name;
|
|---|
| 168 | if (gPad && TestBit(kMustCleanup)) gPad->Modified();
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | // --------------------------------------------------------------------------
|
|---|
| 172 | //
|
|---|
| 173 | // Change (i.e. set) all the MParContainer parameters (name and title).
|
|---|
| 174 | // See also WARNING in SetName
|
|---|
| 175 | //
|
|---|
| 176 | void MParContainer::SetObject(const char *name, const char *title)
|
|---|
| 177 | {
|
|---|
| 178 | fName = name;
|
|---|
| 179 | fTitle = title;
|
|---|
| 180 | if (gPad && TestBit(kMustCleanup)) gPad->Modified();
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | // --------------------------------------------------------------------------
|
|---|
| 184 | //
|
|---|
| 185 | // Change (i.e. set) the title of the MParContainer.
|
|---|
| 186 | //
|
|---|
| 187 | void MParContainer::SetTitle(const char *title)
|
|---|
| 188 | {
|
|---|
| 189 | fTitle = title;
|
|---|
| 190 | if (gPad && TestBit(kMustCleanup)) gPad->Modified();
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | // --------------------------------------------------------------------------
|
|---|
| 194 | //
|
|---|
| 195 | // Return size of the MParContainer part of the TObject.
|
|---|
| 196 | //
|
|---|
| 197 | Int_t MParContainer::Sizeof() const
|
|---|
| 198 | {
|
|---|
| 199 | Int_t nbytes = fName.Sizeof() + fTitle.Sizeof();
|
|---|
| 200 | return nbytes;
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | // --------------------------------------------------------------------------
|
|---|
| 204 | //
|
|---|
| 205 | // If you want to use Ascii-Input/-Output (eg. MWriteAsciiFile) of a
|
|---|
| 206 | // container, overload this function.
|
|---|
| 207 | //
|
|---|
| 208 | void MParContainer::AsciiRead(ifstream &fin)
|
|---|
| 209 | {
|
|---|
| 210 | *fLog << warn << "To use the the ascii input of " << GetName();
|
|---|
| 211 | *fLog << " you have to overload " << ClassName() << "::AsciiRead." << endl;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | // --------------------------------------------------------------------------
|
|---|
| 215 | //
|
|---|
| 216 | // If you want to use Ascii-Input/-Output (eg. MWriteAsciiFile) of a
|
|---|
| 217 | // container, you may overload this function. If you don't overload it
|
|---|
| 218 | // the data member of a class are written to the file in the order of
|
|---|
| 219 | // appearance in the class header (be more specfic: root dictionary)
|
|---|
| 220 | // Only data members which are of integer (Bool_t, Int_t, ...) or
|
|---|
| 221 | // floating point (Float_t, Double_t, ...) type are written.
|
|---|
| 222 | //
|
|---|
| 223 | void MParContainer::AsciiWrite(ofstream &fout) const
|
|---|
| 224 | {
|
|---|
| 225 | // *fLog << warn << "To use the the ascii output of " << GetName();
|
|---|
| 226 | // *fLog << " you have to overload " << ClassName() << "::AsciiWrite." << endl;
|
|---|
| 227 |
|
|---|
| 228 | TDataMember *data = NULL;
|
|---|
| 229 |
|
|---|
| 230 | TIter Next(IsA()->GetListOfDataMembers());
|
|---|
| 231 | while ((data=(TDataMember*)Next()))
|
|---|
| 232 | {
|
|---|
| 233 | if (!data->IsPersistent())
|
|---|
| 234 | continue;
|
|---|
| 235 |
|
|---|
| 236 | /*const*/ TMethodCall *call = data->GetterMethod(); //FIXME: Root
|
|---|
| 237 | if (!call)
|
|---|
| 238 | continue;
|
|---|
| 239 |
|
|---|
| 240 | switch (call->ReturnType())
|
|---|
| 241 | {
|
|---|
| 242 | case TMethodCall::kLong:
|
|---|
| 243 | Long_t l;
|
|---|
| 244 | call->Execute((void*)this, l); // FIXME: const, root
|
|---|
| 245 | fout << l << " ";
|
|---|
| 246 | continue;
|
|---|
| 247 |
|
|---|
| 248 | case TMethodCall::kDouble:
|
|---|
| 249 | Double_t d;
|
|---|
| 250 | call->Execute((void*)this, d); // FIXME: const, root
|
|---|
| 251 | fout << d << " ";
|
|---|
| 252 | continue;
|
|---|
| 253 |
|
|---|
| 254 | case TMethodCall::kOther:
|
|---|
| 255 | /* someone may want to enhance this? */
|
|---|
| 256 | continue;
|
|---|
| 257 | }
|
|---|
| 258 | }
|
|---|
| 259 | }
|
|---|