def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlReadImageHeaderv10.preProcess")
     # First determine the type of image
     xsDataInputReadImageHeader = self.getDataInput()
     xsDataFileImage = xsDataInputReadImageHeader.getImage()
     self.strFileImagePath = xsDataFileImage.getPath().getValue()
     # Plugin for waiting for files
     self.edPluginExecMXWaitFile = self.loadPlugin(self.strPluginExecMXWaitFile)
     xsDataInputMXWaitFile = XSDataInputMXWaitFile()
     xsDataInputMXWaitFile.setFile(XSDataFile(XSDataString(self.strFileImagePath)))
     xsDataInputMXWaitFile.setSize(XSDataInteger(100000))
     xsDataInputMXWaitFile.setTimeOut(XSDataTime(self.fMXWaitFileTimeOut))
     self.edPluginExecMXWaitFile.setDataInput(xsDataInputMXWaitFile)
Ejemplo n.º 2
0
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlReadImageHeaderv10.preProcess")
     # First determine the type of image
     xsDataInputReadImageHeader = self.getDataInput()
     xsDataFileImage = xsDataInputReadImageHeader.getImage()
     self.strFileImagePath = xsDataFileImage.getPath().getValue()
     # Plugin for waiting for files
     self.edPluginExecMXWaitFile = self.loadPlugin(
         self.strPluginExecMXWaitFile)
     xsDataInputMXWaitFile = XSDataInputMXWaitFile()
     xsDataInputMXWaitFile.setFile(
         XSDataFile(XSDataString(self.strFileImagePath)))
     xsDataInputMXWaitFile.setSize(XSDataInteger(100000))
     xsDataInputMXWaitFile.setTimeOut(XSDataTime(self.fMXWaitFileTimeOut))
     self.edPluginExecMXWaitFile.setDataInput(xsDataInputMXWaitFile)
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlPyarchThumbnailGeneratorv1_0.preProcess")
     # Check that the input image exists and is of the expected type
     strPathToDiffractionImage = self.dataInput.diffractionImage.path.value
     strImageFileNameExtension = os.path.splitext(strPathToDiffractionImage)[1]
     if not strImageFileNameExtension in [".img", ".marccd", ".mccd", ".cbf", ".h5"]:
         self.error("Unknown image file name extension for pyarch thumbnail generator: %s" % strPathToDiffractionImage)
         self.setFailure()
     else:
         # Load the MXWaitFile plugin
         xsDataInputMXWaitFile = XSDataInputMXWaitFile()
         pathToImageFile = strPathToDiffractionImage
         # Quite ugly hack to avoid lag problems at the ESRF:
         if EDUtilsPath.isESRF():
             if any(beamline in strPathToDiffractionImage for beamline in ["id23eh1", "id29", "id30b"]):
                 # Pilatus 6M
                 self.minImageSize = 6000000
             elif any(beamline in strPathToDiffractionImage for beamline in ["id23eh2", "id30a1"]):
                 # Pilatus3 2M
                 self.minImageSize = 2000000
             elif strImageFileNameExtension == ".h5":
                 self.h5MasterFilePath, self.h5DataFilePath, self.h5FileNumber = self.getH5FilePath(pathToImageFile)
                 pathToImageFile = self.h5DataFilePath
                 self.isH5 = True
         elif EDUtilsPath.isEMBL():
                 self.minImageSize = 10000
         xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
         xsDataInputMXWaitFile.setFile(XSDataFile(XSDataString(pathToImageFile)))
         if self.getDataInput().getWaitForFileTimeOut():
             xsDataInputMXWaitFile.setTimeOut(self.getDataInput().getWaitForFileTimeOut())
         self.edPluginMXWaitFile = self.loadPlugin(self.strMXWaitFilePluginName)
         self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
         # Load the execution plugin
         self.edPluginExecThumbnail = self.loadPlugin(self.strExecThumbnailPluginName)
         xsDataInputMXThumbnail = XSDataInputMXThumbnail()
         xsDataInputMXThumbnail.image = self.getDataInput().getDiffractionImage()
         xsDataInputMXThumbnail.height = XSDataInteger(1024)
         xsDataInputMXThumbnail.width = XSDataInteger(1024)
         xsDataInputMXThumbnail.format = self.dataInput.format
         # Output path
         strImageNameWithoutExt = os.path.basename(os.path.splitext(strPathToDiffractionImage)[0])
         strImageDirname = os.path.dirname(strPathToDiffractionImage)
         if self.getDataInput().getForcedOutputDirectory():
             strForcedOutputDirectory = self.getDataInput().getForcedOutputDirectory().getPath().getValue()
             if not os.access(strForcedOutputDirectory, os.W_OK):
                 self.error("Cannot write to forced output directory : %s" % strForcedOutputDirectory)
                 self.setFailure()
             else:
                 self.strOutputPathWithoutExtension = os.path.join(strForcedOutputDirectory, strImageNameWithoutExt)
         else:
             # Try to store in the ESRF pyarch directory
             strOutputDirname = EDHandlerESRFPyarchv1_0.createPyarchFilePath(strImageDirname)
             # Check that output pyarch path exists and is writeable:
             bIsOk = False
             if strOutputDirname:
                 if not os.path.exists(strOutputDirname):
                     # Try to create the directory
                     try:
                         os.makedirs(strOutputDirname)
                         bIsOk = True
                     except Exception as e:
                         self.WARNING("Couldn't create the directory %s" % strOutputDirname)
                 elif os.access(strOutputDirname, os.W_OK):
                     bIsOk = True
             if not bIsOk:
                 self.warning("Cannot write to pyarch directory: %s" % strOutputDirname)
                 strTmpUser = os.path.join("/tmp", os.environ["USER"])
                 if not os.path.exists(strTmpUser):
                     os.mkdir(strTmpUser, 0755)
                 strOutputDirname = tempfile.mkdtemp(prefix="EDPluginPyarchThumbnailv10_", dir=strTmpUser)
                 os.chmod(strOutputDirname, 0755)
                 self.warning("Writing thumbnail images to: %s" % strOutputDirname)
             self.strOutputPathWithoutExtension = os.path.join(strOutputDirname, strImageNameWithoutExt)
         if self.dataInput.format is not None:
             self.strSuffix = self.dataInput.format.value.lower()
             self.strImageFormat = self.dataInput.format.value.upper()
         self.strOutputPath = os.path.join(self.strOutputPathWithoutExtension + "." + self.strSuffix)
         xsDataInputMXThumbnail.setOutputPath(XSDataFile(XSDataString(self.strOutputPath)))
         self.edPluginExecThumbnail.setDataInput(xsDataInputMXThumbnail)
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlPyarchThumbnailGeneratorv1_0.preProcess")
     # Check that the input image exists and is of the expected type
     strPathToDiffractionImage = self.dataInput.diffractionImage.path.value
     strImageFileNameExtension = os.path.splitext(
         strPathToDiffractionImage)[1]
     if not strImageFileNameExtension in [
             ".img", ".marccd", ".mccd", ".cbf", ".h5"
     ]:
         self.error(
             "Unknown image file name extension for pyarch thumbnail generator: %s"
             % strPathToDiffractionImage)
         self.setFailure()
     else:
         # Load the MXWaitFile plugin
         xsDataInputMXWaitFile = XSDataInputMXWaitFile()
         pathToImageFile = strPathToDiffractionImage
         # Quite ugly hack to avoid lag problems at the ESRF:
         if EDUtilsPath.isESRF() or EDUtilsPath.isALBA():
             if any(beamline in strPathToDiffractionImage
                    for beamline in ["id23eh1", "id29", "id30b"]):
                 # Pilatus 6M
                 self.minImageSize = 6000000
             elif any(beamline in strPathToDiffractionImage
                      for beamline in ["id23eh2", "id30a1"]):
                 # Pilatus3 2M
                 self.minImageSize = 2000000
             elif strImageFileNameExtension == ".h5":
                 self.h5MasterFilePath, self.h5DataFilePath, self.h5FileNumber = self.getH5FilePath(
                     pathToImageFile)
                 pathToImageFile = self.h5DataFilePath
                 self.isH5 = True
         elif EDUtilsPath.isEMBL():
             self.minImageSize = 10000
         xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
         xsDataInputMXWaitFile.setFile(
             XSDataFile(XSDataString(pathToImageFile)))
         if self.getDataInput().getWaitForFileTimeOut():
             xsDataInputMXWaitFile.setTimeOut(
                 self.getDataInput().getWaitForFileTimeOut())
         self.edPluginMXWaitFile = self.loadPlugin(
             self.strMXWaitFilePluginName)
         self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
         # Load the execution plugin
         self.edPluginExecThumbnail = self.loadPlugin(
             self.strExecThumbnailPluginName)
         xsDataInputMXThumbnail = XSDataInputMXThumbnail()
         xsDataInputMXThumbnail.image = self.getDataInput(
         ).getDiffractionImage()
         xsDataInputMXThumbnail.height = XSDataInteger(1024)
         xsDataInputMXThumbnail.width = XSDataInteger(1024)
         xsDataInputMXThumbnail.format = self.dataInput.format
         # Output path
         strImageNameWithoutExt = os.path.basename(
             os.path.splitext(strPathToDiffractionImage)[0])
         strImageDirname = os.path.dirname(strPathToDiffractionImage)
         if self.getDataInput().getForcedOutputDirectory():
             strForcedOutputDirectory = self.getDataInput(
             ).getForcedOutputDirectory().getPath().getValue()
             if not os.access(strForcedOutputDirectory, os.W_OK):
                 self.error("Cannot write to forced output directory : %s" %
                            strForcedOutputDirectory)
                 self.setFailure()
             else:
                 self.strOutputPathWithoutExtension = os.path.join(
                     strForcedOutputDirectory, strImageNameWithoutExt)
         else:
             # Try to store in the ESRF pyarch directory
             strOutputDirname = EDHandlerESRFPyarchv1_0.createPyarchFilePath(
                 strImageDirname)
             # Check that output pyarch path exists and is writeable:
             bIsOk = False
             if strOutputDirname:
                 if not os.path.exists(strOutputDirname):
                     # Try to create the directory
                     try:
                         os.makedirs(strOutputDirname)
                         bIsOk = True
                     except Exception as e:
                         self.WARNING("Couldn't create the directory %s" %
                                      strOutputDirname)
                 elif os.access(strOutputDirname, os.W_OK):
                     bIsOk = True
             if not bIsOk:
                 self.warning("Cannot write to pyarch directory: %s" %
                              strOutputDirname)
                 strTmpUser = os.path.join("/tmp", os.environ["USER"])
                 if not os.path.exists(strTmpUser):
                     os.mkdir(strTmpUser, 0o755)
                 strOutputDirname = tempfile.mkdtemp(
                     prefix="EDPluginPyarchThumbnailv10_", dir=strTmpUser)
                 os.chmod(strOutputDirname, 0o755)
                 self.warning("Writing thumbnail images to: %s" %
                              strOutputDirname)
             self.strOutputPathWithoutExtension = os.path.join(
                 strOutputDirname, strImageNameWithoutExt)
         if self.dataInput.format is not None:
             self.strSuffix = self.dataInput.format.value.lower()
             self.strImageFormat = self.dataInput.format.value.upper()
         self.strOutputPath = os.path.join(
             self.strOutputPathWithoutExtension + "." + self.strSuffix)
         xsDataInputMXThumbnail.setOutputPath(
             XSDataFile(XSDataString(self.strOutputPath)))
         self.edPluginExecThumbnail.setDataInput(xsDataInputMXThumbnail)