Ignore:
Timestamp:
Sep 1, 1999, 2:45:54 PM (26 years ago)
Author:
ansari
Message:

Integration detecteur d'etoiles DY

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Poubelle/archTOI.old/ssthandler.cc

    r393 r394  
    1313#include <math.h>
    1414#include "ssthandler.h"
    15 #include <iostream.h>
     15#include "pisteetoile.h"
    1616
    1717// diodpermut[i] = channel de la diode i
     
    2525
    2626SSTHandler::SSTHandler()
     27:sstchass("SSTChassLogFile")
    2728{
    2829  diodeHistLength = nb_per_block*2+10;
    2930  diodeT = new int[diodeHistLength*nb_photo_diodes];
    3031  starHistLength = 300;
    31   stars = new (vector<star>[starHistLength]);
     32
    3233  lastBlkNum = -1;
    3334 
    3435  //Has2Bars(false);
    3536  prcTodo=0;
    36   seuil=100;
    37 }
    38 
    39 SSTHandler::SSTHandler(SSTHandler const& x)
     37 
     38  pPiste = NULL;
     39  LastBlockSSTNb = -2;
     40  noStarDet = 0;
     41 
     42  findStarConstruct();
     43 
     44}
     45
     46SSTHandler::SSTHandler(SSTHandler const& x)
     47:sstchass("SSTChassLogFile")
    4048{
    4149  diodeHistLength = x.diodeHistLength;
     
    4351  memcpy(diodeT, x.diodeT, diodeHistLength*nb_photo_diodes);
    4452  starHistLength = x.starHistLength;
    45   stars = new (vector<star>[starHistLength]);
    46   for (int i=0; i<starHistLength; i++)
    47     stars[i] = x.stars[i];
     53   
     54  prcTodo    = x.prcTodo;
     55 // has2bars   = x.has2bars;
     56  lastBlkNum = x.lastBlkNum;
     57 
     58  pPiste = NULL;
     59  LastBlockSSTNb = x.LastBlockSSTNb;
     60  noStarDet = x.noStarDet;
     61
     62  findStarConstruct();
     63  for(int i=0; i<NbPhotDiodBarette; i++) {
     64        *PisteBar[i]=*(x.PisteBar[i]);
     65  }
     66}
     67
     68SSTHandler& SSTHandler::operator = (SSTHandler const& x) {
     69  delete[] diodeT;
     70  diodeHistLength = x.diodeHistLength;
     71  diodeT = new int[diodeHistLength*nb_photo_diodes];
     72  memcpy(diodeT, x.diodeT, diodeHistLength*nb_photo_diodes);
    4873   
    4974  prcTodo    = x.prcTodo;
     
    5176 // elecOffset = x.elecOffset;
    5277  lastBlkNum = x.lastBlkNum;
    53   seuil      = x.seuil;
    54 }
    55 
    56 SSTHandler& SSTHandler::operator = (SSTHandler const& x) {
    57   delete[] stars;
    58   delete[] diodeT;
    59   diodeHistLength = x.diodeHistLength;
    60   diodeT = new int[diodeHistLength*nb_photo_diodes];
    61   memcpy(diodeT, x.diodeT, diodeHistLength*nb_photo_diodes);
    62   starHistLength = x.starHistLength;
    63   stars = new (vector<star>[starHistLength]);
    64   for (int i=0; i<starHistLength; i++)
    65     stars[i] = x.stars[i];
    66    
    67   prcTodo    = x.prcTodo;
    68  // has2bars   = x.has2bars;
    69  // elecOffset = x.elecOffset;
    70   lastBlkNum = x.lastBlkNum;
    71   seuil      = x.seuil;
    72  
     78  for(int i=0; i<NbPhotDiodBarette; i++) *PisteBar[i]=*(x.PisteBar[i]);
    7379  return *this;
    7480}
    7581
    76 SSTHandler::~SSTHandler()
    77 {
    78   delete[] stars;
     82SSTHandler::~SSTHandler(){
    7983  delete[] diodeT;
     84  findStarDestruct();
    8085}
    8186
     
    8590  if (prcTodo & findAxis)   prcTodo |= findPeriod;
    8691  if (prcTodo & findPeriod) prcTodo |= findStars;
    87   if (prcTodo & findStars)  prcTodo |= rmveOffset;
     92  if (prcTodo & findStars)  prcTodo |= permDiode;
    8893}
    8994
     
    96101  elecOffset = eo;
    97102}
    98 
    99 void SSTHandler::ProcessBlock(block_type_sst* blk)
    100 {
    101   lastBlkNum = numero_block(blk);
    102   for (int i = 0; i<nb_per_block*2; i++) {
    103     DecodeTMBlock(blk, i, diodeRaw[i]);
    104   }
    105   if (prcTodo & rmveOffset) {
    106     RemoveOffset();
    107   }
    108   if (prcTodo & findStars) {
    109     FindStars();
    110   }
    111 }
    112 
    113103
    114104void SSTHandler::DecodeTMBlock(block_type_sst* blk, int i, int* diod)
     
    139129
    140130
    141 void SSTHandler::RemoveOffset()
     131void SSTHandler::PermutDiode()
    142132{
    143133  int j0 = diodeHistLength-(nb_per_block*2);
     
    187177}
    188178
    189 int SSTHandler::getStarZ(int imesure, int istar) // for last block
    190 {
    191   int j0 = starHistLength-(nb_per_block*2);
    192   if (imesure+j0<0 || imesure>=nb_per_block*2) return -99999;
    193   if (istar < 0 || istar >= stars[imesure+j0].size()) return -99999;
    194   return stars[imesure+j0][istar].z;
    195 }
    196 
    197 int SSTHandler::getStarF(int imesure, int istar) // for last block
    198 {
    199   int j0 = starHistLength-(nb_per_block*2);
    200   if (imesure+j0<0 || imesure>=nb_per_block*2) return -99999;
    201   if (istar < 0 || istar >= stars[imesure+j0].size()) return -99999;
    202   return stars[imesure+j0][istar].m;
    203 }
    204 
    205 
    206 void SSTHandler::FindStars()  // sur les 72 derniers echantillons dans diode.
    207 {
    208   int js0 = starHistLength-(nb_per_block*2);
    209   int jd0 = diodeHistLength-(nb_per_block*2);
    210   // Decalage vers la gauche de la taille d'un bloc
    211   for (int i=0; i<js0; i++) {
    212     stars[i] = stars[i+(nb_per_block*2)];
    213   }
    214  
    215   // Recherche d'etoiles
    216   for (int i=0; i<(nb_per_block*2); i++) {
    217     stars[js0+i].clear();
    218     for (int idiode=0; idiode<46; idiode++) {
    219       if (diode(jd0+i,idiode) < -seuil) {
    220         if (has2bars) {
    221           for (int j=-2; j>=-5; j--) {
    222             if (diode(jd0+i+j,(idiode+elecOffset)%46) < -seuil) {
    223               star s;
    224               s.z = idiode;
    225               s.m = -diode(jd0+i,idiode);
    226               s.t = i; // $CHECK$ need absolute time...
    227               stars[js0+i].push_back(s);
    228               break;
    229             } else if (idiode<45 && diode(jd0+i+j,(idiode+1+elecOffset)%46) > seuil) {
    230               star s;
    231               s.z = idiode+.5;
    232               s.m = -diode(jd0+i,idiode);
    233               s.t = i; // $CHECK$ need absolute time...
    234               stars[js0+i].push_back(s);
    235               break;
    236             }
    237           }
    238         } else {
    239           if (diode(jd0+i,idiode) > diode(jd0+i-1,idiode)) {
    240             star s;
    241             s.z = idiode;
    242             s.m = -diode(jd0+i-1,idiode);
    243             s.t = i; // $CHECK$ need absolute time...
    244             stars[js0+i].push_back(s);
    245           }
    246         }
    247       }
    248     }
    249   }
    250 
    251 
    252 }
     179int SSTHandler::FindStars(block_type_sst* blk) {
     180        NbStarInBlock=0;
     181        LastBlockStarVec.clear();
     182       
     183        int NoFirstSpInBlock=FirstSplNb(blk);
     184        int jd0 = diodeHistLength-NbSampleBlock;
     185
     186        bool FlagLBlockPerdu=false;
     187        int ThisBlockNumb=numero_block(blk);
     188       
     189        if ((LastBlockSSTNb+1)==ThisBlockNumb) LastBlockSSTNb++;
     190        else {
     191                FlagLBlockPerdu=true;
     192                LastBlockSSTNb=ThisBlockNumb;
     193        }
     194
     195//      On cherche les etoiles 
     196        for(int NoDiode=0;NoDiode<NbPhotDiodBarette; NoDiode++) {       
     197                pPiste=PisteBar[NoDiode];
     198               
     199        // Traitons une diode pendant un block
     200                offseDataDiod=0;
     201                for (int i=0; i<NbSampleBlock; i++) Diodedata[i]=diode(jd0+i,NoDiode);
     202
     203                if (FlagLBlockPerdu)  {
     204                        pPiste->fill(Diodedata+offseDataDiod,FirstSplNb(blk));
     205                        offseDataDiod+=PhDiodTabLong;
     206                }
     207                else {
     208                        pPiste->push(Diodedata);
     209                        offseDataDiod+=Pousslong;
     210                }
     211               
     212        // Recherchons les etoiles
     213                while (true) {
     214                        if (pPiste->traque()) {                         // On a trouve!
     215                                LastStar=pPiste->DonneEtoile();
     216/*                              double dum= LastStar.TEchan;
     217                                pair<const double, SSTEtoile> unepaire=make_pair(dum,LastStar);
     218                                StarHistoryMap.insert(unepaire);       
     219*/
     220                                StarHistoryMap[LastStar.TEchan]=LastStar;
     221                                        //On empile sur la map.
     222                                NbStarInBlock++;
     223#ifdef SST_DEBUG                       
     224                        // On écrit les pistes ayant déclénchées
     225                                int NoDiodeEvt=LastStar.NoDiode;
     226                                if(pPisteDump[NoDiodeEvt]->is_open())   
     227                                        for(int noSamp=0; noSamp<NbSampleBlock;noSamp++)
     228                                                (*pPisteDump[NoDiodeEvt])<<noStarDet<<'\t'<<NoDiode<<'\t'<<NoFirstSpInBlock+noSamp<<'\t'<<Diodedata[noSamp]<<endl;
     229#endif
     230                                noStarDet++;
     231                        }
     232                // Est-on en bout de Piste?
     233                        if(offseDataDiod+Pousslong>=NbSampleBlock) break;
     234                        else {
     235                                pPiste->push(Diodedata+offseDataDiod);
     236                                offseDataDiod+=Pousslong;
     237                        }
     238                }
     239        }
     240       
     241//      On ne garde que les NbEtInSetMax dernières étoiles
     242        int nbEtoileInMap=StarHistoryMap.size();
     243        if(nbEtoileInMap>NbEtInMapMax) {
     244                int nbErase=nbEtoileInMap-NbEtInMapMax;
     245                StarHistIter StarIter=StarHistoryMap.begin();
     246                for(int i=0;i<nbErase;i++){
     247                        StarHistoryMap.erase(StarIter);
     248                        StarIter++;
     249                }
     250                nbEtoileInMap-=nbErase;
     251        }                       
     252       
     253//      On stocke les etoiles du block dans LastBlockStarVec
     254        map<double,SSTEtoile>::reverse_iterator StarHistReIter= StarHistoryMap.rbegin() ;
     255        for(int i=0; i<NbStarInBlock; i++, StarHistReIter++)
     256                LastBlockStarVec.push_back((*StarHistReIter).second);
     257       
     258//#ifdef SST_DEBUG
     259        if(NbStarInBlock>0) {
     260                       
     261        // On écrit les étoiles detectées
     262                vector<SSTEtoile>::reverse_iterator StarVecRevIter;
     263                StarVecRevIter=LastBlockStarVec.rbegin();
     264                for(int i=0; i<NbStarInBlock;i++,StarVecRevIter++)
     265                        (*StarVecRevIter).print(sstchass);
     266        }
     267               
     268//#endif
     269
     270        return NbStarInBlock;
     271}
     272
     273void SSTHandler::findStarConstruct() {
     274        PisteBar=new PisteEtoile*[NbPhotDiodBarette];
     275        for(int i=0; i<NbPhotDiodBarette; i++) PisteBar[i]=new PisteEtoile(i);
     276        StarHistoryMap.clear();
     277        sstchass<<LastStar.printHeader()<<endl;
     278       
     279#ifdef SST_DEBUG       
     280        char s[32];
     281        string fileName;
     282//      if(pPisteDump==NULL)
     283                pPisteDump= new ofstream* [NbChanDump];
     284       
     285        for (int pistNumb=0; pistNumb<NbChanDump; pistNumb++) {
     286                sprintf(s,"%i", pistNumb);     
     287                string piste=s;
     288                fileName="pisteno"+piste+"dump";
     289/*             
     290                if ((*pPisteDump[pistNumb]).is_open()) {
     291                        cerr<<"Erreur: le fichier "<<fileName<<" devrait être libre"<<endl;
     292                                //On libère
     293                        (*pPisteDump[pistNumb]).close();
     294                        delete pPisteDump[pistNumb];
     295                }
     296*/                     
     297                pPisteDump[pistNumb]=new ofstream(fileName.c_str(),ios::out|ios::trunc);
     298               
     299                if(!(*pPisteDump[pistNumb]).is_open()) {
     300                        cerr<<"Warning Echec à l'ouverture du fichier: "<<fileName<<endl;
     301                }
     302        }
     303#endif
     304        return;
     305}
     306
     307void SSTHandler::findStarDestruct() {
     308        for(int i=0; i<NbPhotDiodBarette; i++) {
     309                delete PisteBar[i];
     310        }
     311        delete[] PisteBar;
     312               
     313#ifdef SST_DEBUG       
     314        for (int pistNumb=0; pistNumb<NbChanDump; pistNumb++) {
     315                pPisteDump[pistNumb]->close();
     316                delete pPisteDump[pistNumb];
     317        }
     318        delete  pPisteDump;
     319#endif
     320
     321        return;
     322}
     323
     324int SSTHandler::getNumbStar(int iSampl) {
     325        StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
     326        StarHistIter IterHigh=StarHistoryMap.upper_bound((double)(iSampl+1.));
     327        int Compteur=0;
     328        while (!(IterLow==IterHigh)) {IterLow++; Compteur++;}
     329        return Compteur;
     330}
     331
     332double SSTHandler::getStarF(int iSampl, int istar){
     333        if( (getNumbStar(iSampl)==0)||(getNumbStar(iSampl)<istar)) return -1;
     334        else {
     335                StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
     336                while(!(istar==0)) {
     337                        IterLow++;
     338                        istar--;
     339                }
     340        return (double) ((*IterLow).second).InpCurrent;
     341        }
     342}
     343
     344
     345int SSTHandler::getStarZ(int iSampl, int istar) {
     346        if( (getNumbStar(iSampl)==0)||(getNumbStar(iSampl)<istar)) return -1;
     347        StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
     348        while(!(istar==0)) {
     349                IterLow++;
     350                istar--;
     351        }
     352        return ((*IterLow).second).NoDiode;
     353}
     354
     355double SSTHandler::getStarTime(int iSampl, int istar) {
     356        if( (getNumbStar(iSampl)==0)||(getNumbStar(iSampl)<istar)) return -1;
     357        StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
     358        while(!(istar==0)) {
     359                IterLow++;
     360                istar--;
     361        }
     362        return ((*IterLow).second).TEchan;
     363}
     364
     365int SSTHandler::FirstSplNb(block_type_sst* blk){
     366        return NbSampleBlock*numero_block(blk); // BUGG A verifier
     367}
     368
     369
     370void SSTHandler::ProcessBlock(block_type_sst* blk)
     371{
     372  lastBlkNum = numero_block(blk);
     373  for (int i = 0; i<nb_per_block*2; i++) {
     374    DecodeTMBlock(blk, i, diodeRaw[i]);
     375  }
     376  if (prcTodo & permDiode) {
     377    PermutDiode();
     378  }
     379  if (prcTodo & findStars) {
     380    FindStars(blk);
     381  }
     382}
     383
Note: See TracChangeset for help on using the changeset viewer.