CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

RPCPackingModule Class Reference

#include <RPCPackingModule.h>

Inheritance diagram for RPCPackingModule:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

virtual void produce (edm::Event &, const edm::EventSetup &)
 get data, convert to raw event, attach again to Event
 RPCPackingModule (const edm::ParameterSet &)
 ctor
virtual ~RPCPackingModule ()
 dtor

Static Public Member Functions

static std::vector
< rpcrawtodigi::EventRecords
eventRecords (int fedId, int trigger_BX, const RPCDigiCollection *, const RPCRecordFormatter &)

Private Member Functions

FEDRawDatarawData (int fedId, unsigned int lvl1_ID, const RPCDigiCollection *, const RPCRecordFormatter &)

Private Attributes

edm::InputTag dataLabel_
unsigned long eventCounter_
const RPCReadOutMappingtheCabling

Detailed Description

Driver class for digi to raw data conversions

Definition at line 23 of file RPCPackingModule.h.


Constructor & Destructor Documentation

RPCPackingModule::RPCPackingModule ( const edm::ParameterSet pset) [explicit]

ctor

Definition at line 35 of file RPCPackingModule.cc.

References theCabling.

  : dataLabel_(pset.getParameter<edm::InputTag>("InputLabel")),
    eventCounter_(0)
{
  
  theCabling = new RPCReadOutMapping("");
  produces<FEDRawDataCollection>();

}
RPCPackingModule::~RPCPackingModule ( ) [virtual]

dtor

Definition at line 45 of file RPCPackingModule.cc.

References theCabling.

{
  delete theCabling;
}

Member Function Documentation

vector< EventRecords > RPCPackingModule::eventRecords ( int  fedId,
int  trigger_BX,
const RPCDigiCollection digis,
const RPCRecordFormatter formatter 
) [static]

Definition at line 147 of file RPCPackingModule.cc.

References LogDebug, LogTrace, DetId::rawId(), and RPCRecordFormatter::recordPack().

Referenced by rawData().

{
  typedef  DigiContainerIterator<RPCDetId, RPCDigi> DigiRangeIterator;
  vector<EventRecords> dataRecords;


  LogDebug("RPCRawDataPacker")<<"Packing Fed id="<<fedId;
  for (DigiRangeIterator it=digis->begin(); it != digis->end(); it++) {
    RPCDetId rpcDetId = (*it).first;
    uint32_t rawDetId = rpcDetId.rawId();
    RPCDigiCollection::Range range = digis->get(rpcDetId);
    for (vector<RPCDigi>::const_iterator  id = range.first; id != range.second; id++) {
      const RPCDigi & digi = (*id);
      vector<EventRecords>  rawFromDigi =  formatter.recordPack(rawDetId, digi, trigger_BX);
      dataRecords.insert(dataRecords.end(), rawFromDigi.begin(), rawFromDigi.end());
    }
  }

  //
  // merge data words
  //
  LogTrace("RPCRawDataPacker") <<" size of   data: " << dataRecords.size();
  vector<EventRecords> merged = EventRecords::mergeRecords(dataRecords);
  LogTrace("") <<" size of megred: " << merged.size();

  return merged;
}
void RPCPackingModule::produce ( edm::Event ev,
const edm::EventSetup es 
) [virtual]

get data, convert to raw event, attach again to Event

Implements edm::EDProducer.

Definition at line 51 of file RPCPackingModule.cc.

References edm::ESWatcher< T >::check(), dataLabel_, reco_application_2006_simpleTBanalysis_cfg::digiCollection, edm::EventID::event(), eventCounter_, edm::EventSetup::get(), edm::Event::getByLabel(), edm::EventBase::id(), LogDebug, LogTrace, edm::Handle< T >::product(), edm::Event::put(), rawData(), theCabling, and RPCReadOutMapping::version().

{
  eventCounter_++;
  LogInfo("RPCPackingModule") << "[RPCPackingModule::produce] " 
                              << "event counter: " << eventCounter_;

  Handle< RPCDigiCollection > digiCollection;
  ev.getByLabel(dataLabel_,digiCollection);
  LogDebug("") << DebugDigisPrintout()(digiCollection.product());

  static edm::ESWatcher<RPCEMapRcd> recordWatcher; 
  if(recordWatcher.check(es)) {
    delete theCabling;
    LogTrace("") << "record has CHANGED!!, initialise readout map!";
    ESHandle<RPCEMap> readoutMapping;
    es.get<RPCEMapRcd>().get(readoutMapping);
    theCabling = readoutMapping->convert();
    LogTrace("") <<" READOUT MAP VERSION: " << theCabling->version() << endl; 
  }

  auto_ptr<FEDRawDataCollection> buffers( new FEDRawDataCollection );

//  pair<int,int> rpcFEDS=FEDNumbering::getRPCFEDIds();
  pair<int,int> rpcFEDS(790,792);
  for (int id= rpcFEDS.first; id<=rpcFEDS.second; ++id){

    RPCRecordFormatter formatter(id, theCabling) ;
    unsigned int lvl1_ID = ev.id().event();
    FEDRawData* rawData =  RPCPackingModule::rawData(id, lvl1_ID, digiCollection.product(), formatter);
    FEDRawData& fedRawData = buffers->FEDData(id);

    fedRawData = *rawData;
    delete rawData;
  }
  ev.put( buffers );  
}
FEDRawData * RPCPackingModule::rawData ( int  fedId,
unsigned int  lvl1_ID,
const RPCDigiCollection digis,
const RPCRecordFormatter formatter 
) [private]

Definition at line 90 of file RPCPackingModule.cc.

References FEDRawData::data(), rpcrawtodigi::DataRecord::data(), relativeConstraints::empty, eventRecords(), runtimedef::set(), FEDRawData::size(), and w().

Referenced by produce().

{
  //
  // get merged records
  //
  int trigger_BX = 200;   // FIXME - set event by event but correct bx assigment in digi
  vector<EventRecords> merged = RPCPackingModule::eventRecords(fedId,trigger_BX,digis,formatter);

  //
  // create data words
  //
  vector<Word64> dataWords;
  EmptyWord empty;
  typedef vector<EventRecords>::const_iterator IR;
  for (IR ir = merged.begin(), irEnd =  merged.end() ; ir != irEnd; ++ir) {
    Word64 w = ( ( (Word64(ir->recordBX().data()) << 16) | ir->recordSLD().data() ) << 16
                    | ir->recordCD().data() ) << 16 | empty.data();
    dataWords.push_back(w);
  }

  //
  // create raw data
  //
  int nHeaders = 1;
  int nTrailers = 1;
  int dataSize = (nHeaders+nTrailers+dataWords.size()) * sizeof(Word64);
  FEDRawData * raw = new FEDRawData(dataSize);

  //
  // add header
  //
  unsigned char *pHeader  = raw->data();
  int evt_ty = 3;
  int source_ID = fedId;
  FEDHeader::set(pHeader, evt_ty, lvl1_ID, trigger_BX, source_ID);

  //
  // add datawords
  //
  for (unsigned int idata = 0; idata < dataWords.size(); idata ++) {
    Word64 * word = reinterpret_cast<Word64* >(pHeader+(idata+1)*sizeof(Word64));
    *word = dataWords[idata];
  }

  //
  // add trailer
  //
  unsigned char *pTrailer = pHeader + raw->size()-sizeof(Word64);
  int crc = 0;
  int evt_stat = 15;
  int tts = 0;
  int datasize =  raw->size()/sizeof(Word64);
  FEDTrailer::set(pTrailer, datasize, crc, evt_stat, tts);

  return raw;
}

Member Data Documentation

Definition at line 42 of file RPCPackingModule.h.

Referenced by produce().

unsigned long RPCPackingModule::eventCounter_ [private]

Definition at line 43 of file RPCPackingModule.h.

Referenced by produce().

Definition at line 44 of file RPCPackingModule.h.

Referenced by produce(), RPCPackingModule(), and ~RPCPackingModule().