Changeset 214 in Idarraga


Ignore:
Timestamp:
Jul 20, 2011, 1:28:03 AM (13 years ago)
Author:
idarraga
Message:
 
Location:
EUTelraw2mdm
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • EUTelraw2mdm/USBpixI4ConverterPlugin.cc

    r202 r214  
    1616#  include "IMPL/LCGenericObjectImpl.h"
    1717#  include "UTIL/CellIDEncoder.h"
     18
     19#include "eudaq/write_mdm.h"
     20
    1821#endif
    1922
     
    3033
    3134namespace eudaq {
    32   // The event type for which this converter plugin will be registered
    33   // Modify this to match your actual event type (from the Producer)
    34   static const std::string EVENT_TYPE = "USBPIXI4";
    35 
    36   static const unsigned int CHIP_MIN_COL = 1;
    37   static const unsigned int CHIP_MAX_COL = 80;
    38   static const unsigned int CHIP_MIN_ROW = 1;
    39   static const unsigned int CHIP_MAX_ROW = 336;
    40   static const unsigned int CHIP_MAX_ROW_NORM = CHIP_MAX_ROW - CHIP_MIN_ROW;    // Maximum ROW normalized (starting with 0)
    41   static const unsigned int CHIP_MAX_COL_NORM = CHIP_MAX_COL - CHIP_MIN_COL;
    42 
    43         static int chip_id_offset = 20;
    44 
    45   class USBpixI4ConverterBase {
    46   private:
    47         unsigned int count_boards;
     35// The event type for which this converter plugin will be registered
     36// Modify this to match your actual event type (from the Producer)
     37static const std::string EVENT_TYPE = "USBPIXI4";
     38
     39static const unsigned int CHIP_MIN_COL = 1;
     40static const unsigned int CHIP_MAX_COL = 80;
     41static const unsigned int CHIP_MIN_ROW = 1;
     42static const unsigned int CHIP_MAX_ROW = 336;
     43static const unsigned int CHIP_MAX_ROW_NORM = CHIP_MAX_ROW - CHIP_MIN_ROW;      // Maximum ROW normalized (starting with 0)
     44static const unsigned int CHIP_MAX_COL_NORM = CHIP_MAX_COL - CHIP_MIN_COL;
     45
     46static int chip_id_offset = 20;
     47
     48class USBpixI4ConverterBase {
     49private:
     50        unsigned int count_boards;
    4851        std::vector<unsigned int> board_ids;
    4952
    50   public:
    51         unsigned int consecutive_lvl1;
     53public:
     54
     55        mdm * m_mdmhandler;
     56
     57        USBpixI4ConverterBase () {
     58
     59                // The constructor will be called on the first event since I need to know the number of DUT's
     60                m_mdmhandler = new mdm();
     61
     62        }
     63
     64        ~USBpixI4ConverterBase() {
     65                int nDet = m_mdmhandler->getndet();
     66                for(int detItr = 0 ; detItr < nDet ; detItr++) {
     67                        WriteToNtuple::GetInstance("", "", nDet, m_mdmhandler->getDetIdToIndexArray()[detItr], m_mdmhandler->getDetIdToIndexArray())->closeNtuple();
     68                }
     69        }
     70
     71        unsigned int consecutive_lvl1;
    5272        unsigned int tot_mode;
    5373        int first_sensor_id;
    5474
    55   int getCountBoards() {
     75        int getCountBoards() {
    5676                return count_boards;
    5777        }
     
    6686        }
    6787
    68   void getBOREparameters (const Event & ev) {
     88        void getBOREparameters (const Event & ev) {
    6989                count_boards = ev.GetTag ("boards", -1);
    7090                board_ids.clear();
     
    201221                return plane;
    202222        }
    203   };
    204 
    205   // Declare a new class that inherits from DataConverterPlugin
    206   class USBPixI4ConverterPlugin : public DataConverterPlugin , public USBpixI4ConverterBase {
    207 
    208   public:
    209 
    210     // This is called once at the beginning of each run.
    211     // You may extract information from the BORE and/or configuration
    212     // and store it in member variables to use during the decoding later.
    213     virtual void Initialize(const Event & bore,
    214                             const Configuration & cnf) {
    215       (void)cnf; // just to suppress a warning about unused parameter cnf
    216       getBOREparameters (bore);
    217     }
    218 
    219     // This should return the trigger ID (as provided by the TLU)
    220     // if it was read out, otherwise it can either return (unsigned)-1,
    221     // or be left undefined as there is already a default version.
    222     virtual unsigned GetTriggerID(const Event & ev) const {
     223};
     224
     225// Declare a new class that inherits from DataConverterPlugin
     226class USBPixI4ConverterPlugin : public DataConverterPlugin , public USBpixI4ConverterBase {
     227
     228public:
     229
     230        // This is called once at the beginning of each run.
     231        // You may extract information from the BORE and/or configuration
     232        // and store it in member variables to use during the decoding later.
     233        virtual void Initialize(const Event & bore,
     234                        const Configuration & cnf) {
     235                (void)cnf; // just to suppress a warning about unused parameter cnf
     236                getBOREparameters (bore);
     237        }
     238
     239        // This should return the trigger ID (as provided by the TLU)
     240        // if it was read out, otherwise it can either return (unsigned)-1,
     241        // or be left undefined as there is already a default version.
     242        virtual unsigned GetTriggerID(const Event & ev) const {
    223243
    224244                // Make sure the event is of class RawDataEvent
     
    236256        }
    237257
    238     // Here, the data from the RawDataEvent is extracted into a StandardEvent.
    239     // The return value indicates whether the conversion was successful.
    240     // Again, this is just an example, adapted it for the actual data layout.
    241     virtual bool GetStandardSubEvent(StandardEvent & sev, const Event & ev) const {
     258        // Here, the data from the RawDataEvent is extracted into a StandardEvent.
     259        // The return value indicates whether the conversion was successful.
     260        // Again, this is just an example, adapted it for the actual data layout.
     261        virtual bool GetStandardSubEvent(StandardEvent & sev, const Event & ev) const {
    242262                if (ev.IsBORE()) {
    243263                        return true;
     
    253273                }
    254274
    255         return true;
    256     }
    257 
    258 #if USE_LCIO && USE_EUTELESCOPE
    259     // This is where the conversion to LCIO is done
    260     virtual lcio::LCEvent * GetLCIOEvent(const Event * /*ev*/) const {
     275                return true;
     276        }
     277
     278        //i- #if USE_LCIO && USE_EUTELESCOPE
     279        // This is where the conversion to LCIO is done
     280        virtual lcio::LCEvent * GetLCIOEvent(const Event * /*ev*/) const {
    261281                return 0;
    262     }
     282        }
    263283
    264284        virtual bool GetLCIOSubEvent(lcio::LCEvent & lcioEvent, const Event & eudaqEvent) const {
    265                 //std::cout << "getlciosubevent (I4) event " << eudaqEvent.GetEventNumber() << " | " << GetTriggerID(eudaqEvent) << std::endl;
     285
     286                std::cout << "getlciosubevent (I4) event " << eudaqEvent.GetEventNumber() << " | " << GetTriggerID(eudaqEvent) << std::endl;
     287
    266288                if (eudaqEvent.IsBORE()) {
    267289                        // shouldn't happen
     
    293315                const RawDataEvent & ev_raw = dynamic_cast <const RawDataEvent &> (eudaqEvent);
    294316
     317                // First time. Initialize the mdm handlers, number of DUTs won't change in a run.
     318                if (!m_mdmhandler->isInitialized()) {
     319
     320                        // find sensor ID's
     321                        std::vector<int> sIDs;
     322                        for (size_t chip = 0; chip < ev_raw.NumBlocks(); ++chip) {
     323                                // as calculated and stored later in zsDataEncoder["sensorID"]
     324                                sIDs.push_back(ev_raw.GetID(chip) + chip_id_offset + first_sensor_id);
     325                        }
     326
     327                        // Initialize the Handler !
     328                        m_mdmhandler->init(sIDs, EVENT_TYPE, CHIP_MAX_COL, CHIP_MAX_ROW);
     329
     330                }
     331
    295332                std::vector< eutelescope::EUTelSetupDescription * >  setupDescription;
    296333
     
    320357                        // a single TrackerData object (zsFrame) that will correspond to a single sensor in one event
    321358                        std::auto_ptr< eutelescope::EUTelSparseDataImpl< eutelescope::EUTelAPIXSparsePixel > >
    322                                 sparseFrame( new eutelescope::EUTelSparseDataImpl< eutelescope::EUTelAPIXSparsePixel > ( zsFrame.get() ) );
     359                        sparseFrame( new eutelescope::EUTelSparseDataImpl< eutelescope::EUTelAPIXSparsePixel > ( zsFrame.get() ) );
    323360
    324361                        unsigned int ToT = 0;
     
    330367                                unsigned int Word = (((unsigned int)buffer[i + 3]) << 24) | (((unsigned int)buffer[i + 2]) << 16) | (((unsigned int)buffer[i + 1]) << 8) | (unsigned int)buffer[i];
    331368
     369
    332370                                if (DATA_HEADER_MACRO(Word)) {
    333371                                        lvl1++;
    334372                                } else {
     373
    335374                                        // First Hit
    336375                                        if (getHitData(Word, false, Col, Row, ToT)) {
     
    338377                                                sparseFrame->addSparsePixel( thisHit );
    339378                                                tmphits.push_back( thisHit );
     379
     380                                                //std::cout << ".... f -> " << i << " : " << Col << "," << Row << "," << ToT << "," << lvl1-1 << std::endl;
     381                                                // hit to mdm
     382                                                m_mdmhandler->dofill(zsDataEncoder["sensorID"], Col, Row, ToT, lvl1-1);
    340383                                        }
    341384                                        // Second Hit
     
    344387                                                sparseFrame->addSparsePixel( thisHit );
    345388                                                tmphits.push_back( thisHit );
     389
     390                                                //std::cout << ".... s -> " << i << " : " << Col << "," << Row << "," << ToT << "," << lvl1-1 << std::endl;
     391                                                // hit to mdm
     392                                                m_mdmhandler->dofill(zsDataEncoder["sensorID"], Col, Row, ToT, lvl1-1);
    346393                                        }
    347394                                }
    348395                        }
    349396
     397                        // Write to mdm !  this member clears the matrix after filling
     398                        //std::cout << "chip : " << chip << std::endl;
     399                        m_mdmhandler->writetontuple(zsDataEncoder["sensorID"], lcioEvent.getEventNumber());
     400
    350401                        // write TrackerData object that contains info from one sensor to LCIO collection
    351402                        zsDataCollection->push_back( zsFrame.release() );
     
    353404                        // clean up
    354405                        for( std::list<eutelescope::EUTelAPIXSparsePixel*>::iterator it = tmphits.begin(); it != tmphits.end(); it++ ){
    355                           delete (*it);
     406                                delete (*it);
    356407                        }
    357408                }
     
    380431                return true;
    381432
    382     }
    383 #endif
    384 
    385   private:
    386 
    387     // The constructor can be private, only one static instance is created
    388     // The DataConverterPlugin constructor must be passed the event type
    389     // in order to register this converter for the corresponding conversions
    390     // Member variables should also be initialized to default values here.
    391     USBPixI4ConverterPlugin()
    392       : DataConverterPlugin(EVENT_TYPE)
    393       {}
    394 
    395     // The single instance of this converter plugin
    396     static USBPixI4ConverterPlugin m_instance;
    397   };
    398 
    399   // Instantiate the converter plugin instance
    400   USBPixI4ConverterPlugin USBPixI4ConverterPlugin::m_instance;
     433        }
     434        //#endif
     435
     436private:
     437
     438        // The constructor can be private, only one static instance is created
     439        // The DataConverterPlugin constructor must be passed the event type
     440        // in order to register this converter for the corresponding conversions
     441        // Member variables should also be initialized to default values here.
     442        USBPixI4ConverterPlugin()
     443        : DataConverterPlugin(EVENT_TYPE)
     444        {}
     445
     446        // The single instance of this converter plugin
     447        static USBPixI4ConverterPlugin m_instance;
     448};
     449
     450// Instantiate the converter plugin instance
     451USBPixI4ConverterPlugin USBPixI4ConverterPlugin::m_instance;
     452
    401453
    402454} // namespace eudaq
Note: See TracChangeset for help on using the changeset viewer.