CMS 3D CMS Logo

RPCPackingModule.cc
Go to the documentation of this file.
2 
5 
9 
12 
15 
18 
22 
23 #include <string>
24 #include <sstream>
25 
26 
27 using namespace std;
28 using namespace edm;
29 using namespace rpcrawtodigi;
30 
31 typedef uint64_t Word64;
32 
34 {
35 
36  dataLabel_ = consumes<RPCDigiCollection>(pset.getParameter<edm::InputTag>("InputLabel"));
37  theCabling = new RPCReadOutMapping("");
38  produces<FEDRawDataCollection>();
39 
40 }
41 
43 {
44  delete theCabling;
45 }
46 
47 
49  const edm::EventSetup& es)
50 {
52  ev.getByToken(dataLabel_,digiCollection);
53  LogDebug("") << DebugDigisPrintout()(digiCollection.product());
54 
55  if(recordWatcher_.check(es)) {
56  delete theCabling;
57  LogTrace("") << "record has CHANGED!!, initialise readout map!";
58  ESHandle<RPCEMap> readoutMapping;
59  es.get<RPCEMapRcd>().get(readoutMapping);
60  theCabling = readoutMapping->convert();
61  LogTrace("") <<" READOUT MAP VERSION: " << theCabling->version() << endl;
62  }
63 
64  auto buffers = std::make_unique<FEDRawDataCollection>();
65 
66 // pair<int,int> rpcFEDS=FEDNumbering::getRPCFEDIds();
67  pair<int,int> rpcFEDS(790,792);
68  for (int id= rpcFEDS.first; id<=rpcFEDS.second; ++id){
69 
70  RPCRecordFormatter formatter(id, theCabling) ;
71  unsigned int lvl1_ID = ev.id().event();
72  FEDRawData* rawData = RPCPackingModule::rawData(id, lvl1_ID, digiCollection.product(), formatter);
73  FEDRawData& fedRawData = buffers->FEDData(id);
74 
75  fedRawData = *rawData;
76  delete rawData;
77  }
78  ev.put(std::move(buffers));
79 }
80 
81 
82 FEDRawData * RPCPackingModule::rawData( int fedId, unsigned int lvl1_ID, const RPCDigiCollection * digis, const RPCRecordFormatter & formatter) const
83 {
84  //
85  // get merged records
86  //
87  int trigger_BX = 200; // FIXME - set event by event but correct bx assigment in digi
88  vector<EventRecords> merged = RPCPackingModule::eventRecords(fedId,trigger_BX,digis,formatter);
89 
90  //
91  // create data words
92  //
93  vector<Word64> dataWords;
95  typedef vector<EventRecords>::const_iterator IR;
96  for (IR ir = merged.begin(), irEnd = merged.end() ; ir != irEnd; ++ir) {
97  Word64 w = ( ( (Word64(ir->recordBX().data()) << 16) | ir->recordSLD().data() ) << 16
98  | ir->recordCD().data() ) << 16 | empty.data();
99  dataWords.push_back(w);
100  }
101 
102  //
103  // create raw data
104  //
105  int nHeaders = 1;
106  int nTrailers = 1;
107  int dataSize = (nHeaders+nTrailers+dataWords.size()) * sizeof(Word64);
108  FEDRawData * raw = new FEDRawData(dataSize);
109 
110  //
111  // add header
112  //
113  unsigned char *pHeader = raw->data();
114  int evt_ty = 3;
115  int source_ID = fedId;
116  FEDHeader::set(pHeader, evt_ty, lvl1_ID, trigger_BX, source_ID);
117 
118  //
119  // add datawords
120  //
121  for (unsigned int idata = 0; idata < dataWords.size(); idata ++) {
122  Word64 * word = reinterpret_cast<Word64* >(pHeader+(idata+1)*sizeof(Word64));
123  *word = dataWords[idata];
124  }
125 
126  //
127  // add trailer
128  //
129  unsigned char *pTrailer = pHeader + raw->size()-sizeof(Word64);
130  int crc = 0;
131  int evt_stat = 15;
132  int tts = 0;
133  int datasize = raw->size()/sizeof(Word64);
134  FEDTrailer::set(pTrailer, datasize, crc, evt_stat, tts);
135 
136  return raw;
137 }
138 
139 vector<EventRecords> RPCPackingModule::eventRecords(
140  int fedId,
141  int trigger_BX,
142  const RPCDigiCollection* digis ,
143  const RPCRecordFormatter& formatter)
144 {
145  typedef DigiContainerIterator<RPCDetId, RPCDigi> DigiRangeIterator;
146  vector<EventRecords> dataRecords;
147 
148 
149  LogDebug("RPCRawDataPacker")<<"Packing Fed id="<<fedId;
150  for (DigiRangeIterator it=digis->begin(); it != digis->end(); it++) {
151  RPCDetId rpcDetId = (*it).first;
152  uint32_t rawDetId = rpcDetId.rawId();
153  RPCDigiCollection::Range range = digis->get(rpcDetId);
154  for (vector<RPCDigi>::const_iterator id = range.first; id != range.second; id++) {
155  const RPCDigi & digi = (*id);
156  vector<EventRecords> rawFromDigi = formatter.recordPack(rawDetId, digi, trigger_BX);
157  dataRecords.insert(dataRecords.end(), rawFromDigi.begin(), rawFromDigi.end());
158  }
159  }
160 
161  //
162  // merge data words
163  //
164  LogTrace("RPCRawDataPacker") <<" size of data: " << dataRecords.size();
165  vector<EventRecords> merged = EventRecords::mergeRecords(dataRecords);
166  LogTrace("") <<" size of megred: " << merged.size();
167 
168  return merged;
169 }
#define LogDebug(id)
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
uint64_t Word64
const double w
Definition: UKUtility.cc:23
~RPCPackingModule() override
dtor
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
static std::vector< rpcrawtodigi::EventRecords > eventRecords(int fedId, int trigger_BX, const RPCDigiCollection *, const RPCRecordFormatter &)
bool ev
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
FEDRawData * rawData(int fedId, unsigned int lvl1_ID, const RPCDigiCollection *, const RPCRecordFormatter &) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:60
const Data & data() const
Definition: DataRecord.h:32
uint64_t Word64
std::vector< rpcrawtodigi::EventRecords > recordPack(uint32_t rawDetId, const RPCDigi &digi, int trigger_BX) const
#define LogTrace(id)
T const * product() const
Definition: Handle.h:81
unsigned long long uint64_t
Definition: Time.h:15
RPCPackingModule(const edm::ParameterSet &)
ctor
void produce(edm::Event &, const edm::EventSetup &) override
get data, convert to raw event, attach again to Event
const T & get() const
Definition: EventSetup.h:58
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
std::pair< const_iterator, const_iterator > Range
RPCReadOutMapping const * convert() const
Definition: RPCEMap.h:67
static void set(unsigned char *header, uint8_t triggerType, uint32_t lvl1ID, uint16_t bxID, uint16_t sourceID, uint8_t version=0, bool moreHeaders=false)
Set all fields in the header.
Definition: FEDHeader.cc:47
def move(src, dest)
Definition: eostools.py:510