JSON to ROOT File

I have a python script (decoder) that gives out readable data in json format. I am trying to have that data in ROOT file format. I changed the filename.json to filename.root, but it did not work. Please help out on how to get the data in ROOT format. Thank you.

Since I already have a json file, if there is a way to convert that into ROOT format then that will work as well.

# top directory of the specific run Rawdata_XX_XX_2020. YOU NEED TO MODIFY IT ACCORDINGLY
runFolder = 'run02tri'
#dirToData = "/home/user1/WORK/pcb_readout/3view30degree/data/"+runFolder+"/"
dirToData = "/home/user/Desktop/CERN/Rawdata_05_11_2022/"+runFolder+"/"

# number of events to be analyzed from each bin file .Nowadays we save 100 event in each file. If this is not true, we may have a problem here
numberOfEventsInFile = 25

# bias voltage on the collection plane, in volts
collectionBias = 900

# cathode HV, in volts
cathodeHV = 27200 

# directory and name of the file that the info will be saved. saving in a json format for now.. I assume we have a folder with name "jsonData"
#dataOutputFile = '/home/user1/WORK/pcb_readout/3view30degree/jsonData/'+runFolder+'.json'
dataOutputFile = '/home/user/Desktop/CERN/data.root'

#### THIS FUNCTION DOES THE BINARY DATA TO JSON CONVERSION AND SAVING ####
saveBinToJSON(dirToData,numberOfEventsInFile,collectionBias,cathodeHV,dataOutputFile)

#### Then the analysis of the results. First load the output file
#f = open('/home/user1/WORK/pcb_readout/analysis/jsonData/single_data.json') 
f = open(dataOutputFile) 
data = json.load(f) 

f.close() 

Maybe @linev can help you?

Hi,

ROOT natively supports only special JSON format for objects storage. See docu: ROOT: TBufferJSON Class Reference

But one always can read arbitrary JSON with any parser and store parsed data into ROOT file as tree or as any other objects. In the topic Read JSON file in CERN ROOT shown example how nlohmann parser can be used with ROOT.

Regards,
Sergy

Thank you for your reply. I read the link above but could not understand what they were talking about.

I have an idea on how to solve this problem. Please let me know if you think this is reasonable or not.

My json file is in this format.



Here the 0, 1, 2, … represents an individual event. Inside it are chn0, chn1, … which is the channel number taking the data at that time. Inside the channel are time ticks value and ADC.

I am thinking of opening the json file and iterating among these values and assigning tree, branches, leafs accordingly.

For instance, 0 (event) as a tree. Inside it are different channels (chn0, chn1, …) as a branch. Finally, save it as a root file. Is this a reasonable approach? Please let me know.

In the mentioned topic is an example, how arbitrary JSON data can be parsed.
But how such data can be converted into ROOT object - histogram, graph, collection, tree, collection - fully responsibility of the user.