#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 { unsigned col : 7; unsigned row : 9; unsigned tot : 5; unsigned unused : 11; } 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 char *EVENT_TYPE = "YarrFei4"; // 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) { //m_exampleparam = bore.GetTag("EXAMPLE", 0); #ifndef WIN32 // some linux Stuff //$$change (void)cnf; // just to suppress a warning about unused parameter cnf #endif } virtual unsigned GetTriggerID(const Event &ev) const { if (const RawDataEvent *rev = dynamic_cast (&ev)) { if (rev->GetBlock(0).size() > 0) { //std::cout << "Returning trigger id: " << *((uint32_t*) &(rev->GetBlock(0)[0])) << std::endl; return *((uint32_t*) &(rev->GetBlock(0)[0])); } } return (unsigned) -1; } // 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 = "Fe65p2"; // Create a StandardPlane representing one sensor plane int id = 0; StandardPlane plane(id, EVENT_TYPE, sensortype); // Set the number of pixels int width = 64, height = 64; plane.SetSizeZS(width, height, 0, 1); const RawDataEvent & ev_raw = dynamic_cast(ev); for (int block=0; block ( 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; zsDataEncoder["sensorID"] = 30; zsDataEncoder["sparsePixelType"] = eutelescope::kEUTelGenericSparsePixel; // prepare a new TrackerData object for the ZS data // it contains all the hits for a particular sensor in one event std::auto_ptr 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() ) ); //std::cout << "Number of blocks=" << ev_raw.NumBlocks() << std::endl; for (int block=0; blockaddSparsePixel( thisHit ); tmphits.push_back( thisHit ); } } } // 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), m_exampleparam(0) {} // Information extracted in Initialize() can be stored here: unsigned m_exampleparam; // The single instance of this converter plugin static YARRConverterPlugin m_instance; }; // class ExampleConverterPlugin // Instantiate the converter plugin instance YARRConverterPlugin YARRConverterPlugin::m_instance; } // namespace eudaq