ATLAS Offline Software
Loading...
Searching...
No Matches
CopyBlobFromCrest Namespace Reference

Functions

 fetch_calib_data (server, tag, run, lumi, channels)
 process_channel_list (channel_list)
 output_filename (args)
 save_calib_data_to_file (blobs, output_file, requested_channels=None)
 setup_argparser ()

Variables

 log = getLogger("CopyBlobFromCrest")
 logLevel = logging.DEBUG
 log1 = getLogger("TileCalibTools")
str schema = 'CREST'
 args = setup_argparser()
 payload_data
 ofile = output_filename(args)

Detailed Description

@author Laura.Sargsyan@cern.ch 2025-04-16
CopyBlobFromCrest.py - Tool for retrieving TileCal calibration data from CREST

Description:
------------
This script connects to the CREST service to fetch calibration data (blobs) for TileCal. Users can specify which calibration tag, run number, luminosity
block, and channels to retrieve for fine-grained control of the data. The fetched calibration data is then saved into a JSON file whose name typically
includes metadata such as the tag, run, and luminosity block.

Command-line Parameters:
-----------------------
-s, --server
    CREST server URL. Default: http://crest-j23.cern.ch:8080/api-v5.0

-t, --tag
    Calibration tag to fetch from CREST (e.g., TileOfl02CalibCes-RUN2-UPD4-29). Default: TileOfl02CalibCes-RUN2-UPD4-29)

-r, --run
    The run number.  Default: 2147483647 (retrieves the latest IOV).

-l, --lumi
    Luminosity block number.  Default: 0

-c, --channel
    Space or comma-separated list of COOL channel IDs to retrieve (e.g., 0,1,2). Default: [0..275] plus channel 1000.

-o, --output
    Output filename (JSON). If omitted, a default is generated, typically
    structured as: <tag>.<run>.<lumi>.json. For example: UPD4.2147483647.0.json

Usage Example:
--------------
python CopyBlobFromCrest.py --tag TileOfl02CalibCes-RUN2-UPD4-29 --channel 0,1,2 --output fetched_data.json

What the Script Does:
---------------------
1. Connects to the specified CREST service (-s/--server).
2. Fetches calibration data (blobs) for the given tag, run, lumi block,
   and channels.
3. Saves the data into a JSON file with a filename either provided via
   --output or auto-generated from the tag, run, and lumi.

The output JSON file stores the calibration data keyed by the channel IDs.
Each channel’s data includes the calibration blob(s) retrieved from CREST.

Function Documentation

◆ fetch_calib_data()

CopyBlobFromCrest.fetch_calib_data ( server,
tag,
run,
lumi,
channels )
Fetch calibration data from TileBlobReaderCrest.

Args:
    server (str): CREST server URL.
    tag (str): Tag identifying the calibration data.
    run (int): Run number to fetch data for.
    lumi (int): Lumi block to fetch data for.
    channels (list of int): List of COOL channel numbers.

Returns:
    list: List of calibration data entries retrieved.

Definition at line 68 of file CopyBlobFromCrest.py.

68def fetch_calib_data(server, tag, run, lumi, channels):
69 """
70 Fetch calibration data from TileBlobReaderCrest.
71
72 Args:
73 server (str): CREST server URL.
74 tag (str): Tag identifying the calibration data.
75 run (int): Run number to fetch data for.
76 lumi (int): Lumi block to fetch data for.
77 channels (list of int): List of COOL channel numbers.
78
79 Returns:
80 list: List of calibration data entries retrieved.
81 """
82 try:
83 log.info("Initializing TileBlobReaderCrest...")
84 folderTag = tag
85 if folderTag.upper().startswith("TILE") or folderTag.upper().startswith("CALO") :
86 folderPath = ""
87
88 # Create the TileBlobReaderCrest object and pass the relevant arguments
89 blob_reader = TileCalibCrest.TileBlobReaderCrest(schema, folderPath, tag, run, lumi,copyBlob=True)
90 # blob_reader = TileCalibCrest.TileBlobReaderCrest(server, tag, run, lumi, min(channels), max(channels))
91
92
93 blobs = blob_reader.payload # Retrieve the calibration data
94 log.info(f"Successfully fetched {len(blobs)} calibration entries.")
95 return blobs
96
97 except Exception as e:
98 log.error(f"Error while retrieving calibration data: {e}")
99 raise
100

◆ output_filename()

CopyBlobFromCrest.output_filename ( args)

Definition at line 121 of file CopyBlobFromCrest.py.

121def output_filename(args):
122 if not args.output:
123 # Format run and lumi as strings to ensure they're properly handled
124 run_str = str(args.run)
125 lumi_str = str(args.lumi)
126
127 # Construct filename from components
128 tag = args.tag if args.tag else "default"
129
130 # Add channel numbers in name if they were defined in args
131 if hasattr(args, 'channel') and args.channel:
132 # Process the channel list using the utility function
133 processed_channels = args.channel[0].split(',')
134 channel_str = '-'.join(processed_channels)
135 return f"{tag}.{run_str}.{lumi_str}.ch{channel_str}.json"
136 else:
137 # Return filename without channel information if default value is used
138 return f"{tag}.{run_str}.{lumi_str}.json"
139
140 return args.output
141
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ process_channel_list()

CopyBlobFromCrest.process_channel_list ( channel_list)
Process a list of channel identifiers, handling comma-separated values.

Args: channel_list (list): List of channel identifiers, which may contain comma-separated value
Returns: list: Processed list of individual channel identifiers

Definition at line 101 of file CopyBlobFromCrest.py.

101def process_channel_list(channel_list):
102 """
103 Process a list of channel identifiers, handling comma-separated values.
104
105 Args: channel_list (list): List of channel identifiers, which may contain comma-separated value
106 Returns: list: Processed list of individual channel identifiers
107 """
108 processed_channels = []
109 if channel_list:
110 for item in channel_list:
111 # If an item contains commas, split it and add each part
112 if isinstance(item, str) and ',' in item:
113 parts = [part.strip() for part in item.split(',')]
114 processed_channels.extend(parts)
115 else:
116 processed_channels.append(str(item))
117
118 return processed_channels
119
120

◆ save_calib_data_to_file()

CopyBlobFromCrest.save_calib_data_to_file ( blobs,
output_file,
requested_channels = None )
Save fetched calibration data to a file.
Parameters:
-----------
blobs : dict containing calibration data blobs
output_file : str Path to the output file where data will be saved
requested_channels : list, optional
    List of specific channels to include in the output file.
    If None, all channels from the blobs will be included.

Definition at line 142 of file CopyBlobFromCrest.py.

142def save_calib_data_to_file(blobs, output_file, requested_channels=None):
143 """
144 Save fetched calibration data to a file.
145 Parameters:
146 -----------
147 blobs : dict containing calibration data blobs
148 output_file : str Path to the output file where data will be saved
149 requested_channels : list, optional
150 List of specific channels to include in the output file.
151 If None, all channels from the blobs will be included.
152 """
153 try:
154 log.info(f"Saving calibration data to {output_file}")
155
156 if requested_channels is not None:
157 # Process the channel list using the utility function
158 processed_channels = set(process_channel_list(requested_channels))
159
160 # Filter blobs to only include requested channels
161 filtered_blobs = {channel: data for channel, data in blobs.items()
162 if channel in processed_channels}
163
164 blobs_to_save = filtered_blobs
165 else:
166 # Save all blobs if no channel filtering is requested
167 blobs_to_save = blobs
168
169 with open(output_file, "w") as f:
170 json.dump(blobs_to_save, f)
171
172 log.info("Calibration data successfully written to output file.")
173
174 except Exception as e:
175 log.error(f"Error while saving calibration data: {e}")
176 raise
STL class.

◆ setup_argparser()

CopyBlobFromCrest.setup_argparser ( )
Set up command-line argument parser.

Returns:
    argparse.ArgumentParser: Configured argument parser

Definition at line 177 of file CopyBlobFromCrest.py.

177def setup_argparser():
178 """
179 Set up command-line argument parser.
180
181 Returns:
182 argparse.ArgumentParser: Configured argument parser
183 """
184 parser = argparse.ArgumentParser(description="Read TileCal blobs from CREST and convert them to JSON format.")
185
186 parser = argparse.ArgumentParser(description="Read TileCal blobs from CREST and convert them to JSON format.")
187 parser.add_argument(
188 "-s", "--server",
189 default="http://crest-j23.cern.ch:8080/api-v5.0",
190 help="Specify CREST server URL (default is %(default)s)."
191 )
192
193 parser.add_argument(
194 "-t", "--tag",
195 default='TileOfl02CalibCes-RUN2-UPD4-29',
196 help="Specify the tag to use (e.g., RUN2-UPD4-04). Default is %(default)s."
197 )
198 parser.add_argument(
199 "-r", "--run",
200 type=int,
201 default=2147483647, # Largest IOV value (default for latest run)
202 help="Specify the run number (default is the latest IOV, %(default)s)."
203 )
204 parser.add_argument(
205 "-l", "--lumi",
206 type=int,
207 default=0,
208 help="Specify the lumi block number (default is %(default)s)."
209 )
210 parser.add_argument(
211 "-c", "--channel",
212 type=str, # Changed to str to accept comma values
213 nargs="+",
214 help="Specify COOL channels (default includes all channels from 0-275 and 1000). Use space or comma-separated values."
215 )
216
217 parser.add_argument(
218 "-o", "--output",
219 default=None,
220 help="Specify the output JSON file for saving calibration data. If not provided, will use '[tag].[run].[lumi].json'"
221 )
222
223 # Parse arguments from the command line
224 args = parser.parse_args()
225
226 return args
227

Variable Documentation

◆ args

CopyBlobFromCrest.args = setup_argparser()

Definition at line 230 of file CopyBlobFromCrest.py.

◆ log

CopyBlobFromCrest.log = getLogger("CopyBlobFromCrest")

Definition at line 60 of file CopyBlobFromCrest.py.

◆ log1

CopyBlobFromCrest.log1 = getLogger("TileCalibTools")

Definition at line 64 of file CopyBlobFromCrest.py.

◆ logLevel

CopyBlobFromCrest.logLevel = logging.DEBUG

Definition at line 61 of file CopyBlobFromCrest.py.

◆ ofile

CopyBlobFromCrest.ofile = output_filename(args)

Definition at line 244 of file CopyBlobFromCrest.py.

◆ payload_data

CopyBlobFromCrest.payload_data
Initial value:
1= fetch_calib_data(
2 server=args.server,
3 tag=args.tag,
4 run=args.run,
5 lumi=args.lumi,
6 channels=args.channel,
7 )

Definition at line 235 of file CopyBlobFromCrest.py.

◆ schema

str CopyBlobFromCrest.schema = 'CREST'

Definition at line 66 of file CopyBlobFromCrest.py.