Fork me on GitHub

Changeset bd8c884 in git for external/ExRootAnalysis


Ignore:
Timestamp:
Apr 26, 2016, 3:45:47 PM (9 years ago)
Author:
Pavel Demin <pavel.demin@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
75f49a7
Parents:
3e8bcb9
Message:

add source command to ExRootConfReader

Location:
external/ExRootAnalysis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • external/ExRootAnalysis/ExRootConfReader.cc

    r3e8bcb9 rbd8c884  
    1212#include "tcl/tcl.h"
    1313
     14#include <libgen.h>
     15
    1416#include <iostream>
    1517#include <iomanip>
     
    2224
    2325static Tcl_ObjCmdProc ModuleObjCmdProc;
     26static Tcl_ObjCmdProc SourceObjCmdProc;
    2427
    2528//------------------------------------------------------------------------------
    2629
    2730ExRootConfReader::ExRootConfReader() :
    28   fTclInterp(0)
     31  fTopDir(0), fTclInterp(0)
    2932{
    3033  fTclInterp = Tcl_CreateInterp();
    3134
    3235  Tcl_CreateObjCommand(fTclInterp, "module", ModuleObjCmdProc, this, 0);
     36  Tcl_CreateObjCommand(fTclInterp, "source", SourceObjCmdProc, this, 0);
    3337}
    3438
     
    4246//------------------------------------------------------------------------------
    4347
    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 */
     48void ExRootConfReader::ReadFile(const char *fileName, bool isTop)
     49{
    5450  stringstream message;
    5551
     
    6056    throw runtime_error(message.str());
    6157  }
     58
     59  if(isTop) fTopDir = dirname(const_cast<char *>(fileName));
    6260
    6361  int file_length = inputFileStream.tellg();
     
    9391{
    9492  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);
    9694  object = Tcl_ObjGetVar2(fTclInterp, variableName, 0, TCL_GLOBAL_ONLY);
    9795  return ExRootConfParam(name, object, fTclInterp);
     
    188186int ModuleObjCmdProc(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
    189187{
     188  ExRootConfReader *reader;
     189
    190190  if(objc < 3)
    191191  {
    192 /*
    193     Tcl_SetResult(interp, "wrong # args: should be \"module className moduleName arg ?arg...?\"", 0);
    194 */
    195192    Tcl_WrongNumArgs(interp, 1, objv, "className moduleName ?arg...?");
    196                 return TCL_ERROR;
    197   }
    198 
    199   ExRootConfReader *test = (ExRootConfReader*) clientData;
     193    return TCL_ERROR;
     194  }
     195
     196  reader = (ExRootConfReader*) clientData;
    200197
    201198  // add module to a list of modules to be created
    202199
    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));
    204201
    205202  if(objc > 3)
     
    218215//------------------------------------------------------------------------------
    219216
     217int 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
    220244ExRootConfParam::ExRootConfParam(const char *name, Tcl_Obj *object, Tcl_Interp *interp) :
    221245  fName(name), fObject(object), fTclInterp(interp)
     
    289313  const char *result = defaultValue;
    290314  if(fObject) result = Tcl_GetStringFromObj(fObject, 0);
    291   return result; 
     315  return result;
    292316}
    293317
     
    304328    throw runtime_error(message.str());
    305329  }
    306   return length; 
     330  return length;
    307331}
    308332
  • external/ExRootAnalysis/ExRootConfReader.h

    r3e8bcb9 rbd8c884  
    5050  ~ExRootConfReader();
    5151
    52   void ReadFile(const char *fileName);
     52  void ReadFile(const char *fileName, bool isTop = true);
    5353
    5454  int GetInt(const char *name, int defaultValue, int index = -1);
     
    6363  void AddModule(const char *className, const char *moduleName);
    6464
     65  const char *GetTopDir() const { return fTopDir; }
     66
    6567private:
     68
     69  const char *fTopDir; //!
    6670
    6771  Tcl_Interp *fTclInterp; //!
Note: See TracChangeset for help on using the changeset viewer.