~christopher-hunt08/maus/maus_mc_control

« back to all changes in this revision

Viewing changes to src/output/OutputPyImage/OutputPyImage.py

  • Committer: Durga Rajaram
  • Date: 2013-07-24 00:19:08 UTC
  • mfrom: (659.1.72 release-candidate)
  • Revision ID: durga@fnal.gov-20130724001908-hw36h7kefglgaw3l
Tags: MAUS-v0.6.0
MAUS-v0.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        self.file_prefix = "image"
60
60
        self.directory = os.getcwd()
61
61
        self.end_of_run_directory = os.getcwd()+'/end_of_run/'
62
 
        self.last_event = {}
 
62
        self.last_event = {'maus_event_type':'Image', 'image_list':[]}
63
63
        self.run_number = -9999
64
64
 
65
65
    def birth(self, config_json):
100
100
        """
101
101
        json_doc = json.loads(document)
102
102
        if "maus_event_type" not in json_doc.keys():
103
 
            print json_doc
104
103
            raise KeyError("Expected maus_event_type in json_doc")
105
104
        if json_doc["maus_event_type"] == "Image":
106
 
            self.last_event = json_doc
 
105
            if "image_list" not in json_doc:
 
106
                raise KeyError("Expected image_list in json_doc")      
 
107
            if len(json_doc["image_list"]) > 0: # could search for unique tags
 
108
                self.last_event = json_doc
107
109
            for image in json_doc["image_list"]:
108
110
                self.__handle_image(image, False)
109
111
        elif json_doc["maus_event_type"] == "RunFooter":
110
112
            self.run_number = json_doc["run_number"]
111
113
            for image in self.last_event["image_list"]:
112
114
                self.__handle_image(image, True)
 
115
        else:
 
116
            print "OutputPyImage will not process maus event of type "+\
 
117
                                                str(json_doc["maus_event_type"])
113
118
 
114
119
    def death(self): #pylint: disable=R0201
115
120
        """
163
168
        directory = self.directory
164
169
        if is_end_of_run:
165
170
            directory = self.end_of_run_directory+"/"+str(self.run_number)
166
 
        if not os.path.exists(directory):
167
 
            os.makedirs(directory) 
168
 
        if (not os.path.isdir(directory)):
169
 
            raise ValueError("image_directory is a file: %s" % directory)
 
171
        # Rogers - coincident call to makedirs from two reducers caused crash -
 
172
        # add try ... except ...
 
173
        try:
 
174
            if not os.path.exists(directory):
 
175
                os.makedirs(directory) 
 
176
            if not os.path.isdir(directory):
 
177
                raise ValueError("image_directory is a file: %s" % directory)
 
178
        except OSError:
 
179
            pass
170
180
        file_path = os.path.join(directory, file_name)
171
181
        return file_path
172
182