Skip to content

Commit 2ff87fb

Browse files
committed
Merge remote-tracking branch 'origin/dev/main' into origin/dev/feature/custom_tango
2 parents bbc82db + fc635ec commit 2ff87fb

File tree

16 files changed

+6204
-37
lines changed

16 files changed

+6204
-37
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(

src/dt4acc/core/accelerators/pyat_accelerator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import getpass
23

34
from .accelerator_manager import AcceleratorManager
45

@@ -13,7 +14,7 @@ def setup_accelerator():
1314
Returns:
1415
AcceleratorManager: Singleton instance of the accelerator manager.
1516
"""
16-
prefix = os.getenv("DT4ACC_PREFIX", "Anonym")
17+
prefix = os.getenv("DT4ACC_PREFIX", getpass.getuser())
1718
manager = AcceleratorManager(prefix=prefix)
1819
manager.initialize()
1920
return manager

src/dt4acc/core/calculations/pyat_calculator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import getpass
12
import os
23
from abc import ABCMeta
34
from concurrent.futures import ThreadPoolExecutor
@@ -62,7 +63,7 @@ def calculate(self) -> TwissWithAggregatedKValues:
6263
RuntimeError: If the calculation fails due to invalid input.
6364
"""
6465

65-
logger.warning("Starting Twiss calculation (get_optics)")
66+
logger.info("Starting Twiss calculation (get_optics)")
6667

6768
twiss_in = {
6869
'beta': np.array([8.860461, 4.03432]),
@@ -95,7 +96,7 @@ def _extract_pv_values(self) -> Sequence[MainValue]:
9596
tuple: PV names and their corresponding K values.
9697
"""
9798
main_values = []
98-
prefix = os.environ.get('DT4ACC_PREFIX', 'Anonym')
99+
prefix = os.environ.get('DT4ACC_PREFIX', getpass.getuser())
99100
for element in self.acc:
100101
if element.__class__.__name__ == "Quadrupole":
101102
main_values.append(
@@ -143,7 +144,7 @@ def calculate(self) -> Orbit:
143144
Raises:
144145
RuntimeError: If the calculation fails.
145146
"""
146-
logger.warning("Starting orbit calculation (find_orbit)")
147+
logger.info("Starting orbit calculation (find_orbit)")
147148

148149
try:
149150
x0, orbit = self.acc.find_orbit(at.All)

src/dt4acc/core/views/shared_view.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import getpass
12
import os
23

34
from ..utils.logger import get_logger
@@ -16,7 +17,7 @@ def get_view_instance():
1617
if _view_instance is not None:
1718
return _view_instance
1819

19-
prefix = os.environ.get("DT4ACC_PREFIX", "Anonym")
20+
prefix = os.environ.get("DT4ACC_PREFIX", getpass.getuser())
2021
server_type = os.environ.get("server", "epics").lower()
2122

2223
if server_type == "tango":
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)