1 | // toillsstproducer.cc
|
---|
2 | // Eric Aubourg CEA/DAPNIA/SPP octobre 1999
|
---|
3 |
|
---|
4 | #include "toillsstproducer.h"
|
---|
5 | #include "archfileset.h"
|
---|
6 | #include "toimanager.h"
|
---|
7 | #include "requesthandler.h"
|
---|
8 |
|
---|
9 | #define sstChannel "sstChannel"
|
---|
10 | #define sstChannelCN "sstChannelCN"
|
---|
11 | #define sstDiode "sstDiode"
|
---|
12 | #define sstDiodeCN "sstDiodeCN"
|
---|
13 |
|
---|
14 | // diodpermut[i] = channel de la diode i
|
---|
15 | int TOILLSSTProducer::diodpermut[46]=
|
---|
16 | { 8,24,40, 9,25,41,10,26,42,11,
|
---|
17 | 27,43,16,32, 1,17,33, 2,18,34,
|
---|
18 | 3,19,35,12,28,44,13,29,45,14,
|
---|
19 | 30,46,15,31,47,20,36, 5,21,37,
|
---|
20 | 6,22,38, 7,23,39};
|
---|
21 | // voies 0 et 4 non connectees, voie 1 en panne.
|
---|
22 |
|
---|
23 |
|
---|
24 | TOILLSSTProducer::TOILLSSTProducer()
|
---|
25 | {
|
---|
26 | possibleTOIs.insert(TOI(sstChannel, TOI::all, "", "ADU"));
|
---|
27 | possibleTOIs.insert(TOI(sstChannelCN, TOI::all, "", "ADU"));
|
---|
28 | possibleTOIs.insert(TOI(sstDiode, TOI::all, "", "ADU"));
|
---|
29 | possibleTOIs.insert(TOI(sstDiodeCN, TOI::all, "", "ADU"));
|
---|
30 | }
|
---|
31 |
|
---|
32 | string TOILLSSTProducer::getName() {
|
---|
33 | return("TOILLSSTProducer 1.0");
|
---|
34 | }
|
---|
35 |
|
---|
36 |
|
---|
37 | void TOILLSSTProducer::registerProcessor(SSTDataProcessor* p) {
|
---|
38 | processors.push_back(p);
|
---|
39 | }
|
---|
40 |
|
---|
41 | void TOILLSSTProducer::DecodeTMBlock(block_type_sst* blk, int i, int* diod)
|
---|
42 | {
|
---|
43 | int j; // 0-5 : numero du bloc de 8 diodes
|
---|
44 | int k; // 0-2 : indice du bloc de 4 bits (une diode = 12 bits = 3 blocs de 4 bits)
|
---|
45 | int l; // 0-7 : indice de la diode dans son bloc (8 diodes * 4 bits = 1 mot de 32 bits)
|
---|
46 |
|
---|
47 | // numero de la diode (0-47) = j*8+l;
|
---|
48 | // indice dans le bloc sst du mot de 32 bits (0-17) = j*3+k;
|
---|
49 | // indice dans mot de 32 bits du premier bit utile = 4*l;
|
---|
50 |
|
---|
51 | for (j=0; j<48; j++) diod[j] = 0;
|
---|
52 |
|
---|
53 | for (j=0; j<6; j++)
|
---|
54 | for (k=0; k<3; k++)
|
---|
55 | for (l=0; l<8; l++) {
|
---|
56 | int4 word = blk->sst[i][j*3+k];
|
---|
57 | word = (word >> (4*l)) & 0xF;
|
---|
58 | diod[j*8+l] = (diod[j*8+l] << 4) + word;
|
---|
59 | }
|
---|
60 |
|
---|
61 | for (j=0; j<48; j++) diod[j] -= 2048;
|
---|
62 | }
|
---|
63 |
|
---|
64 | double TOILLSSTProducer::getSSTRawSignalCN(ArchFileSet* fs, int ichannel, int imesure) {
|
---|
65 | // Si pas bloc comprime -> 0.5
|
---|
66 | if (fs->lastSSTComp() == NULL) return .5;
|
---|
67 | if (numero_block(fs->lastSSTComp()) != numero_block(fs->lastSST())) return 0.5;
|
---|
68 |
|
---|
69 | // Attention, on ne transmet pas les canaux 0 et 4....
|
---|
70 | if (ichannel == 0 || ichannel == 4) return 0;
|
---|
71 | int i = ichannel - 1;
|
---|
72 | if (i >= 4) i--;
|
---|
73 | unsigned int4* data = fs->lastSSTComp()->sst[i];
|
---|
74 | // Les deux premieres valeurs sont codees directement...
|
---|
75 | if (imesure<2) return 0.5;
|
---|
76 | int iExp = (imesure-2)/7 + 1;
|
---|
77 | int expo = data[iExp] & 0xf;
|
---|
78 | int noise = 1 << expo;
|
---|
79 | return noise/2.;
|
---|
80 | }
|
---|
81 |
|
---|
82 | void TOILLSSTProducer::handleBlock(ArchFileSet* fs)
|
---|
83 | {
|
---|
84 | block_type_sst* blk = fs->lastSST();
|
---|
85 | long sample0 = numero_block(blk)*72;
|
---|
86 | int channels[48];
|
---|
87 | int diodes[46];
|
---|
88 | for (int j=0; j<nb_per_block*2; j++) {
|
---|
89 | DecodeTMBlock(blk, j, channels);
|
---|
90 | for (int i=0; i<46; i++)
|
---|
91 | diodes[i] = channels[diodpermut[i]];
|
---|
92 | for (vector<SSTDataProcessor*>::iterator i = processors.begin();
|
---|
93 | i != processors.end(); i++) {
|
---|
94 | (*i)->dataFeed(sample0 + j, diodes);
|
---|
95 | }
|
---|
96 | for (set<TOI>::iterator i = producedTOIs.begin(); i != producedTOIs.end(); i++) {
|
---|
97 | int ich = (*i).index;
|
---|
98 | if ((*i).name == sstChannel) {
|
---|
99 | computedValue((*i), sample0+j, channels[ich]);
|
---|
100 | } else if ((*i).name == sstDiode) {
|
---|
101 | computedValue((*i), sample0+j, diodes[ich]);
|
---|
102 | } else if ((*i).name == sstChannelCN) {
|
---|
103 | computedValue((*i), sample0+j, getSSTRawSignalCN(fs, ich, j));
|
---|
104 | } else if ((*i).name == sstDiodeCN) {
|
---|
105 | computedValue((*i), sample0+j, getSSTRawSignalCN(fs, diodpermut[ich], j));
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|