CMS 3D CMS Logo

CastorUnpacker.cc

Go to the documentation of this file.
00001 #include "EventFilter/CastorRawToDigi/interface/CastorUnpacker.h"
00002 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00003 #include "EventFilter/HcalRawToDigi/interface/HcalHTRData.h"
00004 #include "DataFormats/HcalDetId/interface/HcalOtherDetId.h"
00005 #include "DataFormats/HcalDigi/interface/HcalQIESample.h"
00006 #include "DataFormats/HcalDigi/interface/CastorDataFrame.h"
00007 #include "DataFormats/HcalDigi/interface/HcalTriggerPrimitiveSample.h"
00008 #include <iostream>
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 namespace CastorUnpacker_impl {
00012   template <class DigiClass>
00013   const HcalQIESample* unpack(const HcalQIESample* startPoint, const HcalQIESample* limit, DigiClass& digi, int presamples, const CastorElectronicsId& eid, int startSample, int endSample) {
00014     // set parameters
00015     digi.setPresamples(presamples);
00016  //   digi.setReadoutIds(eid);
00017  //   setReadoutIds is missing in  CastorDataFrame class  digi.setReadoutIds(eid);
00018 
00019     // what is my sample number?
00020     int myFiberChan=startPoint->fiberAndChan();
00021     int ncurr=0,ntaken=0;
00022     const HcalQIESample* qie_work=startPoint;
00023     while (qie_work!=limit && qie_work->fiberAndChan()==myFiberChan) {
00024       if (ncurr>=startSample && ncurr<=endSample) {
00025         digi.setSample(ntaken,*qie_work);
00026         ++ntaken;
00027       }
00028       ncurr++;
00029       qie_work++;
00030     }
00031     digi.setSize(ntaken);
00032     return qie_work;
00033   }
00034 }
00035 
00036 namespace { inline bool isTPGSOI(const HcalTriggerPrimitiveSample& s) {
00037   return (s.raw()&0x200)!=0;
00038 }
00039 }
00040 
00041 
00042 CastorUnpacker::CastorUnpacker(int sourceIdOffset, int beg, int end) : sourceIdOffset_(sourceIdOffset)
00043 {
00044  if ( beg >= 0 && beg <= CastorDataFrame::MAXSAMPLES -1 ) {
00045         startSample_ = beg;
00046  } else {
00047         startSample_ = 0;
00048  }
00049  if ( end >= 0 && end <= CastorDataFrame::MAXSAMPLES -1 && end >= beg ) {
00050         endSample_ = end;
00051  } else {
00052         endSample_ = CastorDataFrame::MAXSAMPLES -1;
00053  }
00054 }
00055 
00056 
00057 void CastorUnpacker::unpack(const FEDRawData& raw, const CastorElectronicsMap& emap,
00058                           Collections& colls, HcalUnpackerReport& report) {
00059 
00060   if (raw.size()<16) {
00061     edm::LogWarning("Invalid Data") << "Empty/invalid DCC data, size = " << raw.size();
00062     return;
00063   }
00064 
00065   // get the DCC header
00066   const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
00067   int dccid=dccHeader->getSourceId()-sourceIdOffset_;
00068 
00069   // check the summary status
00070   
00071   // walk through the HTR data...
00072   HcalHTRData htr;
00073   const unsigned short* daq_first, *daq_last, *tp_first, *tp_last;
00074   const HcalQIESample* qie_begin, *qie_end, *qie_work;
00075 //   const HcalTriggerPrimitiveSample *tp_begin, *tp_end, *tp_work; 
00076   for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
00077     if (!dccHeader->getSpigotPresent(spigot)) continue;
00078 
00079     dccHeader->getSpigotData(spigot,htr);
00080     // check
00081     if (!htr.check()) {
00082       edm::LogWarning("Invalid Data") << "Invalid HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
00083       report.countSpigotFormatError();
00084       continue;
00085     }
00086     if (htr.isHistogramEvent()) {
00087       edm::LogWarning("Invalid Data") << "Histogram data passed to non-histogram unpacker on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId();
00088       continue;
00089 
00090     }
00091     // calculate "real" number of presamples
00092     int nps=htr.getNPS()-startSample_;
00093     
00094     // get pointers
00095     htr.dataPointers(&daq_first,&daq_last,&tp_first,&tp_last);
00096     unsigned int smid=htr.getSubmodule();
00097     int htr_tb=smid&0x1;
00098     int htr_slot=(smid>>1)&0x1F;
00099     int htr_cr=(smid>>6)&0x1F;
00100     
00101     
00103     int currFiberChan=0x3F; // invalid fiber+channel...
00104     int ncurr=0;
00105     bool valid=false;
00106 
00107 //     bool tpgSOIbitInUse=htr.getFormatVersion()>=3; // version 3 and later
00108 //     int npre=0;
00109 
00110     qie_begin=(HcalQIESample*)daq_first;
00111     qie_end=(HcalQIESample*)(daq_last+1); // one beyond last..
00112 
00114     currFiberChan=0x3F; // invalid fiber+channel...
00115     ncurr=0;
00116     valid=false;
00117     
00118     for (qie_work=qie_begin; qie_work!=qie_end; ) {
00119       if (qie_work->raw()==0xFFFF) {
00120         qie_work++;
00121         continue; // filler word
00122       }
00123       // always at the beginning ...
00124       currFiberChan=qie_work->fiberAndChan();
00125 
00126       // lookup the right channel
00127       CastorElectronicsId eid(qie_work->fiberChan(),qie_work->fiber(),spigot,dccid);
00128       eid.setHTR(htr_cr,htr_slot,htr_tb);
00129       DetId did=emap.lookup(eid);
00130 
00131       if (!did.null()) {
00132             colls.castorCont->push_back(CastorDataFrame(HcalCastorDetId(did)));
00133             qie_work=CastorUnpacker_impl::unpack<CastorDataFrame>(qie_work, qie_end, colls.castorCont->back(), nps, eid, startSample_, endSample_);
00134       } else {
00135         report.countUnmappedDigi();
00136         if (unknownIds_.find(eid)==unknownIds_.end()) {
00137           edm::LogWarning("CASTOR") << "CastorUnpacker: No match found for electronics id :" << eid;
00138           unknownIds_.insert(eid);
00139         }
00140         for (int fiberC=qie_work->fiberAndChan();
00141              qie_work!=qie_end && qie_work->fiberAndChan()==fiberC;
00142              qie_work++);
00143       }
00144     }
00145   }
00146 }
00147 
00148 CastorUnpacker::Collections::Collections() {
00149   castorCont=0;
00150   tpCont=0;
00151   calibCont=0;
00152 }
00153 
00154 // void CastorUnpacker::unpack(const FEDRawData& raw, const CastorElectronicsMap& emap, std::vector<CastorDataFrame>& container, std::vector<HcalTriggerPrimitiveDigi>& tp) {
00155 //   Collections c;
00156 //   c.castorCont=&container;
00157 //   c.tpCont=&tp;
00158 //   HcalUnpackerReport r;
00159 //   unpack(raw,emap,c,r);
00160 // }
00161 

Generated on Tue Jun 9 17:34:20 2009 for CMSSW by  doxygen 1.5.4