Skip to content

Commit 6788c1f

Browse files
committed
[TASK] mongo dependency temporaryly removed
1 parent 96174f5 commit 6788c1f

File tree

10 files changed

+6178
-21
lines changed

10 files changed

+6178
-21
lines changed

src/dt4acc/core/accelerators/accelerator_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def initialize(self):
4646
"""
4747
try:
4848
from lat2db.model.accelerator import Accelerator
49-
acc_model = Accelerator()
49+
acc_model = Accelerator(file_name ="bessyii_lattice_json.json", from_json= True)
5050

5151
# Initialize the accelerator with required components
5252
self.accelerator = AcceleratorImpl(
Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,82 @@
1-
import os
1+
# import os
2+
#
3+
# import pymongo
24

3-
import pymongo
5+
# from dt4acc import mongodb_
6+
#
7+
# client = pymongo.MongoClient(mongodb_)
8+
# DB_NAME = os.environ.get("MONGODB_DB", "bessyii")
9+
# db = client[DB_NAME]
10+
# collection = db['accelerator.setup']
11+
# TODO
12+
# this is a temporary solution to avoid the MongoDB dependency
13+
# rework this to use the file repository along with mongodb
414

5-
from dt4acc import mongodb_
15+
import json
16+
from pathlib import Path
17+
from typing import Iterable, List, Dict, Any
618

7-
client = pymongo.MongoClient(mongodb_)
8-
DB_NAME = os.environ.get("MONGODB_DB", "bessyii")
9-
db = client[DB_NAME]
10-
collection = db['accelerator.setup']
19+
# -----------------------------------------------------------------
20+
# locate and load the data file once; keep it cached in _DATA
21+
# -----------------------------------------------------------------
22+
_DATA_FILE = (
23+
Path(__file__)
24+
.resolve() # .../src/dt4acc/custom_epics/queries_json.py
25+
.parent # .../src/dt4acc/custom_epics/data
26+
/ "standard"
27+
/ "accelerator_setup.json"
28+
)
1129

30+
with _DATA_FILE.open() as fp:
31+
_DATA: List[Dict[str, Any]] = json.load(fp)
1232

33+
34+
# -----------------------------------------------------------------
35+
# helper: Mongo-style $in filtering for the tiny use-cases we need
36+
# -----------------------------------------------------------------
37+
def _match(doc: Dict[str, Any], field: str, allowed: Iterable[str]) -> bool:
38+
return doc.get(field) in allowed
39+
40+
41+
# -----------------------------------------------------------------
42+
# public API – identical signatures to the Mongo version
43+
# -----------------------------------------------------------------
1344
def get_magnets():
14-
return collection.find({"type": {"$in": ["Quadrupole", "Sextupole", "Steerer"]}})
45+
"""Return all Quadrupole/Sextupole/Steerer magnets as an iterator."""
46+
wanted = {"Quadrupole", "Sextupole", "Steerer"}
47+
return (d for d in _DATA if _match(d, "type", wanted))
48+
1549

50+
def get_magnets_per_power_converters(pc: str) -> List[Dict[str, Any]]:
51+
"""Return all magnets driven by the given power-converter name."""
52+
return [d for d in _DATA if d.get("pc") == pc]
1653

17-
def get_magnets_per_power_converters(pc):
18-
return list(collection.find({"pc": pc}))
1954

55+
def get_unique_power_converters() -> List[str]:
56+
"""Distinct list of power-converter names for Quad/Sext/Steerer magnets."""
57+
wanted = {"Quadrupole", "Sextupole", "Steerer"}
58+
return sorted({d["pc"] for d in _DATA if _match(d, "type", wanted)})
2059

21-
def get_unique_power_converters():
22-
"""Fetch unique power converter names from magnets in the DB."""
23-
return collection.distinct("pc", {"type": {"$in": ["Quadrupole", "Sextupole", "Steerer"]}})
2460

61+
def get_unique_power_converters_type_specified(type_list: Iterable[str]) -> List[str]:
62+
"""Distinct list of power-converter names for the supplied magnet types."""
63+
wanted = set(type_list)
64+
return sorted({d["pc"] for d in _DATA if _match(d, "type", wanted)})
2565

26-
def get_unique_power_converters_type_specified(type_list):
27-
"""Fetch unique power converter names from magnets in the DB."""
28-
return collection.distinct("pc", {"type": {"$in": type_list}})
66+
#
67+
# def get_magnets():
68+
# return collection.find({"type": {"$in": ["Quadrupole", "Sextupole", "Steerer"]}})
69+
#
70+
#
71+
# def get_magnets_per_power_converters(pc):
72+
# return list(collection.find({"pc": pc}))
73+
#
74+
#
75+
# def get_unique_power_converters():
76+
# """Fetch unique power converter names from magnets in the DB."""
77+
# return collection.distinct("pc", {"type": {"$in": ["Quadrupole", "Sextupole", "Steerer"]}})
78+
#
79+
#
80+
# def get_unique_power_converters_type_specified(type_list):
81+
# """Fetch unique power converter names from magnets in the DB."""
82+
# return collection.distinct("pc", {"type": {"$in": type_list}})

0 commit comments

Comments
 (0)