CMS 3D CMS Logo

GctRawToDigi Class Reference

Description: Produce GCT digis from raw data. More...

#include <EventFilter/GctRawToDigi/src/GctRawToDigi.cc>

Inheritance diagram for GctRawToDigi:

edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 GctRawToDigi (const edm::ParameterSet &)
 ~GctRawToDigi ()

Private Member Functions

bool autoDetectRequiredFormatTranslator (const unsigned char *data)
 Looks at the firmware version header in the S-Link packet and instantiates relevant format translator.
virtual void beginJob (const edm::EventSetup &)
void doVerboseOutput (const GctBlockHeaderCollection &bHdrs, const GctUnpackCollections *const colls) const
 Prints out a list of blocks and the various numbers of trigger objects that have been unpacked from them.
virtual void endJob ()
virtual void produce (edm::Event &, const edm::EventSetup &)
void unpack (const FEDRawData &d, edm::Event &e, GctUnpackCollections *const colls)
 Unpacks the raw data.

Private Attributes

int fedId_
 GCT FED ID.
GctFormatTranslateBaseformatTranslator_
const unsigned formatVersion_
 Defines unpacker verison to be used (e.g.: "Auto-detect", "MCLegacy", "V35", etc).
const bool hltMode_
 If true, only outputs the GT output data, and only BX = 0.
edm::InputTag inputLabel_
 FED collection label.
unsigned unpackFailures_
 To count the total number of GCT unpack failures.
const bool unpackSharedRegions_
 Commissioning option: if true, where applicable the shared RCT calo regions will also be unpacked.
const bool verbose_
 If true, then debug print out for each event.

Static Private Attributes

static const unsigned MAX_BLOCKS = 256
 The maximum number of blocks we will try to unpack before thinking something is wrong.


Detailed Description

Description: Produce GCT digis from raw data.

Implementation: <Notes on="" implementation>="">

Definition at line 45 of file GctRawToDigi.h.


Constructor & Destructor Documentation

GctRawToDigi::GctRawToDigi ( const edm::ParameterSet iConfig  )  [explicit]

Register Products

Definition at line 33 of file GctRawToDigi.cc.

References fedId_, formatTranslator_, formatVersion_, hltMode_, LogDebug, and unpackSharedRegions_.

00033                                                          :
00034   inputLabel_(iConfig.getParameter<edm::InputTag>("inputLabel")),
00035   fedId_(iConfig.getParameter<int>("gctFedId")),
00036   hltMode_(iConfig.getParameter<bool>("hltMode")),
00037   unpackSharedRegions_(iConfig.getParameter<bool>("unpackSharedRegions")),
00038   formatVersion_(iConfig.getParameter<unsigned>("unpackerVersion")),
00039   verbose_(iConfig.getUntrackedParameter<bool>("verbose",false)),
00040   formatTranslator_(0),
00041   unpackFailures_(0)
00042 {
00043   LogDebug("GCT") << "GctRawToDigi will unpack FED Id " << fedId_;
00044 
00045   // If the GctFormatTranslate version has been forced from config file, instantiate the relevant one.
00046   /***  THIS OBVIOUSLY STINKS - NEED TO REPLACE WITH SOMETHING BETTER THAN MASSIVE IF-ELSE SOON ***/
00047   if(formatVersion_ == 0) { edm::LogInfo("GCT") << "The required GCT Format Translator will be automatically determined from the first S-Link packet header."; }
00048   else if(formatVersion_ == 1)
00049   {
00050     edm::LogInfo("GCT") << "You have selected to use GctFormatTranslateMCLegacy";
00051     formatTranslator_ = new GctFormatTranslateMCLegacy(hltMode_, unpackSharedRegions_);
00052   }
00053   else if(formatVersion_ == 2)
00054   {
00055     edm::LogInfo("GCT") << "You have selected to use GctFormatTranslateV35";
00056     formatTranslator_ = new GctFormatTranslateV35(hltMode_, unpackSharedRegions_);
00057   }
00058   else if(formatVersion_ == 3)
00059   {
00060     edm::LogInfo("GCT") << "You have selected to use GctFormatTranslateV38";
00061     formatTranslator_ = new GctFormatTranslateV38(hltMode_, unpackSharedRegions_);    
00062   }
00063   else
00064   { 
00065     edm::LogWarning("GCT") << "You have requested a version of GctFormatTranslate that does not exist! Will attempt to auto-detect "
00066                               "the required GCT Format Translator from the first S-Link packet header instead.";
00067   }
00068 
00069   if(hltMode_) { edm::LogInfo("GCT") << "HLT unpack mode selected: HLT unpack optimisations will be used."; }
00070   if(unpackSharedRegions_) { edm::LogInfo("GCT") << "You have selected to unpack shared RCT calo regions - be warned: "
00071                                                     "this is for commissioning purposes only!"; }
00072 
00074   // GCT input collections
00075   produces<L1GctFibreCollection>();
00076   produces<L1CaloEmCollection>();
00077   produces<L1CaloRegionCollection>();
00078 
00079   // GCT internal collections
00080   produces<L1GctInternEmCandCollection>();
00081   produces<L1GctInternJetDataCollection>();
00082   produces<L1GctInternEtSumCollection>();
00083 
00084   // GCT output collections
00085   produces<L1GctEmCandCollection>("isoEm");
00086   produces<L1GctEmCandCollection>("nonIsoEm");
00087   produces<L1GctJetCandCollection>("cenJets");
00088   produces<L1GctJetCandCollection>("forJets");
00089   produces<L1GctJetCandCollection>("tauJets");
00090   produces<L1GctHFBitCountsCollection>();
00091   produces<L1GctHFRingEtSumsCollection>();
00092   produces<L1GctEtTotalCollection>();
00093   produces<L1GctEtHadCollection>();
00094   produces<L1GctEtMissCollection>();
00095   produces<L1GctJetCountsCollection>();  // Deprecated (empty collection still needed by GT)
00096 }

GctRawToDigi::~GctRawToDigi (  ) 

Definition at line 99 of file GctRawToDigi.cc.

References formatTranslator_.

00100 {
00101   // do anything here that needs to be done at destruction time
00102   // (e.g. close files, deallocate resources etc.)
00103   delete formatTranslator_;
00104 }


Member Function Documentation

bool GctRawToDigi::autoDetectRequiredFormatTranslator ( const unsigned char *  data  )  [private]

Looks at the firmware version header in the S-Link packet and instantiates relevant format translator.

Returns false if it fails to instantiate a Format Translator

Definition at line 194 of file GctRawToDigi.cc.

References formatTranslator_, hltMode_, LogDebug, unpackFailures_, and unpackSharedRegions_.

Referenced by unpack().

00195 {
00196   LogDebug("GCT") << "About to auto-detect the required format translator from the firmware version header.";
00197     
00198   const uint32_t * p32 = reinterpret_cast<const uint32_t *>(d);
00199   unsigned firmwareHeader = p32[2];
00200 
00201   /***  THIS OBVIOUSLY STINKS - NEED TO REPLACE WITH SOMETHING BETTER THAN MASSIVE IF-ELSE SOON ***/
00202   if( firmwareHeader >= 25 && firmwareHeader <= 35 )
00203   {
00204     edm::LogInfo("GCT") << "Firmware Version V" << firmwareHeader << " detected: GctFormatTranslateV" << firmwareHeader << " will be used to unpack.";
00205     formatTranslator_ = new GctFormatTranslateV35(hltMode_, unpackSharedRegions_);
00206     return true;
00207   }
00208   else if( firmwareHeader == 38 )
00209   {
00210     edm::LogInfo("GCT") << "Firmware Version V" << firmwareHeader << " detected: GctFormatTranslateV" << firmwareHeader << " will be used to unpack.";
00211     formatTranslator_ = new GctFormatTranslateV38(hltMode_, unpackSharedRegions_);
00212     return true;
00213   }
00214   else if( firmwareHeader == 0x00000000 )
00215   {
00216     edm::LogInfo("GCT") << "Legacy Monte-Carlo data detected: GctFormatTranslateMCLegacy will be used to unpack.";
00217     formatTranslator_ = new GctFormatTranslateMCLegacy(hltMode_, unpackSharedRegions_);
00218     return true;
00219   }
00220   else if(firmwareHeader == 0xdeadffff) { /* Driver detected unknown firmware version. L1TriggerError code? */ }
00221   else if( firmwareHeader == 0xaaaaaaaa) { /* Before driver firmware version checks implemented. L1TriggerError code?  */ }
00222   else { /* Totally unknown firmware header. L1TriggerError code?  */ }
00223   
00224   LogDebug("GCT") << "Failed to determine unpacker to use from the firmware version header! "
00225                      "(firmware header = 0x" << hex << firmwareHeader << dec << ")";
00226 
00227   ++unpackFailures_;
00228   return false;
00229 }

void GctRawToDigi::beginJob ( const edm::EventSetup  )  [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 112 of file GctRawToDigi.cc.

00113 {
00114 }

void GctRawToDigi::doVerboseOutput ( const GctBlockHeaderCollection bHdrs,
const GctUnpackCollections *const   colls 
) const [private]

Prints out a list of blocks and the various numbers of trigger objects that have been unpacked from them.

Definition at line 231 of file GctRawToDigi.cc.

References lat::endl(), formatTranslator_, GctFormatTranslateBase::getBlockDescription(), i, and size.

Referenced by unpack().

00232 {
00233   std::ostringstream os;
00234   os << "Found " << bHdrs.size() << " GCT block headers" << endl;
00235   for (unsigned i=0, size = bHdrs.size(); i < size; ++i)
00236   {
00237     os << "GCT Raw Data Block : " << formatTranslator_->getBlockDescription(bHdrs[i]) << " : " << bHdrs[i] << endl;
00238   }
00239   os << *colls << endl;
00240   edm::LogVerbatim("GCT") << os.str();
00241 }

void GctRawToDigi::endJob ( void   )  [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 244 of file GctRawToDigi.cc.

References unpackFailures_.

00245 {
00246   if(unpackFailures_ > 0)
00247   {
00248     edm::LogError("GCT") << "GCT unpacker encountered " << unpackFailures_
00249                          << " unpack errors in total during this job!";
00250   }  
00251 }

void GctRawToDigi::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDProducer.

Definition at line 118 of file GctRawToDigi.cc.

References fedId_, edm::Event::get(), edm::Event::getByLabel(), hltMode_, inputLabel_, LogDebug, FEDRawData::size(), unpack(), and unpackFailures_.

00119 {
00120   using namespace edm;
00121 
00122   // get raw data collection
00123   edm::Handle<FEDRawDataCollection> feds;
00124   iEvent.getByLabel(inputLabel_, feds);
00125   const FEDRawData& gctRcd = feds->FEDData(fedId_);
00126  
00127   LogDebug("GCT") << "Upacking FEDRawData of size " << std::dec << gctRcd.size();
00128 
00129   // Instantiate all the collections the unpacker needs; puts them in event when this object goes out of scope.
00130   std::auto_ptr<GctUnpackCollections> colls(new GctUnpackCollections(iEvent, hltMode_));
00131   
00132   // do a simple check of the raw data - this will detect empty events
00133   if(gctRcd.size() < 16)
00134   {
00135     LogDebug("GCT") << "Cannot unpack: empty/invalid GCT raw data (size = "
00136                     << gctRcd.size() << "). Returning empty collections!";
00137     ++unpackFailures_;
00138   }
00139   else{ unpack(gctRcd, iEvent, colls.get()); }
00140 }

void GctRawToDigi::unpack ( const FEDRawData d,
edm::Event e,
GctUnpackCollections *const   colls 
) [private]

Unpacks the raw data.

Parameters:
invalidDataFlag - if true, then won't attempt unpack but just output empty collecions.

Definition at line 143 of file GctRawToDigi.cc.

References autoDetectRequiredFormatTranslator(), GctBlockHeader::blockLength(), GctFormatTranslateBase::convertBlock(), FEDRawData::data(), data, doVerboseOutput(), formatTranslator_, GctFormatTranslateBase::generateBlockHeader(), LogDebug, MAX_BLOCKS, GctBlockHeader::nSamples(), GctFormatTranslateBase::setUnpackCollections(), FEDRawData::size(), unpackFailures_, and verbose_.

Referenced by produce().

00144 {
00145   const unsigned char * data = d.data();  // The 8-bit wide raw-data array.  
00146 
00147   // If no format translator yet set, need to auto-detect from header.
00148   if(!formatTranslator_)
00149   {
00150     // If auto format detection fails, we have no concrete format
00151     // translator instantiated... so bail from event.
00152     if(!autoDetectRequiredFormatTranslator(data)) { return; }
00153   }
00154 
00155   // We should now have a valid formatTranslator pointer  
00156   formatTranslator_->setUnpackCollections(colls);
00157 
00158   // Data offset - starts at 16 as there is a 64-bit S-Link header followed
00159   // by a 64-bit software-controlled header (for pipeline format version
00160   // info that is not yet used).
00161   unsigned dPtr = 16;
00162 
00163   const unsigned dEnd = d.size() - 8; // End of payload is at (packet size - final slink header)
00164 
00165   GctBlockHeaderCollection bHdrs; // Vector for storing block headers for verbosity print-out.
00166 
00167   // read blocks
00168   for (unsigned nb=0; dPtr<dEnd; ++nb)
00169   {
00170     if(nb >= MAX_BLOCKS) { LogDebug("GCT") << "Reached block limit - bailing out from this event!"; ++unpackFailures_; break; }
00171   
00172     // read block header
00173     GctBlockHeader blockHeader = formatTranslator_->generateBlockHeader(&data[dPtr]);
00174   
00175     // unpack the block; dPtr+4 is to get to the block data.
00176     if(!formatTranslator_->convertBlock(&data[dPtr+4], blockHeader)) // Record if we had an unpack problem then skip rest of event.
00177     {
00178       LogDebug("GCT") << "Encountered block unpack error - bailing out from this event!";
00179       ++unpackFailures_; break;
00180     } 
00181 
00182     // advance pointer
00183     dPtr += 4*(blockHeader.blockLength()*blockHeader.nSamples()+1); // *4 because blockLen is in 32-bit words, +1 for header
00184 
00185     // If verbose, store the header in vector.
00186     if(verbose_) { bHdrs.push_back(blockHeader); }
00187   }
00188 
00189   // dump summary in verbose mode
00190   if(verbose_) { doVerboseOutput(bHdrs, colls); }
00191 }


Member Data Documentation

int GctRawToDigi::fedId_ [private]

GCT FED ID.

Definition at line 77 of file GctRawToDigi.h.

Referenced by GctRawToDigi(), and produce().

GctFormatTranslateBase* GctRawToDigi::formatTranslator_ [private]

Definition at line 86 of file GctRawToDigi.h.

Referenced by autoDetectRequiredFormatTranslator(), doVerboseOutput(), GctRawToDigi(), unpack(), and ~GctRawToDigi().

const unsigned GctRawToDigi::formatVersion_ [private]

Defines unpacker verison to be used (e.g.: "Auto-detect", "MCLegacy", "V35", etc).

Definition at line 82 of file GctRawToDigi.h.

Referenced by GctRawToDigi().

const bool GctRawToDigi::hltMode_ [private]

If true, only outputs the GT output data, and only BX = 0.

Definition at line 80 of file GctRawToDigi.h.

Referenced by autoDetectRequiredFormatTranslator(), GctRawToDigi(), and produce().

edm::InputTag GctRawToDigi::inputLabel_ [private]

FED collection label.

Definition at line 76 of file GctRawToDigi.h.

Referenced by produce().

const unsigned GctRawToDigi::MAX_BLOCKS = 256 [static, private]

The maximum number of blocks we will try to unpack before thinking something is wrong.

Definition at line 74 of file GctRawToDigi.h.

Referenced by unpack().

unsigned GctRawToDigi::unpackFailures_ [private]

To count the total number of GCT unpack failures.

Definition at line 88 of file GctRawToDigi.h.

Referenced by autoDetectRequiredFormatTranslator(), endJob(), produce(), and unpack().

const bool GctRawToDigi::unpackSharedRegions_ [private]

Commissioning option: if true, where applicable the shared RCT calo regions will also be unpacked.

Definition at line 81 of file GctRawToDigi.h.

Referenced by autoDetectRequiredFormatTranslator(), and GctRawToDigi().

const bool GctRawToDigi::verbose_ [private]

If true, then debug print out for each event.

Definition at line 83 of file GctRawToDigi.h.

Referenced by unpack().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:21:11 2009 for CMSSW by  doxygen 1.5.4