FlyoDoc_2011 Pisa 2011 by GmP --- 011

flyopunta/src/src_main/main.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003 C    Na48  flyo  main program      Tirrenia 11.06.01
00004 Dal 2004 e' tutto in CVS
00005 ***********************************************/
00006 #define MAIN
00007 
00008 #include "flyoh.h"
00009 #include "flyoana.h"
00010 #include "fase3max.h"
00011 
00012 void Get_Data_Gen();
00013 void Compatibility();
00014 
00036 int main ( int argc, char *argv[] )
00037 {
00038     gargc=argc;
00039     gargv=argv;
00040 
00041     //  all init..
00042     flyoinit();
00043     Gout<<"\n Flyoinit done. "<<flush;
00044 
00045     //==========
00046 // test on comnpatibility...
00047     Compatibility();
00048     //==========
00049 //init fits, and the data out_file
00050     FitsControl ( 0 );
00051     Gout<<"\n FitsControl(0) done. "<<flush;
00052     Scrivi_Dati ( 0 );
00053     Gout<<"\n Scrivi_nt(0)) done. "<<flush;
00054 
00055 
00056 // ========================================================
00057 
00058 //***********************************************************
00059 //***********************   L O O P   ***********************
00060 //***********************************************************
00061 
00062     SelRea=0;
00063 
00064 
00065 //  main do loop
00066     while ( Eventi_Fatti<evento_.Mxev )
00067     {
00068         // reset reazioni e  devices...
00069         if ( SelRea!=0 ) SelRea->Reset_Rea();
00070         Reset_Devices();
00071 
00072         Eventi_Fatti++;
00073         evento_.Gen.Event=Eventi_Fatti;
00074 
00075 // flyoevento() ritorna un numero che dipende dai dev colpiti
00076 // se un detector colpito ha il flag veto, si termina la generazione e si va al prossimo evento...
00077 // attenzione la flag veto non è compatibile con pipelin on poichè l'evento non viene tracciato completamente!!!!
00078 
00079 //  ==== E V E N T      G E N E R A T I O N   ====
00080         evento_.Gen.trigger_flag=flyoevento();  //done no zero if at least  one dev has been hit...
00081 //  ==== E V E N T     D O N E   ====
00082 
00083         if ( evento_.Gen.trigger_flag<=0 ) continue; // if no detector was shot skip to the next event.
00084 
00085         if ( Luce!=0 ) Luce->Store_Illumina();// better if Luce  activated without the pipeline. See Compatibility()
00086 
00087         evento_.Define_Standard_Header();      // event title and basic parameters...
00088         if ( Pipeline==1 ) evento_.Put_Header_into_Buffer();
00089 
00090 
00091 //=====================================================
00092 //-----------------------------------------------------
00093 // inizio loop  per la elaborazione degli eventi memorizzati nel buffer circolare.
00094 // che hanno generato un trigger di basso livello: almeno un device toccato (done).
00095 // La elaborazione dei trigger è asincrona rispetto alla generazione,
00096 // si elaborano comunque tutti gli eventi con  trigger generati Tpipe ns prima dell'ultimo evento generato.
00097 // se la pipeline non è attivata la loop è dummy....
00098 
00099 
00100         static double triggerpast=0.0;
00101         while ( 1 )
00102         {
00103             if ( Pipeline==1 )
00104             {
00105 // estraggo i titoli dal buffer degli header...
00106 // estraggo i dati delle pipeline dei dev in una finestra di
00107 // +- Tpipe attorno al tempo del trigger
00108 // il trigger dev essere almeno "Tpipe" ns prima del tempo attuale.
00109                 if ( evento_.Get_Header_from_Buffer() <0 ) break; //if no more events ... skip...
00110             }
00111             else Get_Data_Gen();  // semplicemente copia i dati generati nel buffer  M_Hits
00112 
00113 // if Trigger_box is on .. check the level 0 trigger.
00114             if ( Trigger!=0 )
00115             {
00116                 evento_.Gen.trigger_flag=Trigger->Level0();
00117                 if (evento_.Gen.trigger_flag==0 ) break;   // if not... skip and look for a new trigger
00118                 evento_.Gen.ttrigdif=evento_.Gen.tempo-triggerpast; // redefinition .. see event0.cpp
00119                 triggerpast=evento_.Gen.tempo;
00120             }
00121 
00122 //==================================== S I M U L A ===========================
00123             flyosimuladev();
00124 //==================================== E N D      S I M U L A ===========================
00125 
00129             Device *pv;
00130             pv=Apparato;
00131             while ( pv!=0 )
00132             {
00133                 if ( pv->escludi==0 ) pv->Get_DatiOut();
00134                 pv=pv->next;
00135             }
00136             if ( Radio!=0 ) Radio->Store_Radx(); //take a radiografy of the apparatus!!!
00137 //===============================================================
00138 // si procede all'analisi dei dati misurati se richiesto
00139             if ( Primofit!=0 )   FitsControl ( 1 );
00140 
00141 // e si scrive tutto sul file di uscita
00142             Scrivi_Dati ( 1 );
00143 
00144 // se la pipeline è off non itero...passo alla generazione del prossimo evento...
00145             if ( Pipeline==0 ) break;
00146         }
00147     }  
00148 //=====end event main loop  ======
00149 
00150 //==== closing the simulation ===============
00151 //==================
00152 //  program ends.....
00153 
00154     if ( Fasemx!=0 ) Fasemx->Info();
00155     Gout<<"\n\n ======>>>  E n d      p r o g r a m    s u m m a r y "<<endl;
00156     if ( Primofit!=0 ) FitsControl ( 2 );
00157     Scrivi_Dati ( 2 );
00158     flyoend();
00159     cout<<"\n\n ======>>>  E n d      p r o g r a m  "<<endl;
00160     return 0;
00161 }
00162 //=================================================================
00163 
00164 //=================================================================
00168 void  Get_Data_Gen()
00169 {
00170     Device *dev=Apparato;
00171     while ( dev!=0 )
00172     {
00173         if ( dev->escludi!=1 ) dev->Fill_Default();
00174         dev= dev->next;
00175     }
00176 }
00177 //=================================================================
00181 void  Compatibility()
00182 {
00183     // compatibility....
00184     if ( Pipeline==1 &&  Luce!=0 )
00185     {
00186         Gout<<"\n ****  Pipeline and Illumina  incompatibilty... attention ..."<< endl;
00187         cout<<"\n ****  Pipeline and Illumina  incompatibilty... attention ..."<< endl;
00188         exit ( 0 );
00189     }
00190     if ( Pipeline==1 && Radio!=0 )
00191     {
00192         Gout<<"\n ****  Pipeline and Radx  incompatibilty... attention! ..."<< endl;
00193         cout<<"\n ****  Pipeline and Radx  incompatibilty... attention! ..."<< endl;
00194         exit ( 0 );
00195     }
00196     // triger of low level on....
00197     if ( Trigger_low_on==1 ) Gout<<"\n ***** -> trgtest <-  set up... did you test the Trigger->Calcola procedure?"<<endl;
00198 }
 All Classes Namespaces Files Functions Variables