Skip to content

Commit 014386e

Browse files
authored
Merge pull request #429 from MYOMAO/master
New Updated for SQLite Local Copying for 10% Production
2 parents 89c831d + c70fc87 commit 014386e

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

python/hpsmc/component.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def __init__(self,
6666
self.logger = logging.getLogger("{}.{}".format(__name__, self.__class__.__name__))
6767

6868
def cmd_line_str(self):
69-
cl = [self.command]
69+
cl = []
70+
if self.command:
71+
cl.append(self.command)
7072
cl.extend(self.cmd_args())
7173
return ' '.join(cl)
7274

python/hpsmc/tools.py

+65
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,71 @@ def execute(self, log_out, log_err):
157157
return proc.returncode
158158

159159

160+
161+
class SQLiteProc(Component):
162+
"""!
163+
Copy the SQLite database file to the desired location.
164+
"""
165+
166+
def __init__(self, **kwargs):
167+
"""!
168+
Initialize SQLiteProc to copy the SQLite file.
169+
"""
170+
self.source_file = kwargs.get('source_file')
171+
self.destination_file = kwargs.get('destination_file')
172+
173+
#You can set this under for .hpsmc file to point to a specific local database. For me I used the following in .hpsmc
174+
#[EvioToLcio]
175+
#hps_java_bin_jar = /home/zshi/.m2/repository/org/hps/hps-distribution/5.2.2-SNAPSHOT/hps-distribution-5.2.2-SNAPSHOT-bin.jar
176+
#java_args = -Xmx3g -XX:+UseSerialGC -Dorg.sqlite.tmpdir=/w/hallb-scshelf2102/hps/zshi/swiftjob/SQLite/LocalTest/tmp/ -Dorg.hps.conditions.url=jdbc:sqlite:hps_conditions_2025_03_06.sqlite
177+
#[SQLiteProc]
178+
#source_file = /w/hallb-scshelf2102/hps/zshi/swiftjob/SQLite/LocalTest/hps_conditions_2025_03_06.sqlite
179+
#destination_file = ./hps_conditions_2025_03_06.sqlite
180+
181+
182+
if self.source_file is not None:
183+
self.logger.debug("Setting SQLite local copy source file from config: %s" + self.source_file)
184+
args.append(self.source_file)
185+
if self.destination_file is not None:
186+
self.logger.debug('Setting Job Destination file from config: %s' % self.destination_file)
187+
args.append('-Dorg.hps.conditions.url=%s' % self.destination_file)
188+
189+
# Ensure to call the parent constructor properly
190+
Component.__init__(self, name='sqlite_file_copy', **kwargs)
191+
192+
193+
def cmd_args(self):
194+
"""!
195+
Return dummy command arguments to satisfy the parent class.
196+
"""
197+
cmd_args = ["(no-command-needed)"]
198+
199+
if not all(isinstance(arg, str) for arg in cmd_args):
200+
raise ValueError("All arguments must be strings.")
201+
# return ["(no-command-needed)"]
202+
return ['--source', self.source_file, '--destination', self.destination_file]
203+
204+
def execute(self, log_out, log_err):
205+
"""!
206+
Execute the file copy operation.
207+
"""
208+
209+
try:
210+
# Copy the file
211+
212+
self.logger.info(f"Copying file from {self.source_file} to {self.destination_file}")
213+
shutil.copy(self.source_file, self.destination_file)
214+
215+
# Log success
216+
self.logger.info(f"Successfully copied file to {self.destination_file}")
217+
218+
return 0 # Success code
219+
220+
except Exception as e:
221+
self.logger.error(f"Error during file copy: {e}")
222+
return 1 # Error code
223+
224+
160225
class JobManager(Component):
161226
"""!
162227
Run the hps-java JobManager class.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""!
2+
@file data_cnv_job.py
3+
4+
Convert EVIO to LCIO and then process with HPSTR to produce a recon tuple.
5+
"""
6+
from hpsmc.tools import EvioToLcio, HPSTR, SQLiteProc
7+
8+
job.description = 'EVIO converter'
9+
10+
sqlite = SQLiteProc()
11+
12+
cnv = EvioToLcio(steering='recon')
13+
14+
tuple = HPSTR(run_mode=1, cfg='recon')
15+
16+
job.add([sqlite, cnv, tuple])

0 commit comments

Comments
 (0)