CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/SimCalorimetry/EcalTrigPrimProducers/plugins/EcalTrigPrimESProducer.cc

Go to the documentation of this file.
00001 // user include files
00002 #include "EcalTrigPrimESProducer.h"
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <TMath.h>
00007 #include <sstream>
00008 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 //
00012 // input stream from a gz file
00013 //
00014 
00015 struct GzInputStream
00016  {
00017   typedef voidp gzFile ;
00018   gzFile gzf ;
00019   char buffer[256] ;
00020   std::istringstream iss ;
00021   bool eof ;
00022   GzInputStream( const char * file )
00023    : eof(false)
00024    {
00025     gzf = gzopen(file,"rb") ;
00026     if (gzf==Z_NULL)
00027      {
00028       eof = true ;
00029       edm::LogWarning("EcalTPG") <<"Database file "<<file<<" not found!!!";
00030      }
00031     else readLine() ;
00032    }
00033   void readLine()
00034    {
00035     char * res = gzgets(gzf,buffer,256) ;
00036     eof = (res==Z_NULL) ;
00037     if (!eof)
00038      {
00039       iss.clear() ;
00040       iss.str(buffer) ;
00041      }
00042    }
00043   ~GzInputStream()
00044    { gzclose(gzf) ; }
00045   operator void*()
00046    { return ((eof==true)?((void*)0):iss) ; }
00047  } ;
00048 
00049 template <typename T>
00050 GzInputStream & operator>>( GzInputStream & gis, T & var )
00051  {
00052   while ((gis)&&(!(gis.iss>>var)))
00053    { gis.readLine() ; }
00054   return gis ;
00055  }
00056 
00057 
00058 //
00059 // constructors and destructor
00060 //
00061 
00062 EcalTrigPrimESProducer::EcalTrigPrimESProducer(const edm::ParameterSet& iConfig) :
00063   dbFilename_(iConfig.getUntrackedParameter<std::string>("DatabaseFile","")),
00064   flagPrint_(iConfig.getParameter<bool>("WriteInFile"))
00065 {
00066   //the following line is needed to tell the framework what
00067   // data is being produced
00068   setWhatProduced(this, &EcalTrigPrimESProducer::producePedestals) ;
00069   setWhatProduced(this, &EcalTrigPrimESProducer::produceLinearizationConst) ;
00070   setWhatProduced(this, &EcalTrigPrimESProducer::produceSlidingWindow) ;
00071   setWhatProduced(this, &EcalTrigPrimESProducer::produceFineGrainEB) ;
00072   setWhatProduced(this, &EcalTrigPrimESProducer::produceFineGrainEEstrip) ;
00073   setWhatProduced(this, &EcalTrigPrimESProducer::produceFineGrainEEtower) ;
00074   setWhatProduced(this, &EcalTrigPrimESProducer::produceLUT) ;
00075   setWhatProduced(this, &EcalTrigPrimESProducer::produceWeight) ;
00076   setWhatProduced(this, &EcalTrigPrimESProducer::produceWeightGroup) ;
00077   setWhatProduced(this, &EcalTrigPrimESProducer::produceLutGroup) ;
00078   setWhatProduced(this, &EcalTrigPrimESProducer::produceFineGrainEBGroup) ;
00079   setWhatProduced(this, &EcalTrigPrimESProducer::producePhysicsConst) ;
00080   setWhatProduced(this, &EcalTrigPrimESProducer::produceBadX) ;
00081   setWhatProduced(this, &EcalTrigPrimESProducer::produceBadStrip) ;
00082   setWhatProduced(this, &EcalTrigPrimESProducer::produceBadTT) ;
00083   setWhatProduced(this, &EcalTrigPrimESProducer::produceSpike) ;
00084   //now do what ever other initialization is needed
00085 }
00086 
00087 
00088 EcalTrigPrimESProducer::~EcalTrigPrimESProducer()
00089 { 
00090 }
00091 
00092 //
00093 // member functions
00094 //
00095 
00096 // ------------ method called to produce the data  ------------
00097 
00098 
00099 std::auto_ptr<EcalTPGPedestals> EcalTrigPrimESProducer::producePedestals(const EcalTPGPedestalsRcd & iRecord)
00100 {
00101   std::auto_ptr<EcalTPGPedestals> prod(new EcalTPGPedestals());
00102   parseTextFile() ;
00103   std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00104   for (it = mapXtal_.begin() ; it != mapXtal_.end() ; it++) {
00105     EcalTPGPedestal item ;
00106     item.mean_x12 = (it->second)[0] ;
00107     item.mean_x6  = (it->second)[3] ;
00108     item.mean_x1  = (it->second)[6] ;
00109     prod->setValue(it->first,item) ;
00110   }
00111   return prod;
00112 }
00113 
00114 std::auto_ptr<EcalTPGLinearizationConst> EcalTrigPrimESProducer::produceLinearizationConst(const EcalTPGLinearizationConstRcd & iRecord)
00115 {
00116   std::auto_ptr<EcalTPGLinearizationConst> prod(new EcalTPGLinearizationConst());
00117   parseTextFile() ;
00118   std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00119   for (it = mapXtal_.begin() ; it != mapXtal_.end() ; it++) {
00120     EcalTPGLinearizationConstant item ;
00121     item.mult_x12 = (it->second)[1] ;
00122     item.mult_x6  = (it->second)[4] ;
00123     item.mult_x1  = (it->second)[7] ;
00124     item.shift_x12 = (it->second)[2] ;
00125     item.shift_x6  = (it->second)[5] ;
00126     item.shift_x1  = (it->second)[8] ;
00127     prod->setValue(it->first,item) ;
00128   }
00129   return prod;
00130 }
00131 
00132 std::auto_ptr<EcalTPGSlidingWindow> EcalTrigPrimESProducer::produceSlidingWindow(const EcalTPGSlidingWindowRcd & iRecord)
00133 {
00134   std::auto_ptr<EcalTPGSlidingWindow> prod(new EcalTPGSlidingWindow());
00135   parseTextFile() ;
00136   for (int subdet=0 ; subdet<2 ; subdet++) {
00137     std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00138     for (it = mapStrip_[subdet].begin() ; it != mapStrip_[subdet].end() ; it++) {
00139       prod->setValue(it->first,(it->second)[0]) ;
00140     }
00141   }
00142   return prod;
00143 }
00144 
00145 std::auto_ptr<EcalTPGFineGrainEBIdMap> EcalTrigPrimESProducer::produceFineGrainEB(const EcalTPGFineGrainEBIdMapRcd & iRecord)
00146 {
00147   std::auto_ptr<EcalTPGFineGrainEBIdMap> prod(new EcalTPGFineGrainEBIdMap());
00148   parseTextFile() ;
00149   EcalTPGFineGrainConstEB fg ;
00150   std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00151   for (it = mapFg_.begin() ; it != mapFg_.end() ; it++) {
00152     fg.setValues((it->second)[0], (it->second)[1], (it->second)[2], (it->second)[3], (it->second)[4]) ;
00153     prod->setValue(it->first,fg) ;
00154   }
00155   return prod;
00156 }
00157 
00158 std::auto_ptr<EcalTPGFineGrainStripEE> EcalTrigPrimESProducer::produceFineGrainEEstrip(const EcalTPGFineGrainStripEERcd & iRecord)
00159 {
00160   std::auto_ptr<EcalTPGFineGrainStripEE> prod(new EcalTPGFineGrainStripEE());
00161   parseTextFile() ;
00162   // EE Strips
00163   std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00164   for (it = mapStrip_[1].begin() ; it != mapStrip_[1].end() ; it++) {
00165     EcalTPGFineGrainStripEE::Item item ;
00166     item.threshold = (it->second)[2] ;
00167     item.lut  = (it->second)[3] ;
00168     prod->setValue(it->first,item) ;
00169   }
00170   // EB Strips
00171   for (it = mapStrip_[0].begin() ; it != mapStrip_[0].end() ; it++) {
00172     EcalTPGFineGrainStripEE::Item item ;
00173     item.threshold = (it->second)[2] ;
00174     item.lut  = (it->second)[3] ;
00175     prod->setValue(it->first,item) ;
00176   }
00177   return prod;
00178 }
00179 
00180 std::auto_ptr<EcalTPGFineGrainTowerEE> EcalTrigPrimESProducer::produceFineGrainEEtower(const EcalTPGFineGrainTowerEERcd & iRecord)
00181 {
00182   std::auto_ptr<EcalTPGFineGrainTowerEE> prod(new EcalTPGFineGrainTowerEE());
00183   parseTextFile() ;
00184   std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00185   for (it = mapTower_[1].begin() ; it != mapTower_[1].end() ; it++) {
00186     prod->setValue(it->first,(it->second)[1]) ;
00187   }
00188   return prod;
00189 }
00190 
00191 std::auto_ptr<EcalTPGLutIdMap> EcalTrigPrimESProducer::produceLUT(const EcalTPGLutIdMapRcd & iRecord)
00192 {
00193   std::auto_ptr<EcalTPGLutIdMap> prod(new EcalTPGLutIdMap());
00194   parseTextFile() ;
00195   EcalTPGLut lut ;
00196   std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00197   for (it = mapLut_.begin() ; it != mapLut_.end() ; it++) {
00198     unsigned int lutArray[1024] ;
00199     for (int i=0 ; i <1024 ; i++) lutArray[i] = (it->second)[i] ;
00200     lut.setLut(lutArray) ;
00201     prod->setValue(it->first,lut) ;
00202   }
00203   return prod;
00204 }
00205 
00206 std::auto_ptr<EcalTPGWeightIdMap> EcalTrigPrimESProducer::produceWeight(const EcalTPGWeightIdMapRcd & iRecord)
00207 {
00208   std::auto_ptr<EcalTPGWeightIdMap> prod(new EcalTPGWeightIdMap());
00209   parseTextFile() ;
00210   EcalTPGWeights weights ;
00211   std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00212   for (it = mapWeight_.begin() ; it != mapWeight_.end() ; it++) {
00213     weights.setValues((it->second)[0], 
00214                       (it->second)[1],
00215                       (it->second)[2], 
00216                       (it->second)[3],
00217                       (it->second)[4]) ;
00218     prod->setValue(it->first,weights) ;
00219   }
00220   return prod;
00221 }
00222 
00223 std::auto_ptr<EcalTPGWeightGroup> EcalTrigPrimESProducer::produceWeightGroup(const EcalTPGWeightGroupRcd & iRecord)
00224 {
00225   std::auto_ptr<EcalTPGWeightGroup> prod(new EcalTPGWeightGroup());
00226   parseTextFile() ;
00227   for (int subdet=0 ; subdet<2 ; subdet++) {
00228     std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00229     for (it = mapStrip_[subdet].begin() ; it != mapStrip_[subdet].end() ; it++) {
00230       prod->setValue(it->first,(it->second)[1]) ;
00231     }
00232   }
00233   return prod;
00234 }
00235 
00236 std::auto_ptr<EcalTPGLutGroup> EcalTrigPrimESProducer::produceLutGroup(const EcalTPGLutGroupRcd & iRecord)
00237 {
00238   std::auto_ptr<EcalTPGLutGroup> prod(new EcalTPGLutGroup());
00239   parseTextFile() ;
00240   for (int subdet=0 ; subdet<2 ; subdet++) {
00241     std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00242     for (it = mapTower_[subdet].begin() ; it != mapTower_[subdet].end() ; it++) {
00243       prod->setValue(it->first,(it->second)[0]) ;
00244     }
00245   }
00246   return prod;
00247 }
00248 
00249 std::auto_ptr<EcalTPGFineGrainEBGroup> EcalTrigPrimESProducer::produceFineGrainEBGroup(const EcalTPGFineGrainEBGroupRcd & iRecord)
00250 {
00251   std::auto_ptr<EcalTPGFineGrainEBGroup> prod(new EcalTPGFineGrainEBGroup());
00252   parseTextFile() ;
00253   std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00254   for (it = mapTower_[0].begin() ; it != mapTower_[0].end() ; it++) {
00255     prod->setValue(it->first,(it->second)[1]) ;
00256   }
00257   return prod;
00258 }
00259 
00260 std::auto_ptr<EcalTPGPhysicsConst> EcalTrigPrimESProducer::producePhysicsConst(const EcalTPGPhysicsConstRcd & iRecord)
00261 {
00262   std::auto_ptr<EcalTPGPhysicsConst> prod(new EcalTPGPhysicsConst());
00263   parseTextFile() ;
00264   std::map<uint32_t, std::vector<float> >::const_iterator it ;
00265   for (it = mapPhys_.begin() ; it != mapPhys_.end() ; it++) {
00266     EcalTPGPhysicsConst::Item item ;
00267     item.EtSat = (it->second)[0] ;
00268     item.ttf_threshold_Low = (it->second)[1] ;
00269     item.ttf_threshold_High = (it->second)[2] ;
00270     item.FG_lowThreshold = (it->second)[3] ;
00271     item.FG_highThreshold = (it->second)[4] ;
00272     item.FG_lowRatio = (it->second)[5] ;
00273     item.FG_highRatio = (it->second)[6] ;
00274     prod->setValue(it->first,item) ;
00275   }
00276   return prod;
00277 }
00278 
00279 std::auto_ptr<EcalTPGCrystalStatus> EcalTrigPrimESProducer::produceBadX(const EcalTPGCrystalStatusRcd & iRecord)
00280 {
00281   std::auto_ptr<EcalTPGCrystalStatus> prod(new EcalTPGCrystalStatus());
00282   parseTextFile() ;
00283   std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00284   for (it = mapXtal_.begin() ; it != mapXtal_.end() ; it++) {
00285     
00286     EcalTPGCrystalStatusCode badXValue;
00287     badXValue.setStatusCode(0);
00288     prod->setValue(it->first,badXValue) ;
00289   }
00290   return prod;
00291   
00292 }
00293 
00294 std::auto_ptr<EcalTPGStripStatus> EcalTrigPrimESProducer::produceBadStrip(const EcalTPGStripStatusRcd & iRecord)
00295 {
00296   std::auto_ptr<EcalTPGStripStatus> prod(new EcalTPGStripStatus());
00297   // returns an empty map     
00298   return prod;
00299   
00300 }
00301 
00302 std::auto_ptr<EcalTPGTowerStatus> EcalTrigPrimESProducer::produceBadTT(const EcalTPGTowerStatusRcd & iRecord)
00303 {
00304   std::auto_ptr<EcalTPGTowerStatus> prod(new EcalTPGTowerStatus());
00305   parseTextFile() ;
00306   std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
00307   //Barrel
00308   for (it = mapTower_[0].begin() ; it != mapTower_[0].end() ; it++) {
00309     //set the BadTT status to 0
00310     prod->setValue(it->first,0) ;
00311   }
00312   //Endcap
00313   for (it = mapTower_[1].begin() ; it != mapTower_[1].end() ; it++) {
00314     //set the BadTT status to 0
00315     prod->setValue(it->first,0) ;
00316   }
00317   
00318   return prod; 
00319 }
00320 
00321 std::auto_ptr<EcalTPGSpike> EcalTrigPrimESProducer::produceSpike(const EcalTPGSpikeRcd &iRecord)
00322 {
00323   std::auto_ptr<EcalTPGSpike> prod(new EcalTPGSpike());
00324   parseTextFile();
00325   // Only need to do barrel
00326   std::map<uint32_t, std::vector<uint32_t> >::const_iterator it;
00327   for(it = mapTower_[0].begin(); it != mapTower_[0].end(); ++it)
00328   {
00329     prod->setValue(it->first, (it->second)[2]);
00330   }
00331   return prod;
00332 }
00333 
00334 void EcalTrigPrimESProducer::parseTextFile()
00335 {
00336   if (mapXtal_.size() != 0) return ; // just parse the file once!
00337 
00338   uint32_t id ;
00339   std::string dataCard ;
00340   std::string line;
00341   std::ifstream infile ; 
00342   std::vector<unsigned int> param ;
00343   std::vector<float> paramF ;
00344   int NBstripparams[2] = {4, 4} ;
00345   unsigned int data ;
00346   float dataF ;
00347 
00348   std::string bufString;
00349   std::string iString;
00350   std::string fString;
00351   std::string filename = "SimCalorimetry/EcalTrigPrimProducers/data/"+dbFilename_;
00352   std::string finalFileName ;
00353   size_t slash=dbFilename_.find("/");
00354   if (slash!=0) {
00355     edm::FileInPath fileInPath(filename);
00356     finalFileName = fileInPath.fullPath() ;
00357   }
00358   else {
00359     finalFileName = dbFilename_.c_str() ;
00360     edm::LogWarning("EcalTPG") <<"Couldnt find database file via fileinpath, trying with pathname directly!!";
00361   }
00362 
00363 
00364   int k=0;
00365 
00366   GzInputStream gis(finalFileName.c_str()) ;
00367   while (gis>>dataCard) {
00368 
00369     if (dataCard == "PHYSICS_EB" || dataCard == "PHYSICS_EE") {
00370       gis>>std::dec>>id ;
00371       
00372       if (flagPrint_){
00373         std::cout<<dataCard<<" "<<std::dec<<id <<std::endl;
00374       }
00375       
00376       paramF.clear() ;
00377       
00378       std::string st1;
00379       std::string st2;
00380       
00381       for (int i=0 ; i <7 ; i++) {
00382         gis>>std::dec>>dataF ;
00383         paramF.push_back(dataF) ;
00384         
00385         //std::cout<<", "<<std::dec<<dataF ;
00386         if (flagPrint_){
00387         //---------------------------------
00388           if (i < 3){
00389             std::ostringstream oss;
00390             oss << dataF; 
00391             std::string result1 = oss.str();
00392 
00393             st1.append(result1);
00394             if (i != 2)
00395               st1.append(" ");
00396           }
00397 
00398           if (i > 2){
00399             std::ostringstream oss;
00400             oss << dataF; 
00401             std::string result2 = oss.str();
00402  
00403             st2.append(result2);
00404             if (i != 6)  
00405               st2.append(" ");
00406           }
00407         //----------------------------------     
00408         }
00409       }
00410       
00411       if (flagPrint_){
00412         std::cout << "" << st1 << std::endl;
00413         std::cout << "" << st2 << std::endl;
00414         std::cout << ""<< std::endl;  
00415       }
00416       
00417       //std::cout<<std::endl ;
00418       mapPhys_[id] = paramF ;
00419     }
00420 
00421     if (dataCard == "CRYSTAL") {
00422       
00423       gis>>std::dec>>id ;
00424       //std::cout<<dataCard<<" "<<std::dec<<id;
00425       std::string st3;
00426       std::string st4;
00427       std::string st5;      
00428       
00429       if(flagPrint_){
00430       //Print this comment only one time 
00431         if(k==0)
00432           std::cout << "COMMENT ====== barrel crystals ====== " <<std::endl;
00433       
00434         if (k==61200)
00435           std::cout << "COMMENT ====== endcap crystals ====== " <<std::endl;
00436         
00437         k=k+1;
00438 
00439         std::cout<<dataCard<<" "<<std::dec<<id << std::endl;
00440       }
00441       
00442       param.clear() ;
00443       for (int i=0 ; i <9 ; i++) {
00444         gis>>std::hex>>data ;
00445         //std::cout<<", "<<std::hex<<data ;
00446         param.push_back(data);
00447         
00448         if(flagPrint_){
00449           if (i<3){
00450             std::ostringstream oss;
00451             oss << std::hex<< data; 
00452             std::string result1 = oss.str();
00453            
00454             st3.append("0x"); 
00455             st3.append(result1);
00456             if (i !=2)
00457               st3.append(" ");
00458         
00459           }else if(i>2 && i<6){
00460             std::ostringstream oss;
00461             oss << std::hex << data; 
00462             std::string result2 = oss.str();
00463           
00464             st4.append("0x");
00465             st4.append(result2);
00466             if (i != 5) 
00467               st4.append(" ");
00468           }else if(i>5 && i<9){
00469             std::ostringstream oss;
00470             oss << std::hex<< data; 
00471             std::string result3 = oss.str();
00472           
00473             st5.append("0x");
00474             st5.append(result3);
00475             if (i != 8)
00476               st5.append(" ");
00477           }
00478         }
00479         
00480       }//end for
00481       
00482       if(flagPrint_){
00483         std::cout << " " << st3 << std::endl;
00484         std::cout << " " << st4 << std::endl;
00485         std::cout << " " << st5 << std::endl;
00486       }
00487       
00488       //std::cout<<std::endl ;
00489       mapXtal_[id] = param ;
00490     }
00491 
00492     if (dataCard == "STRIP_EB") {
00493       gis>>std::dec>>id ;
00494       
00495       std::string st1;
00496       
00497       if(flagPrint_)
00498         std::cout<<dataCard<<" "<<std::dec<<id <<std::endl;
00499        
00500       param.clear() ;
00501       for (int i=0 ; i <NBstripparams[0] ; i++) {
00502         gis>>std::hex>>data ;
00503         //std::cout << " data = " << data << std::endl;
00504         param.push_back(data);
00505         
00506         if(flagPrint_){
00507           if (i==0){
00508            std::cout<<"0x"<<std::hex<< data << std::endl;
00509           }
00510           else if (i==1){
00511             std::cout<<""<<std::hex<< data << std::endl;
00512           }
00513           else if (i>1){
00514             std::ostringstream oss;
00515             if (i==2){
00516               oss<<"0x"<<std::hex<<data;
00517               std::string result4 = oss.str();
00518               st1.append(result4);
00519             }else if(i==3){
00520               std::ostringstream oss;
00521               oss<<" 0x"<<std::hex<<data;
00522               std::string result5 = oss.str();
00523           
00524               st1.append(result5);
00525               std::cout<< "" << st1 << std::endl;
00526            }
00527           }
00528         }
00529       }
00530       
00531       //std::cout<<std::endl ;
00532       mapStrip_[0][id] = param ;
00533     }
00534 
00535     if (dataCard == "STRIP_EE") {
00536       gis>>std::dec>>id ;
00537       
00538       std::string st6;
00539       
00540       if(flagPrint_){
00541         std::cout<<dataCard<<" "<<std::dec<<id << std::endl;
00542       }
00543       
00544       param.clear() ;
00545       for (int i=0 ; i <NBstripparams[1] ; i++) {
00546         gis>>std::hex>>data ;
00547         param.push_back(data);
00548         
00549         if(flagPrint_){
00550           if (i==0){
00551             std::cout<<"0x"<<std::hex<<data << std::endl;
00552           }else if (i==1){
00553             std::cout<<" "<<std::hex<<data<< std::endl;
00554           }else if (i>1){
00555             std::ostringstream oss;
00556             if (i==2){
00557               oss<<"0x"<<std::hex<<data;
00558               std::string result4 = oss.str();
00559               st6.append(result4);
00560             }else if(i==3){
00561               std::ostringstream oss;
00562               oss<<" 0x"<<std::hex<<data;
00563               std::string result5 = oss.str();
00564           
00565               st6.append(result5);
00566               std::cout<< "" << st6 << std::endl;
00567            }
00568           }
00569         }
00570       }
00571       
00572       //std::cout<<std::endl ;
00573       mapStrip_[1][id] = param ;
00574     }
00575     
00576     if(dataCard == "TOWER_EE"){
00577       gis>>std::dec>>id ;
00578       
00579       if(flagPrint_)
00580         std::cout<<dataCard<<" "<<std::dec<<id <<std::endl;
00581 
00582       param.clear() ;
00583       for (int i=0 ; i <2 ; i++) {
00584         gis>>std::hex>>data ;
00585         param.push_back(data);
00586       
00587         if(flagPrint_){
00588           if(i==1){
00589             std::cout << "0x" <<std::dec<<data << std::endl;
00590           }else{
00591             std::cout << " " <<std::dec<<data << std::endl;
00592           }
00593         }
00594       }
00595       
00596       //std::cout<<std::endl ;
00597       mapTower_[1][id] = param ;
00598     }
00599 
00600     if (dataCard == "TOWER_EB") {
00601       gis>>std::dec>>id ;
00602       
00603       if(flagPrint_)
00604         std::cout<<dataCard<<" "<<std::dec<<id << std::endl;
00605 
00606       param.clear() ;
00607       for (int i=0 ; i <3 ; i++) {
00608         gis>>std::dec>>data ;
00609         
00610         if(flagPrint_){ 
00611           std::cout << " " << std::dec <<  data << std::endl;
00612         }
00613         
00614         param.push_back(data) ;
00615       }
00616       
00617       //std::cout<<std::endl ;
00618       mapTower_[0][id] = param ;
00619     }
00620 
00621     if (dataCard == "WEIGHT") {
00622           
00623       if(flagPrint_) 
00624         std::cout<<std::endl;
00625      
00626       gis>>std::hex>>id ;  
00627       if(flagPrint_){
00628         std::cout<<dataCard<<" "<<std::dec<<id <<std::endl;
00629       }
00630       
00631       param.clear() ;
00632      
00633       std::string st6;
00634       for (int i=0 ; i <5 ; i++) {
00635         gis>>std::hex>>data ;
00636         param.push_back(data);
00637         
00638         if(flagPrint_){
00639           std::ostringstream oss;
00640           oss << std::hex<< data; 
00641           std::string result4 = oss.str();
00642 
00643           st6.append("0x");
00644           st6.append(result4);
00645           st6.append(" ");
00646         }
00647         
00648       }
00649       
00650       if(flagPrint_){
00651         std::cout << st6 << std::endl;
00652         std::cout<<std::endl;
00653       }
00654        
00655       //std::cout<<std::endl ;
00656       mapWeight_[id] = param ;
00657     }
00658 
00659     if (dataCard == "FG") {
00660       
00661       if(flagPrint_)
00662         std::cout <<std::endl;
00663       
00664       gis>>std::hex>>id ;      
00665       if(flagPrint_)
00666         std::cout<<dataCard<<" "<<std::dec<<id <<std::endl;
00667 
00668       param.clear() ;
00669       std::string st7;
00670       for (int i=0 ; i <5 ; i++) {
00671         gis>>std::hex>>data ;
00672         param.push_back(data);
00673         
00674         if(flagPrint_){
00675           std::ostringstream oss;
00676           oss << std::hex<< data; 
00677         
00678           std::string result5 = oss.str();
00679 
00680           st7.append("0x");
00681           st7.append(result5);
00682           if (i != 4)
00683             st7.append(" ");
00684         }
00685       }
00686       
00687       if(flagPrint_){
00688         std::cout << st7 << std::endl;
00689         std::cout<<std::endl ;
00690       }
00691       
00692       mapFg_[id] = param ;
00693     }
00694  
00695     if (dataCard == "LUT") {
00696       gis>>std::hex>>id ;
00697       
00698       if(flagPrint_)
00699         std::cout<<dataCard<<" "<<std::dec<<id <<std::endl;
00700 
00701       param.clear() ;
00702       for (int i=0 ; i <1024 ; i++) {
00703         gis>>std::hex>>data ;
00704         param.push_back(data);
00705        
00706         if(flagPrint_){
00707           std::cout<<"0x"<<std::hex<<data <<std::endl;
00708         }
00709       }
00710       
00711       if(flagPrint_)
00712         std::cout<<std::endl ;
00713         std::cout<<std::endl ;
00714         
00715       mapLut_[id] = param ;
00716     }
00717   }
00718 }
00719 
00720 std::vector<int> EcalTrigPrimESProducer::getRange(int subdet, int tccNb, int towerNbInTcc, int stripNbInTower, int xtalNbInStrip)
00721 {
00722   std::vector<int> range ;
00723   if (subdet == 0) { 
00724     // Barrel
00725     range.push_back(37)  ; // stccNbMin
00726     range.push_back(73) ; // tccNbMax
00727     range.push_back(1)  ; // towerNbMin
00728     range.push_back(69) ; // towerNbMax
00729     range.push_back(1)  ; // stripNbMin
00730     range.push_back(6)  ; // stripNbMax
00731     range.push_back(1)  ; // xtalNbMin
00732     range.push_back(6)  ; // xtalNbMax
00733   } else {
00734     // Endcap eta >0
00735     if (subdet >0 ) {
00736       range.push_back(73) ; // tccNbMin
00737       range.push_back(109) ; // tccNbMax
00738     } else { //endcap eta <0
00739       range.push_back(1) ; // tccNbMin
00740       range.push_back(37) ; // tccNbMax
00741     }
00742     range.push_back(1)  ; // towerNbMin
00743     range.push_back(29) ; // towerNbMax
00744     range.push_back(1)  ; // stripNbMin
00745     range.push_back(6)  ; // stripNbMax
00746     range.push_back(1)  ; // xtalNbMin
00747     range.push_back(6)  ; // xtalNbMax
00748   }
00749 
00750   if (tccNb>0) {
00751     range[0] = tccNb ; 
00752     range[1] = tccNb+1 ;
00753   }
00754   if (towerNbInTcc>0) {
00755     range[2] = towerNbInTcc ; 
00756     range[3] = towerNbInTcc+1 ;
00757   }
00758   if (stripNbInTower>0) {
00759     range[4] = stripNbInTower ; 
00760     range[5] = stripNbInTower+1 ;
00761   }
00762   if (xtalNbInStrip>0) {
00763     range[6] = xtalNbInStrip ; 
00764     range[7] = xtalNbInStrip+1 ;
00765   }
00766 
00767   return range ;
00768 }
00769 
00770 // bool EcalTrigPrimESProducer::getNextString(gzFile &gzf){
00771 //   size_t blank;
00772 //   if (bufpos_==0) {
00773 //     gzgets(gzf,buf_,80);
00774 //     if (gzeof(gzf)) return true;
00775 //     bufString_=std::string(buf_);
00776 //   }
00777 //   int  pos=0;
00778 //   pos =bufpos_;
00779 //   // look for next non-blank
00780 //   while (pos<bufString_.size()) {
00781 //     if (!bufString_.compare(pos,1," ")) pos++;
00782 //     else break;
00783 //   }
00784 //   blank=bufString_.find(" ",pos);
00785 //   size_t end = blank;
00786 //   if (blank==std::string::npos) end=bufString_.size();
00787 //   sub_=bufString_.substr(pos,end-pos);
00788 //   bufpos_= blank;
00789 //   if (blank==std::string::npos) bufpos_=0;
00790 //   return false;
00791 // }
00792 //  
00793 // int EcalTrigPrimESProducer::converthex() {
00794 //   // converts hex dec string sub to hexa
00795 //   //FIXME:: find something better (istrstream?)!!!!
00796 // 
00797 //   std::string chars("0123456789abcdef");
00798 //   int hex=0;
00799 //   for (size_t i=2;i<sub_.length();++i) {
00800 //     size_t f=chars.find(sub_[i]);
00801 //     if (f==std::string::npos) break;  //FIXME: length is 4 for 0x3!!
00802 //     hex=hex*16+chars.find(sub_[i]);
00803 //   }
00804 //   return hex;
00805 // }