Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:37

0001 /*----------------------------------------------------------*/
0002 /* DCC DATA PARSER                                          */
0003 /*                                                          */
0004 /* Author : N.Almeida (LIP)         Date   : 30/05/2004     */
0005 /*----------------------------------------------------------*/
0006 
0007 #ifndef DCCTBDATAPARSER_HH
0008 #define DCCTBDATAPARSER_HH
0009 
0010 #include <fstream>  //STL
0011 #include <iostream>
0012 #include <string>
0013 #include <vector>
0014 #include <map>
0015 
0016 #include <cstdio>  //C
0017 
0018 #include "ECALParserException.h"  //DATA DECODER
0019 #include "DCCEventBlock.h"
0020 #include "DCCDataMapper.h"
0021 
0022 class DCCTBDataMapper;
0023 class DCCTBEventBlock;
0024 
0025 class DCCTBDataParser {
0026 public:
0027   /**
0028      Class constructor: takes a vector of 10 parameters and flags for parseInternalData and debug
0029      Parameters are: 
0030      0 - crystal samples (default is 10)
0031      1 - number of trigger time samples (default is 1)
0032      2 - number of TT (default is 68)
0033      3 - number of SR Flags (default is 68)
0034      4 - DCC id
0035      5 - SR id
0036      [6-9] - TCC[6-9] id
0037   */
0038   DCCTBDataParser(const std::vector<uint32_t> &parserParameters, bool parseInternalData = true, bool debug = true);
0039 
0040   /**
0041     Parse data from file 
0042   */
0043   void parseFile(std::string fileName, bool singleEvent = false);
0044 
0045   /**
0046      Parse data from a buffer
0047   */
0048   void parseBuffer(const uint32_t *buffer, uint32_t bufferSize, bool singleEvent = false);
0049 
0050   /**
0051      Get method for DCCTBDataMapper
0052   */
0053   DCCTBDataMapper *mapper();
0054 
0055   /**
0056      Check if EVENT LENGTH is coeherent and if BOE/EOE are correctly written
0057      returns 3 bits code with the error found + event length
0058   */
0059   std::pair<uint32_t, uint32_t> checkEventLength(const uint32_t *pointerToEvent,
0060                                                  uint32_t bytesToEnd,
0061                                                  bool singleEvent = false);
0062 
0063   /**
0064      Get methods for parser parameters;
0065   */
0066   std::vector<uint32_t> parserParameters();
0067   uint32_t numbXtalSamples();
0068   uint32_t numbTriggerSamples();
0069   uint32_t numbTTs();
0070   uint32_t numbSRF();
0071   uint32_t dccId();
0072   uint32_t srpId();
0073   uint32_t tcc1Id();
0074   uint32_t tcc2Id();
0075   uint32_t tcc3Id();
0076   uint32_t tcc4Id();
0077 
0078   /**
0079      Set method for parser parameters
0080   */
0081   void setParameters(const std::vector<uint32_t> &newParameters);
0082 
0083   /**
0084      Get methods for block sizes
0085   */
0086   uint32_t srpBlockSize();
0087   uint32_t tccBlockSize();
0088 
0089   /**
0090      Get methods for debug flag
0091   */
0092   bool debug();
0093 
0094   /**
0095      Get method for DCCEventBlocks vector
0096    */
0097   std::vector<DCCTBEventBlock *> &dccEvents();
0098 
0099   /**
0100      Get method for error counters map
0101   */
0102   std::map<std::string, uint32_t> &errorCounters();
0103 
0104   /**
0105    * Get method for events
0106    */
0107   std::vector<std::pair<uint32_t, std::pair<const uint32_t *, uint32_t> > > events();
0108 
0109   /**
0110      Reset Error Counters
0111   */
0112   void resetErrorCounters();
0113 
0114   /**
0115      Methods to get data strings formatted as decimal/hexadecimal, indexes and indexed data
0116   */
0117   std::string getDecString(uint32_t data);
0118   std::string getHexString(uint32_t data);
0119   std::string index(uint32_t position);
0120   std::string getIndexedData(uint32_t indexed, uint32_t *pointer);
0121 
0122   /**
0123    * Retrieves a pointer to the data buffer
0124    */
0125   const uint32_t *getBuffer() { return buffer_; }
0126 
0127   /**
0128      Class destructor
0129   */
0130   ~DCCTBDataParser();
0131 
0132   enum DCCDataParserGlobalFields {
0133     EMPTYEVENTSIZE = 32  //bytes
0134   };
0135 
0136 protected:
0137   void computeBlockSizes();
0138 
0139   const uint32_t *buffer_;  //data buffer
0140   uint32_t bufferSize_;     //buffer size
0141 
0142   uint32_t srpBlockSize_;  //SR block size
0143   uint32_t tccBlockSize_;  //TCC block size
0144 
0145   uint32_t processedEvent_;
0146   std::string eventErrors_;
0147   DCCTBDataMapper *mapper_;
0148 
0149   std::vector<DCCTBEventBlock *> dccEvents_;
0150 
0151   // std::pair< errorMask, std::pair< pointer to event, event size (number of DW)> >
0152   std::vector<std::pair<uint32_t, std::pair<const uint32_t *, uint32_t> > > events_;
0153 
0154   bool parseInternalData_;                  //parse internal data flag
0155   bool debug_;                              //debug flag
0156   std::map<std::string, uint32_t> errors_;  //errors map
0157   std::vector<uint32_t> parameters;         //parameters vector
0158 
0159   enum DCCTBDataParserFields {
0160     EVENTLENGTHMASK = 0xFFFFFF,
0161 
0162     BOEBEGIN = 28,  //begin of event (on 32 bit string starts at bit 28)
0163     BOEMASK = 0xF,  //mask is 4 bits (F)
0164     BOE = 0x5,      //B'0101'
0165 
0166     EOEBEGIN = 28,  //end of event
0167     EOEMASK = 0xF,  //4 bits
0168     EOE = 0xA       //B'1010'
0169   };
0170 };
0171 
0172 inline DCCTBDataMapper *DCCTBDataParser::mapper() { return mapper_; }
0173 
0174 inline std::vector<uint32_t> DCCTBDataParser::parserParameters() { return parameters; }
0175 inline uint32_t DCCTBDataParser::numbXtalSamples() { return parameters[0]; }
0176 inline uint32_t DCCTBDataParser::numbTriggerSamples() { return parameters[1]; }
0177 inline uint32_t DCCTBDataParser::numbTTs() { return parameters[2]; }
0178 inline uint32_t DCCTBDataParser::numbSRF() { return parameters[3]; }
0179 inline uint32_t DCCTBDataParser::dccId() { return parameters[4]; }
0180 inline uint32_t DCCTBDataParser::srpId() { return parameters[5]; }
0181 inline uint32_t DCCTBDataParser::tcc1Id() { return parameters[6]; }
0182 inline uint32_t DCCTBDataParser::tcc2Id() { return parameters[7]; }
0183 inline uint32_t DCCTBDataParser::tcc3Id() { return parameters[8]; }
0184 inline uint32_t DCCTBDataParser::tcc4Id() { return parameters[9]; }
0185 
0186 inline void DCCTBDataParser::setParameters(const std::vector<uint32_t> &newParameters) {
0187   parameters = newParameters;
0188   computeBlockSizes();
0189 }
0190 
0191 inline uint32_t DCCTBDataParser::srpBlockSize() { return srpBlockSize_; }
0192 inline uint32_t DCCTBDataParser::tccBlockSize() { return tccBlockSize_; }
0193 
0194 inline bool DCCTBDataParser::debug() { return debug_; }
0195 inline std::vector<DCCTBEventBlock *> &DCCTBDataParser::dccEvents() { return dccEvents_; }
0196 inline std::map<std::string, uint32_t> &DCCTBDataParser::errorCounters() { return errors_; }
0197 inline std::vector<std::pair<uint32_t, std::pair<const uint32_t *, uint32_t> > > DCCTBDataParser::events() {
0198   return events_;
0199 }
0200 
0201 #endif