CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/EventFilter/DTRawToDigi/plugins/DTROS8Unpacker.cc

Go to the documentation of this file.
00001 
00009 #include <EventFilter/DTRawToDigi/plugins/DTROS8Unpacker.h>
00010 #include <CondFormats/DTObjects/interface/DTReadOutMapping.h>
00011 #include <FWCore/Utilities/interface/Exception.h>
00012 #include <DataFormats/MuonDetId/interface/DTWireId.h> 
00013 
00014 #include <iostream>
00015 #include <map>
00016 
00017 
00018 using namespace std;
00019 using namespace edm;
00020 using namespace cms;
00021 
00022 void DTROS8Unpacker::interpretRawData(const unsigned int* index, int datasize,
00023                                       int dduID,
00024                                       edm::ESHandle<DTReadOutMapping>& mapping, 
00025                                       std::auto_ptr<DTDigiCollection>& product,
00026                                       std::auto_ptr<DTLocalTriggerCollection>& product2,
00027                                       uint16_t rosList) {
00028  
00029 
00031   const int wordLength = 4;
00032   int numberOfWords = datasize / wordLength;
00033   int robID = 0;
00034   int rosID = 0;
00035   int eventID = 0;
00036   int bunchID = 0;
00037 
00038   map<int,int> hitOrder;
00039 
00040   // Loop over the ROS8 words
00041   for ( int i = 1; i < numberOfWords; i++ ) {
00042 
00043     // The word
00044     uint32_t word = index[i];
00045 
00046     // The word type
00047     int type = ( word >> 28 ) & 0xF;
00048 
00049     // Event Header 
00050     if ( type == 15 ) {
00051       robID =   word        & 0x7;
00052       rosID = ( word >> 3 ) & 0xFF;
00053     } 
00054 
00055     // TDC Header/Trailer
00056     else if ( type <= 3 ) {
00057       eventID = ( word >> 12 ) & 0xFFF;
00058       bunchID =   word &         0xFFF; 
00059     }
00060 
00061     // TDC Measurement
00062     else if ( type >= 4 && type <= 5 ) {
00063       
00064       int tdcID = ( word >> 24 ) & 0xF;
00065       int tdcChannel = ( word >> 19 ) & 0x1F;
00066 
00067       int channelIndex = robID << 7 | tdcID << 5 | tdcChannel;
00068       hitOrder[channelIndex]++;
00069 
00070       int tdcMeasurement =  word  & 0x7FFFF;
00071       tdcMeasurement >>= 2;
00072 
00073 
00074       try {
00075 
00076         // Check the ddu ID in the mapping been used
00077         dduID = pset.getUntrackedParameter<int>("dduID",730);
00078 
00079         // Map the RO channel to the DetId and wire
00080         DTWireId detId; 
00081         if ( ! mapping->readOutToGeometry(dduID, rosID, robID, tdcID, tdcChannel,detId)) {
00082           if (pset.getUntrackedParameter<bool>("debugMode",false)) cout<<"[DTROS8Unpacker] "<<detId<<endl;
00083           int wire = detId.wire();
00084           
00085           // Produce the digi
00086           DTDigi digi(wire, tdcMeasurement, hitOrder[channelIndex]-1);
00087           
00088           // Commit to the event
00089           product->insertDigi(detId.layerId(),digi);
00090         }
00091         else if (pset.getUntrackedParameter<bool>("debugMode",false)) 
00092           cout<<"[DTROS8Unpacker] Missing wire!"<<endl;
00093       }
00094 
00095       catch (cms::Exception & e1) {
00096         cout<<"[DTUnpackingModule]: WARNING: Digi not build!"<<endl; 
00097         return;
00098       }
00099     }
00100     
00101   }
00102 }