Skip to content

Working with snapshots and variable lists

Group API allows to extract information related to snapshots and variable lists which will be presented in the code snippets.

Alternatively the same information can be retrieved using QuerySnapshotDataService available in Backport API using the following methods:

Operation such as Snapshot saving (creation and update) can only be performed using Group API.

Initialisation of services required for the code snippets:

QuerySnapshotDataService querySnapshotDataService = ServiceBuilder.getInstance().createQuerySnapshotDataService();
    MetaDataService metaDataService = ServiceBuilder.getInstance().createMetaService();
    GroupService groupService = ServiceClientFactory.createGroupService();

Getting user snapshots with the given criteria.

Retrieval of snapshots owned by user "jjgras" having names beginning with "BI_BWS". Snapshot attributes are printed including information about selected variables:

Condition<Groups> snapCondition = Groups.suchThat().label().eq(GroupType.SNAPSHOT.toString()).and()

List<Group> snapshots2 = new ArrayList<>(groupService.findAll(snapCondition));
 * Get user snapshots with the given criteria.
 * @param criteria - set of criteria to match snapshots against
 * @return returns the set of Snapshots
 * List<Snapshot> getSnapshotsFor(SnapshotCriteria criteria);

SnapshotCriteria criteria = new SnapshotCriteria.SnapshotCriteriaBuilder("BI_BWS%", "jjgras")
List<Snapshot> snapshots = querySnapshotDataService.getSnapshotsFor(criteria);

snapshots.forEach(x -> {
    System.out.println("owner: " + x.getOwner() + " name: " + x.getName());

    SnapshotProperties snapshotProperties = x.getProperties();
    // Get selected variables if true
    Map<SnapshotPropertyName, String> propertiesMap = snapshotProperties.getAttributes(true);

            (key, values) -> System.out.println("\tKey: " + key.getDisplayName() + ", Value: " + values));
Click to see expected application output...
owner: jjgras name: BI_BWS_PSB-R2
    Key: Chart Type, Value: Versus Time
    Key: Data Source Preferences, Value: LDB_PRO
    Key: Derivation Selection, Value: RAW
    Key: Dynamic Duration, Value: 1
    Key: Prior Time, Value: Start of day
    Key: Selected Variables, Value: [BR2.BWS.2L1.H_ROT:ACQ_STATE, BR2.BWS.2L1.H_ROT:DEV_STATE, ... , BR2.BWS.2L1.V_ROT:WIRE_SPEED]
    Key: Selection Output, Value: Statistics
    Key: Time, Value: DAYS
    Key: Time Zone, Value: LOCAL_TIME
    Key: End Time Dynamic, Value: true
owner: jjgras name: BI_BWS_SPS-414
    Key: Chart Type, Value: Versus Time
    Key: Data Source Preferences, Value: LDB_PRO
    Key: Derivation Selection, Value: RAW
    Key: Dynamic Duration, Value: 1
    Key: Prior Time, Value: Start of day
    Key: Selected Variables, Value: [SPS.BWS.414.H_ROT:ACQ_CLOCK_DIV, SPS.BWS.414.H_ROT:ACQ_STATE, ... , SPS.BWS.414.V_ROT:WIRE_SPEED]
    Key: Selection Output, Value: Statistics
    Key: Time, Value: DAYS
    Key: Time Zone, Value: LOCAL_TIME
    Key: End Time Dynamic, Value: true


Visibility search critieria present in the Group API determines whether a user can retrieve information. Only a group owner can access data with a visibility set to PROTECTED. Anyone can access groups with visibility set to PUBLIC.

Gets a List of VariableList objects belonging to the given user

Query for variable lists owned by user "cdroderi" having name starting with "MDB" and any description:

Condition<Groups> groupCondition = Groups.suchThat().label().in(GroupType.GROUP.toString(), GroupType.SNAPSHOT.toString()).and()

VariableListSet variableListSet2 = groupService.findAll(groupCondition).stream().map(VariableList::from)
 * Gets a List of VariableList objects belonging to the given user, and with the list name and description matching
 * the given patterns. % = wildcard.
 * @param userName the user name of the user
 * @param listNamePattern the list name pattern
 * @param listDescriptionPattern the list description pattern
 * @return the user variable lists
 * VariableListSet getVariableListsOfUserWithNameLikeAndDescLike(String userName, String listNamePattern,
 *                 String listDescriptionPattern);

VariableListSet variableListSet = querySnapshotDataService
        .getVariableListsOfUserWithNameLikeAndDescLike("cdroderi", "MDB%", "%");

        .forEach(x -> {
            System.out.println("Onwer " + x.getUserName() + ", List name: " + x.getVariableListName());
Click to see expected application output...
Onwer cdroderi, List name: MDB-DL-PROC-BIS-LOGGING
Onwer cdroderi, List name: MDB-DL-PROC-CALS-LOGGING-PROCESS-1
Onwer cdroderi, List name: MDB-DL-PROC-CESAR-LOGGING
Onwer cdroderi, List name: MDB-DL-PROC-CESAR-SERVER
Onwer cdroderi, List name: MDB-DL-PROC-CNGS-LOGGING
Onwer cdroderi, List name: MDB-DL-PROC-DEV1
Onwer cdroderi, List name: MDB-DL-PROC-ISOLDE-LOGGING
Onwer cdroderi, List name: MDB-DL-PROC-LHC-BI-LOGGING
Onwer cdroderi, List name: MDB-DL-PROC-LHC-BLM-MDB
Onwer cdroderi, List name: MDB-DL-PROC-LHC-BT-LOGGING
Onwer cdroderi, List name: MDB-DL-PROC-LHC-FGC-LOGGING
Onwer cdroderi, List name: MDB-DL-PROC-LHC-OP-LOGGING
Onwer cdroderi, List name: MDB-DL-PROC-LHC-RADIATION-LOGGING

Get a set of variables with a given datatype

Extract all the variables of any type attached to "BI_BCT_LHCDC2" variable list:

Condition<Groups> condition = Groups.suchThat().label().eq(GroupType.GROUP.toString())
VariableList variableList2 = groupService.findOne(condition).map(VariableList::from).orElse(null);
 * Get a set of variables with a given datatype which can found in a variableList
 * @param variableList - VariableList object which can be extracted using
 *            cern.accsoft.backport.extr.domain.client.QuerySnapshotDataService
 * @param dataType - VariableDataType to match the variables to. This is represented by an enum which can be found
 *            at VariableDataType
 * @return VariableSet - Collection of variables returned
 * VariableSet getVariablesOfDataTypeInVariableList(
 *                 VariableList variableList, VariableDataType dataType);

VariableList variableList = querySnapshotDataService.getVariableListWithName("BI_BCT_LHCDC2");

if (variableList != null) {
    VariableSet variableSet = metaDataService.getVariablesOfDataTypeInVariableList(variableList, VariableDataType.ALL);

    variableSet.forEach(x -> {
Click to see expected application output...

Snapshots saving

In order to create a snapshot an ordinary group (labeled "SNAPSHOT") must be created. In the example below we are checking for the presence of the "Test snapshot" in order to (re)create it. After creation of the snapshot variables starting with ""LHCB:LUMI%"" will be attached.

Snapshot creation and deletion:

GroupService groupService = ServiceClientFactory.createGroupService();
VariableService variableService = ServiceClientFactory.createVariableService();
SystemSpecService systemSpecService = ServiceClientFactory.createSystemSpecService();

String systemName = "MOCK-SYSTEM";
SystemSpec systemSpec = systemSpecService.findByName(systemName)
        .orElseThrow(() -> new IllegalArgumentException("Could not find: " + systemName));

String variableListName = "Test snapshot";
Condition<Groups> snapCondition = Groups.suchThat().label().in(GroupType.SNAPSHOT.toString()).and()

groupService.findOne(snapCondition).ifPresent(group -> groupService.delete(group.getId()));

Group variableListFromGroup = Group.builder().systemSpec(systemSpec).name(variableListName).description("Snapshot description")
Group newlyCreatedVariableList = groupService.create(variableListFromGroup);

Set<Long> variableIds = variableService.findAll(Variables.suchThat()
Map<String, Set<Long>> variableAssociations = new HashMap<>();
variableAssociations.put(, variableIds);

groupService.setVariables(newlyCreatedVariableList.getId(), variableAssociations);

The result of the operation can be visualised using the following code snippet:

groupService.findAll(snapCondition).forEach(snapshot -> {
    Map<String, Set<Variable>>  map = groupService.getVariables(snapshot.getId());

    map.forEach((k,variableSet) -> {

        variableSet.forEach(variable -> {
            System.out.println("Variable name: " + variable.getVariableName() + " Variable id: " + variable.getId());
Click to see expected application output...
Variable name: LHCB:LUMI_REC_INT_IONS Variable id: 153846
Variable name: LHCB:LUMI_COLLISION_RATE_ERR Variable id: 153947
Variable name: LHCB:LUMI_COLLISION_RATE Variable id: 153938
Variable name: LHCB:LUMI_TOT_INST Variable id: 153946
Variable name: LHCB:LUMI_DEL_STABLE_INT_IONS Variable id: 153845

Snapshot update:

Snapshot which needs to be modified (for example for changing of the description) must be retrieved in the first place:

        .name().eq(variableListName)).ifPresent( variableListToUpdate -> {
    variableListToUpdate.toBuilder().description("New Snapshot description").build();