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