CMS 3D CMS Logo

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