Logo coherent WaveBurst  
Config Reference Guide
Logo
Functions | Variables
converttonotebook Namespace Reference

Functions

def changeMarkdown (code)
 
def cppComments (text)
 
def cppFunction (text)
 
def declareIncludes (code)
 
def declareNamespace (code)
 
def disableDrawProgressBar (code)
 
def findFunctionName (text)
 
def findTimeout ()
 
def fixes (code)
 
def getLibMathMore (code)
 
def isCpp ()
 
def mainfunction (text)
 
def processmain (text)
 
def pythonComments (text)
 
def pythonMainFunction (text)
 
def readHeaderCpp (text)
 
def readHeaderPython (text)
 
def removePaletteEditor (code)
 
def roofitRemoveSpacesComments (code)
 
def rs401dGetFiles (code)
 
def runEventExe (code)
 
def split (text)
 
def tree4GetFiles (code)
 
def unindenter (string, spaces=3)
 

Variables

 author
 
 date = datetime.now().strftime("%A, %B %d, %Y at %I:%M %p")
 
 description
 
 extension
 
list gTypesList
 
 isJsroot
 
 isNotebook
 
 needsHeaderFile
 
 nodraw
 
 outdir = str(sys.argv[2])
 
string outname = tutFileName + ".ipynb"
 
string outnameconverted = tutFileName + ".nbconvert.ipynb"
 
 outPathName = os.path.join(outdir, outname)
 
 starttime = time.time()
 
 text = fin.read()
 
 tutFileName = os.path.basename(tutPathName)
 
string tutName = "tutorial"
 
 tutPath = os.path.dirname(tutPathName)
 
 tutPathName = str(sys.argv[1])
 
string tutRelativePath = "$ROOTSYS/tutorials/%s/" % tutPath.split("/")[-1]
 
 tutTitle = re.sub( r"([A-Z\d])", r" \1", tutName).title()
 
 verbose
 

Function Documentation

◆ changeMarkdown()

def converttonotebook.changeMarkdown (   code)

Definition at line 635 of file converttonotebook.py.

◆ cppComments()

def converttonotebook.cppComments (   text)
Converts comments delimited by // and on a new line into a markdown cell. For C++ files only.
>>> cppComments('''// This is a
... // multiline comment
... void function(){}''') 
'# <markdowncell>\\n# This is a\\n#  multiline comment\\n# <codecell>\\nvoid function(){}\\n'
>>> cppComments('''void function(){
...    int variable = 5 // Comment not in cell
...    // Comment also not in cell
... }''')
'void function(){\\n   int variable = 5 // Comment not in cell\\n   // Comment also not in cell\\n}\\n'

Definition at line 338 of file converttonotebook.py.

◆ cppFunction()

def converttonotebook.cppFunction (   text)
Extracts main function for the function enclosure by means of regular expression
>>> cppFunction('''void mainfunction(arguments = values){
...    content of function
...    which spans
...    several lines
... }''')
'\\n   content of function\\n   which spans\\n   several lines\\n'
>>> cppFunction('''void mainfunction(arguments = values)
... {
...    content of function
...    which spans
...    several lines
... }''')
'\\n   content of function\\n   which spans\\n   several lines\\n'
>>> cppFunction('''void mainfunction(arguments = values
... morearguments = morevalues)
... {
...    content of function
...    which spans
...    several lines
... }''')
'\\n   content of function\\n   which spans\\n   several lines\\n'

Definition at line 304 of file converttonotebook.py.

◆ declareIncludes()

def converttonotebook.declareIncludes (   code)

Definition at line 608 of file converttonotebook.py.

◆ declareNamespace()

def converttonotebook.declareNamespace (   code)

Definition at line 589 of file converttonotebook.py.

◆ disableDrawProgressBar()

def converttonotebook.disableDrawProgressBar (   code)

Definition at line 621 of file converttonotebook.py.

◆ findFunctionName()

def converttonotebook.findFunctionName (   text)
Takes a string representation of a C++ function as an input,
finds and returns the name of the function
>>> findFunctionName('void functionName(arguments = values){}')
'functionName'
>>> findFunctionName('void functionName (arguments = values){}')
'functionName'
>>> findFunctionName('void *functionName(arguments = values){}')
'functionName'
>>> findFunctionName('void* functionName(arguments = values){}')
'functionName'
>>> findFunctionName('void * functionName(arguments = values){}')
'functionName'
>>> findFunctionName('void class::functionName(arguments = values){}')
'class::functionName'

Definition at line 473 of file converttonotebook.py.

◆ findTimeout()

def converttonotebook.findTimeout ( )

Definition at line 649 of file converttonotebook.py.

◆ fixes()

def converttonotebook.fixes (   code)

Definition at line 624 of file converttonotebook.py.

◆ getLibMathMore()

def converttonotebook.getLibMathMore (   code)

Definition at line 570 of file converttonotebook.py.

◆ isCpp()

def converttonotebook.isCpp ( )
Return True if extension is a C++ file

Definition at line 642 of file converttonotebook.py.

◆ mainfunction()

def converttonotebook.mainfunction (   text)
Main function. Calls all other functions, depending on whether the macro input is in python or c++.
It adds the header information. Also, it adds a cell that draws all canvases. The working text is
then converted to a version 3 jupyter notebook, subsequently updated to a version 4. Then, metadata
associated with the language the macro is written in is attatched to he notebook. Finally the
notebook is executed and output as a Jupyter notebook.

Definition at line 660 of file converttonotebook.py.

◆ processmain()

def converttonotebook.processmain (   text)
Evaluates whether the main function returns a TCanvas or requires input. If it
does then the keepfunction flag is True, meaning the function wont be extracted
by cppFunction. If the initial condition is true then an extra cell is added
before at the end that calls the main function is returned, and added later.
>>> processmain('''void function(){
...    content of function
...    spanning several
...    lines
... }''')
('void function(){\\n   content of function\\n   spanning several\\n   lines\\n}', '')
>>> processmain('''void function(arguments = values){
...    content of function
...    spanning several
...    lines
... }''')
('void function(arguments = values){\\n   content of function\\n   spanning several\\n   lines\\n}', '# <markdowncell> \\n Arguments are defined. \\n# <codecell>\\narguments = values;\\n# <codecell>\\n')
>>> processmain('''void function(argument1 = value1, //comment 1
...                              argument2 = value2 /*comment 2*/ ,
...                              argument3 = value3, 
...                              argument4 = value4)
... {
...    content of function
...    spanning several
...    lines
... }''')
('void function(argument1 = value1, //comment 1\\n                             argument2 = value2 /*comment 2*/ ,\\n                             argument3 = value3, \\n                             argument4 = value4)\\n{\\n   content of function\\n   spanning several\\n   lines\\n}', '# <markdowncell> \\n Arguments are defined. \\n# <codecell>\\nargument1 = value1;\\nargument2 = value2;\\nargument3 = value3;\\nargument4 = value4;\\n# <codecell>\\n')
>>> processmain('''TCanvas function(){
...    content of function
...    spanning several 
...    lines
...    return c1
... }''') 
('TCanvas function(){\\n   content of function\\n   spanning several \\n   lines\\n   return c1\\n}', '')

Definition at line 504 of file converttonotebook.py.

◆ pythonComments()

def converttonotebook.pythonComments (   text)
Converts comments delimited by # or ## and on a new line into a markdown cell.
For python files only
>>> pythonComments('''## This is a
... ## multiline comment
... def function()''') 
'# <markdowncell>\\n## This is a\\n## multiline comment\\n# <codecell>\\ndef function()\\n'
>>> pythonComments('''def function():
...     variable = 5 # Comment not in cell
...     # Comment also not in cell''')
'def function():\\n    variable = 5 # Comment not in cell\\n    # Comment also not in cell\\n'

Definition at line 176 of file converttonotebook.py.

◆ pythonMainFunction()

def converttonotebook.pythonMainFunction (   text)

Definition at line 206 of file converttonotebook.py.

◆ readHeaderCpp()

def converttonotebook.readHeaderCpp (   text)
Extract author and description from header, eliminate header from text. Also returns
notebook boolean, which is True if the string \notebook is present in the header
Also determine options (-js, -nodraw, -header) passed in \notebook command, and
return their booleans
>>> readHeaderCpp('''/// \\file
... /// \\ingroup tutorials
... /// \\\\notebook
... /// This is the description of the tutorial
... ///
... /// \\macro_image
... /// \\macro_code
... ///
... /// \\\\author John Brown
... void tutorialfuncion(){}''')
('void tutorialfuncion(){}\\n', '# This is the description of the tutorial\\n# \\n# \\n', 'John Brown', True, False, False, False)
>>> readHeaderCpp('''/// \\file
... /// \\ingroup tutorials
... /// \\\\notebook -js
... /// This is the description of the tutorial
... ///
... /// \\macro_image
... /// \\macro_code
... ///
... /// \\\\author John Brown
... void tutorialfuncion(){}''')
('void tutorialfuncion(){}\\n', '# This is the description of the tutorial\\n# \\n# \\n', 'John Brown', True, True, False, False)
>>> readHeaderCpp('''/// \\file
... /// \\ingroup tutorials
... /// \\\\notebook -nodraw
... /// This is the description of the tutorial
... ///
... /// \\macro_image
... /// \\macro_code
... ///
... /// \\\\author John Brown
... void tutorialfuncion(){}''')
('void tutorialfuncion(){}\\n', '# This is the description of the tutorial\\n# \\n# \\n', 'John Brown', True, False, True, False)

Definition at line 231 of file converttonotebook.py.

◆ readHeaderPython()

def converttonotebook.readHeaderPython (   text)
Extract author and description from header, eliminate header from text. Also returns
notebook boolean, which is True if the string \notebook is present in the header
Also determine options (-js, -nodraw, -header) passed in \notebook command, and
return their booleans
>>> readHeaderPython('''## \\file
... ## \\ingroup tutorials
... ## \\\\notebook
... ## This is the description of the tutorial
... ##
... ## \\macro_image
... ## \\macro_code
... ##
... ## \\\\author John Brown
... def tutorialfuncion()''')
('def tutorialfuncion()\\n', 'This is the description of the tutorial\\n\\n\\n', 'John Brown', True, False, False, False)
>>> readHeaderPython('''## \\file
... ## \\ingroup tutorials
... ## \\\\notebook -js
... ## This is the description of the tutorial
... ##
... ## \\macro_image
... ## \\macro_code
... ##
... ## \\\\author John Brown
... def tutorialfuncion()''')
('def tutorialfuncion()\\n', 'This is the description of the tutorial\\n\\n\\n', 'John Brown', True, True, False, False)
>>> readHeaderPython('''## \\file
... ## \\ingroup tutorials
... ## \\\\notebook -nodraw
... ## This is the description of the tutorial
... ##
... ## \\macro_image
... ## \\macro_code
... ##
... ## \\\\author John Brown
... def tutorialfuncion()''')
('def tutorialfuncion()\\n', 'This is the description of the tutorial\\n\\n\\n', 'John Brown', True, False, True, False)

Definition at line 105 of file converttonotebook.py.

◆ removePaletteEditor()

def converttonotebook.removePaletteEditor (   code)

Definition at line 558 of file converttonotebook.py.

◆ roofitRemoveSpacesComments()

def converttonotebook.roofitRemoveSpacesComments (   code)

Definition at line 576 of file converttonotebook.py.

◆ rs401dGetFiles()

def converttonotebook.rs401dGetFiles (   code)

Definition at line 601 of file converttonotebook.py.

◆ runEventExe()

def converttonotebook.runEventExe (   code)

Definition at line 564 of file converttonotebook.py.

◆ split()

def converttonotebook.split (   text)
Splits the text string into main, helpers, and rest. main is the main function,
i.e. the function tha thas the same name as the macro file. Helpers is a list of
strings, each a helper function, i.e. any other function that is not the main function.
Finally, rest is a string containing any top-level code outside of any function.
Comments immediately prior to a helper cell are converted into markdown cell,
added to the helper, and removed from rest.
Intended for C++ files only.
>>> split('''void tutorial(){
...    content of tutorial
... }''')
('void tutorial(){\\n   content of tutorial\\n}', [], '')
>>> split('''void tutorial(){
...    content of tutorial
... }
... void helper(arguments = values){
...    helper function
...    content spans lines
... }''')
('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n A helper function is created: \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '')
>>> split('''#include <header.h>
... using namespace NAMESPACE
... void tutorial(){
...    content of tutorial
... }
... void helper(arguments = values){
...    helper function
...    content spans lines
... }''')
('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n A helper function is created: \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '#include <header.h>\\nusing namespace NAMESPACE')
>>> split('''void tutorial(){
...    content of tutorial
... }
... // This is a multiline
... // description of the
... // helper function
... void helper(arguments = values){
...    helper function
...    content spans lines
... }''')
('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n  This is a multiline\\n description of the\\n helper function\\n \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '')

Definition at line 375 of file converttonotebook.py.

◆ tree4GetFiles()

def converttonotebook.tree4GetFiles (   code)

Definition at line 614 of file converttonotebook.py.

◆ unindenter()

def converttonotebook.unindenter (   string,
  spaces = 3 
)
Returns string with each line unindented by 3 spaces. If line isn't indented, it stays the same.
>>> unindenter("   foobar")
'foobar\\n'
>>> unindenter("foobar")
'foobar\\n'
>>> unindenter('''foobar
...    foobar
... foobar''')
'foobar\\nfoobar\\nfoobar\\n'

Definition at line 82 of file converttonotebook.py.

Variable Documentation

◆ author

converttonotebook.author

Definition at line 827 of file converttonotebook.py.

◆ date

converttonotebook.date = datetime.now().strftime("%A, %B %d, %Y at %I:%M %p")

Definition at line 811 of file converttonotebook.py.

◆ description

converttonotebook.description

Definition at line 827 of file converttonotebook.py.

◆ extension

converttonotebook.extension

Definition at line 798 of file converttonotebook.py.

◆ gTypesList

list converttonotebook.gTypesList
Initial value:
1 = ["void", "int", "Int_t", "TF1", "string", "bool", "double", "float", "char",
2  "TCanvas", "TTree", "TString", "TSeqCollection", "Double_t", "TFile", "Long64_t", "Bool_t", "TH1",
3  "RooDataSet", "RooWorkspace" , "HypoTestInverterResult" , "TVectorD" , "TArrayF", "UInt_t"]

Definition at line 74 of file converttonotebook.py.

◆ isJsroot

converttonotebook.isJsroot

Definition at line 827 of file converttonotebook.py.

◆ isNotebook

converttonotebook.isNotebook

Definition at line 827 of file converttonotebook.py.

◆ needsHeaderFile

converttonotebook.needsHeaderFile

Definition at line 827 of file converttonotebook.py.

◆ nodraw

converttonotebook.nodraw

Definition at line 827 of file converttonotebook.py.

◆ outdir

converttonotebook.outdir = str(sys.argv[2])

Definition at line 805 of file converttonotebook.py.

◆ outname

string converttonotebook.outname = tutFileName + ".ipynb"

Definition at line 800 of file converttonotebook.py.

◆ outnameconverted

string converttonotebook.outnameconverted = tutFileName + ".nbconvert.ipynb"

Definition at line 801 of file converttonotebook.py.

◆ outPathName

converttonotebook.outPathName = os.path.join(outdir, outname)

Definition at line 809 of file converttonotebook.py.

◆ starttime

converttonotebook.starttime = time.time()

Definition at line 832 of file converttonotebook.py.

◆ text

converttonotebook.text = fin.read()

Definition at line 823 of file converttonotebook.py.

◆ tutFileName

converttonotebook.tutFileName = os.path.basename(tutPathName)

Definition at line 797 of file converttonotebook.py.

◆ tutName

converttonotebook.tutName = "tutorial"

Definition at line 784 of file converttonotebook.py.

◆ tutPath

converttonotebook.tutPath = os.path.dirname(tutPathName)

Definition at line 794 of file converttonotebook.py.

◆ tutPathName

converttonotebook.tutPathName = str(sys.argv[1])

Definition at line 793 of file converttonotebook.py.

◆ tutRelativePath

string converttonotebook.tutRelativePath = "$ROOTSYS/tutorials/%s/" % tutPath.split("/")[-1]

Definition at line 796 of file converttonotebook.py.

◆ tutTitle

converttonotebook.tutTitle = re.sub( r"([A-Z\d])", r" \1", tutName).title()

Definition at line 799 of file converttonotebook.py.

◆ verbose

converttonotebook.verbose

Definition at line 785 of file converttonotebook.py.