Truncation of large numbers using TTree query

I have been using ROOT Trees for years to store and read tables from analysis of supernova data. However, I recently noticed a problem storing Galaxy ID, which can be very large. I tried both double and ‘long long int’. In both cases I can Scan the values back with interactive root, as long as I specify something like “precision=20” as an option. Within the C code, however, the query option always truncates very large numbers to just 4 digits of precision. For ID=131336659, for example, it reads back a string value 1.313e+11. I searched online for tricks, but couldn’t find anything. Below is the relevant code snippet. “scanString” is a colon-separated list of variables to read. The optString seems to be ignored, even if I fill it with garbage characters.

TREE_INFO_READ.SQL_Result =
TREE_INFO_READ.tree->Query(scanString, “”, optString,
NROW_READ, IROW_START);

Nfield = TREE_INFO_READ.SQL_Result->GetFieldCount();
Nrow = TREE_INFO_READ.SQL_Result->GetRowCount();

while( (TREE_INFO_READ.SQL_Row =
(TSQLRow *)TREE_INFO_READ.SQL_Result->Next()) ) {

for (i=0; i < Nfield; i++) {  // ivar_read loop                             
  sprintf(tmpString,"%s ", TREE_INFO_READ.SQL_Row->GetField(i));

Unsigned long 64 bit has a range from 0 to 18,446,744,073,709,551,615. Isn’t it enough?

The 64 bit range is fine, but the problem is when reading back with TTree query, it only returns 4 digits and an exponent. The question is how to read back all of the digits, since we need all the digits for a Galaxy identifier.

Well, I guess the problem is that when you print it then the default output format is what you see (i.e. internally it has the full precision).

Correct, internally it has the full precision, and the question is how to extract the values with full precision.