Changeset bd8c884 in git for external/ExRootAnalysis
- Timestamp:
- Apr 26, 2016, 3:45:47 PM (9 years ago)
- Branches:
- ImprovedOutputFile, Timing, dual_readout, llp, master
- Children:
- 75f49a7
- Parents:
- 3e8bcb9
- Location:
- external/ExRootAnalysis
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
external/ExRootAnalysis/ExRootConfReader.cc
r3e8bcb9 rbd8c884 12 12 #include "tcl/tcl.h" 13 13 14 #include <libgen.h> 15 14 16 #include <iostream> 15 17 #include <iomanip> … … 22 24 23 25 static Tcl_ObjCmdProc ModuleObjCmdProc; 26 static Tcl_ObjCmdProc SourceObjCmdProc; 24 27 25 28 //------------------------------------------------------------------------------ 26 29 27 30 ExRootConfReader::ExRootConfReader() : 28 fT clInterp(0)31 fTopDir(0), fTclInterp(0) 29 32 { 30 33 fTclInterp = Tcl_CreateInterp(); 31 34 32 35 Tcl_CreateObjCommand(fTclInterp, "module", ModuleObjCmdProc, this, 0); 36 Tcl_CreateObjCommand(fTclInterp, "source", SourceObjCmdProc, this, 0); 33 37 } 34 38 … … 42 46 //------------------------------------------------------------------------------ 43 47 44 void ExRootConfReader::ReadFile(const char *fileName) 45 { 46 /* 47 ifstream inputFileStream(fileName); 48 string cmdBuffer = string(istreambuf_iterator<char>(inputFileStream), istreambuf_iterator<char>()); 49 50 Tcl_Obj *cmdObjPtr = Tcl_NewObj(); 51 cmdObjPtr->bytes = const_cast<char *>(cmdBuffer.c_str()); 52 cmdObjPtr->length = cmdBuffer.size(); 53 */ 48 void ExRootConfReader::ReadFile(const char *fileName, bool isTop) 49 { 54 50 stringstream message; 55 51 … … 60 56 throw runtime_error(message.str()); 61 57 } 58 59 if(isTop) fTopDir = dirname(const_cast<char *>(fileName)); 62 60 63 61 int file_length = inputFileStream.tellg(); … … 93 91 { 94 92 Tcl_Obj *object; 95 Tcl_Obj *variableName = Tcl_NewStringObj(const_cast<char *>(name), -1);93 Tcl_Obj *variableName = Tcl_NewStringObj(const_cast<char *>(name), -1); 96 94 object = Tcl_ObjGetVar2(fTclInterp, variableName, 0, TCL_GLOBAL_ONLY); 97 95 return ExRootConfParam(name, object, fTclInterp); … … 188 186 int ModuleObjCmdProc(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) 189 187 { 188 ExRootConfReader *reader; 189 190 190 if(objc < 3) 191 191 { 192 /*193 Tcl_SetResult(interp, "wrong # args: should be \"module className moduleName arg ?arg...?\"", 0);194 */195 192 Tcl_WrongNumArgs(interp, 1, objv, "className moduleName ?arg...?"); 196 197 } 198 199 ExRootConfReader *test= (ExRootConfReader*) clientData;193 return TCL_ERROR; 194 } 195 196 reader = (ExRootConfReader*) clientData; 200 197 201 198 // add module to a list of modules to be created 202 199 203 test->AddModule(Tcl_GetStringFromObj(objv[1], 0), Tcl_GetStringFromObj(objv[2], 0));200 reader->AddModule(Tcl_GetStringFromObj(objv[1], 0), Tcl_GetStringFromObj(objv[2], 0)); 204 201 205 202 if(objc > 3) … … 218 215 //------------------------------------------------------------------------------ 219 216 217 int SourceObjCmdProc(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) 218 { 219 const char *fileName; 220 char *fullName; 221 ExRootConfReader *reader; 222 size_t size; 223 224 if(objc != 2) 225 { 226 Tcl_WrongNumArgs(interp, 1, objv, "fileName"); 227 return TCL_ERROR; 228 } 229 230 reader = (ExRootConfReader*) clientData; 231 fileName = Tcl_GetStringFromObj(objv[1], 0); 232 size = strlen(reader->GetTopDir()) + strlen(fileName) + 2; 233 fullName = static_cast<char *>(malloc(size)); 234 strcpy(fullName, reader->GetTopDir()); 235 strcat(fullName, "/"); 236 strcat(fullName, fileName); 237 reader->ReadFile(fullName, false); 238 239 return TCL_OK; 240 } 241 242 //------------------------------------------------------------------------------ 243 220 244 ExRootConfParam::ExRootConfParam(const char *name, Tcl_Obj *object, Tcl_Interp *interp) : 221 245 fName(name), fObject(object), fTclInterp(interp) … … 289 313 const char *result = defaultValue; 290 314 if(fObject) result = Tcl_GetStringFromObj(fObject, 0); 291 return result; 315 return result; 292 316 } 293 317 … … 304 328 throw runtime_error(message.str()); 305 329 } 306 return length; 330 return length; 307 331 } 308 332 -
external/ExRootAnalysis/ExRootConfReader.h
r3e8bcb9 rbd8c884 50 50 ~ExRootConfReader(); 51 51 52 void ReadFile(const char *fileName );52 void ReadFile(const char *fileName, bool isTop = true); 53 53 54 54 int GetInt(const char *name, int defaultValue, int index = -1); … … 63 63 void AddModule(const char *className, const char *moduleName); 64 64 65 const char *GetTopDir() const { return fTopDir; } 66 65 67 private: 68 69 const char *fTopDir; //! 66 70 67 71 Tcl_Interp *fTclInterp; //!
Note:
See TracChangeset
for help on using the changeset viewer.