Skip to content

Commit d03c88d

Browse files
committed
Documentation to code fixes
1 parent 8f20a9d commit d03c88d

32 files changed

Lines changed: 853 additions & 260 deletions

docs-audit-report.md

Lines changed: 371 additions & 0 deletions
Large diffs are not rendered by default.

docs/Adding-condition-values.md

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ def add_condition(run, name, value, replace=False)
1313
There is a common situation when one has a collection of values (E.g. after parsing a file), for this case there is a handy function that allows to add many conditions values at one time.
1414

1515
```python
16-
def add_conditions(run, name_values, replace=False)
16+
def add_conditions(run, key_values, replace=False)
1717
```
1818

19-
The ```name_values``` could be a dictionary or list of name-value pairs:
19+
The ```key_values``` could be a dictionary or list of name-value pairs:
2020

2121
```python
2222
# dict
23-
name_values = {"name1":value1, "name2":value2, ...}
23+
key_values = {"name1":value1, "name2":value2, ...}
2424
# list of tuples
25-
name_values = [("name1",value1), ("name2",value2), ...]
25+
key_values = [("name1",value1), ("name2",value2), ...]
2626
# list of lists
27-
name_values = [["name1",value1], ["name2",value2], ...]
27+
key_values = [["name1",value1], ["name2",value2], ...]
2828
```
2929

3030
**(!) performance:** ```add_conditions``` tries to use as less transactions as possible to check and commit all values. So for it provides a big performance gain vs calling ```add_condition``` for each value separately
@@ -69,10 +69,10 @@ Lets example it:
6969
db = RCDBProvider("sqlite:///example.db")
7070

7171
# Crete condition types
72-
db.create_condition_type("int_val", ConditionType.INT_FIELD)
73-
db.create_condition_type("float_val", ConditionType.FLOAT_FIELD)
74-
db.create_condition_type("bool_val", ConditionType.BOOL_FIELD)
75-
db.create_condition_type("string_val", ConditionType.STRING_FIELD)
72+
db.create_condition_type("int_val", ConditionType.INT_FIELD, "Integer value example")
73+
db.create_condition_type("float_val", ConditionType.FLOAT_FIELD, "Float value example")
74+
db.create_condition_type("bool_val", ConditionType.BOOL_FIELD, "Bool value example")
75+
db.create_condition_type("string_val", ConditionType.STRING_FIELD, "String value example")
7676

7777
# Add values to run 1
7878
db.add_condition(1, "int_val", 1000)
@@ -83,16 +83,16 @@ db.add_condition(1, "string_val", "test test")
8383
# Read values for run 1 and use them
8484

8585
condition = db.get_condition(1, "int_val")
86-
print condition.value
86+
print(condition.value)
8787

8888
condition = db.get_condition(1, "float_val")
89-
print condition.value
89+
print(condition.value)
9090

9191
condition = db.get_condition(1, "bool_val")
92-
print condition.value
92+
print(condition.value)
9393

9494
condition = db.get_condition(1, "string_val")
95-
print condition.value
95+
print(condition.value)
9696
```
9797

9898
The output:
@@ -110,7 +110,7 @@ ConditionType.TIME_FIELD is used for time fields. Standard python datetime is us
110110

111111
```python
112112
# Create condition type
113-
db.create_condition_type("my_val", ConditionType.TIME_FIELD)
113+
db.create_condition_type("my_val", ConditionType.TIME_FIELD, "Time value example")
114114

115115
# Add value and time information
116116
db.add_condition(1, "my_val", datetime(2015, 10, 10, 15, 28, 12, 111111))
@@ -125,15 +125,15 @@ RCDB conditions API doesn't provide mechanisms of converting objects to JSON and
125125
For arrays it is done easily by json module.
126126

127127

128-
The example from [[https://docs.python.org/2/library/json.html python 2.7 documentation]]:
128+
The example from [[https://docs.python.org/3/library/json.html python documentation]]:
129129

130130
```
131131
>>> import json
132132
>>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
133133
'["foo", {"bar": ["baz", null, 1.0, 2]}]'
134134
135135
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
136-
[u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
136+
['foo', {'bar': ['baz', None, 1.0, 2]}]
137137
```
138138

139139
So, serialization is on the users side. It is done to have a better control over serialization.
@@ -151,8 +151,8 @@ from rcdb.model import ConditionType
151151
db = RCDBProvider("sqlite:///example.db")
152152

153153
# Create condition type
154-
db.create_condition_type("list_data", ConditionType.JSON_FIELD)
155-
db.create_condition_type("dict_data", ConditionType.JSON_FIELD)
154+
db.create_condition_type("list_data", ConditionType.JSON_FIELD, "Data list")
155+
db.create_condition_type("dict_data", ConditionType.JSON_FIELD, "Data dict")
156156

157157
list_to_store = [1, 2, 3]
158158
dict_to_store = {"x": 1, "y": 2, "z": 3}
@@ -165,19 +165,19 @@ db.add_condition(1, "dict_data", json.dumps(dict_to_store))
165165
restored_list = json.loads(db.get_condition(1, "list_data").value)
166166
restored_dict = json.loads(db.get_condition(1, "dict_data").value)
167167

168-
print restored_list
169-
print restored_dict
168+
print(restored_list)
169+
print(restored_dict)
170170

171-
print restored_dict["x"]
172-
print restored_dict["y"]
173-
print restored_dict["z"]
174-
python
171+
print(restored_dict["x"])
172+
print(restored_dict["y"])
173+
print(restored_dict["z"])
174+
```
175175

176176
The output is:
177177

178178
```
179179
[1, 2, 3]
180-
{u'y': 2, u'x': 1, u'z': 3}
180+
{'y': 2, 'x': 1, 'z': 3}
181181
1
182182
2
183183
3
@@ -187,30 +187,28 @@ The output is:
187187
The example is located at
188188

189189
```
190-
$RCDB_HOME/python/example_conditions_store_array.py
190+
$RCDB_HOME/python/examples/11_crete_conditions_store_array.py
191191
```
192192

193193
and can be run as:
194194
```bash
195-
python $RCDB_HOME/python/create_empty_sqlite.py example.db
196-
python $RCDB_HOME/python/example_conditions_store_array.py
195+
python $RCDB_HOME/python/examples/11_crete_conditions_store_array.py
197196
```
198197

199-
As one can mention unicode string is returned as unicode after json deserialization (look at u"x" instead of just "x").
200-
It is not a problem if you just work with this array, because python acts seamlessly with unicode strings.
201-
As you can see in example, we use usual string "x" in restored_dict["x"] and it just works.
202-
203-
If it is a problem, there is a
204-
[[http://stackoverflow.com/questions/956867/how-to-get-string-objects-instead-of-unicode-ones-from-json-in-python stackoverlow question on that]]
198+
Run without arguments it creates an in-memory database. You can also pass a
199+
connection string to use a file-based SQLite database, e.g.
200+
`python $RCDB_HOME/python/examples/11_crete_conditions_store_array.py sqlite:///example.db`.
205201

206-
Using pyYAML to deserialize to strings looks easy.
202+
In Python 3 all strings are unicode, so strings returned after json deserialization are
203+
ordinary `str` objects. As you can see in the example, we use the usual string "x" in
204+
restored_dict["x"] and it just works.
207205

208206

209207

210208
### Custom python objects
211209

212-
To save custom python objects to database, jsonpickle package could be used. It is an open source project available
213-
via pip install. It is not shipped with RCDB at the moment.
210+
To save custom python objects to database, jsonpickle package could be used. It is an open source project
211+
that can be installed via the package manager. It is not shipped with RCDB at the moment.
214212

215213
```python
216214
from rcdb.provider import RCDBProvider
@@ -228,7 +226,7 @@ class Cat(object):
228226
db = RCDBProvider("sqlite:///example.db")
229227

230228
# Create condition type
231-
db.create_condition_type("cat", ConditionType.JSON_FIELD)
229+
db.create_condition_type("cat", ConditionType.JSON_FIELD, "A cat object")
232230

233231

234232
# Create a cat and store in in the DB for run 1
@@ -239,11 +237,11 @@ db.add_condition(1, "cat", jsonpickle.encode(cat))
239237
condition = db.get_condition(1, "cat")
240238
loaded_cat = jsonpickle.decode(condition.value)
241239

242-
print "How cat is stored in DB:"
243-
print condition.value
244-
print "Deserialized cat:"
245-
print "name:", loaded_cat.name
246-
print "mice_eaten:", loaded_cat.mice_eaten
240+
print("How cat is stored in DB:")
241+
print(condition.value)
242+
print("Deserialized cat:")
243+
print("name:", loaded_cat.name)
244+
print("mice_eaten:", loaded_cat.mice_eaten)
247245
```
248246

249247
The result:
@@ -261,6 +259,14 @@ mice_eaten: 1230
261259

262260
jsonpickle installation:
263261

262+
RCDB uses [uv](https://docs.astral.sh/uv/) as its package manager. To add jsonpickle to the project:
263+
264+
```
265+
uv add jsonpickle
266+
```
267+
268+
Alternatively, with plain pip:
269+
264270
system level:
265271

266272
```

docs/Cpp.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ That also means that MySQL and SQLite libraries should be linked to the applicat
4444

4545
In order for your code to build ensure flags/configuration:
4646

47-
* There is at lease C++11 support enabled and stdc++ library linked. This means that probably minimum GCC version to be used is 4.8:
47+
* There is at least C++11 support enabled and stdc++ library linked. This means that probably minimum GCC version to be used is 4.8:
4848

4949
```-std=c++11 -lstdc++```
5050

@@ -96,7 +96,7 @@ The example shows how to get values from RCDB:
9696
Connection con("mysql://rcdb@hallddb/rcdb");
9797

9898
// Get event_count for run 10173
99-
auto cnd = prov.GetCondition(10173, "event_count");
99+
auto cnd = con.GetCondition(10173, "event_count");
100100

101101
// Check event_count has a value for the run
102102
if(!cnd) {
@@ -116,7 +116,7 @@ bool ToBool(); /// For bool or int in DB
116116
double ToDouble(); /// For Double or int in DB
117117
std::string ToString(); /// For Json, String or Blob
118118
time_point<system_clock> ToTime(); /// For time value
119-
rapidjson::Document ToJsonDocument(); /// For JSon document
119+
rapidjson::Document ToJsonDocument(); /// DEPRECATED: use json ToJson() instead. For JSon document
120120
121121
rcdb::ValueTypes GetValueType(); /// Returns the type enum
122122
```
@@ -144,21 +144,25 @@ RCDB_TEST_CONNECTION="sqlite:///cpp_test.sqlite" ./build/test_rcdb_cpp
144144
Examples are located in the [$RCDB_HOME/cpp/examples](https://github.com/JeffersonLab/rcdb/tree/main/cpp/examples) folder
145145
and are built as the `examples_*` targets by the `cmake --build build` command above.
146146

147-
After examples are built they are located in `$RCDB_HOME/cpp/bin` directory named as `exmpl_<...>`
147+
After examples are built they are located in the `cpp/build` directory, named after their CMake
148+
targets (e.g. `examples_trigger_params`). There is no separate install step or custom output directory.
148149

149150
<br>
150151

151152
**List of examples:**
152153

153-
* [simple.cpp](https://github.com/JeffersonLab/rcdb/blob/main/cpp/examples/simple.cpp) - Simple condition readout
154-
* [get_trigger_params.cpp](https://github.com/JeffersonLab/rcdb/blob/main/cpp/examples/get_trigger_params.cpp) - Versatile data readout example. It includes:
154+
* [simple.cpp](https://github.com/JeffersonLab/rcdb/blob/main/cpp/examples/simple.cpp) - Simple condition readout. Note: this example has no CMake target and is not built by `cmake --build build`; compile it manually with `gcc` as shown in the Installation section.
155+
* [get_trigger_params.cpp](https://github.com/JeffersonLab/rcdb/blob/main/cpp/examples/get_trigger_params.cpp) (target `examples_trigger_params`) - Versatile data readout example. It includes:
155156
* Reading conditions
156157
* Working with JSON serialized objects
157158
* Getting RCDB stored files contents
158159
* Working with config file parser
159-
* [write_conditions.cpp](https://github.com/JeffersonLab/rcdb/blob/main/cpp/examples/write_conditions.cpp) - Writing conditions to RCDB from C++. It includes:
160-
* Using WriteConnection
160+
* [get_fadc_masks.cpp](https://github.com/JeffersonLab/rcdb/blob/main/cpp/examples/get_fadc_masks.cpp) (target `examples_fadc_masks`) - Reading FADC masks
161+
* [write_conditions.cpp](https://github.com/JeffersonLab/rcdb/blob/main/cpp/examples/write_conditions.cpp) (target `examples_write_conditions`) - Writing conditions to RCDB from C++. It includes:
162+
* Using WritingConnection
161163
* Adding condition values of different types
164+
* [write_array_to_json.cpp](https://github.com/JeffersonLab/rcdb/blob/main/cpp/examples/write_array_to_json.cpp) (target `examples_write_array_to_json`) - Writing an array serialized to JSON
165+
* [write_objects_to_json.cpp](https://github.com/JeffersonLab/rcdb/blob/main/cpp/examples/write_objects_to_json.cpp) (target `examples_write_objects_to_json`) - Writing objects serialized to JSON
162166

163167

164168

docs/Creating-condition-types.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Lets look ''create_condition_type'' from the example above (we add parameter nam
44

55
```python
66
db.create_condition_type(name="my_val",
7-
value_type,
8-
description)
7+
value_type=value_type,
8+
description=description)
99
```
1010

1111
**name** - The first parameter is condition name. When we say "event_count for run 100", "event_count" is that name.
@@ -36,4 +36,4 @@ Names are just strings. RCDB doesn't provide special treatment of slashes '/' or
3636
More examples of how to use types are presented in the next section
3737

3838

39-
**description** - 255 chars max human readable description, that other users can see. It is optional but it is very good practice to fill it.
39+
**description** - 255 chars max human readable description, that other users can see. It is a required argument, and it is very good practice to fill it with something meaningful.

0 commit comments

Comments
 (0)