#include "eudaq/DataConverterPlugin.hh" #include "eudaq/StandardEvent.hh" #include "eudaq/Utils.hh" // All LCIO-specific parts are put in conditional compilation blocks // so that the other parts may still be used if LCIO is not available. #if USE_LCIO #include "IMPL/LCEventImpl.h" #include "IMPL/TrackerRawDataImpl.h" #include "IMPL/LCCollectionVec.h" #include "lcio.h" #endif #if USE_EUTELESCOPE #include "EUTELESCOPE.h" #include "EUTelSetupDescription.h" #include "EUTelEventImpl.h" #include "EUTelTrackerDataInterfacerImpl.h" #include "EUTelGenericSparsePixel.h" #include "EUTelRunHeaderImpl.h" #endif typedef struct { uint16_t col; uint16_t row; uint16_t tot; } Fei4Hit; namespace eudaq { // The event type for which this converter plugin will be registered // Modify this to match your actual event type (from the Producer) static const std::string EVENT_TYPE = "Yarr"; // Declare a new class that inherits from DataConverterPlugin class YARRConverterPlugin : public DataConverterPlugin { public: // This is called once at the beginning of each run. // You may extract information from the BORE and/or configuration // and store it in member variables to use during the decoding later. virtual void Initialize(const Event &bore, const Configuration &cnf) { #ifndef WIN32 // some linux Stuff //$$change (void)cnf; // just to suppress a warning about unused parameter cnf #endif } // Here, the data from the RawDataEvent is extracted into a StandardEvent. // The return value indicates whether the conversion was successful. // Again, this is just an example, adapted it for the actual data layout. virtual bool GetStandardSubEvent(StandardEvent &sev, const Event &ev) const { // If the event type is used for different sensors // they can be differentiated here std::string sensortype = "Rd53a"; // Create a StandardPlane representing one sensor plane int base_id = 110; int width = 400, height = 192; const RawDataEvent & my_ev = dynamic_cast(ev); int ev_id = my_ev.GetTag("EventNumber", -1); for (unsigned i=0; i ( lcioEvent.getCollection( "zsdata_apix" ) ); zsDataCollectionExists = true; } catch ( lcio::DataNotAvailableException& e ) { zsDataCollection = new LCCollectionVec( lcio::LCIO::TRACKERDATA ); } //create cell encoders to set sensorID and pixel type CellIDEncoder zsDataEncoder ( eutelescope::EUTELESCOPE::ZSDATADEFAULTENCODING, zsDataCollection ); //this is an event as we sent from Producer, needs to be converted to concrete type RawDataEvent const RawDataEvent & ev_raw = dynamic_cast (eudaqEvent); std::vector< eutelescope::EUTelSetupDescription * > setupDescription; std::list tmphits; // std::string sensortype = "Rd53a"; int base_id = 110; int width = 400, height = 192; const RawDataEvent & my_ev = dynamic_cast(ev_raw); for (int i=0; i zsFrame( new lcio::TrackerDataImpl ); // set some values of "Cells" for this object zsDataEncoder.setCellID( zsFrame.get() ); // this is the structure that will host the sparse pixel // it helps to decode (and later to decode) parameters of all hits (x, y, charge, ...) to // a single TrackerData object (zsFrame) that will correspond to a single sensor in one event std::auto_ptr< eutelescope::EUTelTrackerDataInterfacerImpl< eutelescope::EUTelGenericSparsePixel > > sparseFrame( new eutelescope::EUTelTrackerDataInterfacerImpl< eutelescope::EUTelGenericSparsePixel > ( zsFrame.get() ) ); unsigned it = 0; unsigned fragmentCnt = 0; while (it < block.size()){ uint32_t tag = *((uint32_t*)(&block[it])); it+= sizeof(uint32_t); uint32_t l1id = *((uint16_t*)(&block[it])); it+= sizeof(uint16_t); uint32_t bcid = *((uint16_t*)(&block[it])); it+= sizeof(uint16_t); uint32_t nHits = *((uint16_t*)(&block[it])); it+= sizeof(uint16_t); for (unsigned i=0; iaddSparsePixel( thisHit ); sparseFrame->emplace_back( hit.col, hit.row, hit.tot, l1id ); tmphits.push_back( thisHit ); } fragmentCnt++; } // write TrackerData object that contains info from one sensor to LCIO collection zsDataCollection->push_back( zsFrame.release() ); } for( std::list::iterator it = tmphits.begin(); it != tmphits.end(); it++ ){ delete (*it); } // add this collection to lcio event if ( ( !zsDataCollectionExists ) && ( zsDataCollection->size() != 0 ) ) lcioEvent.addCollection( zsDataCollection, "zsdata_apix" ); if (lcioEvent.getEventNumber() == 0) { // do this only in the first event LCCollectionVec * apixSetupCollection = NULL; bool apixSetupExists = false; try { apixSetupCollection = static_cast< LCCollectionVec* > ( lcioEvent.getCollection( "apix_setup" ) ) ; apixSetupExists = true; } catch (...) { apixSetupCollection = new LCCollectionVec( lcio::LCIO::LCGENERICOBJECT ); } for ( size_t iPlane = 0 ; iPlane < setupDescription.size() ; ++iPlane ) { apixSetupCollection->push_back( setupDescription.at( iPlane ) ); } if (!apixSetupExists) lcioEvent.addCollection( apixSetupCollection, "apix_setup" ); } return true; } #endif private: // The constructor can be private, only one static instance is created // The DataConverterPlugin constructor must be passed the event type // in order to register this converter for the corresponding conversions // Member variables should also be initialized to default values here. YARRConverterPlugin() : DataConverterPlugin(EVENT_TYPE) {} // Information extracted in Initialize() can be stored here: unsigned m_run; // The single instance of this converter plugin static YARRConverterPlugin m_instance; }; // class ExampleConverterPlugin // Instantiate the converter plugin instance YARRConverterPlugin YARRConverterPlugin::m_instance; } // namespace eudaq