Skip to content
Snippets Groups Projects
Commit 4fc43031 authored by Carlos Yero's avatar Carlos Yero
Browse files

Merge

Merge remote-tracking branch 'upstream/master'
parents 8803b849 aa1b1477
No related branches found
No related tags found
No related merge requests found
Showing
with 164 additions and 195 deletions
==== Crate 7 type vme Bank Decoding
# slot model bank
\ No newline at end of file
==== Crate 2 type vme
# slot model clear header mask nchan ndata
4 1190 1 0x40000004 0xff00001f 128 4096
5 1190 1 0x40000005 0xff00001f 128 4096
7 1190 1 0x40000007 0xff00001f 128 4096
8 1190 1 0x40000008 0xff00001f 128 4096
10 1190 1 0x4000000a 0xff00001f 128 4096
13 1190 1 0x4000000d 0xff00001f 128 4096
14 1190 1 0x4000000e 0xff00001f 128 4096
16 1190 1 0x40000010 0xff00001f 128 4096
17 1190 1 0x40000011 0xff00001f 128 4096
==== Crate 20 type vme
# slot model clear header mask nchan ndata
6 1190 1 0x40000006 0xff00001f 128 4096
7 1190 1 0x40000007 0xff00001f 128 4096
8 1190 1 0x40000008 0xff00001f 128 4096
9 1190 1 0x40000009 0xff00001f 128 4096
10 1190 1 0x4000000a 0xff00001f 128 4096
11 1190 1 0x4000000b 0xff00001f 128 4096
...@@ -71,7 +71,6 @@ ...@@ -71,7 +71,6 @@
==== Crate 6 type vme Bank Decoding ==== Crate 6 type vme Bank Decoding
# slot model bank # slot model bank
5 1190 1190
6 1190 1190 6 1190 1190
7 1190 1190 7 1190 1190
8 1190 1190 8 1190 1190
...@@ -81,8 +80,6 @@ ...@@ -81,8 +80,6 @@
12 1190 1190 12 1190 1190
13 1190 1190 13 1190 1190
14 1190 1190 14 1190 1190
15 1190 1190
==== Crate 7 type vme Bank Decoding
# slot model bank
#!/usr/bin/perl
# Read a Hall C style MAP file and output a
# Hall A style crate map DB file.
#
# 22.03.2012 (saw)
# 11.04.2014 (saw) Perl cleanup
%crates=();
$crate = 0;
$nsubadd = 0;
$bsub = 0;
$modtype = 0;
$slot = 0;
while(<>) {
chomp($line=$_);
if($line=~/^\s*ROC=\s*(\d*)/i) {
$i++;
$crate = $1;
if(not $crates{$crate}) {
$slotlist={};
$crates{$crate} = $slotlist;
}
$modtype = 0;
$slot = 0;
} elsif ($line=~/^\s*nsubadd=\s*(\d*)/i) {
$nsubadd = $1;
$modtype = 0;
} elsif ($line=~/^\s*bsub=\s*(\d*)/i) {
$bsub = $1;
$modtype = 0;
} elsif ($line=~/^\s*slot=\s*(\d*)/i) {
$slot = $1;
$modtype = 0;
} elsif ($line=~/^\s*(\d*)\s*,\s*(\d*)\s*,\s*(\d*)/) {
if($modtype == 0) { # Slot not yet registered
if($nsubadd == 96) {
$modtype = 1877;
} elsif($nsubadd == 64) {
if($bsub == 16) {
$modtype = 1875;
} elsif($bsub == 17) {
$modtype = 1881;
}
}
if($modtype == 0) {
print "Unknown module Crate $crate, Slot $slot\n";
}
$crates{$crate}{$slot} = $modtype;
# print "$crate $slot $modtype\n";
}
}
}
print "# Hall C Crate map\n";
foreach $crate (sort {$a <=> $b} keys %crates) {
print "==== Crate $crate type fastbus\n";
print "# slot model clear header mask nchan ndata\n";
foreach $slot (sort {$a <=> $b} keys %{ $crates{$crate}}) {
$modtype = $crates{$crate}{$slot};
if($modtype == 1877) {
$ndata = 256;
} else {
$ndata = 64;
}
printf " %2d %d 1 0x0 0x0 %3d %d\n"
,$slot,$modtype,$nsubadd, $ndata;
}
}
...@@ -14,10 +14,10 @@ function proceed { ...@@ -14,10 +14,10 @@ function proceed {
done done
for crate in "${arr[@]}"; do for crate in "${arr[@]}"; do
if ((crate%2 == 1)) && ((crate != 7)); then if ((crate%2 == 1)) && ((crate != 7)); then
(cat ${PWD}/HMS/db_crate${crate}map.dat; echo; echo) >> db_cratemap.dat (cat ${PWD}/HMS/CRATE/db_crate${crate}map.dat; echo; echo) >> db_cratemap.dat
echo; echo "HMS Crate ${crate} has been added to db_cratemap.dat" echo; echo "HMS Crate ${crate} has been added to db_cratemap.dat"
elif ((crate%2 == 0)) || ((crate == 7)); then elif ((crate%2 == 0)) || ((crate == 7)); then
(cat ${PWD}/SHMS/db_crate${crate}map.dat; echo; echo) >> db_cratemap.dat (cat ${PWD}/SHMS/CRATE/db_crate${crate}map.dat; echo; echo) >> db_cratemap.dat
echo; echo "SHMS Crate ${crate} has been added to db_cratemap.dat" echo; echo "SHMS Crate ${crate} has been added to db_cratemap.dat"
if ((crate == 7)); then echo; fi if ((crate == 7)); then echo; fi
fi fi
......
...@@ -2,34 +2,92 @@ ...@@ -2,34 +2,92 @@
from __future__ import division, print_function from __future__ import division, print_function
import copy
from pprint import pprint
import sys import sys
slotKWs = [
'REFCHAN',
'REFINDEX',
]
skipKws = [
'MASK',
'NSUBADD',
'BSUB',
]
class Detector: class Detector:
def __init__(self): def __init__(self):
self.ID = -1 self.ID = -1
self.slots = [] self.comment = ''
self.rocs = [Roc()]
def __str__(self):
string = 'DETECTOR={0.ID}'.format(self)
if self.comment != '':
string += ' ! {0.comment}'.format(self)
return string
class Roc:
def __init__(self):
self.ID = -1
self.comment = ''
self.slots = [Slot()]
def __str__(self):
string = 'ROC={0.ID}'.format(self)
if self.comment != '':
string += ' ! {0.comment}'.format(self)
return string
class Slot: class Slot:
def __init__(self): def __init__(self):
self.num = -1 self.ID = -1
# These go in front of SLOT number. self.comment = ''
self.KWs1 = { self.KWs = {kw: -1 for kw in slotKWs}
'ROC': -1, self.channels = []
}
# These go after the SLOT number. def __str__(self):
self.KWs2 = { string = 'SLOT={0.ID}'.format(self)
'REFCHAN': -1, if self.comment != '':
'REFINDEX': -1 string += ' ! {0.comment}'.format(self)
} string += '\n'
# These are ignored. for k, v in self.KWs.items():
self.SkipKWs = set([ if v > -1:
'MASK', string += '{}={}\n'.format(k, v)
'NSUBADD',
'BSUB', return string
])
self.entries = []
class Channel:
def __init__(self, ID, plane, bar, signal=-1, comment=''):
self.ID = ID
self.plane = plane
self.bar = bar
self.signal = signal
self.comment = comment
def __str__(self):
string = '{0.ID:>4},{0.plane:>4},{0.bar:>4}'.format(self)
if self.signal >= 0:
string += ',{0.signal:>4}'.format(self)
if self.comment:
string += ' ! {0.comment}'.format(self)
return string
if (sys.argv[1] == '-h' or len(sys.argv) != 3):
print('Call as:')
print(' merge_maps.py merge_list.txt outfile.map')
sys.exit()
listName = sys.argv[1] listName = sys.argv[1]
...@@ -44,21 +102,19 @@ with open(listName, 'r') as fi: ...@@ -44,21 +102,19 @@ with open(listName, 'r') as fi:
] ]
# Header information. header = {
KWs = [] "KWs": [],
IDs = [] "IDs": [],
signals = [] "signals": [],
}
# Detector information.
detectors = [] detectors = []
for fileName in fileNames: for fileName in fileNames:
detector = Detector()
slot = Slot()
# Track detector IDs in current file. # Track detector IDs in current file.
IDsCurrent = [] currentIDs = []
detectors.append(Detector())
with open(fileName, 'r') as fi: with open(fileName, 'r') as fi:
for line in fi: for line in fi:
...@@ -66,6 +122,8 @@ for fileName in fileNames: ...@@ -66,6 +122,8 @@ for fileName in fileNames:
if line.isspace(): if line.isspace():
continue continue
line = line.strip()
# Check if comment line. # Check if comment line.
if line.startswith('!'): if line.startswith('!'):
# Check if header line. # Check if header line.
...@@ -73,25 +131,23 @@ for fileName in fileNames: ...@@ -73,25 +131,23 @@ for fileName in fileNames:
i = line.find('_ID=') i = line.find('_ID=')
if i == -1: if i == -1:
continue continue
else:
KW = line[1:i].strip()
ID = line[i+4:].split()[0].strip()
signal = ','.join(line[i+4:].split()[1:])
if KW in KWs:
print('Detector keyword `{}` already present!'.format(KW))
sys.exit(1)
if ID in IDs:
print('Detector ID `{}` already present!'.format(ID))
sys.exit(1)
KWs.append(KW) KW = line[1:i].strip()
IDs.append(ID) ID = line[i+4:].split()[0].strip()
IDsCurrent.append(ID) signal = ','.join(line[i+4:].split()[1:])
signals.append(signal)
continue if KW in header['KWs']:
print('Detector keyword `{}` already present!'.format(KW))
line = line.strip() sys.exit(1)
if ID in header['IDs']:
print('Detector ID `{}` already present!'.format(ID))
sys.exit(1)
header['KWs'].append(KW)
header['IDs'].append(ID)
header['signals'].append(signal)
currentIDs.append(ID)
continue
# Get comments. # Get comments.
i = line.find('!') i = line.find('!')
...@@ -100,93 +156,102 @@ for fileName in fileNames: ...@@ -100,93 +156,102 @@ for fileName in fileNames:
line = ''.join(line[:i].split()) line = ''.join(line[:i].split())
else: else:
line = ''.join(line.split()) line = ''.join(line.split())
comment = ''
# Check if there is keyword. # Check if there is keyword.
i = line.find('=') i = line.find('=')
if i > -1: if i > -1:
command = line[:i].upper() command = line[:i].upper()
value = line[i+1:] ID = line[i+1:]
if command in slot.KWs1.keys(): if command == 'DETECTOR':
slot.KWs1[command] = value if detectors[-1].ID > 0:
elif command in slot.KWs2.keys(): detectors.append(Detector())
slot.KWs2[command] = value if ID not in currentIDs:
elif command in slot.SkipKWs: print('Detector ID `{}` not found!'.format(ID))
continue sys.exit(1)
detectors[-1].ID = ID
detectors[-1].comment = comment
elif command == 'DETECTOR': elif command == 'ROC':
if detector.ID > 0: if detectors[-1].rocs[-1].ID > 0:
detectors.append(detector) detectors[-1].rocs.append(Roc())
detector = Detector() detectors[-1].rocs[-1].ID = ID
if value not in IDsCurrent: detectors[-1].rocs[-1].comment = comment
print('Detector ID `{}` not found!'.format(value))
sys.exit()
detector.ID = value
elif command == 'SLOT': elif command == 'SLOT':
if slot.num > 0: if detectors[-1].rocs[-1].slots[-1].ID > 0:
detector.slots.append(slot) detectors[-1].rocs[-1].slots.append(Slot())
slot = Slot() detectors[-1].rocs[-1].slots[-1].ID = ID
slot.num = value detectors[-1].rocs[-1].slots[-1].comment = comment
elif command in slotKWs:
detectors[-1].rocs[-1].slots[-1].KWs[command] = ID
elif command in skipKWs:
pass
else: else:
print('Unknown command `{}` in line:'.format(command)) print('Unknown command `{}` in line:'.format(command))
print(line) print(line)
continue continue
# This must be channel line.
values = line.split(',') values = line.split(',')
values = ','.join(['{:>4}'.format(val) for val in values]) detectors[-1].rocs[-1].slots[-1].channels.append(
slot.entries.append('{} ! {}'.format(values, comment)) Channel(*values, comment=comment)
)
detectors.append(detector)
# Check if each detector has defined at least one ROC and slot.
# Check if each detector has at least one slot and ROC defined. for ID, KW in sorted(zip(header['IDs'], header['KWs'])):
for ID, KW in sorted(zip(IDs, KWs)):
found = False found = False
for detector in detectors: for detector in detectors:
if detector.ID == ID: if detector.ID == ID:
found = True found = True
if len(detector.slots) == 0: if detector.rocs[0].ID < 0:
print('Detector with ID {} has no slots!'.format(ID)) print('No crate defined for detector {}!'.format(ID))
sys.exit(1)
if detector.slots[0].KWs1['ROC'] == -1:
print('No crate defined for detector with ID {}!'.format(ID))
sys.exit(1) sys.exit(1)
for roc in detector.rocs:
if roc.slots[0].ID < 0:
print(
'No slot defined for crate {} in detector {}!'.format(
roc.ID, detector.ID
)
)
sys.exit(1)
if not found: if not found:
print('No entry for detector with ID {}!'.format(ID)) print('No entry for detector {}!'.format(ID))
# Write merged map file.
with open(mergedName, 'w') as fo: with open(mergedName, 'w') as fo:
# Write header. # Write header.
for ID, KW, signal in sorted(zip(IDs, KWs, signals)): for ID, KW, signals in sorted(zip(
header['IDs'], header['KWs'], header['signals']
)):
IDString = '{}_ID={}'.format(KW, ID) IDString = '{}_ID={}'.format(KW, ID)
fo.write('! {:15} :: {}\n'.format(IDString, signal)) fo.write('! {:15} :: {}\n'.format(IDString, signal))
# Write detectors sorted by their ID. # Write detector maps sorted by IDs.
for ID, KW in sorted(zip(IDs, KWs)): for ID, KW in sorted(zip(
header['IDs'], header['KWs']
)):
for detector in detectors: for detector in detectors:
if detector.ID == ID: if detector.ID == ID:
fo.write('\n\n{}\n'.format(detector))
fo.write('\n\n') for roc in detector.rocs:
fo.write('DETECTOR={0.ID} ! {1}\n'.format(detector, KW)) fo.write('\n{}\n'.format(roc))
for slot in detector.slots:
fo.write('\n')
for key, value in sorted(slot.KWs1.items()):
if value > 0:
fo.write('{}={}\n'.format(key, value))
fo.write('SLOT={0.num}\n'.format(slot)) for slot in roc.slots:
fo.write('\n{}'.format(slot))
for key, value in sorted(slot.KWs2.items()): for channel in slot.channels:
if value > 0: fo.write('{}\n'.format(channel))
fo.write('{}={}\n'.format(key, value))
for entry in slot.entries:
fo.write('{}\n'.format(entry))
break print('\nDone.')
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment