| 1 |
# Copyright(C) 1999-2020, 2024 National Technology & Engineering Solutions |
| 2 |
# of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
# NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
# |
| 5 |
# Redistribution and use in source and binary forms, with or without |
| 6 |
# modification, are permitted provided that the following conditions are |
| 7 |
# met: |
| 8 |
# |
| 9 |
# * Redistributions of source code must retain the above copyright |
| 10 |
# notice, this list of conditions and the following disclaimer. |
| 11 |
# |
| 12 |
# * Redistributions in binary form must reproduce the above |
| 13 |
# copyright notice, this list of conditions and the following |
| 14 |
# disclaimer in the documentation and/or other materials provided |
| 15 |
# with the distribution. |
| 16 |
# |
| 17 |
# * Neither the name of NTESS nor the names of its |
| 18 |
# contributors may be used to endorse or promote products derived |
| 19 |
# from this software without specific prior written permission. |
| 20 |
# |
| 21 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 24 |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 25 |
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 26 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 27 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 |
|
| 33 |
from phactori import * |
| 34 |
import datetime |
| 35 |
|
| 36 |
#phactori_combine_to_single_python_file_subpiece_begin_1 |
| 37 |
|
| 38 |
class PhactoriDataArtifactMetaDataControl: |
| 39 |
def __init__(self, myProcessId, numProcesses): |
| 40 |
self.outputEnabled = True |
| 41 |
self.artifactListCsvFileName = None |
| 42 |
self.artifactListCsvFileHandle = None |
| 43 |
self.artifactListTryOpenCount = 0 |
| 44 |
self.thisProcessIsWritingProcess = -1 |
| 45 |
if myProcessId == int(numProcesses/2): |
| 46 |
self.thisProcessIsWritingProcess = 1 |
| 47 |
else: |
| 48 |
self.thisProcessIsWritingProcess = 0 |
| 49 |
if PhactoriDbg(100): |
| 50 |
myDebugPrint3("PhactoriDataArtifactMetaDataControl:__init__ " + \ |
| 51 |
str(myProcessId) + ", " + str(numProcesses) + ", " + \ |
| 52 |
str(self.thisProcessIsWritingProcess) + "\n", 100) |
| 53 |
|
| 54 |
def EnableOutput(self, onOff): |
| 55 |
self.outputEnabled = onOff |
| 56 |
|
| 57 |
def CloseFiles(self): |
| 58 |
if self.artifactListCsvFileHandle != None: |
| 59 |
self.artifactListCsvFileHandle.close() |
| 60 |
|
| 61 |
def ThisProcessIsWritingProcess(self): |
| 62 |
return self.thisProcessIsWritingProcess > 0 |
| 63 |
|
| 64 |
def DataArtifactOutputListOpen(self): |
| 65 |
if self.artifactListCsvFileHandle == None: |
| 66 |
if self.artifactListTryOpenCount > 0: |
| 67 |
return False |
| 68 |
self.artifactListTryOpenCount += 1 |
| 69 |
myNow = datetime.datetime.now() |
| 70 |
myFormat = "%Y-%m-%d-%H:%M:%S" |
| 71 |
self.artifactListCsvFileName = "DataArtifactList_" + myNow.strftime(myFormat) + ".csv" |
| 72 |
self.artifactListCsvFileHandle = open(self.artifactListCsvFileName, "w") |
| 73 |
if self.artifactListCsvFileHandle == None: |
| 74 |
print("AddImageToDataArtifactOutputList: unable to open file:\n", |
| 75 |
self.artifactListCsvFileName) |
| 76 |
return False |
| 77 |
return True |
| 78 |
|
| 79 |
def CheckIfDoOutput(self): |
| 80 |
if self.outputEnabled == False: |
| 81 |
return False |
| 82 |
|
| 83 |
if self.ThisProcessIsWritingProcess() == False: |
| 84 |
return False |
| 85 |
|
| 86 |
if self.DataArtifactOutputListOpen() == False: |
| 87 |
return False |
| 88 |
|
| 89 |
return True |
| 90 |
|
| 91 |
def AddDataArtifactToDataArtifactOutputList(self, fileName): |
| 92 |
|
| 93 |
if self.CheckIfDoOutput() == False: |
| 94 |
return |
| 95 |
|
| 96 |
myNow = datetime.datetime.now() |
| 97 |
outDate = str(myNow) |
| 98 |
outStr = fileName + "," + outDate + "\n" |
| 99 |
self.artifactListCsvFileHandle.write(outStr) |
| 100 |
self.artifactListCsvFileHandle.flush() |
| 101 |
|
| 102 |
def AddDataExportToDataArtifactOutputList(self, fileName): |
| 103 |
self.AddDataArtifactToDataArtifactOutputList(fileName) |
| 104 |
|
| 105 |
def AddImageToDataArtifactOutputList(self, fileName): |
| 106 |
self.AddDataArtifactToDataArtifactOutputList(fileName) |
| 107 |
|
| 108 |
if __name__ == '__main__': |
| 109 |
pdamdc = PhactoriDataArtifactMetaDataControl(1,2) |
| 110 |
pdamdc.AddImageToDataArtifactOutputList("CatalystOutput/test1.png") |
| 111 |
pdamdc.AddDataExportToDataArtifactOutputList("CatalystVtkDataOutput/test2.vtm") |
| 112 |
|
| 113 |
#phactori_combine_to_single_python_file_subpiece_end_1 |