/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/analyse/root/example.cpp File Reference

#include <map>
#include "TKey.h"
#include "TList.h"
#include <TROOT.h>
#include <TRint.h>
#include <TTree.h>
#include <TFile.h>
#include <stdlib.h>
#include <TSystem.h>
#include <iostream>
#include <sstream>
#include "Log.hh"
#include "MicroException.hh"
#include <string>
#include "mysql/Mysql.hh"
#include "root/MTRun.hh"
#include "root/MTTrack.hh"
#include "root/MTChamber.hh"
#include "root/MTDetector.hh"
#include "root/MTBoard.hh"
#include "root/MTChip.hh"
#include "root/MTChannel.hh"
#include "root/MTEvent.hh"
#include "root/MTDif.hh"
#include "root/MTHardroc1Chip.hh"
#include "root/MTHardroc2Chip.hh"
#include "root/MTDiracChip.hh"
#include "root/MTMicrorocChip.hh"

Include dependency graph for example.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 41 of file example.cpp.

00041                               {
00042 
00043   Mysql mysql;
00044   MYSQL_ROW row;
00045 
00046   string sql = "SELECT * FROM RUN";
00047 
00048   MYSQL_RES* result = mysql.executeSelect(sql);
00049 
00050   int num_fields = mysql_num_fields(result);
00051 
00052   while ((row = mysql_fetch_row(result)))
00053   {
00054       for( int i = 0; i < num_fields; i++)
00055       {
00056           printf("%s ", row[i] ? row[i] : "NULL");
00057       }
00058       printf("\n");
00059   }
00060 
00061   int id = -1;
00062   try {
00063     id  = mysql.getReconstructionSoftwareId("114");
00064   }
00065   catch (MicroException e) {}
00066 
00067   cout << "Id[" << id << "]" <<endl ;
00068   id = mysql.addReconstructionSoftware("$Revision: 1770 $", "comments");
00069   cout << "Id[" << id << "]" <<endl ;
00070   try {
00071     id  = mysql.getReconstructionSoftwareId("114");
00072   }
00073   catch (MicroException e) {}
00074   cout << "Id[" << id << "]" <<endl ;
00075 
00076 
00077 
00078    if ( argc !=2  ) {
00079    FILE_LOG(logERROR)  << "usage: example rootFile " << endl;
00080    exit(1);
00081   }
00082 
00083   string rootName;
00084   rootName.assign(argv[1]);
00085   int nbHit = 0;
00086   int nbEvt = 0;
00087 
00088   TFile f(rootName.c_str());
00089   f.ls();
00090 
00091 
00092 
00093   TIter nextkey(f.GetListOfKeys());
00094   TKey *key;
00095   while (key = (TKey*)nextkey()) 
00096   {
00097     TTree *tree = (TTree*)key->ReadObj();                
00098     MTRun *run=NULL;
00099     try 
00100     {
00101       run=dynamic_cast<MTRun *>(tree->GetUserInfo()->First());
00102       cout << "---------------------------- NEW TTREE ---------------------------"<< endl;
00103       nbEvt =0;
00104       nbHit = 0;
00105       cout << "RunId[" << run->GetRunId() << "]" << endl;
00106 
00107       bool showConfig = false;
00108       if ( run != NULL && showConfig) 
00109       {
00110         run->Info(); 
00111         MTDetector* det = run->GetDetector();
00112         // loop over chamber config
00113           
00114         const std::map<UInt_t,MTChamber*>& chambers = det->GetChambers();
00115         for( std::map<UInt_t,MTChamber*>::const_iterator ii=chambers.begin(); ii!=chambers.end(); ++ii)
00116         {
00117           const MTChamber& chamber= *((*ii).second);
00118           cout << "chamber id: " << chamber.GetId() << endl;
00119           cout << "chamber type: " << chamber.GetType() << endl;
00120 
00121           // loop over dif config
00122           //const std::map<UInt_t,MTDif*>& difs = chamber.GetDifs();
00123           //for( std::map<UInt_t,MTDif*>::const_iterator ii=difs.begin(); ii!=difs.end(); ++ii)
00124           //{
00125             //const MTDif& dif= *((*ii).second);
00126             //dif.Info();
00127           //}
00128           // loop over board config
00129           const std::map<UInt_t,MTBoard*>& boards = chamber.GetBoards();
00130           for( std::map<UInt_t,MTBoard*>::const_iterator ii=boards.begin(); ii!=boards.end(); ++ii)
00131           {
00132             const MTBoard& board= *((*ii).second);
00133             board.Info();
00134 
00135             cout << endl << endl << "\t\t\t**** Chips configuration ****" << endl ;
00136 
00137             map<UInt_t,MTChip*> chips = board.GetChips();
00138             for( map<UInt_t,MTChip*>::const_iterator iiChip=chips.begin(); iiChip!=chips.end(); ++iiChip)
00139             {
00140               const MTChip& chip  = *((*iiChip).second);
00141               if ( chip.IsConfigured() )
00142               {
00143               cout << endl << "   -- New Chip configuration:" <<  chip.GetSoftId().toString() << " softId[" << chip.GetSoftId().GetValue() <<"], serial Number[" << chip.GetSerialNumber() << "]"<< endl <<endl  <<endl ;
00144               try {
00145                 const MTDiracChip &diracChip = dynamic_cast<const MTDiracChip &> (chip);
00146                 cout << "   ** Dirac Chip config **" << endl;
00147                 cout << "      threshold B High: " << diracChip.GetBHiThreshold()  << endl;
00148                 cout << "      threshold B Mid : " << diracChip.GetBMidThreshold()  << endl;
00149                 cout << "      threshold B Low : " << diracChip.GetBLoThreshold()  << endl;
00150 
00151                 cout << "      threshold A High :" << diracChip.GetAHiThreshold()  << endl;
00152                 cout << "      threshold A Mid : " << diracChip.GetAMidThreshold()  << endl;
00153                 cout << "      threshold A Low : " << diracChip.GetALoThreshold()  << endl;
00154                 cout << "   ** END Dirac Chip config **" << endl;
00155               }
00156               catch (...) {}
00157 
00158               try{
00159                 const MTHardroc1Chip &hr1Chip = dynamic_cast<const MTHardroc1Chip &> (chip);
00160                 cout << "   ** Hardroc1 Chip config **" << endl;
00161                 cout << "      threshold dac 0: " << hr1Chip.GetThresholdDac_0()  << endl;
00162                 cout << "      threshold dac 1: " << hr1Chip.GetThresholdDac_1()  << endl;
00163                 cout <<    "   gain   :         " << hr1Chip.GetGain() << endl;
00164                 cout << "   ** END Hardroc1 Chip config **" << endl;
00165               }
00166               catch (...) {}
00167 
00168               try{
00169                 const MTHardroc2Chip &hr2Chip = dynamic_cast<const MTHardroc2Chip &> (chip);
00170                 cout << "   ** Hardroc2 Chip config **" << endl;
00171                 cout << "      threshold dac 0: " << hr2Chip.GetThresholdDac_0()  << endl;
00172                 cout << "      threshold dac 1: " << hr2Chip.GetThresholdDac_1()  << endl;
00173                 cout << "      threshold dac 2: " << hr2Chip.GetThresholdDac_2()  << endl;
00174                 cout <<    "   gain   :         " << hr2Chip.GetGain() << endl;
00175                 cout << "   ** END Hardroc2 Chip config **" << endl;
00176               }
00177               catch (...) {}
00178 
00179               try{
00180                 const MTMicrorocChip &micro2Chip = dynamic_cast<const MTMicrorocChip &> (chip);
00181                 cout << "   ** MicrorocChip Chip config **" << endl;
00182                 cout << dec << "      Serial number : " << micro2Chip.GetSerialNumber()  << endl;
00183                 cout << dec << "      low shaper : " << micro2Chip.GetShaper_lg()  << endl;
00184                 cout << dec << "      high shaper : " << micro2Chip.GetShaper_hg()  << endl;
00185                 cout << dec << "      threshold dac 0: " << micro2Chip.GetThresholdDac_0()  << endl;
00186                 cout << dec << "      threshold dac 1: " << micro2Chip.GetThresholdDac_1()  << endl;
00187                 cout << dec << "      threshold dac 2: " << micro2Chip.GetThresholdDac_2()  << endl;
00188                 cout << "   ** END MicrorocChip Chip config **" << endl;
00189               }
00190               catch (...) {}
00191 
00192               cout << endl << endl << "* channels config **" << endl << endl;
00193               cout <<"      Enable channel:" ;
00194               for ( UInt_t num = 0 ; num <=63 ; num++)
00195               {
00196                 cout << "[" << dec <<num << ":"<< chip.GetEnableChannel(num) << "]";
00197               }
00198               cout << endl <<endl << endl <<  "    Stimulate channel:";
00199               for ( UInt_t num = 0 ; num <=63 ; num++)
00200               {
00201                 cout << "[" << dec <<num << ":"<< chip.GetStimulatedChannel(num) << "]";
00202               }
00203 
00204               cout << endl <<endl << endl <<  "    Mask ( Microroc Only  ) channel:";
00205               for ( UInt_t num = 0 ; num <=63 ; num++)
00206               {
00207                 for ( UInt_t index = 0 ; index < 3 ; index++ )
00208                 {
00209                   cout << "[" << dec <<num << ":MASK" << index << "-> "<< chip.GetMaskChannel(num,index) << "]";
00210                 }
00211               }
00212 
00213 
00214               cout << endl <<endl << endl  << "    pedastal correction channel:";
00215               for ( UInt_t num = 0 ; num <=63 ; num++)
00216               {
00217                 cout << "[" <<dec << num << ":"<< chip.GetPedestalChannel(num) << "]";
00218               }
00219               cout << endl << "   -- End Chip configuration:" << endl;
00220               } // end if chip is configured
00221 
00222               }  // end loop for chip
00223                 cout  <<endl << "\t\t\t**** END Chips configuration **** "<< endl  << endl << endl;
00224           }
00225         }
00226       }
00227     }
00228     catch (MicroException e) {}
00229 
00230 
00231   MTEvent *evt =  new MTEvent();
00232   TBranch *branch= tree->GetBranch("MTEvent");
00233   branch->SetAddress(&evt);
00234 
00235   MTChannel* channel =NULL;
00236   int nbEntries = tree->GetEntries();
00237   for ( int evtNum = 0; evtNum < nbEntries ; evtNum++)
00238   {
00239     tree->GetEntry(evtNum);
00240     nbEvt++;
00241 
00242     //UInt_t nbPad = 1300;
00243     //UInt_t my_asu;
00244     //UInt_t my_abstime;
00245     //cout<<evt->IsSquare(nbPad,my_asu,my_abstime)<<endl;
00246 
00247     //if (!evt->GetCrcIsCorrect())
00248     {
00249       cout << "**** Event Information "<< dec << evtNum+1 << "/" << nbEntries<< " ****" <<  endl;
00250       cout << "    event num in TTree:" << evtNum <<endl;
00251     } 
00252 
00253     bool spark = false;
00254     std::map< UInt_t, std::map<UInt_t, UInt_t>* >& nbHitPerAbsTime = evt->GetNbHitPerAbsTime();
00255     for (std::map< UInt_t, std::map<UInt_t, UInt_t>* >::iterator iter = nbHitPerAbsTime.begin(); iter != nbHitPerAbsTime.end(); iter++)
00256     {
00257     map<UInt_t, UInt_t> *byBoard = iter->second;
00258     for ( map<UInt_t,UInt_t>::iterator it = byBoard->begin(); it != byBoard->end(); it++)
00259     {
00260     UInt_t absTime = it->first;
00261     UInt_t nbHit   = it->second;
00262         cout << "Board[" << iter->first << "] Absolute time [" << absTime  << "]nbHit[" << nbHit <<"]"    << endl;
00263     if (nbHit > 1) { spark = true; }
00264     }
00265     }
00266 
00267 
00268     //if (!evt->GetCrcIsCorrect())
00269     {
00270     cout << "    event id:" << evt->GetEventId() <<endl;
00271 
00272     cout << "    event Dif suynchro:" << evt->GetDifSynchro() <<endl;
00273     cout << "    event total Trigger counter:" << evt->GetGlobalTriggerCounter() <<endl;
00274     cout << "    event Dif Trigger counter:" << evt->GetDifTriggerCounter() <<endl;
00275 
00276     const map<unsigned int , float>& tempAsu1 = evt->GetTemperatureAsu1();
00277     for ( map<unsigned int , float>::const_iterator it = tempAsu1.begin() ; it != tempAsu1.end(); it++)
00278     {
00279       cout << "    temperature dif: " << it->first << " Asu1:" << it->second <<endl;
00280     }
00281     const map<unsigned int , float>& tempAsu2 = evt->GetTemperatureAsu2();
00282     for ( map<unsigned int , float>::const_iterator it = tempAsu2.begin() ; it != tempAsu2.end(); it++)
00283     {
00284       cout << "    temperature dif: " << it->first << " Asu2:" << it->second <<endl;
00285     }
00286     const map<unsigned int , float>& tempDif = evt->GetTemperatureDif();
00287     for ( map<unsigned int , float>::const_iterator it = tempDif.begin() ; it != tempDif.end(); it++)
00288     {
00289       cout << "    temperature dif: " << it->first << " dif:" << it->second <<endl;
00290     }
00291     cout << "    temperature:" << evt->GetTemperature() <<endl;
00292     cout << "    pressure:"<< evt->GetPressure() <<endl;
00293     cout << "    timestamp:"<< evt->GetTimestamp() <<endl;
00294     cout << "    dif_synchro:"<< evt->GetDifSynchro() <<endl;
00295     cout << "    CRC is correct:"<< evt->GetCrcIsCorrect() <<endl;
00296 
00297     const std::map<UInt_t, std::map<UInt_t, std::map<UInt_t, Float_t>* >* >& meshs = evt->GetMeshVoltage();
00298     for ( std::map<UInt_t, std::map<UInt_t, std::map<UInt_t, Float_t>* >* >::const_iterator iterChamber = meshs.begin(); iterChamber != meshs.end(); iterChamber++)
00299     {
00300       std::map<UInt_t, std::map<UInt_t, Float_t>* >&difContainer = *(iterChamber)->second;
00301       for ( std::map<UInt_t, std::map<UInt_t, Float_t>* >::const_iterator iterDif = difContainer.begin(); iterDif != difContainer.end(); iterDif++)
00302       {
00303         std::map<UInt_t, Float_t> &boardContainer = *(iterDif)->second;
00304         for ( std::map<UInt_t, Float_t>::const_iterator iterVoltage = boardContainer.begin(); iterVoltage != boardContainer.end(); iterVoltage++)
00305         {
00306           cout << "    MeshVoltage for chamber [" << iterChamber->first << "]Dif = ["<< iterDif->first << "] board[" << iterVoltage->first << "] :" <<iterVoltage->second << "]" << endl;
00307         }
00308       }
00309 
00310     }
00311 
00312 
00313     const std::map<UInt_t, std::map<UInt_t, std::map<UInt_t, Float_t>* >* >& drifts = evt->GetDriftVoltage();
00314     for ( std::map<UInt_t, std::map<UInt_t, std::map<UInt_t, Float_t>* >* >::const_iterator iterChamber = drifts.begin(); iterChamber != drifts.end(); iterChamber++)
00315     {
00316     std::map<UInt_t, std::map<UInt_t, Float_t>* >&difContainer = *(iterChamber)->second;
00317     for ( std::map<UInt_t, std::map<UInt_t, Float_t>* >::const_iterator iterDif = difContainer.begin(); iterDif != difContainer.end(); iterDif++)
00318     {
00319     std::map<UInt_t, Float_t> &boardContainer = *(iterDif)->second;
00320     for ( std::map<UInt_t, Float_t>::const_iterator iterVoltage = boardContainer.begin(); iterVoltage != boardContainer.end(); iterVoltage++)
00321     {
00322     // mergedEvt->SetDriftMeshVoltage(iterChamber->first,iterDif->first,iterVoltage->first,iterVoltage->second);
00323     cout << "    DriftVoltage for chamber [" << iterChamber->first << "]Dif = ["<< iterDif->first << "] board[" << iterVoltage->first << "] :" <<iterVoltage->second << "]" << endl;
00324 
00325     }
00326     }
00327 
00328     }
00329     }
00330 
00331     //if ( !evt->GetCrcIsCorrect()) 
00332     {
00333 
00334       if ( run->GetProcessed() == true )
00335       {
00336         cout << "    is square[" << evt->GetSquareEvt() << "]"  << endl;
00337         cout << "    is time info correct[" << evt->GetTimeInfo() << "]"  << endl;
00338         MTTrack *track = evt->GetTrack();
00339         if ( track != NULL )
00340         {
00341           cout << "    straight: " << track->GetStraight()
00342           << ", from Strip: " << track->GetFromStrip()
00343           << ", from Pad: " << track->GetFromPad()
00344           << ", single hit: " << track->GetSingleHit()
00345           << ", ax: " << track->GetAx()
00346           << ", bx: " << track->GetBx()
00347           << ", ay: " << track->GetAy()
00348           << ", by: " << track->GetBy()  << endl;
00349         }
00350       }
00351       cout << "    number of channel hit:" << evt->GetNchannel() <<endl;
00352       int nbChannel = evt->GetNchannel();
00353       for(int i=0;i<nbChannel  ;i++)
00354       {
00355         nbHit++;
00356         channel = (MTChannel*)evt->GetChannels()->UncheckedAt(i);
00357 
00358 
00359         //if ( channel->GetSoftId().GetChamberId() == 4 )
00360         //if ( channel->GetAnalogValue() != 0 && channel->GetDigitalValue() != 0)
00361         {
00362         cout << "****** Channels Information "<< i+1 << "/" << nbChannel << " ******" <<  endl;
00363         cout << "      Hit num:            " << i << endl;
00364         cout << "      chamber id:         " << channel->GetChamberId() <<endl;
00365         cout << "      dif id:             " << channel->GetDifId() <<endl;
00366         cout << "      boardId id:         " << channel->GetBoardId() <<endl;
00367         cout << "      chip id(format dec):" << dec << channel->GetChipId() <<endl;
00368         cout << "      hard id    :        " << dec << channel->GetHardId() <<endl;
00369         cout << "      row inside chip :   " << channel->GetRowInChip() <<endl;
00370         cout << "      col inside chip:    " << channel->GetColInChip() <<endl ;
00371         cout << "      soft id:            " << channel->GetSoftId().GetValue() << endl<< endl;
00372         cout << "      soft id:            " << channel->GetSoftId().GetValue() << endl<< endl;
00373         cout << "      asu row:            " << channel->GetSoftId().GetBoardRow() << endl<< endl;
00374         cout << "      asu col:            " << channel->GetSoftId().GetBoardCol() << endl<< endl;
00375         cout << "      channel row inside chamber: " << channel->GetRowInChamber() <<endl;
00376         cout << "      channel col inside chamber: " << channel->GetColInChamber() <<endl ;
00377         cout << "      analog value:       " << channel->GetAnalogValue() <<endl;
00378         cout << "      digital value:      " <<  channel->GetDigitalValue() <<endl;
00379         cout << "      x:                  " <<  channel->GetX() <<endl;
00380         cout << "      y:                  " << channel->GetY() <<endl;
00381         cout << "      z:                  " << channel->GetZ() <<endl;
00382         cout << "      order:              " << channel->GetOrder() <<endl;
00383         cout << "      timestamp:          " <<  channel->GetTimestamp() <<endl;
00384         cout << "      bcId abs:           " << channel->GetBcId_Abs() <<endl;
00385         cout << "      bcId dif:           " << channel->GetBcId_Dif() <<endl;
00386         cout << "      bcId hit:           " << channel->GetBcId_Hit() <<endl;
00387         UInt_t absTime =  channel->GetBcId_Abs() - (channel->GetBcId_Dif() - channel->GetBcId_Hit() );
00388         cout << "      absolute time:bcid_abs - (bcid_dif - bcid_hit)       " << absTime <<endl;
00389         cout << "      nbHit for this absolute time:" << evt->GetNbHitPerAbsTime(channel->GetSoftId().GetBoardId(),absTime)<<endl;
00390         cout << "      bcId hit Fine:      " << channel->GetBcId_Hit_Fine() <<endl;
00391         cout << "      memory order :      " << channel->GetMemoryOrder() <<endl;
00392         }
00393       }
00394     }
00395   }
00396   cout << "End of TTree[" << tree->GetName() << "]" <<endl;
00397   cout << endl << "** Nombre d Event["<< nbEvt <<"] ** "<< endl;
00398   cout << endl << "** Nombre de Hits["<< nbHit <<"] ** "<< endl;
00399 
00400 }
00401 return 0 ;
00402 }


Generated on Mon Jun 11 16:57:28 2012 for MicromegasFramework by  doxygen 1.4.7