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

In This Package:

Metadata.py

Go to the documentation of this file.
00001 class Metadata:
00002 
00003     # Constants
00004     SENSOR_DAYABAY = 'DAYABAY > The Entire DayaBay Experiment'
00005     SENSOR_DB = 'DAYABAY-DB > The DayaBay (near) Hall of DayaBay Experiment'
00006     SENSOR_LA = 'DAYABAY-LA > The Ling Ao Hall of the DayaBay Experiment'
00007     SENSOR_FH = 'DAYABAY-FH > The Far Hall of the DayaBay Experiment'
00008     SENSOR_SAB = 'DAYABAY-SAB > The Surface Assembly Building of the DayaBay Experiment'
00009 
00010     DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
00011 
00012     # Constants that define the XML representation of the metadata
00013     ROOT = (0, 0)
00014     DIF = (1, 0)
00015     PLUS = (1, DIF[1] + 1)
00016     ENTRY_ID = (2, 0)
00017     ENTRY_TITLE = (2, ENTRY_ID[1] + 1)
00018     PARAMETERS = (2, ENTRY_TITLE[1] + 1)
00019     ISO_TOPIC = (2, PARAMETERS[1] + 1)
00020     DATA_CENTER = (2, ISO_TOPIC[1] + 1)
00021     SUMMARY = (2, DATA_CENTER[1] + 1)
00022     META_NAME = (2, SUMMARY[1] + 1)
00023     META_VERS = (2, META_NAME[1] + 1)
00024     SENSOR = (2, META_VERS[1] + 1)
00025     SOURCE = (2, SENSOR[1] + 1)
00026     ORIGIN = (2, SOURCE[1] + 1)
00027     CREATION = (2, ORIGIN[1] + 1)
00028     START_TIME = (2, CREATION[1] + 1)
00029     END_TIME = (2, START_TIME[1] + 1)
00030     CATEGORY = (2, END_TIME[1] + 1)
00031     SUB_CATEGORY = (2, CATEGORY[1] + 1)
00032     COMMAND_LINE = (2, SUB_CATEGORY[1] + 1)
00033     DATA_CENTER_NAME = (3, 0)
00034     DC_PERSONNEL = (3, DATA_CENTER_NAME[1] + 1)
00035     DC_ROLE = (4, 0)
00036     DC_CONTACT = (4, DC_ROLE[1] + 1)
00037 
00038     ELEMENTS = ['',
00039                 [('DIF', ROOT[1]),
00040                      ('Plus', ROOT[1])],
00041                 [('Entry_ID', DIF[1]),
00042                    ('Entry_Title', DIF[1]),
00043                    ('Parameters', DIF[1]),
00044                    ('ISO_Topic_Category', DIF[1]),
00045                    ('Data_Center', DIF[1]),
00046                    ('Summary', DIF[1]),
00047                    ('Metadata_Name', DIF[1]),
00048                    ('Metadata_Version', DIF[1]),
00049                    ('Sensor_Name', DIF[1]),
00050                    ('Source_Name', DIF[1]),
00051                    ('Originating_Center', DIF[1]),
00052                    ('DIF_Creation_Date', DIF[1]),
00053                    ('Start_DateTime', PLUS[1]),
00054                    ('End_DateTime', PLUS[1]),
00055                    ('Category', PLUS[1]),
00056                    ('Subcategory', PLUS[1]),
00057                    ('Command_Line', PLUS[1])],
00058                 [('Data_Center_Name', DATA_CENTER[1]),
00059                      ('Personnel', DATA_CENTER[1])],
00060                 [('Role', DC_PERSONNEL[1]),
00061                      ('Contact_Address', DC_PERSONNEL[1])]]
00062 
00063 
00064     def __init__(self,
00065                  fileId):
00066         import socket
00067         host = socket.gethostname()
00068         from time import gmtime
00069         self.entryId = fileId
00070         self.title = 'title'
00071         self.parameters = 'PARTICLE PHYSICS > Neutrinos > Mixing'
00072         if host.endswith('.cn'):
00073             self.dataCenter = {'name':'IHEP/BEIJING > Institute of High Energy Physics, Beijing, China'}
00074         else:
00075             self.dataCenter = {'name':'DOE/LBNL > Lawrence Berkeley National Laboratory, U. S. Department of Energy'}
00076         self.summary = 'My Summary'
00077         self.sensor = self.SENSOR_DAYABAY
00078         self.source = 'SIMULATION > Data which are numerically generated'
00079         self.origin = host
00080         self.creationDate = None
00081         self.startTime = gmtime(0)
00082         self.endTime = gmtime(0)
00083         self.category = 'calibration'
00084         self.subcategory = 'unset'
00085         self.commandLine = ''
00086 
00087 
00088     def createXML(self):
00089         # Create the minidom document
00090         from xml.dom.minidom import Document
00091         self.doc = Document()
00092         dif_plus = self.doc.createElement('DIF_Plus')
00093         dif_plus.setAttribute('xmlns:xsi',
00094                               'http://www.w3.org/2001/XMLSchema-instance')
00095         dif_plus.setAttribute('xsi:noNamespaceSchemaLocation',
00096                               'http://dayabay.lbl.gov/xml/spade/v0.1/DybMetadata.xsd')
00097         self.doc.appendChild(dif_plus)
00098 
00099         self.nodes = [[dif_plus],
00100                  [],
00101                  [],
00102                  [],
00103                  []]
00104 
00105         from time import strftime
00106         for depth in range (1, len(self.nodes)):
00107             for e in range(0, len(self.ELEMENTS[depth])):
00108                 self.nodes[depth].append(self.doc.createElement(self.ELEMENTS[depth][e][0]))
00109                 self.nodes[depth - 1][self.ELEMENTS[depth][e][1]].appendChild(self.nodes[depth][e])
00110         self.fillNode(self.ENTRY_ID,
00111                       self.entryId)        
00112         self.fillNode(self.ENTRY_TITLE,
00113                       self.title)
00114         self.fillNode(self.PARAMETERS,
00115                       self.parameters)
00116         self.fillNode(self.ISO_TOPIC,
00117                       'Geoscientific Information')
00118         self.fillNode(self.DATA_CENTER_NAME,
00119                       self.dataCenter['name'])
00120         self.fillNode(self.DC_ROLE,
00121                       'Data Center Contact')
00122         self.fillNode(self.SUMMARY,
00123                       self.summary)
00124         self.fillNode(self.META_NAME,
00125                       'DIF')
00126         self.fillNode(self.META_VERS,
00127                       '9.7.1')
00128         self.fillNode(self.SENSOR,
00129                       self.sensor)
00130         self.fillNode(self.SOURCE,
00131                       self.source)
00132         self.fillNode(self.ORIGIN,
00133                       self.origin)
00134         if (None == self.creationDate):
00135             self.creationDate = self.today()
00136         self.fillNode(self.CREATION,
00137                       self.creationDate)
00138         self.fillNode(self.START_TIME,
00139                       strftime(self.DATETIME_FORMAT,
00140                                self.startTime))
00141         self.fillNode(self.END_TIME,
00142                       strftime(self.DATETIME_FORMAT,
00143                                self.endTime))
00144         self.fillNode(self.CATEGORY,
00145                       self.category)
00146         self.fillNode(self.SUB_CATEGORY,
00147                       self.subcategory)
00148         self.fillNode(self.COMMAND_LINE,
00149                       self.commandLine)
00150         return self.doc
00151         
00152 
00153     def fillNode(self,
00154                  element,
00155                  text):
00156         self.nodes[element[0]][element[1]].appendChild(self.doc.createTextNode(text))    
00157 
00158 
00159     def today(self):
00160         from time import gmtime, strftime
00161         return strftime('%Y-%m-%d',
00162                         gmtime())
00163 
00164 if __name__ == '__main__' :
00165     fileId = 'filebase'
00166     outFile = open(fileId + '.meta.xml',
00167                    'w')
00168     metadata = Metadata(fileId)
00169     outFile.write(metadata.createXML().toxml())
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:12:48 2011 for SpadeSvc by doxygen 1.4.7