2 #include "dictionaries.h"
4 #include "datasource_evt.h"
7 #include "IMPL/LCEventImpl.h"
8 #include "IMPL/TrackerRawDataImpl.h"
9 #include "IMPL/TrackerDataImpl.h"
10 #include "IMPL/LCCollectionVec.h"
11 #include "IMPL/LCGenericObjectImpl.h"
12 #include "UTIL/CellIDEncoder.h"
17 #include "EUTELESCOPE.h"
18 #include "EUTelEventImpl.h"
19 #include "EUTelTrackerDataInterfacerImpl.h"
20 #include "EUTelGenericSparsePixel.h"
21 #include "EUTelRunHeaderImpl.h"
23 using eutelescope::EUTELESCOPE;
32 CMSPixelHelper(std::string event_type) : m_event_type(event_type){};
35 DeviceDictionary *devDict;
36 std::string roctype = bore.GetTag(
"ROCTYPE",
"");
37 std::string tbmtype = bore.GetTag(
"TBMTYPE",
"notbm");
39 m_detector = bore.GetTag(
"DETECTOR",
"");
40 std::string pcbtype = bore.GetTag(
"PCBTYPE",
"");
42 (pcbtype.find(
"-rot") != std::string::npos ?
true :
false);
45 m_nplanes = bore.GetTag(
"PLANES", 1);
47 m_roctype = devDict->getInstance()->getDevCode(roctype);
48 m_tbmtype = devDict->getInstance()->getDevCode(tbmtype);
50 if (m_roctype == 0x0) {
51 EUDAQ_THROW(
"Data contains invalid ROC type: " + roctype);
53 if(m_tbmtype == 0x0) {
54 EUDAQ_THROW(
"Data contains invalid TBM type: " + tbmtype);
57 std::cout <<
"CMSPixel Converter initialized with detector " << m_detector
58 <<
", Event Type " << m_event_type <<
", TBM type " << tbmtype
59 <<
" (" <<
static_cast<int>(m_tbmtype) <<
")"
60 <<
", ROC type " << roctype <<
" ("
61 << static_cast<int>(m_roctype) <<
")" << std::endl;
63 if (m_detector ==
"TRP") {
66 else if (m_detector ==
"DUT") {
69 else if (m_detector ==
"REF") {
77 pxar::Log::ReportingLevel() = pxar::Log::FromString(
"WARNING");
81 src = evtSource(0, m_nplanes, 0, m_tbmtype, m_roctype, FLAG_DISABLE_EVENTID_CHECK);
82 src >> splitter >> decoder >> Eventpump;
90 std::cout <<
"Decoding statistics for detector " << m_detector
92 pxar::Log::ReportingLevel() = pxar::Log::FromString(
"INFO");
93 decoder.getStatistics().dump();
97 else if (in.IsBORE()) {
104 EUDAQ_ERROR(
"Only one data block is expected!");
109 src.AddData(TransformRawData(in_raw.
GetBlock(0)));
111 pxar::Event *evt = Eventpump.Get();
115 if (m_tbmtype <= TBM_EMU)
116 GetMultiPlanes(out, m_planeid, evt);
120 GetSinglePlane(out, m_planeid, evt);
123 #if USE_LCIO && USE_EUTELESCOPE
124 virtual void GetLCIORunHeader(lcio::LCRunHeader &header,
127 eutelescope::EUTelRunHeaderImpl runHeader(&header);
129 runHeader.setDAQHWName(EUTELESCOPE::DAQDATA);
132 virtual bool GetLCIOSubEvent(lcio::LCEvent &result,
133 const Event &source)
const {
135 if (source.IsBORE()) {
136 std::cout <<
"CMSPixelConverterPlugin::GetLCIOSubEvent BORE " << source
139 }
else if (source.IsEORE()) {
140 std::cout <<
"CMSPixelConverterPlugin::GetLCIOSubEvent EORE " << source
146 result.parameters().setValue(eutelescope::EUTELESCOPE::EVENTTYPE,
150 LCCollectionVec *zsDataCollection;
151 bool zsDataCollectionExists =
false;
154 static_cast<LCCollectionVec *
>(result.getCollection(m_event_type));
155 zsDataCollectionExists =
true;
156 }
catch (lcio::DataNotAvailableException &e) {
157 zsDataCollection =
new LCCollectionVec(lcio::LCIO::TRACKERDATA);
161 CellIDEncoder<TrackerDataImpl> zsDataEncoder(
162 eutelescope::EUTELESCOPE::ZSDATADEFAULTENCODING, zsDataCollection);
166 GetStandardSubEvent(tmp_evt, source);
169 for (
size_t iPlane = 0; iPlane < tmp_evt.NumPlanes(); ++iPlane) {
173 zsDataEncoder[
"sensorID"] = plane.ID();
174 zsDataEncoder[
"sparsePixelType"] =
175 eutelescope::kEUTelGenericSparsePixel;
178 size_t nPixel = plane.HitPixels();
181 std::auto_ptr<lcio::TrackerDataImpl> zsFrame(
new lcio::TrackerDataImpl);
182 zsDataEncoder.setCellID(zsFrame.get());
185 std::auto_ptr<eutelescope::EUTelTrackerDataInterfacerImpl<
186 eutelescope::EUTelGenericSparsePixel>>
187 sparseFrame(
new eutelescope::EUTelTrackerDataInterfacerImpl<
188 eutelescope::EUTelGenericSparsePixel>(zsFrame.get()));
191 std::auto_ptr<eutelescope::EUTelGenericSparsePixel> sparsePixel(
192 new eutelescope::EUTelGenericSparsePixel);
193 for (
size_t iPixel = 0; iPixel < nPixel; ++iPixel) {
196 sparsePixel->setXCoord((
size_t)plane.GetX(iPixel));
197 sparsePixel->setYCoord((
size_t)plane.GetY(iPixel));
199 sparsePixel->setSignal((int32_t)plane.GetPixel(iPixel));
202 sparseFrame->addSparsePixel(sparsePixel.get());
206 zsDataCollection->push_back(zsFrame.release());
211 if (!zsDataCollectionExists) {
212 if (zsDataCollection->size() != 0) {
213 result.addCollection(zsDataCollection, m_event_type);
215 delete zsDataCollection;
225 uint8_t m_roctype, m_tbmtype;
228 std::string m_detector;
230 std::string m_event_type;
232 mutable evtSource src;
233 mutable passthroughSplitter splitter;
234 mutable dtbEventDecoder decoder;
235 mutable dataSink<pxar::Event *> Eventpump;
238 pxar::Event *evt)
const {
240 for (
size_t roc = 0; roc < m_nplanes; roc++) {
243 StandardPlane plane(plane_id + roc, m_event_type, m_detector);
248 plane.SetSizeZS(ROC_NUMROWS, ROC_NUMCOLS, 0);
250 plane.SetSizeZS(ROC_NUMCOLS, ROC_NUMROWS, 0);
252 plane.SetTLUEvent(0);
255 for (std::vector<pxar::pixel>::iterator it = evt->pixels.begin();
256 it != evt->pixels.end(); ++it) {
258 if (it->roc() == roc) {
260 plane.PushPixel(it->row(), it->column(), it->value());
262 plane.PushPixel(it->column(), it->row(), it->value());
273 pxar::Event *evt)
const {
285 plane.SetSizeZS(2 * ROC_NUMROWS, 8 * ROC_NUMCOLS, 0);
287 plane.SetSizeZS(8 * ROC_NUMCOLS, 2 * ROC_NUMROWS, 0);
289 plane.SetTLUEvent(0);
292 for (std::vector<pxar::pixel>::iterator it = evt->pixels.begin();
293 it != evt->pixels.end(); ++it) {
296 plane.PushPixel(roc_to_mod_row(it->roc(), it->row()),
297 roc_to_mod_col(it->roc(), it->column()), it->value());
299 plane.PushPixel(roc_to_mod_col(it->roc(), it->column()),
300 roc_to_mod_row(it->roc(), it->row()), it->value());
308 static inline uint16_t roc_to_mod_row(uint8_t roc, uint16_t row) {
312 return (2 * ROC_NUMROWS - row - 1);
315 static inline uint16_t roc_to_mod_col(uint8_t roc, uint16_t col) {
317 return (col + roc * ROC_NUMCOLS);
319 return ((16 - roc) * ROC_NUMCOLS - col - 1);
322 static std::vector<uint16_t>
323 TransformRawData(
const std::vector<unsigned char> &block) {
326 std::vector<uint16_t> rawData;
328 int size = block.size();
334 while (i < size - 1) {
335 uint16_t temp = ((uint16_t)block.data()[i + 1] << 8) | block.data()[i];
336 rawData.push_back(temp);
size_t NumBlocks() const
Return the number of data blocks in the RawDataEvent.
Definition: RawDataEvent.hh:80
Definition: Configuration.hh:12
Definition: StandardEvent.hh:10
Definition: StandardEvent.hh:128
Definition: RawDataEvent.hh:14
const data_t & GetBlock(size_t i) const
Definition: RawDataEvent.cc:34
Definition: CMSPixelHelper.hh:30