CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/RecoTBCalo/HcalTBObjectUnpacker/src/HcalTBObjectUnpacker.cc

Go to the documentation of this file.
00001 using namespace std;
00002 
00003 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00004 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTriggerData.h"
00005 #include "TBDataFormats/HcalTBObjects/interface/HcalTBRunData.h"
00006 #include "TBDataFormats/HcalTBObjects/interface/HcalTBEventPosition.h"
00007 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTiming.h"
00008 #include "TBDataFormats/HcalTBObjects/interface/HcalTBBeamCounters.h"
00009 #include "RecoTBCalo/HcalTBObjectUnpacker/interface/HcalTBObjectUnpacker.h"
00010 #include "DataFormats/Common/interface/EDCollection.h"
00011 #include "DataFormats/Common/interface/Handle.h"
00012 #include "FWCore/Framework/interface/Selector.h"
00013 #include <iostream>
00014 #include <fstream>
00015 
00016 
00017   HcalTBObjectUnpacker::HcalTBObjectUnpacker(edm::ParameterSet const& conf):
00018     triggerFed_(conf.getUntrackedParameter<int>("HcalTriggerFED",-1)),
00019     sdFed_(conf.getUntrackedParameter<int>("HcalSlowDataFED",-1)),
00020     spdFed_(conf.getUntrackedParameter<int>("HcalSourcePositionFED",-1)),
00021     tdcFed_(conf.getUntrackedParameter<int>("HcalTDCFED",-1)),
00022     qadcFed_(conf.getUntrackedParameter<int>("HcalQADCFED",-1)),
00023     calibFile_(conf.getUntrackedParameter<string>("ConfigurationFile","")),
00024     tdcUnpacker_(conf.getUntrackedParameter<bool>("IncludeUnmatchedHits",false)),
00025     doRunData_(false),doTriggerData_(false),doEventPosition_(false),doTiming_(false),doSourcePos_(false),doBeamADC_(false)
00026   {
00027 
00028     if (triggerFed_ >=0) {
00029       std::cout << "HcalTBObjectUnpacker will unpack Trigger FED ";
00030       std::cout << triggerFed_ << endl;
00031       doTriggerData_=true;
00032     }
00033 
00034     if (sdFed_ >=0) {
00035       std::cout << "HcalTBObjectUnpacker will unpack SlowData FED ";
00036       std::cout << sdFed_ << endl;
00037       doRunData_=true;
00038       doEventPosition_=true; // at least the table
00039     }
00040 
00041     if (tdcFed_ >=0) {
00042       std::cout << "HcalTBObjectUnpacker will unpack TDC FED ";
00043       std::cout << tdcFed_ << endl;
00044       doTiming_=true;
00045       doEventPosition_=true; // at least the WC
00046     }
00047 
00048     if (qadcFed_ >=0) {
00049       std::cout << "HcalTBObjectUnpacker will unpack QADC FED ";
00050       std::cout << qadcFed_ << endl;
00051       doBeamADC_=true;
00052     }
00053 
00054     if (spdFed_ >=0) {
00055       std::cout << "HcalTBObjectUnpacker will unpack Source Position Data FED ";
00056       std::cout << spdFed_ << endl;
00057       doSourcePos_=true;
00058     }
00059 
00060 
00061     if (tdcFed_ >= 0 || qadcFed_ >=0 ) {
00062       calibLines_.clear();
00063       if(calibFile_.size()>0){
00064         parseCalib();
00065         //  printf("I got %d lines!\n",calibLines_.size());
00066         if(calibLines_.size()==0)
00067           throw cms::Exception("Incomplete configuration") << 
00068             "HcalTBObjectUnpacker: TDC/QADC/WC configuration file not found or is empty: "<<calibFile_<<endl;
00069       }
00070       else{
00071         throw cms::Exception("Incomplete configuration") << 
00072           "HcalTBObjectUnpacker: TDC/QADC/WC configuration file not found: "<<calibFile_<<endl;
00073       }
00074     }
00075 
00076 
00077     if (doTriggerData_) produces<HcalTBTriggerData>();
00078     if (doRunData_) produces<HcalTBRunData>();
00079     if (doEventPosition_) produces<HcalTBEventPosition>();
00080     if (doTiming_) produces<HcalTBTiming>();
00081 //    if (doBeamADC_) produces<HcalTBBeamCounters>();
00082     if (doBeamADC_) {produces<HcalTBBeamCounters>();qadcUnpacker_.setCalib(calibLines_);}
00083 //    if (doSourcePos_) produces<HcalSourcePositionData>();
00084     if(doTiming_||doEventPosition_)tdcUnpacker_.setCalib(calibLines_);
00085   }
00086 
00087   // Virtual destructor needed.
00088   HcalTBObjectUnpacker::~HcalTBObjectUnpacker() { }  
00089 
00090   // Functions that gets called by framework every event
00091   void HcalTBObjectUnpacker::produce(edm::Event& e, const edm::EventSetup&)
00092   {
00093     // Step A: Get Inputs 
00094     edm::Handle<FEDRawDataCollection> rawraw;  
00095     //    edm::ProcessNameSelector s("PROD"); // HACK!
00096     e.getByType(rawraw);           
00097 
00098     // Step B: Create empty output    
00099     std::auto_ptr<HcalTBTriggerData>
00100       trigd(new HcalTBTriggerData);
00101 
00102     std::auto_ptr<HcalTBRunData>
00103       rund(new HcalTBRunData);
00104 
00105     std::auto_ptr<HcalTBEventPosition>
00106       epd(new HcalTBEventPosition);
00107 
00108     std::auto_ptr<HcalTBTiming>
00109       tmgd(new HcalTBTiming);
00110 
00111     std::auto_ptr<HcalTBBeamCounters>
00112       bcntd(new HcalTBBeamCounters);
00113 
00114     std::auto_ptr<HcalSourcePositionData>
00115       spd(new HcalSourcePositionData);
00116     
00117     if (triggerFed_ >=0) {
00118       // Step C: unpack all requested FEDs
00119       const FEDRawData& fed = rawraw->FEDData(triggerFed_);
00120       tdUnpacker_.unpack(fed,*trigd);
00121     }
00122 
00123     if (sdFed_ >=0) {
00124       // Step C: unpack all requested FEDs
00125       const FEDRawData& fed = rawraw->FEDData(sdFed_);
00126       sdUnpacker_.unpack(fed, *rund, *epd);
00127     }
00128 
00129     if (tdcFed_ >=0) {
00130       // Step C: unpack all requested FEDs
00131       const FEDRawData& fed = rawraw->FEDData(tdcFed_);
00132       tdcUnpacker_.unpack(fed, *epd, *tmgd);
00133     }
00134 
00135     if (qadcFed_ >=0) {
00136       // Step C: unpack all requested FEDs
00137       const FEDRawData& fed = rawraw->FEDData(qadcFed_);
00138       bool is04 = true;
00139       if(qadcFed_==8) is04=false;
00140       qadcUnpacker_.unpack(fed, *bcntd,is04);
00141     }
00142 
00143     if (spdFed_ >=0) {      
00144       // Step C: unpack all requested FEDs
00145       const FEDRawData& fed = rawraw->FEDData(spdFed_);
00146       spdUnpacker_.unpack(fed, *spd);
00147     }
00148 
00149     // Step D: Put outputs into event
00150     if (doTriggerData_) e.put(trigd);
00151     if (doRunData_) e.put(rund);
00152     if (doEventPosition_) e.put(epd);
00153     if (doTiming_) e.put(tmgd);
00154     if (doBeamADC_) e.put(bcntd);
00155     if (doSourcePos_) e.put(spd);
00156   }
00157 
00158 
00159 void HcalTBObjectUnpacker::parseCalib(){
00160   
00161   if(calibFile_.size()==0){
00162     printf("HcalTBObjectUnpacker cowardly refuses to parse a NULL file...\n"); 
00163     return;
00164   }
00165  
00166   ifstream infile(calibFile_.c_str());
00167 
00168   char buffer [1024];
00169   string tmpStr;
00170   
00171   while (infile.getline(buffer, 1024)) {
00172     if (buffer [0] == '#') continue; //ignore comment
00173     if (buffer [0] == '/' && buffer [1] == '/') continue; //ignore comment
00174     tmpStr = string(buffer);
00175     vector<string> lineVect;
00176     
00177     int start = 0; bool empty = true;
00178     for (unsigned i=0; i<=tmpStr.size(); i++) {
00179       if (tmpStr[i] == ' ' || i==tmpStr.size()) {
00180         if (!empty) {
00181           std::string item(tmpStr, start, i-start);
00182           lineVect.push_back(item);
00183           empty = true;
00184 //        printf("Got: %s\n",item.c_str());
00185         }
00186         start = i+1;
00187       }
00188       else {
00189         if (empty) empty = false;       
00190       }
00191     }  
00192     
00193     if(lineVect.size()>0) calibLines_.push_back(lineVect);    
00194   }
00195 
00196   infile.close();
00197   return;
00198 }