forked from diamondIPP/IPADiamondCCD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvertAllRunsAgain.py
executable file
·68 lines (62 loc) · 2.49 KB
/
ConvertAllRunsAgain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
import numpy as np
from struct import unpack
import time, os, sys
from optparse import OptionParser
import ipdb
import cPickle as pickle
from Utils import *
from Settings_Caen import Settings_Caen
from Converter_Caen import Converter_Caen
import subprocess as subp
import multiprocessing as mp
from ParallelManager import ParallelManager
# from DataAcquisition import DataAcquisition
class ConvertAllRunsAgain:
def __init__(self, runsdir=''):
self.time0 = time.time()
self.runsdir = Correct_Path(runsdir)
runstemp = glob.glob('{d}/*'.format(d=self.runsdir))
if len(runstemp) < 1:
ExitMessage('The directory does not have any runs', os.EX_USAGE)
self.num_cores = 1
self.runs = []
self.runs_settings = []
for run in runstemp:
settingsfs = glob.glob(run + '/*.settings')
if len(settingsfs) > 0:
self.runs.append(run)
self.runs_settings.append(settingsfs[0])
self.num_runs = len(self.runs)
if self.num_runs < 1: ExitMessage('There is not even the required data to convert one run', os.EX_DATAERR)
self.job_chunks = []
self.analysis_processes = {}
self.workind_dir = os.getcwd()
self.queue = {}
self.queue_running = {}
self.queue_showing = {}
self.queue_runs = {}
self.runs_dic_completed = {}
self.runs_dic_running = {}
self.parallelManager = None
def DoAll(self, num_cores=2):
self.time0 = time.time()
working_dir = os.getcwd()
self.num_cores = num_cores if num_cores <= int(mp.cpu_count()/2.0) else int(mp.cpu_count()/2.0) if mp.cpu_count() != 1 else 1
self.job_chunks = [self.runs[i:i + self.num_cores] for i in xrange(0, self.num_runs, self.num_cores)]
self.num_cores = min(self.num_cores, self.num_runs)
self.parallelManager = ParallelManager()
options = [[self.runs_settings[pos], self.runs[pos], '0'] for pos in xrange(self.num_runs)]
self.parallelManager.SetVariables(working_dir=working_dir, runlist=self.runs, exec_command='Converter_Caen.py', options=options, num_cores=self.num_cores)
self.parallelManager.RunParallelConversion()
self.time0 = time.time() - self.time0
print 'Runs converted in', self.time0, 'seconds,', self.time0/float(self.num_runs + 0.0000001), 'seconds per run. Exiting :D'
def main():
parser = OptionParser()
parser.add_option('-d', '--runsdir', dest='runsdir', type='str', default='', help='path to folder containing all the run folders to modify')
(options, args) = parser.parse_args()
runsdir = str(options.runsdir)
cara = ConvertAllRunsAgain(runsdir)
return cara
if __name__ == '__main__':
cara = main()