emcDataFormatter.C

Go to the documentation of this file.
00001 #include "emcDataFormatter.h"
00002 #include "EmcIndexer.h"
00003 #include "emcRawDataAccessor.h"
00004 #include "emcRawDataObject.h"
00005 #include "Event.h"
00006 #include "EmcDynamicData.h"
00007 
00008 using namespace std;
00009 // **********************************************************************
00010 
00011 // #define HG_PRE_OUT       0x4     // high gain pre-sample value is OUT-OF-RANGE
00012 // #define HG_POST_OUT      0x8     // high gain post-sample value is OUT-OF-RANGE
00013 
00014 // #define LG_PRE_OUT       0x40    // low gain pre-sample value is OUT-OF-RANGE
00015 // #define LG_POST_OUT      0x80    // low gain post-sample value is OUT-OF-RANGE
00016 
00017 // #define TAC_OUT          0x400   // TAC value is OUT-OF-RANGE
00018 // #define CHANNEL_DISABLED 0x2000  // 
00019 
00020 // #define HG_MIN           1024
00021 // #define HG_MAX           4095
00022 // #define LG_MIN           0
00023 // #define LG_MAX           4095
00024 // #define TAC_MIN          0
00025 // #define TAC_MAX          4095
00026 
00027 
00028 bool emcDataFormatter::fillRDO(Event * ev){
00029   //  cout<<"emcDataFormatter::fillRDO "<<endl;
00030   //  ev->identify();
00031   emcRawDataAccessor * rda = emcRawDataAccessor::GetInstance();
00032   emcRawDataObject   * rdo = rda->GetRawDataObject() ;
00033   EmcDynamicData     * fDynamicData = rda->GetDynamicData() ;
00034   const SuperModule  * SMMap = fDynamicData->getSMMap();
00035   struct emcChannelLongList ecl[144];
00036   int    nw;
00037   int    NumberOfChannels;
00038 
00039   // loop over packets
00040   for(int iSM=0;iSM<fDynamicData->getnSM(); iSM++){
00041     empty(rdo, iSM);
00042     int packetId = 8001+SMMap[iSM].absPosition;
00043     Packet * p = ev->getPacket(packetId);
00044     //    if(!p) cout<<"Packet "<<packetId<<" not found"<<endl;
00045     if(p) {
00046       int ctac = p->iValue(0,"AMU");
00047       int cpre = p->iValue(1,"AMU");
00048       int cpost= p->iValue(2,"AMU");
00049       rdo->SetCells(iSM, ctac, cpre, cpost);
00050       int hF   = p->getHitFormat();
00051       NumberOfChannels = p->fillIntArray ( (int *) ecl, sizeof(*ecl), &nw, "SPARSE");
00052 
00053 
00054 
00055 //       if(packetId>8100&&packetId<8176) {
00056 //      cout<<packetId<<" Channels "<<NumberOfChannels<<" HitFormat "<<p->getHitFormat()<<" Words "<<nw<<endl;
00057 //      cout<<packetId<<" "<<ctac<<" "<<cpre<<" "<<cpost<<endl;
00058 //      }
00059 
00060 
00061       //     if(NumberOfChannels==0) {
00062       //        for(int i=0;i<144;i++){
00063       //          cout<<i<<" "<<p->iValue(i,0)<<" "<<p->iValue(i,1)<<" "<<p->iValue(i,2)<<" "<<p->iValue(i,3)<<" "<<p->iValue(i,4)<<endl;
00064       //        }
00065       //       }
00066       int start = iSM*144;
00067       delete p;
00068       if((packetId<=8172||packetId>=8176) ||
00069          // beginning Run5 we have new FPGA code and similar data structures in all FEM's including Monitoring
00070          (packetId>8172&&packetId<8176&&NumberOfChannels>72)) {
00071 
00072         //  All normal calorimeter data packets
00073         for (int i=0; i< NumberOfChannels; i++){
00074           int errCode = 0;
00075           int tac     = 4095-ecl[i].time;
00076           int hg_pre  = 4095-ecl[i].highpre;
00077           int hg_post = 4095-ecl[i].highpost;
00078           int lg_pre  = 4095-ecl[i].lowpre;
00079           int lg_post = 4095-ecl[i].lowpost;
00080           if(tac    <=TAC_MIN||tac    >=TAC_MAX) errCode |= TAC_OUT;
00081           if(hg_pre <=HG_MIN ||hg_pre >=HG_MAX)  errCode |= HG_PRE_OUT;
00082           if(hg_post<=HG_MIN ||hg_post>=HG_MAX)  errCode |= HG_POST_OUT;
00083           if(lg_pre <=LG_MIN ||lg_pre >=LG_MAX)  errCode |= LG_PRE_OUT;
00084           if(lg_post<=LG_MIN ||lg_post>=LG_MAX)  errCode |= LG_POST_OUT;
00085           rdo->Set(start+ecl[i].channel, tac, hg_post, lg_post, hg_pre, lg_pre, errCode);
00086           // cout<<"Set twr "<<start+i<<" "<<ecl[i].channel<<" TAC "<<tac<<" HG-POST "<<hg_post<<" LG-POST "<<lg_post <<" HG-PRE "<<hg_pre<<" LG-PRE "<<lg_pre<<" ERR-CODE "<<hex<<errCode<<dec<<endl;
00087         }
00088       } else {
00089         // PBSC monitoring FEM's
00090         for (int i=0; i< NumberOfChannels; i++){
00091           int errCode = 0;
00092           int tac     = 4095-ecl[i].time;
00093           int hg_pre  = 4095-ecl[i].highpre;
00094           int hg_post = 4095-ecl[i].highpost;
00095           int lg_pre  = 4095-ecl[i].lowpre;
00096           int lg_post = 4095-ecl[i].lowpost;
00097           if(tac    <=TAC_MIN||tac    >=TAC_MAX) errCode |= TAC_OUT;
00098           if(hg_pre <=HG_MIN ||hg_pre >=HG_MAX)  errCode |= HG_PRE_OUT;
00099           if(hg_post<=HG_MIN ||hg_post>=HG_MAX)  errCode |= HG_POST_OUT;
00100           if(lg_pre <=LG_MIN ||lg_pre >=LG_MAX)  errCode |= LG_PRE_OUT;
00101           if(lg_post<=LG_MIN ||lg_post>=LG_MAX)  errCode |= LG_POST_OUT;
00102           int ch      = ecl[i].channel;
00103           int loc     = ch%24 + (ch/24)*48;
00104           rdo->Set(start+loc, tac, hg_post, lg_post, hg_pre, lg_pre, errCode);  
00105           //      cout<<"Set ref "<<i<<" "<<ecl[i].channel<<" "<<loc<<" TAC "<<tac<<" HG-POST "<<hg_post<<" LG-POST "<<lg_post <<" HG-PRE "<<hg_pre<<" LG-PRE "<<lg_pre<<" ERR-CODE "<<hex<<errCode<<dec<<endl;
00106         }
00107       }
00108 
00109     }
00110   }
00111   return true;
00112 }
00113 
00114 void emcDataFormatter::empty(emcRawDataObject * rdo, const int iSM){
00115   int start = iSM*144;
00116   for (int i=0; i<144; i++){
00117     rdo->Set(start+i, 0,0,0,0,0,CHANNEL_DISABLED);
00118   }
00119   rdo->resetAMUAddresses(iSM);
00120 }
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129