CMS 3D CMS Logo

SiStripBadStripFromASCIIFile.cc

Go to the documentation of this file.
00001 // system include files
00002 #include <memory>
00003 #include <cstdio>
00004 #include <string>
00005 
00006 
00007 // user include files
00008 
00009 
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 
00012 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" 
00013 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00014 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00015 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00016 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00017 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00018 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetType.h"
00019 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00020 
00021 
00022 #include "CLHEP/Random/RandFlat.h"
00023 #include "CLHEP/Random/RandGauss.h"
00024 
00025 
00026 
00027 #include "CalibTracker/SiStripQuality/plugins/SiStripBadStripFromASCIIFile.h"
00028 
00029 
00030 
00031 using namespace std;
00032 
00033 SiStripBadStripFromASCIIFile::SiStripBadStripFromASCIIFile( const edm::ParameterSet& iConfig ):
00034   ConditionDBWriter<SiStripBadStrip>( iConfig),
00035   printdebug_(iConfig.getUntrackedParameter<bool>("printDebug",false))
00036 {
00037   fp_ = iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripQuality/data/DefectsFromConstructionDB.dat"));
00038  }
00039 
00040 
00041 SiStripBadStrip *SiStripBadStripFromASCIIFile::getNewObject() {
00042 
00043   SiStripBadStrip* SiStripBadStrip_ = new SiStripBadStrip();
00044 
00045    // open file and fill DB
00046   ifstream infile((fp_.fullPath()).c_str());
00047   if(!infile){std::cout << "Problem while trying to open File: " << (fp_.fullPath()).c_str() << std::endl;}
00048   
00049 
00050   //variables needed for reading file and filling of SiStripBadStripObject
00051   uint32_t detid;
00052   short flag;
00053   short channel;
00054  
00055   bool firstrun=true;
00056   short tempchannel=0;
00057   int count =0;
00058   std::vector<unsigned int> theSiStripVector;
00059   uint32_t tempflag=0;
00060   uint32_t tempdetid=0;
00061 
00062 
00063    while(!infile.eof()){
00064 
00065     // get data from file: 
00066     infile >> detid >> channel >> flag;
00067 
00068     unsigned int theBadStripRange=0;
00069 
00070     // first loop ?
00071     if(firstrun) {
00072       tempdetid=detid;
00073       tempchannel=channel;
00074       tempflag=flag;
00075       count =0;
00076       firstrun=false;
00077     }
00078 
00079 
00080     if(detid==tempdetid){
00081       if (channel!=tempchannel+count || flag != tempflag){
00082                                           // 1.badstrip, nconsectrips, flag
00083           theBadStripRange = SiStripBadStrip_->encode(tempchannel, count, tempflag); 
00084                 
00085           edm::LogInfo("SiStripBadStripFromASCIIFile")<< "detid " << tempdetid << " \t"
00086                                                            << " firstBadStrip " << tempchannel << "\t "
00087                                                            << " NconsecutiveBadStrips " << count  << "\t "
00088                                                            <<"flag " << tempflag << "\t"
00089                                                            << " packed integer " << std::hex << theBadStripRange  << std::dec
00090                                                            << std::endl;            
00091 
00092           theSiStripVector.push_back(theBadStripRange);
00093           count=1;
00094           tempchannel=channel;
00095           tempflag=flag;
00096                 
00097       }else{count++;}
00098     }
00099     
00100     if(detid!=tempdetid){
00101                                                     // 1.badstrip, nconsectrips, flag
00102           theBadStripRange = SiStripBadStrip_->encode(tempchannel, count, tempflag); 
00103           edm::LogInfo("SiStripBadStripFromASCIIFile")<< "detid " << tempdetid << " \t"
00104                                                            << " firstBadStrip " << tempchannel << "\t "
00105                                                            << " NconsecutiveBadStrips " << count  << "\t "
00106                                                            <<"flag " << tempflag << "\t"
00107                                                            << " packed integer " << std::hex << theBadStripRange  << std::dec
00108                                                            << std::endl;            
00109           
00110           theSiStripVector.push_back(theBadStripRange);
00111           
00112           // populate db  object
00113           SiStripBadStrip::Range range(theSiStripVector.begin(),theSiStripVector.end());
00114     if ( ! SiStripBadStrip_->put(tempdetid,range) )
00115       edm::LogError("SiStripBadStripFromASCIIFile")<<"[SiStripBadStripFromASCIIFile::GetNewObject] detid already exists"<<std::endl;
00116     theSiStripVector.clear();
00117     
00118     count=1;
00119     tempdetid=detid;
00120     tempchannel=channel;
00121     tempflag=flag;
00122     }
00123    }
00124  
00125   return SiStripBadStrip_;
00126 }

Generated on Tue Jun 9 17:25:51 2009 for CMSSW by  doxygen 1.5.4