CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DataFormats/SiStripCommon/src/SiStripEventSummary.cc

Go to the documentation of this file.
00001 // Last commit: $Id: SiStripEventSummary.cc,v 1.11 2008/11/26 16:47:10 bainbrid Exp $
00002 
00003 #include "DataFormats/SiStripCommon/interface/SiStripEventSummary.h"
00004 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include <iostream>
00007 #include <iomanip>
00008 
00009 using namespace sistrip;
00010 
00011 // -----------------------------------------------------------------------------
00012 //
00013 SiStripEventSummary::SiStripEventSummary() : 
00014   valid_(true),
00015   triggerFed_(0),
00016   runType_(sistrip::UNDEFINED_RUN_TYPE), 
00017   event_(0), 
00018   bx_(0),
00019   spillNumber_(0),
00020   nDataSenders_(0),
00021   fedReadoutMode_(sistrip::UNDEFINED_FED_READOUT_MODE),
00022   apvReadoutMode_(sistrip::UNDEFINED_APV_READOUT_MODE),
00023   apveAddress_(0),
00024   nApvsInSync_(0),
00025   nApvsOutOfSync_(0),
00026   nApvsErrors_(0),
00027   params_(5,0)
00028 {;}
00029 
00030 // -----------------------------------------------------------------------------
00031 //
00032 void SiStripEventSummary::commissioningInfo( const uint32_t* const buffer,
00033                                              const uint32_t& event ) {
00034   
00035   // Set RunType
00036   uint16_t run = static_cast<uint16_t>( buffer[10] & 0xFFFF );
00037   runType_ = SiStripEnumsAndStrings::runType(run);
00038 
00039   // Set spill number
00040   spillNumber_ = buffer[0];
00041 
00042   // Set number of DataSenders
00043   nDataSenders_ = buffer[20];
00044 
00045   // Set FED readout mode
00046   if      ( buffer[15] == 0 ) { fedReadoutMode_ = sistrip::FED_SCOPE_MODE; }
00047   else if ( buffer[15] == 1 ) { fedReadoutMode_ = sistrip::FED_VIRGIN_RAW; }
00048   else if ( buffer[15] == 2 ) { fedReadoutMode_ = sistrip::FED_PROC_RAW; }
00049   else if ( buffer[15] == 3 ) { fedReadoutMode_ = sistrip::FED_ZERO_SUPPR; }
00050   else if ( buffer[15] == 4 ) { fedReadoutMode_ = sistrip::FED_ZERO_SUPPR_LITE; }
00051   else { fedReadoutMode_ = sistrip::UNKNOWN_FED_READOUT_MODE; }
00052   
00053   // Set hardware parameters
00054   if ( runType_ == sistrip::CALIBRATION ||
00055        runType_ == sistrip::CALIBRATION_DECO ||
00056        runType_ == sistrip::CALIBRATION_SCAN ||
00057        runType_ == sistrip::CALIBRATION_SCAN_DECO ||
00058        runType_ == sistrip::APV_LATENCY ) { 
00059 
00060     params_[0] = buffer[11]; // latency
00061     params_[1] = buffer[12]; // cal_chan
00062     params_[2] = buffer[13]; // cal_sel
00063     params_[3] = buffer[15]; // isha
00064     params_[4] = buffer[16]; // vfs
00065 
00066   } else if ( runType_ == sistrip::OPTO_SCAN ) { 
00067 
00068     params_[0] = buffer[11]; // opto gain
00069     params_[1] = buffer[12]; // opto bias
00070 
00071   } else if ( runType_ == sistrip::APV_TIMING ||
00072               runType_ == sistrip::FED_TIMING ) {
00073     params_[0] = buffer[11]; // pll coarse delay
00074     params_[1] = buffer[12]; // pll fine delay
00075     params_[2] = buffer[13]; // ttcrx delay
00076   } else if ( runType_ == sistrip::FINE_DELAY || //@@ layer
00077               runType_ == sistrip::FINE_DELAY_PLL ||
00078               runType_ == sistrip::FINE_DELAY_TTC ) { 
00079     params_[0] = buffer[11]; // pll coarse delay
00080     params_[1] = buffer[12]; // pll fine delay
00081     params_[2] = buffer[13]; // ttcrx delay
00082     params_[3] = buffer[14]; // layer (private format: DDSSLLLL, det, side, layer)
00083 
00084   } else if ( runType_ == sistrip::FAST_CABLING ) { 
00085 
00086     params_[0] = buffer[11]; // bin number
00087     params_[1] = buffer[12]; // fec instance
00088     params_[2] = buffer[13]; // fec ip
00089     params_[3] = buffer[14]; // dcu hard id 
00090 
00091   } else if ( runType_ == sistrip::FED_CABLING ||
00092               runType_ == sistrip::QUITE_FAST_CABLING ) { 
00093 
00094     if ( runType_ == sistrip::QUITE_FAST_CABLING ) { 
00095 
00096       uint16_t ii = 0;
00097       bool found = false;
00098       while ( !found && ii < 20 ) {
00099         uint32_t dcu = buffer[21+3*ii];
00100         uint32_t key = buffer[21+3*ii+1];
00101         uint32_t evt = buffer[21+3*ii+2];
00102         if ( evt == event ) {
00103           params_[0] = key; // device id
00104           params_[1] = 0;   // process id
00105           params_[2] = 0;   // process ip
00106           params_[3] = dcu; // dcu hard id
00107           found = true;
00108         } 
00109         ii++;
00110       }
00111       if ( !found ) { 
00112         if ( edm::isDebugEnabled() ) {
00113           std::stringstream ss;
00114           ss << "[SiStripEventSummary::" << __func__ << "]"
00115              << " Did not find DeviceId/DCUid for event " 
00116              << event << "!";
00117           edm::LogWarning(mlDigis_) << ss.str();
00118         }
00119         params_[0] = 0; 
00120         params_[1] = 0; 
00121         params_[2] = 0;
00122         params_[3] = 0;
00123       } else {
00124         if ( edm::isDebugEnabled() ) {
00125           std::stringstream ss;
00126           ss << "[SiStripEventSummary::" << __func__ << "]"
00127              << " Found DeviceId/DCUid for event " 
00128              << event << ": 0x" 
00129              << std::hex << std::setw(8) << std::setfill('0') << params_[0] << std::dec
00130              << "/0x"
00131              << std::hex << std::setw(8) << std::setfill('0') << params_[3] << std::dec;
00132           LogTrace(mlDigis_) << ss.str();
00133         }
00134       }
00135 
00136     } else {
00137 
00138       params_[0] = buffer[11]; // device id
00139       params_[1] = buffer[12]; // process id
00140       params_[2] = buffer[13]; // process ip
00141       params_[3] = buffer[14]; // dcu hard id
00142 
00143     }
00144 
00145   } else if ( runType_ == sistrip::VPSP_SCAN ) { 
00146 
00147     params_[0] = buffer[11]; // vpsp value
00148     params_[1] = buffer[12]; // ccu channel
00149 
00150   } else if ( runType_ == sistrip::DAQ_SCOPE_MODE ) { 
00151 
00152     // nothing interesting!
00153 
00154   } else if (  runType_ == sistrip::PHYSICS ||
00155                runType_ == sistrip::PHYSICS_ZS ||
00156                runType_ == sistrip::PEDESTALS ) { 
00157 
00158     //@@ do anything?...
00159 
00160   } else { 
00161     
00162     if ( edm::isDebugEnabled() ) {
00163       edm::LogWarning(mlDigis_)
00164         << "[SiStripEventSummary::" << __func__ << "]"
00165         << " Unexpected commissioning task: "
00166         << runType_;
00167     }
00168 
00169   }
00170 
00171 }
00172 
00173 // -----------------------------------------------------------------------------
00174 //
00175 
00176 // -----------------------------------------------------------------------------
00177 //
00178 void SiStripEventSummary::commissioningInfo( const uint32_t& daq1,
00179                                              const uint32_t& daq2 ) {
00180   
00181   // Extract if commissioning info are valid or not 
00182   uint16_t temp = static_cast<uint16_t>( (daq1>>8)&0x3 );
00183   if      ( temp == uint16_t(1) ) { valid_ = true; }
00184   else if ( temp == uint16_t(2) ) { valid_ = false; }
00185   else if ( temp == uint16_t(3) && 
00186             daq1 == sistrip::invalid32_ ) {
00187     if ( edm::isDebugEnabled() ) {
00188       edm::LogWarning(mlDigis_)
00189         << "[SiStripEventSummary::" << __func__ << "]"
00190         << " DAQ register contents set to invalid: 0x"
00191         << std::hex 
00192         << std::setw(8) << std::setfill('0') << daq1 
00193         << std::dec;
00194     }
00195     valid_ = false;
00196   } else {
00197     if ( edm::isDebugEnabled() ) {
00198       edm::LogWarning(mlDigis_)
00199         << "[SiStripEventSummary::" << __func__ << "]"
00200         << " Unexpected bit pattern set in DAQ1: 0x"
00201         << std::hex 
00202         << std::setw(8) << std::setfill('0') << daq1 
00203         << std::dec;
00204     }
00205     valid_ = false;
00206   }
00207   
00208   // Set RunType
00209   uint16_t run = static_cast<uint16_t>( daq1&0xFF );
00210   runType_ = SiStripEnumsAndStrings::runType(run);
00211   
00212   // Set hardware parameters
00213   if        ( runType_ == sistrip::PHYSICS ) { 
00214   } else if ( runType_ == sistrip::PHYSICS_ZS ) { 
00215   } else if ( runType_ == sistrip::PEDESTALS ) { 
00216   } else if ( runType_ == sistrip::DAQ_SCOPE_MODE ) { 
00217   } else if ( runType_ == sistrip::CALIBRATION ) { 
00218   } else if ( runType_ == sistrip::CALIBRATION_DECO ) { 
00219     params_[0] = (daq2>>8)&0xFF; // latency
00220     params_[1] = (daq2>>4)&0x0F; // cal_chan
00221     params_[2] = (daq2>>0)&0x0F; // cal_sel
00222   } else if ( runType_ == sistrip::CALIBRATION_SCAN ) { 
00223     params_[0] = (daq2>>8)&0xFF; // latency
00224     params_[1] = (daq2>>4)&0x0F; // cal_chan
00225     params_[2] = (daq2>>0)&0x0F; // cal_sel
00226   } else if ( runType_ == sistrip::OPTO_SCAN ) { 
00227     params_[0] = (daq2>>8)&0xFF; // opto gain
00228     params_[1] = (daq2>>0)&0xFF; // opto bias
00229   } else if ( runType_ == sistrip::APV_TIMING ) { 
00230     params_[1] = (daq2>>0)&0xFF; // pll fine delay
00231   } else if ( runType_ == sistrip::APV_LATENCY ) { 
00232     params_[0] = (daq2>>0)&0xFF; // latency
00233   } else if ( runType_ == sistrip::FINE_DELAY_PLL ) { 
00234   } else if ( runType_ == sistrip::FINE_DELAY_TTC ) { 
00235   } else if ( runType_ == sistrip::FINE_DELAY ) { //@@ layer
00236     params_[2] = (daq2>>0 )&0xFFFF; // ttcrx delay
00237     params_[0] = params_[2]/25;   // pll coarse delay
00238     params_[1] = uint32_t((params_[2]%25)*24./25.); // pll fine delay
00239     params_[3] = (daq2>>0)&0xFFFF0000; // layer (private format: DDSSLLLL (det, side, layer)
00240   } else if ( runType_ == sistrip::FED_TIMING ) { 
00241     params_[1] = (daq2>>0)&0xFF; // pll fine delay
00242   } else if ( runType_ == sistrip::VPSP_SCAN ) { 
00243     params_[0] = (daq2>>8)&0xFF; // vpsp value
00244     params_[1] = (daq2>>0)&0xFF; // ccu channel
00245   } else if ( runType_ == sistrip::FED_CABLING ) { 
00246   } else if ( runType_ == sistrip::QUITE_FAST_CABLING ) { 
00247   } else if ( runType_ == sistrip::FAST_CABLING ) { 
00248     params_[0] = (daq2>>0)&0xFF; // key
00249   } else { 
00250     if ( edm::isDebugEnabled() ) {
00251       edm::LogWarning(mlDigis_)
00252         << "[SiStripEventSummary::" << __func__ << "]"
00253         << " Unexpected commissioning task: "
00254         << runType_;
00255     }
00256   }
00257 
00258 }
00259 
00260 // -----------------------------------------------------------------------------
00261 //
00262 void SiStripEventSummary::fedReadoutMode( const uint16_t& mode ) {
00263   if      ( mode ==  1 ) { fedReadoutMode_ = sistrip::FED_SCOPE_MODE; }
00264   else if ( mode ==  2 ) { fedReadoutMode_ = sistrip::FED_VIRGIN_RAW; }
00265   else if ( mode ==  6 ) { fedReadoutMode_ = sistrip::FED_PROC_RAW; }
00266   else if ( mode == 10 ) { fedReadoutMode_ = sistrip::FED_ZERO_SUPPR; }
00267   else if ( mode == 12 ) { fedReadoutMode_ = sistrip::FED_ZERO_SUPPR_LITE; }
00268   else { fedReadoutMode_ = sistrip::UNKNOWN_FED_READOUT_MODE; }
00269 }
00270 
00271 // -----------------------------------------------------------------------------
00272 //
00273 std::ostream& operator<< ( std::ostream& os, const SiStripEventSummary& input ) {
00274   return os << "[SiStripEventSummary::" << __func__ << "]" << std::endl
00275             << " isSet                : " << std::boolalpha << input.isSet() << std::noboolalpha << std::endl
00276             << " Trigger FED id       : " << input.triggerFed() << std::endl
00277             << " isValid              : " << std::boolalpha << input.valid() << std::noboolalpha << std::endl
00278             << " Run type             : " << SiStripEnumsAndStrings::runType( input.runType() ) << std::endl
00279             << " Event number         : " << input.event() << std::endl 
00280             << " Bunch crossing       : " << input.bx() << std::endl
00281             << " FED readout mode     : " << SiStripEnumsAndStrings::fedReadoutMode( input.fedReadoutMode() ) << std::endl
00282             << " APV readout mode     : " << SiStripEnumsAndStrings::apvReadoutMode( input.apvReadoutMode() ) << std::endl
00283             << " Commissioning params : "
00284             << input.params()[0] << ", " 
00285             << input.params()[1] << ", " 
00286             << input.params()[2] << ", "  
00287             << input.params()[3] 
00288             << std::endl;
00289 }