CMS 3D CMS Logo

CMSSW_4_4_3_patch1/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       if(flagPrint_)
00496         std::cout<<dataCard<<" "<<std::dec<<id <<std::endl;
00497 
00498       param.clear() ;
00499       for (int i=0 ; i <NBstripparams[0] ; i++) {
00500         gis>>std::hex>>data ;
00501         param.push_back(data);
00502         
00503         if(flagPrint_){
00504           if (i==0){
00505             std::cout<<"0x"<<std::hex<<data << std::endl;
00506           }else if (i==1){
00507             std::cout<<" "<<std::hex<<data << std::endl;
00508           }
00509         }
00510       }
00511       
00512       //std::cout<<std::endl ;
00513       mapStrip_[0][id] = param ;
00514     }
00515 
00516     if (dataCard == "STRIP_EE") {
00517       gis>>std::dec>>id ;
00518       
00519       std::string st6;
00520       
00521       if(flagPrint_){
00522         std::cout<<dataCard<<" "<<std::dec<<id << std::endl;
00523       }
00524       
00525       param.clear() ;
00526       for (int i=0 ; i <NBstripparams[1] ; i++) {
00527         gis>>std::hex>>data ;
00528         param.push_back(data);
00529         
00530         if(flagPrint_){
00531           if (i==0){
00532             std::cout<<"0x"<<std::hex<<data << std::endl;
00533           }else if (i==1){
00534             std::cout<<" "<<std::hex<<data<< std::endl;
00535           }else if (i>1){
00536             std::ostringstream oss;
00537             if (i==2){
00538               oss<<"0x"<<std::hex<<data;
00539               std::string result4 = oss.str();
00540               st6.append(result4);
00541             }else if(i==3){
00542               std::ostringstream oss;
00543               oss<<" 0x"<<std::hex<<data;
00544               std::string result5 = oss.str();
00545           
00546               st6.append(result5);
00547               std::cout<< "" << st6 << std::endl;
00548            }
00549           }
00550         }
00551       }
00552       
00553       //std::cout<<std::endl ;
00554       mapStrip_[1][id] = param ;
00555     }
00556     
00557     if(dataCard == "TOWER_EE"){
00558       gis>>std::dec>>id ;
00559       
00560       if(flagPrint_)
00561         std::cout<<dataCard<<" "<<std::dec<<id <<std::endl;
00562 
00563       param.clear() ;
00564       for (int i=0 ; i <2 ; i++) {
00565         gis>>std::hex>>data ;
00566         param.push_back(data);
00567       
00568         if(flagPrint_){
00569           if(i==1){
00570             std::cout << "0x" <<std::dec<<data << std::endl;
00571           }else{
00572             std::cout << " " <<std::dec<<data << std::endl;
00573           }
00574         }
00575       }
00576       
00577       //std::cout<<std::endl ;
00578       mapTower_[1][id] = param ;
00579     }
00580 
00581     if (dataCard == "TOWER_EB") {
00582       gis>>std::dec>>id ;
00583       
00584       if(flagPrint_)
00585         std::cout<<dataCard<<" "<<std::dec<<id << std::endl;
00586 
00587       param.clear() ;
00588       for (int i=0 ; i <3 ; i++) {
00589         gis>>std::dec>>data ;
00590         
00591         if(flagPrint_){ 
00592           std::cout << " " << std::hex <<  data << std::endl;
00593         }
00594         
00595         param.push_back(data) ;
00596       }
00597       
00598       //std::cout<<std::endl ;
00599       mapTower_[0][id] = param ;
00600     }
00601 
00602     if (dataCard == "WEIGHT") {
00603           
00604       if(flagPrint_) 
00605         std::cout<<std::endl;
00606      
00607       gis>>std::hex>>id ;  
00608       if(flagPrint_){
00609         std::cout<<dataCard<<" "<<std::dec<<id <<std::endl;
00610       }
00611       
00612       param.clear() ;
00613      
00614       std::string st6;
00615       for (int i=0 ; i <5 ; i++) {
00616         gis>>std::hex>>data ;
00617         param.push_back(data);
00618         
00619         if(flagPrint_){
00620           std::ostringstream oss;
00621           oss << std::hex<< data; 
00622           std::string result4 = oss.str();
00623 
00624           st6.append("0x");
00625           st6.append(result4);
00626           st6.append(" ");
00627         }
00628         
00629       }
00630       
00631       if(flagPrint_){
00632         std::cout << st6 << std::endl;
00633       }
00634        
00635       //std::cout<<std::endl ;
00636       mapWeight_[id] = param ;
00637     }
00638 
00639     if (dataCard == "FG") {
00640       
00641       if(flagPrint_)
00642         std::cout <<std::endl;
00643       
00644       gis>>std::hex>>id ;      
00645       if(flagPrint_)
00646         std::cout<<dataCard<<" "<<std::dec<<id <<std::endl;
00647 
00648       param.clear() ;
00649       std::string st7;
00650       for (int i=0 ; i <5 ; i++) {
00651         gis>>std::hex>>data ;
00652         param.push_back(data);
00653         
00654         if(flagPrint_){
00655           std::ostringstream oss;
00656           oss << std::hex<< data; 
00657         
00658           std::string result5 = oss.str();
00659 
00660           st7.append("0x");
00661           st7.append(result5);
00662           if (i != 4)
00663             st7.append(" ");
00664         }
00665       }
00666       
00667       if(flagPrint_){
00668         std::cout << st7 << std::endl;
00669         std::cout<<std::endl ;
00670       }
00671       
00672       mapFg_[id] = param ;
00673     }
00674  
00675     if (dataCard == "LUT") {
00676       gis>>std::hex>>id ;
00677       
00678       if(flagPrint_)
00679         std::cout<<dataCard<<" "<<std::dec<<id <<std::endl;
00680 
00681       param.clear() ;
00682       for (int i=0 ; i <1024 ; i++) {
00683         gis>>std::hex>>data ;
00684         param.push_back(data);
00685        
00686         if(flagPrint_){
00687           std::cout<<"0x"<<std::hex<<data <<std::endl;
00688         }
00689       }
00690       
00691       if(flagPrint_)
00692         std::cout<<std::endl ;
00693       
00694       mapLut_[id] = param ;
00695     }
00696   }
00697 }
00698 
00699 std::vector<int> EcalTrigPrimESProducer::getRange(int subdet, int tccNb, int towerNbInTcc, int stripNbInTower, int xtalNbInStrip)
00700 {
00701   std::vector<int> range ;
00702   if (subdet == 0) { 
00703     // Barrel
00704     range.push_back(37)  ; // stccNbMin
00705     range.push_back(73) ; // tccNbMax
00706     range.push_back(1)  ; // towerNbMin
00707     range.push_back(69) ; // towerNbMax
00708     range.push_back(1)  ; // stripNbMin
00709     range.push_back(6)  ; // stripNbMax
00710     range.push_back(1)  ; // xtalNbMin
00711     range.push_back(6)  ; // xtalNbMax
00712   } else {
00713     // Endcap eta >0
00714     if (subdet >0 ) {
00715       range.push_back(73) ; // tccNbMin
00716       range.push_back(109) ; // tccNbMax
00717     } else { //endcap eta <0
00718       range.push_back(1) ; // tccNbMin
00719       range.push_back(37) ; // tccNbMax
00720     }
00721     range.push_back(1)  ; // towerNbMin
00722     range.push_back(29) ; // towerNbMax
00723     range.push_back(1)  ; // stripNbMin
00724     range.push_back(6)  ; // stripNbMax
00725     range.push_back(1)  ; // xtalNbMin
00726     range.push_back(6)  ; // xtalNbMax
00727   }
00728 
00729   if (tccNb>0) {
00730     range[0] = tccNb ; 
00731     range[1] = tccNb+1 ;
00732   }
00733   if (towerNbInTcc>0) {
00734     range[2] = towerNbInTcc ; 
00735     range[3] = towerNbInTcc+1 ;
00736   }
00737   if (stripNbInTower>0) {
00738     range[4] = stripNbInTower ; 
00739     range[5] = stripNbInTower+1 ;
00740   }
00741   if (xtalNbInStrip>0) {
00742     range[6] = xtalNbInStrip ; 
00743     range[7] = xtalNbInStrip+1 ;
00744   }
00745 
00746   return range ;
00747 }
00748 
00749 // bool EcalTrigPrimESProducer::getNextString(gzFile &gzf){
00750 //   size_t blank;
00751 //   if (bufpos_==0) {
00752 //     gzgets(gzf,buf_,80);
00753 //     if (gzeof(gzf)) return true;
00754 //     bufString_=std::string(buf_);
00755 //   }
00756 //   int  pos=0;
00757 //   pos =bufpos_;
00758 //   // look for next non-blank
00759 //   while (pos<bufString_.size()) {
00760 //     if (!bufString_.compare(pos,1," ")) pos++;
00761 //     else break;
00762 //   }
00763 //   blank=bufString_.find(" ",pos);
00764 //   size_t end = blank;
00765 //   if (blank==std::string::npos) end=bufString_.size();
00766 //   sub_=bufString_.substr(pos,end-pos);
00767 //   bufpos_= blank;
00768 //   if (blank==std::string::npos) bufpos_=0;
00769 //   return false;
00770 // }
00771 //  
00772 // int EcalTrigPrimESProducer::converthex() {
00773 //   // converts hex dec string sub to hexa
00774 //   //FIXME:: find something better (istrstream?)!!!!
00775 // 
00776 //   std::string chars("0123456789abcdef");
00777 //   int hex=0;
00778 //   for (size_t i=2;i<sub_.length();++i) {
00779 //     size_t f=chars.find(sub_[i]);
00780 //     if (f==std::string::npos) break;  //FIXME: length is 4 for 0x3!!
00781 //     hex=hex*16+chars.find(sub_[i]);
00782 //   }
00783 //   return hex;
00784 // }