/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/RawDataCnv/RawDataCnv-00-04-35/src/EventManagement/EmcBuilder.cxx

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include "Identifier/EmcID.h"
00004 #include "RawDataCnv/EventManagement/EmcBuilder.h"
00005 using namespace std;
00006 
00007 EmcBuilder::EmcBuilder()
00008   :Builder()
00009 {
00010   // set vector size (2^13) and initialize to -1
00011   m_re2te = new uint32_t[8192];  // we have 2^14 different REID
00012   memset((void*)m_re2te, 0xFF, 8192*sizeof(uint32_t));
00013 
00014   initialize (Builder::m_confFile);
00015 }
00016 
00017 EmcBuilder::~EmcBuilder()
00018 {
00019    delete m_re2te;
00020 }
00021 
00022 void EmcBuilder::unPack(uint32_t reDigi, uint32_t &REId, uint32_t &TETDC, uint32_t &TEADC,
00023                         uint32_t &measure)
00024 {
00025    REId = (reDigi&m_idMask) >> m_idIndex; 
00026    TETDC = (reDigi&m_tdcMask) >> m_tdcIndex; 
00027    TEADC = (reDigi&m_adcMask) >> m_adcIndex;
00028    measure = (reDigi&m_measureMask) >> m_measureIndex; 
00029 
00030    return;
00031 }
00032 
00033 StatusCode EmcBuilder::pack(EmcDigiCol* digiCol, WriteRawEvent*& re)
00034 {
00035   if (digiCol == 0 ) {
00036     cerr << "EmcBuilder::pack can't get digiCol" << endl;
00037     return StatusCode::FAILURE;
00038   }
00039 
00040   uint32_t size = 0;
00041   uint32_t teid = 0, tetdc = 0, teadc = 0, reid = 0, redigi = 0, measure = 0;
00042 
00043   EmcDigiCol::const_iterator pEmcDigi = digiCol->begin();
00044   for (pEmcDigi; pEmcDigi!= digiCol->end(); pEmcDigi++) {
00045     teid  = (*pEmcDigi)->getIntId();
00046     reid  = getREID(teid);
00047     tetdc = (*pEmcDigi)->getTimeChannel();
00048     teadc = (*pEmcDigi)->getChargeChannel();
00049     measure = (*pEmcDigi)->getMeasure();
00050 
00051     // if negative energy, don't record 
00052     if(teadc&0x80000000) continue;
00053     // set ...
00054     redigi = ((reid<<m_idIndex)&m_idMask)|
00055              ((tetdc<<m_tdcIndex)&m_tdcMask)|
00056              ((teadc<<m_adcIndex)&m_adcMask)|
00057              ((measure<<m_measureIndex)&m_measureMask);
00058     m_buf[size++] = redigi;
00059   }
00060 
00061   append2event(re, 0xa30000, size);
00062 
00063   return StatusCode::SUCCESS;
00064 }
00065 
00066 // initialize re2te tables
00067 
00068 StatusCode  EmcBuilder::initialize(string& initFile)
00069 {
00070   ifstream f;
00071 
00072   uint32_t nREThetaPos, nREPhiPos, nREEaWePos;
00073   uint32_t nREThetaMask, nREPhiMask, nREEaWeMask;
00074   
00075   //-----------------------------------------------------------
00076   // read initFile
00077   f.open( initFile.c_str());
00078   
00079   if( f.bad() )
00080   {
00081      cerr << "Error: could not open file " << initFile << endl;
00082      return false;
00083   }
00084 
00085   if (!Builder::find( f, "##EmcDigiConf", initFile)) {
00086     cerr << "Error: could not find '##EmcDigiConf' in file " << initFile << endl;
00087     return StatusCode::FAILURE;
00088   }
00089 
00090   if( !Builder::expect( f, "#Index,mask", initFile) ||  
00091       !Builder::expectInt( f, "id", initFile, m_idIndex, m_idMask) ||   
00092       !Builder::expectInt( f, "tdc", initFile, m_tdcIndex, m_tdcMask) ||   
00093       !Builder::expectInt( f, "measure", initFile, m_measureIndex, m_measureMask) ||   
00094       !Builder::expectInt( f, "adc", initFile, m_adcIndex, m_adcMask) ||   
00095       !Builder::expectInt( f, "Phi", initFile, nREPhiPos, nREPhiMask) ||  
00096       !Builder::expectInt( f, "Theta", initFile, nREThetaPos, nREThetaMask) ||
00097       !Builder::expectInt( f, "EaWe", initFile, nREEaWePos, nREEaWeMask))
00098     return false; 
00099  
00100   
00101   f.close();
00102 
00103   //-----------------------------------------------------------
00104   //Build re2te table
00105   for(uint32_t  barrel_ec_eawe = EmcID::getBARREL_EC_MIN(); 
00106       barrel_ec_eawe <= EmcID::getBARREL_EC_MAX(); barrel_ec_eawe++)
00107   {
00108       uint32_t TEthetaMax, TEphiMax;
00109       uint32_t TEthetaMin, TEphiMin;
00110       uint32_t eawe, theta, phi;
00111       if(barrel_ec_eawe == EmcID::getBARREL())
00112       {
00113            //it is BARREL
00114            TEthetaMax = EmcID::getTHETA_BARREL_MAX();//43
00115            TEthetaMin = EmcID::getTHETA_BARREL_MIN();//0
00116       } else
00117       {
00118            //it is ease and west ENDCAP
00119            TEthetaMax = EmcID::getTHETA_ENDCAP_MAX();//5
00120            TEthetaMin = EmcID::getTHETA_ENDCAP_MIN();//0
00121            if (barrel_ec_eawe == EmcID::getBARREL_EC_MIN()) 
00122                eawe = 0;//east
00123            else
00124                eawe = 1;//west
00125       }
00126       for(uint32_t  TEtheta = TEthetaMin; TEtheta <= TEthetaMax; TEtheta++ )
00127       {
00128            if(barrel_ec_eawe == EmcID::getBARREL())
00129            {
00130                //it is BARREL
00131                if (TEtheta <= EmcID::getTHETA_BARREL_MAX()/2) 
00132                {
00133                   eawe = 0; //east
00134                   theta = EmcID::getTHETA_BARREL_MAX()/2 +1 - TEtheta; //0-21=>22-1
00135                }
00136                else {
00137                   eawe = 1; //west
00138                   theta = TEtheta - EmcID::getTHETA_BARREL_MAX()/2; //22-43=>1-22
00139                }
00140                TEphiMax = EmcID::getPHI_BARREL_MAX();//119
00141                TEphiMin = EmcID::getPHI_BARREL_MIN();//0
00142 
00143            } else
00144            {
00145                //it is ease and west ENDCAP
00146                theta = TEtheta + EmcID::getTHETA_BARREL_MAX()/2 + 2;
00147                TEphiMax = EmcID::getPHI_ENDCAP_MAX(TEtheta);//64,80,96
00148                TEphiMin = EmcID::getPHI_ENDCAP_MIN();
00149 
00150            }
00151 
00152            for(uint32_t TEphi = TEphiMin; TEphi <= TEphiMax; TEphi++ )
00153            {
00154              phi = TEphi + 1;
00155              //cout << "eawe" << hex << eawe <<endl;
00156              //cout << "__FILE__ theta " << theta << "phi " << phi << endl;
00157              uint32_t reid = ((eawe<<nREEaWePos)&nREEaWeMask)|
00158                ((theta<<nREThetaPos)&nREThetaMask)|
00159                ((phi<<nREPhiPos)&nREPhiMask);
00160              uint32_t teid = EmcID::getIntID(barrel_ec_eawe, TEtheta, TEphi);
00161              //cout << "barrel_ec_eawe" << barrel_ec_eawe <<endl;
00162              //cout << "TEtheta" << hex << TEtheta << endl;
00163              //cout << "TEphi" << hex << TEphi <<endl;
00164 
00165              if( reid >= 8192 )
00166              {
00167                cerr << "Error: REID overflow !" << reid << endl;
00168                exit(8);
00169              }
00170              //cout << "reid" << hex << reid << endl;
00171              //cout << "teid" << hex << teid << endl; 
00172              m_re2te[reid] = teid;
00173              m_te2reMap.insert(TE2REMAP::value_type(teid, reid)) ; 
00174            }
00175        }
00176     }
00177     // return successful initialization
00178     return StatusCode::SUCCESS;
00179 }
00180 
00181 
00182 uint32_t EmcBuilder::getREID(uint32_t teid)
00183 {
00184   TE2REMAP::iterator itr = m_te2reMap.find(teid);
00185  
00186   if (itr == m_te2reMap.end()) {
00187       cout<<"wrong teid in emc "<<teid<<endl;
00188       exit(8);
00189   }
00190 
00191   return itr->second;
00192 }
00193 

Generated on Tue Nov 29 22:58:32 2016 for BOSS_7.0.2 by  doxygen 1.4.7