From e1515c699d0b027ecf6cddf0dadd3e31ac79ca7b Mon Sep 17 00:00:00 2001 From: formica <andrea.formica@cern.ch> Date: Sun, 4 Feb 2024 17:50:31 +0100 Subject: [PATCH 01/10] Add a script to generate LAR tag --- examples/crest-store-lar.py | 103 ++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 examples/crest-store-lar.py diff --git a/examples/crest-store-lar.py b/examples/crest-store-lar.py new file mode 100644 index 0000000..b97502f --- /dev/null +++ b/examples/crest-store-lar.py @@ -0,0 +1,103 @@ +from pycrest.api.crest_api import CrestApi +from pycrest.api.crest_cond_container import CrestCondContainer +from pycrest.api.tag_info_container import TagInfoContainer +from hep.crest.client.model.iov_set_dto import IovSetDto +from hep.crest.client.model.tag_dto import TagDto +from hep.crest.client.model.tag_meta_dto import TagMetaDto +import json + +# create an instance of the API class +api_instance = CrestApi(host='http://crest.cern.ch/api-v4.0') + +# Define tag +desttag='Test-LARBadChannelsOflBadChannels-RUN2-00' + +def random_data(): + import random + import string + return ''.join(random.choices(string.ascii_uppercase + string.digits, k=4096)) + +def random_record(): + import random + return { + 'ChannelSize': random.randint(0, 100), + 'StatusWordSize': random.randint(0, 100), + 'Endianness': random.randint(0, 1), + 'Version': random.randint(0, 100), + 'Blob': random_data() + } + +# Clean up the existing tag +# Remove the tag +print('Delete tag %s if exists' % desttag) +try: + tag = api_instance.get_tag(name=desttag) + if tag is not None and isinstance(tag, TagDto): + tagname = tag.name + description = tag.description + print(f'Found tag {tagname} - {description} for name {desttag}: removing it...') + api_response = api_instance.remove_tag(name=desttag) +except Exception as e: + print("Exception when calling CrestApi: %s\n" % e) + +# tag description +description = 'A Test LAR CREST tag' +# tag time type +time_type = 'time' +# Tag meta information +destfolder='/LAR/BadChannelsOfl/BadChannels' +tag_info_builder = TagInfoContainer(payload_spec='ChannelSize:UInt32,StatusWordSize:UInt32,Endianness:UInt32,Version:UInt32,Blob:Blob64k', node_description='<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>') +tag_info_builder.add_channel(channel_id='0', channel_name='LAR-Bad-00') +tag_info_builder.add_channel(channel_id='1', channel_name='LAR-Bad-01') +tag_info_builder.add_channel(channel_id='2', channel_name='LAR-Bad-02') +tag_info_builder.add_channel(channel_id='3', channel_name='LAR-Bad-03') +tag_info_builder.add_channel(channel_id='4', channel_name='LAR-Bad-04') +tag_info_builder.add_channel(channel_id='5', channel_name='LAR-Bad-05') +tag_info_builder.add_channel(channel_id='6', channel_name='LAR-Bad-06') +tag_info_builder.add_channel(channel_id='7', channel_name='LAR-Bad-07') +# Build the tag info dictionary + +# Create a payload record +# use the columns defined before to create a typical payload: we use a Cool compatible format +# In this function we emulate new data for different run-lumi and channels +def generate_since_data(since=0): + payload_streamer = {'author': 'larexpert', 'comment': 'this has the same Blob data'} + crest_payload = CrestCondContainer(payload_spec=tag_info_builder.get_payload_spec()) + for chan in range(0, 8): + rec = random_record() + crest_payload.add_record(attribute_list=rec) + crest_payload.add_data(channel_id=chan, record=rec) + crest_payload.add_iov(since=since, data=crest_payload.get_payload(), streamer_info=payload_streamer) + return crest_payload + +# Start creating everything in Crest +try: + # Create a new tag + api_response = api_instance.create_tag(name=desttag, timeType=time_type, description=description) + if isinstance(api_response, TagDto): + print(f'Created tag {api_response.name}') + else: + print(f'Error creating tag {desttag}: {api_response}') + # Add tag info + ti = tag_info_builder.dump_tag_info() + channel_size = tag_info_builder.get_channels_size() + column_size = tag_info_builder.get_columns_size() + print(f'Creating tag meta info for {desttag} with specs: {ti} and channels: {channel_size} and columns: {column_size}') + api_response = api_instance.create_tag_meta_info(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size) + if isinstance(api_response, TagMetaDto): + print(f'Created tag meta info for {api_response.tag_name}') + tag_info = api_response.tag_info + dic_info = json.loads(tag_info) + print(f'Tag info has specs: {dic_info["payload_spec"]} and channels: {dic_info["channel_list"]}') + else: + print(f'Error creating tag meta info for {desttag}: {api_response}') + # Add iovs + for since in range(0, 10000, 1000): + crest_payload = generate_since_data(since) + api_response = api_instance.store_json_data(tagname=desttag, json_array=crest_payload.dump_iovs()) + print(f'Stored data in tag {desttag} for since {since}') + +except Exception as e: + print("Exception when calling CrestApi : %s\n" % e) + +# Verify your data using crest-read-lar.py \ No newline at end of file -- GitLab From 6065adb24a1b605302979906fa57429ba61d4491 Mon Sep 17 00:00:00 2001 From: formica <andrea.formica@cern.ch> Date: Sun, 4 Feb 2024 17:50:34 +0100 Subject: [PATCH 02/10] Add a script to generate LAR tag --- examples/crest-store-lar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/crest-store-lar.py b/examples/crest-store-lar.py index b97502f..fb2a9d9 100644 --- a/examples/crest-store-lar.py +++ b/examples/crest-store-lar.py @@ -92,7 +92,7 @@ try: else: print(f'Error creating tag meta info for {desttag}: {api_response}') # Add iovs - for since in range(0, 10000, 1000): + for since in range(0, 10000, 100): crest_payload = generate_since_data(since) api_response = api_instance.store_json_data(tagname=desttag, json_array=crest_payload.dump_iovs()) print(f'Stored data in tag {desttag} for since {since}') -- GitLab From d0690884346d1da32ecbce619a9d4f2e43e38269 Mon Sep 17 00:00:00 2001 From: formica <andrea.formica@cern.ch> Date: Sun, 4 Feb 2024 17:59:49 +0100 Subject: [PATCH 03/10] Add a script to generate LAR tag --- examples/crest-store-lar.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/crest-store-lar.py b/examples/crest-store-lar.py index fb2a9d9..bdb6245 100644 --- a/examples/crest-store-lar.py +++ b/examples/crest-store-lar.py @@ -94,9 +94,10 @@ try: # Add iovs for since in range(0, 10000, 100): crest_payload = generate_since_data(since) - api_response = api_instance.store_json_data(tagname=desttag, json_array=crest_payload.dump_iovs()) - print(f'Stored data in tag {desttag} for since {since}') - + print(f'Add data for since {since}') + api_response = api_instance.store_json_data(tagname=desttag, json_array=crest_payload.dump_iovs()) + print('Stored data in tag %s' % desttag) + except Exception as e: print("Exception when calling CrestApi : %s\n" % e) -- GitLab From b97f16d193f0b5ce4d08c73e49d3d42d19010c9c Mon Sep 17 00:00:00 2001 From: formica <andrea.formica@cern.ch> Date: Sun, 4 Feb 2024 18:03:42 +0100 Subject: [PATCH 04/10] Add a script to generate LAR tag --- examples/crest-read-lar.py | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 examples/crest-read-lar.py diff --git a/examples/crest-read-lar.py b/examples/crest-read-lar.py new file mode 100644 index 0000000..573b3e1 --- /dev/null +++ b/examples/crest-read-lar.py @@ -0,0 +1,45 @@ +from pycrest.api.crest_api import CrestApi +from pycrest.api.crest_cond_container import CrestCondContainer +from pycrest.api.tag_info_container import TagInfoContainer +from hep.crest.client.model.iov_set_dto import IovSetDto +from hep.crest.client.model.tag_dto import TagDto +from hep.crest.client.model.tag_meta_dto import TagMetaDto +import json + +# create an instance of the API class +api_instance = CrestApi(host='http://crest.cern.ch/api-v4.0') + +# Define tag +desttag='Test-LARBadChannelsOflBadChannels-RUN2-00' + +# Verify your data +# Check tag +print('Check tag %s' % desttag) +try: + tag = api_instance.get_tag(name=desttag) + if tag is not None and isinstance(tag, TagDto): + tagname = tag.name + description = tag.description + print(f'Found tag {tagname} - {description} for name {desttag}') +except Exception as e: + print("Exception when calling CrestApi: %s\n" % e) + +# Query data from the tag +print('List iovs for tag %s' % desttag) +iovs = [] +try: + api_response = api_instance.find_all_iovs(tagname=desttag) + if isinstance(api_response, IovSetDto): + print(f'Found iovs list for tag {desttag} of size {api_response.size}') + iovs = api_response.resources + print(f'Found iovs : {iovs}') +# Get data for a given since + since = 2020 + print(f'Get data for since {since}') + sel_hash = api_instance.find_payload_hash(iovs, since) + print(f'Select hash {sel_hash} for since {since}') + api_response = api_instance.get_payload(hash=sel_hash) + print(api_response) + +except Exception as e: + print("Exception when calling CrestApi for iov load or payload access: %s\n" % e) -- GitLab From aa14d1f5a863ded1bf6148a47dab0119c699a2df Mon Sep 17 00:00:00 2001 From: formica <andrea.formica@cern.ch> Date: Sun, 4 Feb 2024 18:15:04 +0100 Subject: [PATCH 05/10] Add a script to generate LAR tag --- examples/crest-store-lar.py | 74 ++++++++++++++++------------- pycrest/api/crest_cond_container.py | 4 +- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/examples/crest-store-lar.py b/examples/crest-store-lar.py index bdb6245..7672f3d 100644 --- a/examples/crest-store-lar.py +++ b/examples/crest-store-lar.py @@ -5,6 +5,18 @@ from hep.crest.client.model.iov_set_dto import IovSetDto from hep.crest.client.model.tag_dto import TagDto from hep.crest.client.model.tag_meta_dto import TagMetaDto import json +# Author: Andrea Formica (CERN) +# Example taken from LAR COOL data, using folder /LAR/BadChannelsOfl/BadChannels. +# +# In this snippet we will create a new tag, add tag info and add iovs to the tag. +# The tag will be created with a specific payload specification and a set of channels +# The iovs will be created with a random payload for each channel, and the since will be incremented by 100. +# The data are stored in one go at the end of the process, for all the iovs. +# This avoid the need to call crest api http requests for each iov. +# +# To read the data back use the script crest-read-lar.py +# Every time you run this script you will create a new tag with new data, and remove the old one. + # create an instance of the API class api_instance = CrestApi(host='http://crest.cern.ch/api-v4.0') @@ -12,34 +24,6 @@ api_instance = CrestApi(host='http://crest.cern.ch/api-v4.0') # Define tag desttag='Test-LARBadChannelsOflBadChannels-RUN2-00' -def random_data(): - import random - import string - return ''.join(random.choices(string.ascii_uppercase + string.digits, k=4096)) - -def random_record(): - import random - return { - 'ChannelSize': random.randint(0, 100), - 'StatusWordSize': random.randint(0, 100), - 'Endianness': random.randint(0, 1), - 'Version': random.randint(0, 100), - 'Blob': random_data() - } - -# Clean up the existing tag -# Remove the tag -print('Delete tag %s if exists' % desttag) -try: - tag = api_instance.get_tag(name=desttag) - if tag is not None and isinstance(tag, TagDto): - tagname = tag.name - description = tag.description - print(f'Found tag {tagname} - {description} for name {desttag}: removing it...') - api_response = api_instance.remove_tag(name=desttag) -except Exception as e: - print("Exception when calling CrestApi: %s\n" % e) - # tag description description = 'A Test LAR CREST tag' # tag time type @@ -55,13 +39,27 @@ tag_info_builder.add_channel(channel_id='4', channel_name='LAR-Bad-04') tag_info_builder.add_channel(channel_id='5', channel_name='LAR-Bad-05') tag_info_builder.add_channel(channel_id='6', channel_name='LAR-Bad-06') tag_info_builder.add_channel(channel_id='7', channel_name='LAR-Bad-07') -# Build the tag info dictionary + +def random_data(): + import random + import string + return ''.join(random.choices(string.ascii_uppercase + string.digits, k=4096)) + +def random_record(): + import random + return { + 'ChannelSize': random.randint(0, 100), + 'StatusWordSize': random.randint(0, 100), + 'Endianness': random.randint(0, 1), + 'Version': random.randint(0, 100), + 'Blob': random_data() + } # Create a payload record # use the columns defined before to create a typical payload: we use a Cool compatible format # In this function we emulate new data for different run-lumi and channels def generate_since_data(since=0): - payload_streamer = {'author': 'larexpert', 'comment': 'this has the same Blob data'} + payload_streamer = {'author': 'larexpert', 'comment': 'this has new Blob data'} crest_payload = CrestCondContainer(payload_spec=tag_info_builder.get_payload_spec()) for chan in range(0, 8): rec = random_record() @@ -70,6 +68,19 @@ def generate_since_data(since=0): crest_payload.add_iov(since=since, data=crest_payload.get_payload(), streamer_info=payload_streamer) return crest_payload +# Clean up the existing tag +# Remove the tag +print('Delete tag %s if exists' % desttag) +try: + tag = api_instance.get_tag(name=desttag) + if tag is not None and isinstance(tag, TagDto): + tagname = tag.name + description = tag.description + print(f'Found tag {tagname} - {description} for name {desttag}: removing it...') + api_response = api_instance.remove_tag(name=desttag) +except Exception as e: + print("Exception when calling CrestApi: %s\n" % e) + # Start creating everything in Crest try: # Create a new tag @@ -97,8 +108,7 @@ try: print(f'Add data for since {since}') api_response = api_instance.store_json_data(tagname=desttag, json_array=crest_payload.dump_iovs()) print('Stored data in tag %s' % desttag) - + except Exception as e: print("Exception when calling CrestApi : %s\n" % e) -# Verify your data using crest-read-lar.py \ No newline at end of file diff --git a/pycrest/api/crest_cond_container.py b/pycrest/api/crest_cond_container.py index 20d87d6..a6a3bbb 100644 --- a/pycrest/api/crest_cond_container.py +++ b/pycrest/api/crest_cond_container.py @@ -25,9 +25,7 @@ class CrestCondContainer(): for key, value in attribute_list.items(): if key not in self._payload_spec: raise ValueError('Attribute %s is not in the payload spec' % key) - if self._payload_spec[key] == 'String4k': - if len(value) > 4096: - raise ValueError('Attribute %s is too long' % key) + if 'String' in self._payload_spec[key]: self._record[key] = value if 'Blob' in self._payload_spec[key]: self._record[key] = value -- GitLab From 8b5107e1d22c0a128204af9e42465416e42a3556 Mon Sep 17 00:00:00 2001 From: formica <andrea.formica@cern.ch> Date: Sun, 4 Feb 2024 18:18:58 +0100 Subject: [PATCH 06/10] Add a script to generate LAR tag --- examples/crest-read-lar.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/crest-read-lar.py b/examples/crest-read-lar.py index 573b3e1..21c698d 100644 --- a/examples/crest-read-lar.py +++ b/examples/crest-read-lar.py @@ -6,6 +6,14 @@ from hep.crest.client.model.tag_dto import TagDto from hep.crest.client.model.tag_meta_dto import TagMetaDto import json +# Author: Andrea Formica (CERN) +# Example taken from LAR COOL data, using folder /LAR/BadChannelsOfl/BadChannels. +# +# In this snippet we will read a crest tag create by the script crest-store-lar.py +# +# Ths script checks the tag, list the iovs and get the payload for a given since. +# + # create an instance of the API class api_instance = CrestApi(host='http://crest.cern.ch/api-v4.0') -- GitLab From b74f2b9d56fb46df7dce3deb57f620763e31ffef Mon Sep 17 00:00:00 2001 From: formica <andrea.formica@cern.ch> Date: Sun, 4 Feb 2024 18:30:33 +0100 Subject: [PATCH 07/10] Add a script to generate Tile tag --- examples/crest-store-tile.py | 100 +++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 examples/crest-store-tile.py diff --git a/examples/crest-store-tile.py b/examples/crest-store-tile.py new file mode 100644 index 0000000..3f5c008 --- /dev/null +++ b/examples/crest-store-tile.py @@ -0,0 +1,100 @@ +from pycrest.api.crest_api import CrestApi +from pycrest.api.crest_cond_container import CrestCondContainer +from pycrest.api.tag_info_container import TagInfoContainer +from hep.crest.client.model.iov_set_dto import IovSetDto +from hep.crest.client.model.tag_dto import TagDto +from hep.crest.client.model.tag_meta_dto import TagMetaDto +import json +import secrets + +# Author: Andrea Formica (CERN) +# Example taken from TILE COOL data, using folder /TILE/OFL02/CALIB/CES. +# +# In this snippet we will create a new tag, add tag info and add iovs to the tag. +# The tag will be created with a specific payload specification and a set of channels +# The iovs will be created with a random payload for each channel, and the since will be incremented by 100. +# The data are stored in one go at the end of the process, for all the iovs. +# This avoid the need to call crest api http requests for each iov. +# +# To read the data back use the script crest-read-tile.py +# Every time you run this script you will create a new tag with new data, and remove the old one. + + +# create an instance of the API class +api_instance = CrestApi(host='http://crest.cern.ch/api-v4.0') + +# Define tag +desttag='Test-TileOfl02CalibCes-RUN2-01' + +# tag description +description = 'A Test Tile CREST tag' +# tag time type +time_type = 'time' +# Tag meta information +destfolder='/TILE/OFL02/CALIB/CES' +tag_info_builder = TagInfoContainer(payload_spec='TileCalibBlob:Blob64k', node_description='<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>') +for chan in range(0, 50): + tag_info_builder.add_channel(channel_id=str(chan), channel_name=f'TileCalib-0{chan}') + +def generate_random_binary_payload(num_bytes): + # Generate a random binary sequence with the specified number of bytes + random_bytes = secrets.token_bytes(num_bytes) + return random_bytes + +# Create a payload record +# use the columns defined before to create a typical payload: we use a Cool compatible format +# In this function we emulate new data for different run-lumi and channels +def generate_since_data(since=0): + payload_streamer = {'author': 'larexpert', 'comment': 'this has new Blob data'} + crest_payload = CrestCondContainer(payload_spec=tag_info_builder.get_payload_spec()) + for chan in range(0, 50): + rec = generate_random_binary_payload(10000) + crest_payload.add_record(attribute_list=rec) + crest_payload.add_data(channel_id=chan, record=rec) + crest_payload.add_iov(since=since, data=crest_payload.get_payload(), streamer_info=payload_streamer) + return crest_payload + +# Clean up the existing tag +# Remove the tag +print('Delete tag %s if exists' % desttag) +try: + tag = api_instance.get_tag(name=desttag) + if tag is not None and isinstance(tag, TagDto): + tagname = tag.name + description = tag.description + print(f'Found tag {tagname} - {description} for name {desttag}: removing it...') + api_response = api_instance.remove_tag(name=desttag) +except Exception as e: + print("Exception when calling CrestApi: %s\n" % e) + +# Start creating everything in Crest +try: + # Create a new tag + api_response = api_instance.create_tag(name=desttag, timeType=time_type, description=description) + if isinstance(api_response, TagDto): + print(f'Created tag {api_response.name}') + else: + print(f'Error creating tag {desttag}: {api_response}') + # Add tag info + ti = tag_info_builder.dump_tag_info() + channel_size = tag_info_builder.get_channels_size() + column_size = tag_info_builder.get_columns_size() + print(f'Creating tag meta info for {desttag} with specs: {ti} and channels: {channel_size} and columns: {column_size}') + api_response = api_instance.create_tag_meta_info(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size) + if isinstance(api_response, TagMetaDto): + print(f'Created tag meta info for {api_response.tag_name}') + tag_info = api_response.tag_info + dic_info = json.loads(tag_info) + print(f'Tag info has specs: {dic_info["payload_spec"]} and channels: {dic_info["channel_list"]}') + else: + print(f'Error creating tag meta info for {desttag}: {api_response}') + # Add iovs + for since in range(0, 10000, 1000): + crest_payload = generate_since_data(since) + print(f'Add data for since {since}') + api_response = api_instance.store_json_data(tagname=desttag, json_array=crest_payload.dump_iovs()) + print('Stored data in tag %s' % desttag) + +except Exception as e: + print("Exception when calling CrestApi : %s\n" % e) + -- GitLab From 10f9070f9a1dbdab81a977e7d2f8a403b3b89e79 Mon Sep 17 00:00:00 2001 From: formica <andrea.formica@cern.ch> Date: Sun, 4 Feb 2024 18:37:25 +0100 Subject: [PATCH 08/10] Add a script to generate Tile tag --- examples/crest-store-lar.py | 2 +- examples/crest-store-tile.py | 2 +- examples/crest-store.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/crest-store-lar.py b/examples/crest-store-lar.py index 7672f3d..b9fe419 100644 --- a/examples/crest-store-lar.py +++ b/examples/crest-store-lar.py @@ -94,7 +94,7 @@ try: channel_size = tag_info_builder.get_channels_size() column_size = tag_info_builder.get_columns_size() print(f'Creating tag meta info for {desttag} with specs: {ti} and channels: {channel_size} and columns: {column_size}') - api_response = api_instance.create_tag_meta_info(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size) + api_response = api_instance.create_tag_meta(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size) if isinstance(api_response, TagMetaDto): print(f'Created tag meta info for {api_response.tag_name}') tag_info = api_response.tag_info diff --git a/examples/crest-store-tile.py b/examples/crest-store-tile.py index 3f5c008..53bbabf 100644 --- a/examples/crest-store-tile.py +++ b/examples/crest-store-tile.py @@ -80,7 +80,7 @@ try: channel_size = tag_info_builder.get_channels_size() column_size = tag_info_builder.get_columns_size() print(f'Creating tag meta info for {desttag} with specs: {ti} and channels: {channel_size} and columns: {column_size}') - api_response = api_instance.create_tag_meta_info(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size) + api_response = api_instance.create_tag_meta(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size) if isinstance(api_response, TagMetaDto): print(f'Created tag meta info for {api_response.tag_name}') tag_info = api_response.tag_info diff --git a/examples/crest-store.py b/examples/crest-store.py index e86c5e1..661ae7f 100644 --- a/examples/crest-store.py +++ b/examples/crest-store.py @@ -70,7 +70,7 @@ try: channel_size = tag_info_builder.get_channels_size() column_size = tag_info_builder.get_columns_size() print(f'Creating tag meta info for {desttag} with specs: {ti} and channels: {channel_size} and columns: {column_size}') - api_response = api_instance.create_tag_meta_info(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size) + api_response = api_instance.create_tag_meta(name=desttag, tag_info=ti, chansize=channel_size, colsize=column_size) if isinstance(api_response, TagMetaDto): print(f'Created tag meta info for {api_response.tag_name}') tag_info = api_response.tag_info -- GitLab From 928c4e74f566b85c44646c828bd068379cf86887 Mon Sep 17 00:00:00 2001 From: formica <andrea.formica@cern.ch> Date: Sun, 4 Feb 2024 18:39:59 +0100 Subject: [PATCH 09/10] Add a script to generate Tile tag --- examples/crest-store-tile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/crest-store-tile.py b/examples/crest-store-tile.py index 53bbabf..9d75773 100644 --- a/examples/crest-store-tile.py +++ b/examples/crest-store-tile.py @@ -48,8 +48,8 @@ def generate_since_data(since=0): payload_streamer = {'author': 'larexpert', 'comment': 'this has new Blob data'} crest_payload = CrestCondContainer(payload_spec=tag_info_builder.get_payload_spec()) for chan in range(0, 50): - rec = generate_random_binary_payload(10000) - crest_payload.add_record(attribute_list=rec) + lob = generate_random_binary_payload(10000) + rec = crest_payload.add_record(attribute_list={'TileCalibBlob': lob}) crest_payload.add_data(channel_id=chan, record=rec) crest_payload.add_iov(since=since, data=crest_payload.get_payload(), streamer_info=payload_streamer) return crest_payload -- GitLab From 0c31e1c57a3118e20d43bf666f065246cf0229af Mon Sep 17 00:00:00 2001 From: formica <andrea.formica@cern.ch> Date: Sun, 4 Feb 2024 18:43:55 +0100 Subject: [PATCH 10/10] Add a script to generate Tile tag --- pycrest/api/crest_cond_container.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pycrest/api/crest_cond_container.py b/pycrest/api/crest_cond_container.py index a6a3bbb..bf73104 100644 --- a/pycrest/api/crest_cond_container.py +++ b/pycrest/api/crest_cond_container.py @@ -1,4 +1,5 @@ import json +import base64 # Utility class for the Crest API # This class is a container for the payload data and its specification @@ -28,7 +29,10 @@ class CrestCondContainer(): if 'String' in self._payload_spec[key]: self._record[key] = value if 'Blob' in self._payload_spec[key]: - self._record[key] = value + if isinstance(value, (bytes, bytearray)): + self._record[key] = base64.b64encode(value).decode('utf-8') + else: + self._record[key] = value if 'Int' in self._payload_spec[key]: self._record[key] = int(value) if 'Float' in self._payload_spec[key] or 'Double' in self._payload_spec[key]: @@ -59,4 +63,3 @@ class CrestCondContainer(): # clean up the list in the object self._iov_list = [] return loc_list - \ No newline at end of file -- GitLab