Bug #1611
Problem
Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Python API
Start date:
21 January 2015
Due date:
% Done:
100%
Estimated time:
Description
I run:
import cdb from cdb import BeamlineSuperMouse def main(): blm_super = BeamlineSuperMouse("http://preprodcdb.mice.rl.ac.uk") print blm_super.get_beamline_for_tag("6-200+M0") print blm_super.get_beamline_for_tag("MockDataRunTest2") if __name__ == "__main__": main()
and get:
{'6-200+M0': {'beam_stop': 'Open', 'diffuser_thickness': 6, 'magnets': {'Q1': 102.38, 'Q3': 89.0, 'Q2': 127.91, 'Q5': 212.02, 'Q4': 158.1, 'Q7': 138.67, 'Q6': 140.57, 'Q9': 179.18, 'Q8': 209.82, 'D2': 94.15, 'DS': 668.63, 'D1': 323.15}, 'proton_absorber_thickness': 6}} {'MockDataRunTest2': {'beam_stop': 'Open', 'diffuser_thickness': 1111, 'magnets': {'Q1': 184.4, 'Q3': 112.6, 'Q2': 101.2, 'Q5': 395.6, 'Q4': 295.0, 'Q7': 197.8, 'Q6': 260.9, 'Q9': 253.5, 'Q8': 298.4, 'D2': 167.7, 'DS': 200.0, 'D1': 387.9}, 'proton_absorber_thickness': 1111}, '6-200+M0': {'beam_stop': 'Open', 'diffuser_thickness': 6, 'magnets': {'Q1': 102.38, 'Q3': 89.0, 'Q2': 127.91, 'Q5': 212.02, 'Q4': 158.1, 'Q7': 138.67, 'Q6': 140.57, 'Q9': 179.18, 'Q8': 209.82, 'D2': 94.15, 'DS': 668.63, 'D1': 323.15}, 'proton_absorber_thickness': 6}}
I think I should get:
{'6-200+M0': {'beam_stop': 'Open', 'diffuser_thickness': 6, 'magnets': {'Q1': 102.38, 'Q3': 89.0, 'Q2': 127.91, 'Q5': 212.02, 'Q4': 158.1, 'Q7': 138.67, 'Q6': 140.57, 'Q9': 179.18, 'Q8': 209.82, 'D2': 94.15, 'DS': 668.63, 'D1': 323.15}, 'proton_absorber_thickness': 6}} {'MockDataRunTest2': {'beam_stop': 'Open', 'diffuser_thickness': 1111, 'magnets': {'Q1': 184.4, 'Q3': 112.6, 'Q2': 101.2, 'Q5': 395.6, 'Q4': 295.0, 'Q7': 197.8, 'Q6': 260.9, 'Q9': 253.5, 'Q8': 298.4, 'D2': 167.7, 'DS': 200.0, 'D1': 387.9}, 'proton_absorber_thickness': 1111}}
Updated by Rogers, Chris over 8 years ago
Note the issue is that on second call to get_beamline_for_tag
we get both beam settings out, not just the first beam setting out.
Updated by Martyniak, Janusz about 8 years ago
Hi Chris,
The bug is actually in the client code. The problem is that the XML parser is initialised only by the Beamline constructor and not by the get_beamline_for_tag(a_tag) method. Consequently the tags are added up as you call the method. The XML received from the server is correct:
<tags><tag name='MockDataRunTest2' beamStop='true' diffuserThickness='1111' protonAbsorberThickness='1111'> <magnet name='Q1' setCurrent='184.4'/><magnet name='Q2' setCurrent='101.2'/> <magnet name='Q3' setCurrent='112.6'/><magnet name='D1' setCurrent='387.9'/> <magnet name='DS' setCurrent='200.0'/><magnet name='D2' setCurrent='167.7'/> <magnet name='Q4' setCurrent='295.0'/><magnet name='Q5' setCurrent='395.6'/> <magnet name='Q6' setCurrent='260.9'/><magnet name='Q7' setCurrent='197.8'/> <magnet name='Q8' setCurrent='298.4'/><magnet name='Q9' setCurrent='253.5'/> </tag> </tags>
but the python call adds it's content to the existing dictionary created by a previous call.
The 'fix' : >>> def main(): ... blm_super = BeamlineSuperMouse("http://preprodcdb.mice.rl.ac.uk") ... print blm_super.get_beamline_for_tag("6-200+M0") ... blm_super = BeamlineSuperMouse("http://preprodcdb.mice.rl.ac.uk") ... print blm_super.get_beamline_for_tag("MockDataRunTest2") ... >>> if __name__ == "__main__": ... main() ...
I'll look into it in more details, the same parser is used for all 'get' calls, so I have to be sure if resetting it within a relevant method would not break something else. cheers JM
Updated by Martyniak, Janusz about 8 years ago
- Category set to Python API
Hello,
I fixed the code, the parser is now initialised at every method call:
>>> import cdb >>> from cdb import BeamlineSuperMouse >>> blm_super = BeamlineSuperMouse("http://preprodcdb.mice.rl.ac.uk") >>> print blm_super.get_beamline_for_tag("6-200+M0") {'6-200+M0': {'beam_stop': 'Open', 'diffuser_thickness': 0, 'magnets': {'Q1': 102.4, 'Q3': 89.0, 'Q2': 127.9, 'Q5': 212.0, 'Q4': 158.1, 'Q7': 138.7, 'Q6': 140.6, 'Q9': 179.2, 'Q8': 209.8, 'D2': 94.2, 'DS': 668.6, 'D1': 323.1}, 'proton_absorber_thickness': 82}} >>> print blm_super.get_beamline_for_tag_xml("6-200+M0") <tags> <tag name='6-200+M0' beamStop='true' diffuserThickness='0' protonAbsorberThickness='82'> <magnet name='Q1' setCurrent='102.4'/> <magnet name='Q2' setCurrent='127.9'/> <magnet name='Q3' setCurrent='89.0'/> <magnet name='D1' setCurrent='323.1'/> <magnet name='DS' setCurrent='668.6'/> <magnet name='D2' setCurrent='94.2'/> <magnet name='Q4' setCurrent='158.1'/> <magnet name='Q5' setCurrent='212.0'/> <magnet name='Q6' setCurrent='140.6'/> <magnet name='Q7' setCurrent='138.7'/> <magnet name='Q8' setCurrent='209.8'/> <magnet name='Q9' setCurrent='179.2'/> </tag> </tags> >>> print blm_super.get_beamline_for_tag("MockDataRunTest2") {'MockDataRunTest2': {'beam_stop': 'Open', 'diffuser_thickness': 1111, 'magnets': {'Q1': 184.4, 'Q3': 112.6, 'Q2': 101.2, 'Q5': 395.6, 'Q4': 295.0, 'Q7': 197.8, 'Q6': 260.9, 'Q9': 253.5, 'Q8': 298.4, 'D2': 167.7, 'DS': 200.0, 'D1': 387.9}, 'proton_absorber_thickness': 1111}}
The code is uploaded to:
bzr+ssh://bazaar.launchpad.net/~janusz-martyniak/mcdb/mice.cdb.client.api-python/
I also added
get_beamline_for_tag_xml(tag)
method for convenience.
Thanks, JM
Updated by Martyniak, Janusz over 5 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
Fixed and closed.