Project

General

Profile

Bug #1274

Json to Cpp UInt conversion failure

Added by Lane, Peter over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Urgent
Assignee:
Taylor, Ian
Category:
Data Structure
Target version:
Start date:
03 May 2013
Due date:
% Done:

100%

Estimated time:
Workflow:
Under Test

Description

My MapCppGlobalRawTracks class uses the new global recon data structure to store Tracks under GlobalEvent. Upon attempting to write a ROOT file using the standard outputer I get the following error:

Traceback (most recent call last):
File "/home/lane/Development/maus/devel/src/common_py/ErrorHandler.py", line 162, in HandleCppException
raise CppError(error_message)
ErrorHandler.CppError: In branch recon_events
In branch global_event
In branch tracks
In branch detector_points
Failed to convert json value "0
// {"path":"#recon_events/0/global_event/tracks/2/detector_points"}

" to unsigned int at UIntProcessor::JsonToCpp

NOTE: I modified the UIntProcessor error message to show the actual json value it choked on:

unsigned int* UIntProcessor::JsonToCpp(const Json::Value& json_uint) {
  if (json_uint.isUInt()) {
      return new unsigned int (json_uint.asUInt());
  } else if (json_uint.isInt() && json_uint.asInt() > 0) {
      return new unsigned int (json_uint.asUInt());
  } else {
      std::stringstream message;
      message << "Failed to convert json value \"" << json_uint << "\"" 
              << " to unsigned int";
      throw(Squeal(
          Squeal::recoverable,
          message.str(),
          "UIntProcessor::JsonToCpp" 
      ));
  }
}

The easiest way to reproduce this is to modify simulate_mice.py to simply read in a JSON document and write out a root file (attached load_json.py), and create a configuration file (attached load_json_config.py) which reads in the attached bad.json file.


Files

bad.json (1.13 MB) bad.json Lane, Peter, 03 May 2013 22:20
load_json.py (1.69 KB) load_json.py Lane, Peter, 03 May 2013 22:20
load_json_config.py (889 Bytes) load_json_config.py Lane, Peter, 03 May 2013 22:20
#1

Updated by Taylor, Ian over 8 years ago

  • Assignee changed from Rogers, Chris to Lane, Peter
  • Target version set to Future MAUS release
  • Workflow changed from New Issue to Under Test

Okay, annoying, but apparently simple (not to be confused with quick).

The bug was even in the code that Peter included. The Json writer doesn't store unsigned ints as special values (which would be helpful...). So when the reader reads the value in, it assumes it is a signed int, unless it can't fit. This is why we have the code above. However, that code misses the fact that 0 is a valid int value.

Changing it to simply

  } else if (json_uint.isInt() && json_uint.asInt() >= 0) {

should be sufficient. It works on my machine, but it would be great if Peter could test it on his.

#2

Updated by Lane, Peter over 8 years ago

That did the trick.

#3

Updated by Lane, Peter over 8 years ago

  • Assignee changed from Lane, Peter to Taylor, Ian

Sending back to Ian for closing.

#4

Updated by Taylor, Ian over 8 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Fix has been committed to the merge branch, along with an improved test of the UInt Processor.

#5

Updated by Rogers, Chris over 8 years ago

  • Target version changed from Future MAUS release to MAUS-v0.5.3

Also available in: Atom PDF