CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/Alignment/LaserAlignment/plugins/RawDataConverter.h

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDAnalyzer.h"
00002 #include "Alignment/LaserAlignment/interface/LASGlobalData.h"
00003 #include <DataFormats/Common/interface/DetSetVector.h>
00004 #include <FWCore/Framework/interface/Event.h> 
00005 
00006 // Forward declarations 
00007 class TFile;
00008 class TTree;
00009 
00010 class RawDataConverter : public edm::EDAnalyzer {
00011   
00012  public:
00013   explicit RawDataConverter(const edm::ParameterSet&);
00014   ~RawDataConverter();
00015   
00016   
00017  private:
00018   enum DigiType {ZeroSuppressed, VirginRaw, ProcessedRaw, Unknown};
00019   virtual void beginJob() ;
00020   virtual void beginRun(edm::Run const &, edm::EventSetup const &) ;
00021   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00022   virtual void endJob() ;
00023 
00024   void fillDetectorId( void );
00025   void ClearData( void );
00026   DigiType GetValidLabels( const edm::Event& iEvent ); // Check what kind of file is being processed and get valid module and instance labels returns the type of Digis that was found
00027 
00028   template <class T>
00029   void GetDigis(const edm::Event&); // Copy the Digis into the local container (theData)
00030 
00031   std::vector<std::string> theDigiModuleLabels;
00032   std::vector<std::string> theProductInstanceLabels;
00033 
00034   std::string CurrentModuleLabel;
00035   std::string CurrentInstanceLabel;
00036 
00037   TFile* theOutputFile;
00038   TTree* theOutputTree;
00039   LASGlobalData<std::vector<float> > theData;
00040 
00041   int latency;
00042   int eventnumber;
00043   int runnumber;
00044   int lumiBlock;
00045   LASGlobalData<int> detectorId;
00046   
00047 };
00048 
00049 
00050 // Copy the Digis into the local container (theData)
00051 // Currently this has only been implemented and tested for SiStripDigis
00052 // SiStripRawDigis and SiStripProcessedRawDigis will need some changes to work (this is the final goal)
00053 template <class Digitype>
00054 void RawDataConverter::GetDigis( const edm::Event& iEvent)
00055 {
00056   LogDebug("RawDataConverter") << "Fill ZeroSuppressed Digis into the Tree";
00057 
00058   // Get the DetSetVector for the SiStripDigis 
00059   // This is a vector with all the modules, each module containing zero or more strips with signal (Digis)
00060   edm::Handle< edm::DetSetVector< Digitype > > detSetVector;  // Handle for holding the DetSetVector
00061   iEvent.getByLabel( CurrentModuleLabel , CurrentInstanceLabel , detSetVector );
00062   if( ! detSetVector.isValid() ) throw std::runtime_error("Could not find the Digis");
00063 
00064   // set everything in the local container to zero
00065   ClearData();
00066   
00067   // Fill the Digis into the Raw Data Container
00068 
00069   LASGlobalLoop loop;  // loop helper
00070   int det, ring, beam, disk, pos; // and its variables
00071 
00072   // loop over TEC+- (internal) modules
00073   det = 0; ring = 0; beam = 0; disk = 0;
00074   do {
00075     // Find the module in the DetSetVector and get a pointer (iterator) to it
00076     typename edm::DetSetVector< Digitype >::const_iterator theModule = detSetVector->find( detectorId.GetTECEntry( det, ring, beam, disk ) );
00077 
00078     if ( theModule != detSetVector->end() ) {
00079       // loop over all the Digis in this Module
00080       typename edm::DetSet< Digitype >::const_iterator theDigi;
00081       for (theDigi = theModule->data.begin(); theDigi != theModule->data.end(); ++theDigi ) {
00082         // fill the number of adc counts into the local container
00083         if ( theDigi->channel() < 512 ) theData.GetTECEntry( det, ring, beam, disk ).at( theDigi->channel() ) = theDigi->adc();
00084       }
00085     }
00086   } while( loop.TECLoop( det, ring, beam, disk ) );
00087 
00088   // loop TIB/TOB
00089   det = 2; beam = 0; pos = 0; // <- set det = 2 (TIB)
00090   do {
00091     // Find the module in the DetSetVector and get a pointer (iterator) to it
00092     typename edm::DetSetVector< Digitype >::const_iterator theModule = detSetVector->find( detectorId.GetTIBTOBEntry( det, beam, pos ) );
00093 
00094     if ( theModule != detSetVector->end() ) {
00095       // loop over all the Digis in this Module
00096       typename edm::DetSet< Digitype >::const_iterator theDigi;
00097       for (theDigi = theModule->data.begin(); theDigi != theModule->data.end(); ++theDigi ) {
00098         // fill the number of adc counts into the local container
00099         if ( theDigi->channel() < 512 ) theData.GetTIBTOBEntry( det, beam, pos ).at( theDigi->channel() ) = theDigi->adc();
00100       }
00101     }
00102   } while( loop.TIBTOBLoop( det, beam, pos ) );
00103 
00104 
00105   // loop TEC (AT)
00106   det = 0; beam = 0; disk = 0;
00107   do {
00108     // Find the module in the DetSetVector and get a pointer (iterator) to it
00109     typename edm::DetSetVector< Digitype >::const_iterator theModule = detSetVector->find( detectorId.GetTEC2TECEntry( det, beam, disk ) );
00110 
00111     if ( theModule != detSetVector->end() ) {
00112       // loop over all the Digis in this Module
00113       typename edm::DetSet< Digitype >::const_iterator theDigi;
00114       for (theDigi = theModule->data.begin(); theDigi != theModule->data.end(); ++theDigi ) {
00115         // fill the number of adc counts into the local container
00116         if ( theDigi->channel() < 512 ) theData.GetTEC2TECEntry( det, beam, disk ).at( theDigi->channel() ) = theDigi->adc();
00117       }
00118     }
00119   } while( loop.TEC2TECLoop( det, beam, disk ) );
00120 }
00121