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

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include "Identifier/MdcID.h"
00004 #include "RawDataCnv/EventManagement/MdcBuilder.h"
00005 using namespace std;
00006 
00007 MdcBuilder::MdcBuilder()
00008    :Builder()
00009 {
00010   // set vector size (2^14) and initialize to -1
00011   m_re2te = new uint32_t[16384];  // we have 2^14 different REID
00012   memset((void*)m_re2te, 0xFF, 16384*sizeof(uint32_t));
00013 
00014   initialize (Builder::m_confFile);
00015 }
00016 
00017 MdcBuilder::~MdcBuilder()
00018 {
00019    delete m_re2te;
00020 }
00021 
00022 void MdcBuilder::unPack(uint32_t reDigi, uint32_t &REId, uint32_t &TEData,
00023                         uint32_t &overFlow, uint32_t &TorQ)
00024 {
00025    REId = (reDigi&m_idMask)>>m_idIndex;
00026    //cout << "MdcBuilder::unPack  reDigi: 0x" << hex << reDigi << "  reid: 0x" << reid << dec << endl;
00027    TEData = reDigi&m_dataMask;
00028    overFlow = (reDigi&m_overflowMask)>>m_overflowIndex;
00029    TorQ = (reDigi&m_TQMask)>>m_TQIndex;
00030    //cout << "reid" << hex << reid << endl;
00031    //cout << "teid" << hex << TEId << endl;
00032    return;
00033 }
00034 
00035 StatusCode MdcBuilder::pack(MdcDigiCol* digiCol, WriteRawEvent*& re)
00036 {
00037   if (digiCol == 0 ) {
00038     cerr << "MdcBuilder::pack can't get digiCol" << endl;
00039     return StatusCode::FAILURE;
00040   }
00041 
00042   uint32_t size = 0;
00043   uint32_t teid = 0, tetdc = 0, teadc = 0, reid = 0, redigi = 0, overflow = 0;
00044 
00045   MdcDigiCol::const_iterator pMdcDigi = digiCol->begin();
00046   for (pMdcDigi; pMdcDigi!= digiCol->end(); pMdcDigi++) {
00047     //zoujh+++++++++++, be consistent with DAQ raw data
00048     Identifier id = (*pMdcDigi)->identify();
00049     int layer = MdcID::layer(id), wire = MdcID::wire(id);
00050     if ( layer == 20 && wire < 8 ) {
00051         layer = 42;
00052     }
00053     else if ( layer == 42 && wire < 8 ) {
00054         layer = 20;
00055     }
00056     else if ( layer == 40 ) {
00057         if ( wire >= 200 && wire < 208 ) {
00058             wire += 8;
00059         }
00060         else if ( wire >= 208 && wire < 216 ) {
00061             wire -= 8;
00062         }
00063     }
00064     //teid  = (*pMdcDigi)->getIntId();
00065     teid = MdcID::getIntID(layer, wire);
00066     //zoujh-----------
00067     reid  = getREID(teid);
00068     tetdc = (*pMdcDigi)->getTimeChannel();
00069     teadc = (*pMdcDigi)->getChargeChannel();
00070     // overflow
00071     uint32_t overflow_tmp = (*pMdcDigi)->getOverflow();
00072     // set tdc
00073     if(tetdc!=0x7FFFFFFF){
00074       overflow = ((tetdc > m_dataMask) ? 1 : 0) | (overflow_tmp&1);
00075       redigi = (tetdc&m_dataMask)|
00076                ((reid<<m_idIndex)&m_idMask)|
00077                ((overflow<<m_overflowIndex)&m_overflowMask)|
00078                ((0<<m_TQIndex)&m_TQMask);
00079       m_buf[size++] = redigi;
00080     }
00081     // set adc
00082     if(teadc!=0x7FFFFFFF){
00083       overflow = ((teadc > m_dataMask) ? 1 : 0) | ((overflow_tmp>>1)&1);
00084       redigi = (teadc&m_dataMask)|
00085                ((reid<<m_idIndex)&m_idMask)|
00086                ((overflow<<m_overflowIndex)&m_overflowMask)|
00087                ((1<<m_TQIndex)&m_TQMask);
00088       m_buf[size++] = redigi;
00089     }
00090   }
00091 
00092   append2event(re, 0xa10000, size);
00093 
00094   return StatusCode::SUCCESS;
00095 }
00096 
00097 // initialize re2te tables
00098 
00099 StatusCode  MdcBuilder::initialize(string& initFile)
00100 {
00101   ifstream f;
00102 
00103   uint32_t NRELAYERPOS, NREWIREPOS, NREEAWEPOS;
00104   uint32_t NRELAYERMASK, NREWIREMASK, NREEAWEMASK;
00105 
00106   
00107   //-----------------------------------------------------------
00108   // read initFile
00109   f.open( initFile.c_str());
00110   
00111   if( f.bad() ) {
00112      cerr << "Error: could not open file " << initFile << endl;
00113      return false;
00114   }
00115 
00116   if (!Builder::find( f, "##MdcDigiConf", initFile)) {
00117     cerr << "Error: could not find '##MdcDigiConf' in file " << initFile << endl;
00118     return StatusCode::FAILURE;
00119   }
00120 
00121   if( !Builder::expect( f, "#Index,mask", initFile) ||
00122       !Builder::expectInt( f, "id", initFile, m_idIndex, m_idMask) ||
00123       !Builder::expectInt( f, "data", initFile, m_dataIndex, m_dataMask) ||
00124       !Builder::expectInt( f, "Overflow", initFile, m_overflowIndex, m_overflowMask) ||
00125       !Builder::expectInt( f, "T/Q", initFile, m_TQIndex, m_TQMask) ||
00126       !Builder::expectInt( f, "Wire", initFile, NREWIREPOS, NREWIREMASK) ||
00127       !Builder::expectInt( f, "Layer", initFile, NRELAYERPOS, NRELAYERMASK) )
00128     return false; 
00129   
00130   f.close();
00131   //-----------------------------------------------------------
00132   //Build re2te table
00133   uint32_t  nRELayerPos, nREWirePos, nREEaWePos;  
00134   uint32_t  nRELayerMask, nREWireMask, nREEaWeMask;  
00135 
00136 
00137   uint32_t TELayerMax = MdcID::getAXIAL_LAYER_MAX()+MdcID::getSTEREO_LAYER_MAX()+1;
00138   uint32_t TEWireMax = MdcID::getAXIAL_WIRE_MAX();
00139 
00140   int i = 0; 
00141 
00142   uint32_t layer, wire;
00143         
00144   nRELayerPos =  NRELAYERPOS;
00145   nREWirePos =  NREWIREPOS;
00146   nRELayerMask = NRELAYERMASK;
00147   nREWireMask = NREWIREMASK; 
00148 
00149   for(uint32_t  TELayer = 0; TELayer <= TELayerMax; TELayer++ )
00150   {
00151     layer = TELayer + 1;
00152     // After Layer 32, there are changes in positions of Layers and wires
00153     if(layer >= 0x20) {
00154       layer = layer + i ;
00155       i++;   
00156       nRELayerMask = nRELayerMask&0xFFFFFBFF;
00157       nREWireMask = nREWireMask|0x00000400;
00158       TEWireMax = MdcID::getAXIAL_WIRE_MAX();
00159     }
00160     else {
00161       //When Layer is less than 32, the number of wire is less than 240 to prevent overflow;
00162       TEWireMax = 240;
00163     } 
00164 
00165     for(uint32_t TEWire = 0; TEWire <= TEWireMax; TEWire++ )
00166     {
00167       wire = TEWire + 1;
00168       uint32_t reid = (((layer<<nRELayerPos)&nRELayerMask)|
00169           ((wire<<nREWirePos)&nREWireMask))>>2;
00170       //cout << "TELayer" << hex << TELayer;
00171       //cout << " TEWire" << hex << TEWire;
00172       //cout << " layer" << hex << layer;
00173       //cout << " wire" << hex << wire;
00174 
00175       uint32_t teid = MdcID::getIntID(TELayer, TEWire);
00176 
00177       if( reid >= 16384 )
00178       {
00179         cerr << "Error: REID overflow !" << reid << endl;
00180         exit(8);
00181       }
00182       //cout << " reid" << hex << reid;
00183       //cout << " teid" << hex << teid << endl;
00184       m_re2te[reid] = teid;
00185       m_te2reMap.insert(TE2REMAP::value_type(teid, reid)) ;
00186     }
00187   }
00188 
00189    // return successful initialization
00190    return StatusCode::SUCCESS;
00191 }
00192 
00193 
00194 uint32_t MdcBuilder::getREID(uint32_t teid)
00195 {
00196   TE2REMAP::iterator itr = m_te2reMap.find(teid);
00197  
00198   if (itr == m_te2reMap.end()) {
00199       cout << "wrong teid in mdc " << teid << endl;
00200       exit(8);
00201   }
00202 
00203   return itr->second;
00204 }
00205 

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