Bug #1274

Json to Cpp UInt conversion failure

Added by Lane, Peter about 11 years ago. Updated about 11 years ago.

Taylor, Ian
Data Structure
Target version:
Start date:
03 May 2013
Due date:
% Done:


Estimated time:
Under Test


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/", 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";

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


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

Updated by Taylor, Ian about 11 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.


Updated by Lane, Peter about 11 years ago

That did the trick.


Updated by Lane, Peter about 11 years ago

  • Assignee changed from Lane, Peter to Taylor, Ian

Sending back to Ian for closing.


Updated by Taylor, Ian about 11 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.


Updated by Rogers, Chris about 11 years ago

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

Also available in: Atom PDF