Changeset 1176
- Timestamp:
- 01/14/02 17:56:43 (23 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc
r1080 r1176 48 48 ClassImp(MWriteAsciiFile); 49 49 50 void MWriteAsciiFile::Init(const char *filename, const char *name, const char *title) 51 { 52 fName = name ? name : "MWriteAsciiFile"; 53 fTitle = title ? title : "Task to write one container to an ascii file"; 54 55 fNameFile = filename; 56 57 fOut = new ofstream(fNameFile); 58 } 59 50 60 // -------------------------------------------------------------------------- 51 61 // … … 61 71 MWriteAsciiFile::MWriteAsciiFile(const char *filename, const char *contname, 62 72 const char *name, const char *title) 63 : fOut(NULL), fContainer(NULL)64 73 { 65 fName = name ? name : "MWriteAsciiFile"; 66 fTitle = title ? title : "Task to write one container to an ascii file"; 74 Init(filename, name, title); 67 75 68 fNameFile = filename; 69 fNameContainer = contname; 70 71 fOut = new ofstream(fNameFile); 76 AddContainer(contname); 72 77 } 73 78 … … 85 90 MWriteAsciiFile::MWriteAsciiFile(const char *filename, MParContainer *cont, 86 91 const char *name, const char *title) 87 : fOut(NULL), fContainer(cont)88 92 { 89 fName = name ? name : "MWriteAsciiFile"; 90 fTitle = title ? title : "Task to write one container to an ascii file"; 93 Init(filename, name, title); 91 94 92 fNameFile = filename; 93 fNameContainer = cont->GetName(); 94 95 fOut = new ofstream(fNameFile); 95 AddContainer(cont); 96 96 } 97 97 … … 103 103 MWriteAsciiFile::~MWriteAsciiFile() 104 104 { 105 fContNames.SetOwner(); 106 105 107 delete fOut; 106 108 } … … 112 114 void MWriteAsciiFile::CheckAndWrite() const 113 115 { 114 if (fContainer->IsReadyToSave()) 115 fContainer->AsciiWrite(*fOut); 116 Bool_t written = kFALSE; 117 118 MParContainer *cont = NULL; 119 120 TIter Next(&fContainer); 121 122 while ((cont=(MParContainer*)Next())) 123 { 124 if (!cont->IsReadyToSave()) 125 continue; 126 127 cont->AsciiWrite(*fOut); 128 *fOut << " "; 129 written = kTRUE; 130 } 131 132 if (written) 133 *fOut << endl; 116 134 } 117 135 … … 132 150 Bool_t MWriteAsciiFile::GetContainer(MParList *pList) 133 151 { 134 // 135 // Try to find the container which should be stored. 136 // 137 if (fContainer) 138 return kTRUE; 152 TObject *obj = NULL; 139 153 140 fContainer = (MParContainer*)pList->FindObject(fNameContainer); 141 if (fContainer) 142 return kTRUE; 154 TIter Next(&fContNames); 143 155 144 *fLog << err << dbginf << "Cannot find parameter container '" << fContainer << "'." << endl; 145 return kFALSE; 156 while ((obj=Next())) 157 { 158 const char *name = obj->GetName(); 159 160 MParContainer *cont = (MParContainer*)pList->FindObject(name); 161 if (!cont) 162 { 163 *fLog << err << dbginf << "Cannot find parameter container '" << name << "'." << endl; 164 return kFALSE; 165 } 166 167 if (!cont->InheritsFrom(MParContainer::Class())) 168 { 169 *fLog << err << dbginf << "'" << name << "' doesn't inherit from MParContainer." << endl; 170 return kFALSE; 171 172 } 173 174 AddContainer(cont); 175 } 176 177 return kTRUE; 146 178 } 179 180 // -------------------------------------------------------------------------- 181 // 182 // 183 void MWriteAsciiFile::AddContainer(const char *cname) 184 { 185 TNamed *named = new TNamed(cname, ""); 186 fContNames.AddLast(named); 187 } 188 189 // -------------------------------------------------------------------------- 190 // 191 // 192 void MWriteAsciiFile::AddContainer(MParContainer *cont) 193 { 194 fContainer.AddLast(cont); 195 } 196 -
trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h
r1014 r1176 4 4 #ifndef MARS_MWriteFile 5 5 #include "MWriteFile.h" 6 #endif 7 #ifndef ROOT_TObjArray 8 #include <TObjArray.h> 6 9 #endif 7 10 … … 11 14 ofstream *fOut; 12 15 16 TObjArray fContNames; 17 TObjArray fContainer; 18 13 19 TString fNameFile; 14 TString fNameContainer;15 16 MParContainer *fContainer;17 20 18 21 virtual void CheckAndWrite() const; … … 21 24 virtual const char *GetFileName() const { return fNameFile; } 22 25 26 void Init(const char *filename, const char *name, const char *title); 23 27 24 28 public: 25 29 MWriteAsciiFile(const char *filename, const char *contname, 26 30 const char *name=NULL, const char *title=NULL); 27 MWriteAsciiFile(const char *filename, MParContainer *cont ,31 MWriteAsciiFile(const char *filename, MParContainer *cont=NULL, 28 32 const char *name=NULL, const char *title=NULL); 29 33 ~MWriteAsciiFile(); 34 35 void AddContainer(const char *cname); 36 void AddContainer(MParContainer *cont); 30 37 31 38 ClassDef(MWriteAsciiFile, 0) // Class to write one container to an ascii file
Note:
See TracChangeset
for help on using the changeset viewer.