/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Classes | Functions | Variables
RandomGain::Tools Namespace Reference

Classes

class  PmtTableWriterAlg

Functions

def mergeTables
def parseTable

Variables

list __all__ = [ "PmtTableWriterAlg", "mergeTables", "parseTable" ]
 Detector = gbl.DayaBay.Detector
 Site = gbl.Site
 DetectorId = gbl.DetectorId
 Context = gbl.Context
 TimeStamp = gbl.TimeStamp
 ServiceMode = gbl.ServiceMode
 PmtCalibData = gbl.DayaBay.PmtCalibData
 AdPmtSensor = gbl.DayaBay.AdPmtSensor

Function Documentation

def RandomGain::Tools::mergeTables (   primaryFile,
  changeMap,
  outputFile 
)

Definition at line 404 of file Tools.py.

00405                                                    :
00406     "Simple Non-NuWa python function for merging calibration text tables"
00407     inputTable = parseTable(primaryFile)
00408     # Update table
00409     for changeFile in changeMap.keys():
00410         changeTable = parseTable(changeFile)
00411         changeFields = changeMap[changeFile]
00412         for fieldName in changeFields:
00413             fieldName = fieldName.strip()
00414             if not inputTable["columns"].has_key(fieldName):
00415                 print "Field \"",fieldName,"\" doesn't exist in input table."
00416                 return
00417             inputTable["columns"][fieldName] = changeTable["columns"][fieldName]
00418     # Write output table comments and header
00419     outputTableLines = []
00420     for comment in inputTable["comments"]:
00421         outputTableLines.append(comment)
00422     outputTableLines.append(inputTable["header"])
00423     # determine field lengths
00424     fieldLength = {}
00425     for fieldName in inputTable["fields"]:
00426         fieldLength[fieldName] = max( [len(data) for data in
00427                                        inputTable["columns"][fieldName] ] )
00428     # write data lines
00429     for rowIdx in range(inputTable["numberOfRows"]):
00430         line = ""
00431         for fieldName in inputTable["fields"]:
00432             format = "%"+str(fieldLength[fieldName])+"s " 
00433             line += format % inputTable["columns"][fieldName][rowIdx]
00434         outputTableLines.append(line+"\n")
00435     open(outputFile,"w").writelines(outputTableLines)

def RandomGain::Tools::parseTable (   filename)

Definition at line 436 of file Tools.py.

00437                         :
00438     "Simple text table parser"
00439     tableLines = open(filename).readlines()
00440     fieldNames = []
00441     comments = []
00442     headerLine = None
00443     columns = {}
00444     nRows = 0
00445     for line in tableLines:
00446         data = line.strip()
00447         # Catch comments / header
00448         if len(data)>0 and data[0]=='#':
00449             comment = data[1:].strip()
00450             if len(comment)>0 and comment[0] =='[':
00451                 # Found header
00452                 if len(fieldNames) > 0:
00453                     print "Headers already defined by line \"",line,"\""
00454                     return None
00455                 tokens = comment.split(']')
00456                 if len(tokens[-1].strip())==0: tokens = tokens[:-1]
00457                 for token in tokens:
00458                     fieldStart = token.rfind('[')
00459                     if fieldStart<0:
00460                         print "Invalid token \"",token,"\" in line \"",line,"\""
00461                         return None
00462                     fieldName = token[fieldStart+1:].strip()
00463                     fieldNames.append(fieldName)
00464                     columns[fieldName] = []
00465                 headerLine = line
00466             else:
00467                 comments.append(line)
00468             continue
00469         # Data line
00470         fields = data.split()
00471         if len(fields)==0: continue  # Empty line
00472         if len(fields) != len(columns):
00473             print "Invalid number of fields in line \"",line,"\""
00474             return None
00475         for fieldIdx in range(len(fields)):
00476             columns[fieldNames[fieldIdx]].append( fields[fieldIdx] )
00477         nRows += 1
00478     return { "fields":fieldNames,
00479              "comments":comments,
00480              "header":headerLine,
00481              "columns":columns,
00482              "numberOfRows":nRows}

Variable Documentation

list RandomGain::Tools::__all__ = [ "PmtTableWriterAlg", "mergeTables", "parseTable" ]

Definition at line 6 of file Tools.py.

Definition at line 16 of file Tools.py.

Definition at line 17 of file Tools.py.

Definition at line 18 of file Tools.py.

Definition at line 19 of file Tools.py.

Definition at line 20 of file Tools.py.

Definition at line 21 of file Tools.py.

RandomGain::Tools::PmtCalibData = gbl.DayaBay.PmtCalibData

Definition at line 22 of file Tools.py.

Definition at line 23 of file Tools.py.

| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:03:04 for RandomGain by doxygen 1.7.4