CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/EventFilter/SiStripRawToDigi/interface/SiStripRawToDigiUnpacker.h

Go to the documentation of this file.
00001 
00002 #ifndef EventFilter_SiStripRawToDigi_SiStripRawToDigiUnpacker_H
00003 #define EventFilter_SiStripRawToDigi_SiStripRawToDigiUnpacker_H
00004 
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "DataFormats/Common/interface/DetSetVector.h"
00007 #include "DataFormats/DetId/interface/DetIdCollection.h"
00008 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00009 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"
00010 #include "boost/cstdint.hpp"
00011 #include <iostream>
00012 #include <string>
00013 #include <vector>
00014  
00016 namespace sistrip { class RawToClustersLazyUnpacker; }
00017 namespace sistrip { class RawToDigiUnpacker; }
00018 
00020 class FEDRawDataCollection;
00021 class FEDRawData;
00022 class SiStripDigi;
00023 class SiStripRawDigi;
00024 class SiStripEventSummary;
00025 class SiStripFedCabling;
00026 
00027 namespace sistrip {
00028   
00029   class RawToDigiUnpacker {
00030     
00031     friend class RawToClustersLazyUnpacker;
00032     
00033   public:
00034     
00035     typedef edm::DetSetVector<SiStripDigi> Digis;
00036     typedef edm::DetSetVector<SiStripRawDigi> RawDigis;
00037     
00039     RawToDigiUnpacker( int16_t appended_bytes, int16_t fed_buffer_dump_freq, int16_t fed_event_dump_freq, int16_t trigger_fed_id, bool using_fed_key,
00040                        bool unpack_bad_channels, bool mark_missing_feds, const uint32_t errorThreshold ); 
00041     
00043     ~RawToDigiUnpacker();
00044     
00046     void createDigis( const SiStripFedCabling&, const FEDRawDataCollection&, SiStripEventSummary&, RawDigis& scope_mode, RawDigis& virgin_raw, RawDigis& proc_raw, Digis& zero_suppr, DetIdCollection&, RawDigis& common_mode );
00047     
00049     void triggerFed( const FEDRawDataCollection&, SiStripEventSummary&, const uint32_t& event );
00050     
00052     void locateStartOfFedBuffer( const uint16_t& fed_id, const FEDRawData& input, FEDRawData& output );
00053     
00055     inline void quiet( bool );
00056     
00058     inline void useDaqRegister( bool );
00059 
00060     inline void extractCm( bool );
00061     
00062     inline void doFullCorruptBufferChecks( bool );
00063     
00064   private:
00065     
00067     void update( RawDigis& scope_mode, RawDigis& virgin_raw, RawDigis& proc_raw, Digis& zero_suppr, RawDigis& common_mode );
00068     
00070     RawToDigiUnpacker();
00071     
00073     void updateEventSummary( const sistrip::FEDBuffer&, SiStripEventSummary& );
00074     
00076     inline void readoutOrder( uint16_t& physical_order, uint16_t& readout_order );
00077     
00079     inline void physicalOrder( uint16_t& readout_order, uint16_t& physical_order ); 
00080     
00082     inline sistrip::FedBufferFormat fedBufferFormat( const uint16_t& register_value );
00083     
00085     inline sistrip::FedReadoutMode fedReadoutMode( const uint16_t& register_value );
00086     
00088     void dumpRawData( uint16_t fed_id, const FEDRawData&, std::stringstream& );
00089     
00091     void handleException( std::string method_name, std::string extra_info = "" );
00092     
00094     void cleanupWorkVectors();
00095     
00097     class Registry {
00098     public:
00100       Registry(uint32_t aDetid, uint16_t firstStrip, size_t indexInVector, uint16_t numberOfDigis) : 
00101         detid(aDetid), first(firstStrip), index(indexInVector), length(numberOfDigis) {}
00103       bool operator<(const Registry &other) const {return (detid != other.detid ? detid < other.detid : first < other.first);}
00105       uint32_t detid;
00106       uint16_t first;
00107       size_t index;
00108       uint16_t length;
00109     };
00110     
00112     int16_t headerBytes_;
00113     int16_t fedBufferDumpFreq_;
00114     int16_t fedEventDumpFreq_;
00115     int16_t triggerFedId_;
00116     bool useFedKey_;
00117     bool unpackBadChannels_;
00118     bool markMissingFeds_;
00119     
00121     uint32_t event_;
00122     bool once_;
00123     bool first_;
00124     bool useDaqRegister_;
00125     bool quiet_;
00126     bool extractCm_;    
00127     bool doFullCorruptBufferChecks_;
00128     uint32_t errorThreshold_;
00129     
00131     std::vector<Registry> zs_work_registry_;
00132     std::vector<Registry> virgin_work_registry_;
00133     std::vector<Registry> scope_work_registry_;
00134     std::vector<Registry> proc_work_registry_;
00135     std::vector<Registry> cm_work_registry_;
00136     
00138     std::vector<SiStripDigi> zs_work_digis_;
00139     std::vector<SiStripRawDigi> virgin_work_digis_; 
00140     std::vector<SiStripRawDigi> scope_work_digis_; 
00141     std::vector<SiStripRawDigi> proc_work_digis_;
00142     std::vector<SiStripRawDigi> cm_work_digis_;
00143   };
00144   
00145 }
00146 
00147 void sistrip::RawToDigiUnpacker::readoutOrder( uint16_t& physical_order, uint16_t& readout_order ) 
00148 {
00149   readout_order = ( 4*((static_cast<uint16_t>((static_cast<float>(physical_order)/8.0)))%4) + static_cast<uint16_t>(static_cast<float>(physical_order)/32.0) + 16*(physical_order%8) );
00150 }
00151 
00152 void sistrip::RawToDigiUnpacker::physicalOrder( uint16_t& readout_order, uint16_t& physical_order ) 
00153 {
00154   physical_order = ( (32 * (readout_order%4)) + (8 * static_cast<uint16_t>(static_cast<float>(readout_order)/4.0)) - (31 * static_cast<uint16_t>(static_cast<float>(readout_order)/16.0)) );
00155 }
00156 
00157 sistrip::FedBufferFormat sistrip::RawToDigiUnpacker::fedBufferFormat( const uint16_t& register_value ) 
00158 {
00159   if ( (register_value&0xF) == 0x1 ) { return sistrip::FULL_DEBUG_FORMAT; }
00160   else if ( (register_value&0xF) == 0x2 ) { return sistrip::APV_ERROR_FORMAT; }
00161   else if ( (register_value&0xF) == 0x0 ) { return sistrip::UNDEFINED_FED_BUFFER_FORMAT; }
00162   else { return sistrip::UNKNOWN_FED_BUFFER_FORMAT; }
00163 }
00164 
00165 sistrip::FedReadoutMode sistrip::RawToDigiUnpacker::fedReadoutMode( const uint16_t& register_value ) 
00166 {
00167   if ( ((register_value>>1)&0x7) == 0x0 ) { return sistrip::FED_SCOPE_MODE; }
00168   else if ( ((register_value>>1)&0x7) == 0x1 ) { return sistrip::FED_VIRGIN_RAW; }
00169   else if ( ((register_value>>1)&0x7) == 0x3 ) { return sistrip::FED_PROC_RAW; }
00170   else if ( ((register_value>>1)&0x7) == 0x5 ) { return sistrip::FED_ZERO_SUPPR; }
00171   else if ( ((register_value>>1)&0x7) == 0x6 ) { return sistrip::FED_ZERO_SUPPR_LITE; }
00172   else { return sistrip::UNKNOWN_FED_READOUT_MODE; }
00173 }
00174 
00175 void sistrip::RawToDigiUnpacker::quiet( bool quiet ) { quiet_ = quiet; }
00176 
00177 void sistrip::RawToDigiUnpacker::useDaqRegister( bool use ) { useDaqRegister_ =  use; }
00178 
00179 void sistrip::RawToDigiUnpacker::extractCm( bool extract_cm ) { extractCm_ = extract_cm; }
00180 
00181 void sistrip::RawToDigiUnpacker::doFullCorruptBufferChecks( bool do_full_corrupt_buffer_checks ) { doFullCorruptBufferChecks_ = do_full_corrupt_buffer_checks; }
00182 
00183 #endif // EventFilter_SiStripRawToDigi_SiStripRawToDigiUnpacker_H
00184 
00185 
00186