CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/EventFilter/CastorRawToDigi/src/CastorCtdcUnpacker.cc

Go to the documentation of this file.
00001 #include "EventFilter/CastorRawToDigi/interface/CastorCtdcUnpacker.h"
00002 #include "EventFilter/CastorRawToDigi/interface/CastorCTDCHeader.h"
00003 #include "EventFilter/CastorRawToDigi/interface/CastorCORData.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 using namespace std;
00011 
00012 CastorCtdcUnpacker::CastorCtdcUnpacker(int sourceIdOffset, int beg, int end) : sourceIdOffset_(sourceIdOffset)
00013 {
00014  if ( beg >= 0 && beg <= CastorDataFrame::MAXSAMPLES -1 ) {
00015         startSample_ = beg;
00016  } else {
00017         startSample_ = 0;
00018  }
00019  if ( end >= 0 && end <= CastorDataFrame::MAXSAMPLES -1 && end >= beg ) {
00020         endSample_ = end;
00021  } else {
00022         endSample_ = CastorDataFrame::MAXSAMPLES -1;
00023  }
00024 }
00025 
00026 
00027 void CastorCtdcUnpacker::unpack(const FEDRawData& raw, const CastorElectronicsMap& emap,
00028                           CastorRawCollections& colls, HcalUnpackerReport& report) {
00029 
00030   if (raw.size()<16) {
00031     edm::LogWarning("Invalid Data") << "Empty/invalid DCC data, size = " << raw.size();
00032     return;
00033   }
00034 
00035   // get the CTDC header
00036   const CastorCTDCHeader* ctdcHeader=(const CastorCTDCHeader*)(raw.data());
00037   int ctdcid=ctdcHeader->getSourceId()-sourceIdOffset_;
00038 
00039   // space for unpacked data from one COR
00040   std::vector<unsigned short> precdata(CastorCORData::CHANNELS_PER_SPIGOT*CastorCORData::MAXIMUM_SAMPLES_PER_CHANNEL);
00041   std::vector<unsigned short> trigdata(CastorCORData::CHANNELS_PER_SPIGOT*CastorCORData::MAXIMUM_SAMPLES_PER_CHANNEL);
00042   std::vector<unsigned char>  preclen(CastorCORData::CHANNELS_PER_SPIGOT);
00043   std::vector<unsigned char>  triglen(CastorCORData::CHANNELS_PER_SPIGOT);
00044   
00045   // walk through the COR data...
00046   CastorCORData cor;
00047   for (int spigot=0; spigot<CastorCTDCHeader::SPIGOT_COUNT; spigot++) {
00048     if (!ctdcHeader->getSpigotPresent(spigot)) continue;
00049 
00050     int retval=ctdcHeader->getSpigotData(spigot,cor,raw.size());
00051     if (retval!=0) {
00052       if (retval==-1) {
00053         edm::LogWarning("Invalid Data") << "Invalid COR data (data beyond payload size) observed on spigot " << spigot << " of CTDC with source id " << ctdcHeader->getSourceId();
00054         report.countSpigotFormatError();
00055       }
00056       continue;
00057     }
00058     // check
00059     if (!cor.check()) {
00060       edm::LogWarning("Invalid Data") << "Invalid COR data observed on spigot " << spigot << " of CTDC with source id " << ctdcHeader->getSourceId();
00061       report.countSpigotFormatError();
00062       continue;
00063     }
00064     if (cor.isHistogramEvent()) {
00065       edm::LogWarning("Invalid Data") << "Histogram data passed to non-histogram unpacker on spigot " << spigot << " of CTDC with source id " << ctdcHeader->getSourceId();
00066       continue;
00067 
00068     }
00069     // calculate "real" number of presamples
00070     int nps=cor.getNPS()-startSample_;
00071 
00072     // new: do not use get pointers .. instead make use of CastorCORData::unpack   
00073 
00074      cor.unpack(&(preclen[0]),&(precdata[0]),
00075                             &(triglen[0]),&(trigdata[0]));
00076  
00077     
00079    int ichan;
00080    for ( ichan = 0; ichan<CastorCORData::CHANNELS_PER_SPIGOT; ichan++) {
00081            if ( preclen[ichan] == 0 || preclen[ichan] & 0xc0 ) continue;
00082                 int fiber = ichan/3;
00083                 int fiberchan = ichan%3;
00084         // lookup the right channel
00085             CastorElectronicsId partialEid(fiberchan,fiber+1,spigot,ctdcid);
00086             // does this partial id exist?
00087             CastorElectronicsId eid;
00088             HcalGenericDetId did;
00089             bool found;
00090             found = emap.lookup(partialEid,eid,did);
00091 
00092                 if (found) {                    
00093                         CastorDataFrame digi = CastorDataFrame(HcalCastorDetId(did));
00094                         // set parameters - presamples
00095                         digi.setPresamples(nps);
00096 
00097                         int ntaken = 0;
00098                         for ( int sample = startSample_; sample <= endSample_; sample++ ) {
00099                                         digi.setSample(ntaken,precdata[ichan*CastorCORData::MAXIMUM_SAMPLES_PER_CHANNEL+sample]);
00100                                         ntaken++;
00101                         }
00102                         digi.setSize(ntaken);
00103                         colls.castorCont->push_back(digi);                      
00104                 } else {
00105                         report.countUnmappedDigi();
00106                         if (unknownIds_.find(partialEid)==unknownIds_.end()) {
00107                           edm::LogWarning("CASTOR") << "CastorCtdcUnpacker: No match found for electronics partialEid :" << partialEid;
00108                           unknownIds_.insert(partialEid);
00109                     }
00110                 }
00111     }
00112 
00113   }
00114 }
00115 
00116