CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/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     inline void doAPVEmulatorCheck( bool );
00065 
00066   private:
00067     
00069     void update( RawDigis& scope_mode, RawDigis& virgin_raw, RawDigis& proc_raw, Digis& zero_suppr, RawDigis& common_mode );
00070     
00072     RawToDigiUnpacker();
00073     
00075     void updateEventSummary( const sistrip::FEDBuffer&, SiStripEventSummary& );
00076     
00078     inline void readoutOrder( uint16_t& physical_order, uint16_t& readout_order );
00079     
00081     inline void physicalOrder( uint16_t& readout_order, uint16_t& physical_order ); 
00082     
00084     inline sistrip::FedBufferFormat fedBufferFormat( const uint16_t& register_value );
00085     
00087     inline sistrip::FedReadoutMode fedReadoutMode( const uint16_t& register_value );
00088     
00090     void dumpRawData( uint16_t fed_id, const FEDRawData&, std::stringstream& );
00091     
00093     void handleException( std::string method_name, std::string extra_info = "" );
00094     
00096     void cleanupWorkVectors();
00097     
00099     class Registry {
00100     public:
00102       Registry(uint32_t aDetid, uint16_t firstStrip, size_t indexInVector, uint16_t numberOfDigis) : 
00103         detid(aDetid), first(firstStrip), index(indexInVector), length(numberOfDigis) {}
00105       bool operator<(const Registry &other) const {return (detid != other.detid ? detid < other.detid : first < other.first);}
00107       uint32_t detid;
00108       uint16_t first;
00109       size_t index;
00110       uint16_t length;
00111     };
00112     
00114     int16_t headerBytes_;
00115     int16_t fedBufferDumpFreq_;
00116     int16_t fedEventDumpFreq_;
00117     int16_t triggerFedId_;
00118     bool useFedKey_;
00119     bool unpackBadChannels_;
00120     bool markMissingFeds_;
00121     
00123     uint32_t event_;
00124     bool once_;
00125     bool first_;
00126     bool useDaqRegister_;
00127     bool quiet_;
00128     bool extractCm_;    
00129     bool doFullCorruptBufferChecks_;
00130     bool doAPVEmulatorCheck_;
00131     uint32_t errorThreshold_;
00132     
00134     std::vector<Registry> zs_work_registry_;
00135     std::vector<Registry> virgin_work_registry_;
00136     std::vector<Registry> scope_work_registry_;
00137     std::vector<Registry> proc_work_registry_;
00138     std::vector<Registry> cm_work_registry_;
00139     
00141     std::vector<SiStripDigi> zs_work_digis_;
00142     std::vector<SiStripRawDigi> virgin_work_digis_; 
00143     std::vector<SiStripRawDigi> scope_work_digis_; 
00144     std::vector<SiStripRawDigi> proc_work_digis_;
00145     std::vector<SiStripRawDigi> cm_work_digis_;
00146   };
00147   
00148 }
00149 
00150 void sistrip::RawToDigiUnpacker::readoutOrder( uint16_t& physical_order, uint16_t& readout_order ) 
00151 {
00152   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) );
00153 }
00154 
00155 void sistrip::RawToDigiUnpacker::physicalOrder( uint16_t& readout_order, uint16_t& physical_order ) 
00156 {
00157   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)) );
00158 }
00159 
00160 sistrip::FedBufferFormat sistrip::RawToDigiUnpacker::fedBufferFormat( const uint16_t& register_value ) 
00161 {
00162   if ( (register_value&0xF) == 0x1 ) { return sistrip::FULL_DEBUG_FORMAT; }
00163   else if ( (register_value&0xF) == 0x2 ) { return sistrip::APV_ERROR_FORMAT; }
00164   else if ( (register_value&0xF) == 0x0 ) { return sistrip::UNDEFINED_FED_BUFFER_FORMAT; }
00165   else { return sistrip::UNKNOWN_FED_BUFFER_FORMAT; }
00166 }
00167 
00168 sistrip::FedReadoutMode sistrip::RawToDigiUnpacker::fedReadoutMode( const uint16_t& register_value ) 
00169 {
00170   if ( ((register_value>>1)&0x7) == 0x0 ) { return sistrip::FED_SCOPE_MODE; }
00171   else if ( ((register_value>>1)&0x7) == 0x1 ) { return sistrip::FED_VIRGIN_RAW; }
00172   else if ( ((register_value>>1)&0x7) == 0x3 ) { return sistrip::FED_PROC_RAW; }
00173   else if ( ((register_value>>1)&0x7) == 0x5 ) { return sistrip::FED_ZERO_SUPPR; }
00174   else if ( ((register_value>>1)&0x7) == 0x6 ) { return sistrip::FED_ZERO_SUPPR_LITE; }
00175   else { return sistrip::UNKNOWN_FED_READOUT_MODE; }
00176 }
00177 
00178 void sistrip::RawToDigiUnpacker::quiet( bool quiet ) { quiet_ = quiet; }
00179 
00180 void sistrip::RawToDigiUnpacker::useDaqRegister( bool use ) { useDaqRegister_ =  use; }
00181 
00182 void sistrip::RawToDigiUnpacker::extractCm( bool extract_cm ) { extractCm_ = extract_cm; }
00183 
00184 void sistrip::RawToDigiUnpacker::doFullCorruptBufferChecks( bool do_full_corrupt_buffer_checks ) { doFullCorruptBufferChecks_ = do_full_corrupt_buffer_checks; }
00185 
00186 void sistrip::RawToDigiUnpacker::doAPVEmulatorCheck( bool do_APVEmulator_check) { doAPVEmulatorCheck_ = do_APVEmulator_check; }
00187 
00188 #endif // EventFilter_SiStripRawToDigi_SiStripRawToDigiUnpacker_H
00189 
00190 
00191