From efe465ea945dd40b58db25b7ce390e4df95b5c15 Mon Sep 17 00:00:00 2001
From: Karim Ahmed <karim.ahmed@xfel.eu>
Date: Tue, 27 Aug 2019 13:23:22 +0200
Subject: [PATCH]  instr. and det. prefix in path through repservice

---
 reportservice/report_conf.yaml  | 10 +++++-----
 reportservice/report_service.py | 17 ++++++++++++-----
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/reportservice/report_conf.yaml b/reportservice/report_conf.yaml
index e515db3b3..945b4ca14 100644
--- a/reportservice/report_conf.yaml
+++ b/reportservice/report_conf.yaml
@@ -37,7 +37,7 @@ SPB:
             - 176
         photon-energy: 9.2
         use-existing: "''"
-        out-folder: "/gpfs/exfel/data/scratch/xcal/report_service/tmp/AGIPD1M1_out1/"
+        out-folder: "/gpfs/exfel/data/scratch/xcal/report_service/tmp/{instrument}/{detector}/"
         cal-db-timeout: 180000
         cal-db-interface: "tcp://max-exfl016:8015#8025"
 
@@ -62,7 +62,7 @@ MID:
             - 176
         photon-energy: 9.2
         use-existing: "''"
-        out-folder: "/gpfs/exfel/data/scratch/xcal/report_service/tmp/AGIPD1M2_out1/"
+        out-folder: "/gpfs/exfel/data/scratch/xcal/report_service/tmp/{instrument}/{detector}/"
         cal-db-timeout: 180000
         cal-db-interface: "tcp://max-exfl016:8015#8025"
         range-offset:
@@ -115,7 +115,7 @@ MID:
             - 50
         photon-energy: 9.2
         use-existing: "''"
-        out-folder: "/gpfs/exfel/data/scratch/xcal/report_service/tmp/EPIX01_out1/"
+        out-folder: "/gpfs/exfel/data/scratch/xcal/report_service/tmp/{instrument}/{detector}/"
         cal-db-timeout: 180000
         cal-db-interface: "tcp://max-exfl016:8015#8025"
 
@@ -138,7 +138,7 @@ MID:
             - 50
         photon-energy: 9.2
         use-existing: "''"
-        out-folder: "/gpfs/exfel/data/scratch/xcal/report_service/tmp/EPIX02_out1/"
+        out-folder: "/gpfs/exfel/data/scratch/xcal/report_service/tmp/{instrument}/{detector}/"
         cal-db-timeout: 180000
         cal-db-interface: "tcp://max-exfl016:8015#8025"
 
@@ -166,6 +166,6 @@ FXE:
             - 512
         photon-energy: 9.2
         use-existing: "''"
-        out-folder: "/gpfs/exfel/data/scratch/xcal/report_service/tmp/LPD1M1_out1/"
+        out-folder: "/gpfs/exfel/data/scratch/xcal/report_service/tmp/{instrument}/{detector}/"
         cal-db-timeout: 180000
         cal-db-interface: "tcp://max-exfl016:8015#8025"
diff --git a/reportservice/report_service.py b/reportservice/report_service.py
index 39185789e..cff949f9d 100644
--- a/reportservice/report_service.py
+++ b/reportservice/report_service.py
@@ -71,7 +71,7 @@ async def wait_jobs(joblist):
         counter += 10
 
 
-async def get_run_base(detector):
+async def get_run_base(instr_name, det_name, detector):
 
     run_base = ['xfel-calibrate'] + detector['det-type']
 
@@ -82,6 +82,9 @@ async def get_run_base(detector):
 
         run_base += ['--{}'.format(str(key))]
         if not isinstance(item, list):
+            if key == 'out-folder':
+                item = detector['out-folder'].format(instrument=instr_name,
+                                                     detector=det_name)
             run_base += [str(item)]
         else:
             for val in item:
@@ -224,8 +227,9 @@ async def server_runner(conf_file):
                     logging.info('Process detector: {}'.format(det_name))
                     logging.debug('Config information: {}'.format(det_conf))
 
-                    run_base = await get_run_base(det_conf)
-
+                    run_base = await get_run_base(instr_name,
+                                                  det_name,
+                                                  det_conf)
                     try:
                         output = await asyncio.create_subprocess_shell(
                                  " ".join(run_base), stdout=PIPE, stderr=PIPE)
@@ -264,7 +268,9 @@ async def server_runner(conf_file):
                 # Copy all plots
                 for det_name, det_conf in instrument.items():
                     
-                    out_folder = det_conf['out-folder']
+                    out_folder = det_conf['out-folder'].format(
+                                          instrument=instr_name,
+                                          detector=det_name)
                     path = cfg['GLOBAL']['git']['figures-local']
                     figures = glob.glob("{}/*png".format(out_folder))
 
@@ -272,7 +278,8 @@ async def server_runner(conf_file):
 
                     for f in figures:
                         const = f.split('/')[-1].split('_')[0]
-                        fpath = '{}/{}/{}'.format(path, det_name, const)
+                        fpath = '{}/{}/{}'.format(path, instr_name,
+                                                  det_name, const)
 
                         os.makedirs(fpath, exist_ok=True)
                         det_new_files[f] = fpath
-- 
GitLab