- Timestamp:
- 06/05/02 10:20:05 (22 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r1347 r1348 1 1 -*-*- 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 3 27 4 28 * mhist/MHCompProb.[h,cc]: … … 10 34 * mhist/Makefile: 11 35 - added -I../mmc 36 37 * mbase/Makefile: 38 - added -I../mdata 12 39 13 40 * mhist/MHHadroness.cc: -
trunk/MagicSoft/Mars/mbase/MParContainer.h
r1283 r1348 64 64 virtual void SetLogStream(MLog *lg) { fLog = lg; } 65 65 virtual void Reset() { } 66 virtual Bool_t IsReadyToSave() 66 virtual Bool_t IsReadyToSave() const { return fReadyToSave; } 67 67 virtual void SetReadyToSave(Bool_t flag=kTRUE) { fReadyToSave=flag; } 68 68 -
trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc
r1337 r1348 52 52 #include <TClass.h> // IsA 53 53 #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 55 59 56 60 #include "MLog.h" … … 92 96 93 97 if (contname) 94 98 AddContainer(contname); 95 99 } 96 100 … … 122 126 MWriteAsciiFile::~MWriteAsciiFile() 123 127 { 124 fContNames.SetOwner(); 125 fMembers.SetOwner(); 126 128 fAutoDel.SetOwner(); 127 129 delete fOut; 128 130 } … … 130 132 // -------------------------------------------------------------------------- 131 133 // 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 // 136 Bool_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 // 146 void 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 // 167 void MWriteAsciiFile::AddContainer(MParContainer *cont, const TString member, Double_t scale) 168 { 169 if (member.IsNull()) 170 { 171 fList.Add(cont); 172 172 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); 216 190 } 217 191 … … 231 205 // used millimeters) 232 206 // 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; 207 void 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 // 239 Bool_t MWriteAsciiFile::GetContainer(MParList *plist) 240 { 241 TObject *obj=NULL; 269 242 270 243 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) 273 267 return kFALSE; 274 268 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 // 281 void 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 9 9 #endif 10 10 11 class MData; 12 11 13 class MWriteAsciiFile : public MWriteFile 12 14 { 13 15 private: 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 23 17 24 ofstream *fOut;18 TString fNameFile; // name of the ascii file 25 19 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 29 22 30 TString fNameFile;31 /*32 TList fList;33 */34 23 virtual void CheckAndWrite() const; 35 24 virtual Bool_t IsFileOpen() const; … … 46 35 ~MWriteAsciiFile(); 47 36 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); 50 39 51 /* 52 Bool_t PreProcess(MParList *plist); 53 void Add(const char *rule); 54 */ 40 void AddRule(const char *rule); 55 41 56 42 ClassDef(MWriteAsciiFile, 0) // Class to write one container to an ascii file -
trunk/MagicSoft/Mars/mbase/Makefile
r1346 r1348 20 20 # @endcode 21 21 22 INCLUDES = -I. -I../mraw -I../MRawFormat -I../mmc 22 INCLUDES = -I. -I../mraw -I../MRawFormat -I../mmc -I../mdata 23 23 24 24 # @code -
trunk/MagicSoft/Mars/mdata/MData.cc
r1304 r1348 48 48 #include "MData.h" 49 49 50 #include <ostream.h> 51 50 52 ClassImp(MData); 53 54 Bool_t MData::AsciiWrite(ostream &out) const 55 { 56 out << GetValue() << " "; 57 return kTRUE; 58 } 59 -
trunk/MagicSoft/Mars/mdata/MData.h
r1338 r1348 23 23 Double_t operator()() { return GetValue(); } 24 24 25 Bool_t AsciiWrite(ostream &out) const; 26 25 27 ClassDef(MData, 0) // A Base class for a generalized value 26 28 }; -
trunk/MagicSoft/Mars/mdata/MDataChain.cc
r1339 r1348 81 81 #include "MDataChain.h" 82 82 83 #include <math.h> // fabs on Alpha 83 84 #include <ctype.h> // isalnum, ... 84 85 #include <stdlib.h> // strtod, ... … … 131 132 { 132 133 return fMember ? fMember->PreProcess(pList) : kFALSE; 134 } 135 136 // -------------------------------------------------------------------------- 137 // 138 // Checks whether at least one member has the ready-to-save flag. 139 // 140 Bool_t MDataChain::IsReadyToSave() const 141 { 142 *fLog << all << "fM=" << fMember << "/" << (int)fMember->IsReadyToSave() << " " << endl; 143 return fMember ? fMember->IsReadyToSave() : kFALSE; 133 144 } 134 145 -
trunk/MagicSoft/Mars/mdata/MDataChain.h
r1338 r1348 58 58 59 59 Bool_t IsValid() const { return fMember ? kTRUE : kFALSE; } 60 Bool_t IsReadyToSave() const; 60 61 61 62 void Print(Option_t *opt = "") const; -
trunk/MagicSoft/Mars/mdata/MDataList.cc
r1338 r1348 142 142 // -------------------------------------------------------------------------- 143 143 // 144 // Checks whether at least one member has the ready-to-save flag. 145 // 146 Bool_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 // 144 161 // If you want to add a new member to the list call this function with the 145 162 // pointer to the member to be added. -
trunk/MagicSoft/Mars/mdata/MDataList.h
r1305 r1348 41 41 42 42 Bool_t IsValid() const { return fMembers.GetSize() ? kTRUE : kFALSE; } 43 Bool_t IsReadyToSave() const; 43 44 44 45 Double_t GetValue() const; -
trunk/MagicSoft/Mars/mdata/MDataMember.cc
r1334 r1348 59 59 fObject = obj; 60 60 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 // 70 MDataMember::MDataMember(MParContainer *obj, const TString call) 71 { 72 fObject = obj; 73 fCall = obj->GetterMethod(call); 61 74 } 62 75 … … 134 147 // -------------------------------------------------------------------------- 135 148 // 149 // Returns the ready-to-save flag of the data member container 150 // 151 Bool_t MDataMember::IsReadyToSave() const 152 { 153 return IsValid() ? fObject->IsReadyToSave() : kFALSE; 154 } 155 156 // -------------------------------------------------------------------------- 157 // 136 158 // Print the name of the data member without an CR. 137 159 // -
trunk/MagicSoft/Mars/mdata/MDataMember.h
r1305 r1348 24 24 } 25 25 MDataMember(MParContainer *obj, TMethodCall *call); 26 MDataMember(MParContainer *obj, const TString call); 26 27 27 28 Double_t GetValue() const; … … 29 30 30 31 Bool_t IsValid() const { return fCall ? kTRUE : kFALSE; } 32 Bool_t IsReadyToSave() const; 31 33 32 34 void Print(Option_t *opt = "") const; -
trunk/MagicSoft/Mars/mdata/MDataValue.h
r1305 r1348 26 26 27 27 Bool_t IsValid() const { return kTRUE; } 28 Bool_t IsReadyToSave() const { return kFALSE; } 28 29 29 30 void Print(Option_t *opt = "") const; -
trunk/MagicSoft/Mars/mhist/MHMatrix.cc
r1345 r1348 45 45 #include "MHMatrix.h" 46 46 47 #include <math.h> // fabs on Alpha 48 47 49 #include <TList.h> 48 50 #include <TArrayD.h>
Note:
See TracChangeset
for help on using the changeset viewer.