public class JSONWriter extends Writer implements stream.StatefulProcessor
Writes a keys from the data item to .json files. The format will be:
[ {"key1": value, ...}, ..., {"key1": value, ...} ]
keys
is evaluated using the stream.Keys class, so wild cards
*
, ?
and negations with !
are possible.
This will write all keys ending with `Pointing` to the json file but not AzPointing.
<fact.io.JSONWriter keys="*Pointing,!AzPointing" url="file:test.json" />
The writer also supports the .jsonl format. http://jsonlines.org/ To use the .jsonl format provide the key jsonl="true" in the xml.
In this case the format will be:
{"key1": value, ...} ... {"key1": value, ...}
To be able to store special float values we use the extension of the json standard found in most implementations. E. g. Google's gson, most JavaScript parsers and python's json module. So we are using Infinity, -Infinity and NaN by default. python's pandas das not support this format directly, so use json to load the data and then create the DataFrame:
import json import pandas as pd with open('test.json', 'r') as f: data = json.load(f) df = pd.DataFrame(data)
If you do not want this behaviour, you can use
specialDoubleValuesAsString="true"
to convert these values to json compatible strings containing "inf", "-inf" or "nan"
fact.container.PixelSet is converted to an array of chids by default,
if you want to have the full output of this container, set
pixelSetsAsInt="false"
The following keys are added by default to the output: EventNum, TriggerType, NROI, NPIX
By default, the JSONWriter overwrites an existing file, if you want to append
(which actually only makes sense if jsonl="true
),
you can use:
append="true"
The JSONWriter can also add gzip compression on the fly. Use the gzip
Option
to directly write gzip compressed files.
append="true"
Modifier and Type | Class and Description |
---|---|
class |
JSONWriter.DateTimeAdapter |
class |
JSONWriter.PixelSetAdapter |
class |
JSONWriter.SignDigitsAdapter |
class |
JSONWriter.SpecialDoubleValuesAdapter |
Modifier and Type | Field and Description |
---|---|
boolean |
allowNullKeys |
boolean |
append |
boolean |
caseSensitive |
Integer |
doubleSignDigits |
boolean |
gzip |
boolean |
jsonl |
stream.Keys |
keys |
boolean |
pixelSetsAsInt |
boolean |
specialDoubleValuesAsString |
URL |
url |
Constructor and Description |
---|
JSONWriter() |
Modifier and Type | Method and Description |
---|---|
void |
finish() |
void |
init(stream.ProcessContext processContext) |
stream.Data |
process(stream.Data data) |
void |
resetState() |
getDefaultKeys, isSimulated, testKeys
@Parameter(description="Keys to save to the outputfile, if not given, the default keys for observations and simulations are stored, taken from the default/settings.properties file") public stream.Keys keys
@Parameter(required=false, description="Defines how many significant digits are used for double values", defaultValue="null") public Integer doubleSignDigits
@Parameter(required=false, description="If true, use jsonl format instead of json format", defaultValue="false") public boolean jsonl
@Parameter(required=false, description="If true, append to existing file else overwrite", defaultValue="false") public boolean append
@Parameter(required=false, description="If true, PixelSets are written out as int arrays of chids", defaultValue="true") public boolean pixelSetsAsInt
@Parameter(required=false, description="If true, Infinity, -Infinity and NaN are converted to strings \'inf\', \'-inf\' and \'nan\'", defaultValue="false") public boolean specialDoubleValuesAsString
@Parameter(required=false, description="If true, use gzip compression") public boolean gzip
@Parameter(required=false, description="Set if you want to allow empty keys.") public boolean allowNullKeys
@Parameter(required=false, description="If the matching of the keys should be done case sensitive") public boolean caseSensitive
@Parameter(required=true) public URL url
public stream.Data process(stream.Data data)
process
in interface stream.Processor
public void init(stream.ProcessContext processContext) throws Exception
init
in interface stream.StatefulProcessor
Exception
public void resetState() throws Exception
resetState
in interface stream.StatefulProcessor
Exception
Copyright © 2019. All rights reserved.