CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CalibTracker/SiStripQuality/plugins/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   short 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     //if no flag is available, use the following:
00069     infile >> detid >> channel;
00070     flag = 1;
00071 
00072     unsigned int theBadStripRange=0;
00073 
00074     // first loop ?
00075     if(firstrun) {
00076       tempdetid=detid;
00077       tempchannel=channel;
00078       tempflag=flag;
00079       count =0;
00080       firstrun=false;
00081     }
00082 
00083 
00084     if(detid==tempdetid){
00085       if (channel!=tempchannel+count || flag != tempflag){
00086                                           // 1.badstrip, nconsectrips, flag
00087         theBadStripRange = SiStripBadStrip_->encode(tempchannel-1, count, tempflag); // In the quality object, strips are counted from 0 to 767!!! Therefore "tempchannel-1"!
00088                                                                                      // In the input txt-file, they have to be from 1 to 768 instead!!!
00089           edm::LogInfo("SiStripBadStripFromASCIIFile")<< "detid " << tempdetid << " \t"
00090                                                            << " firstBadStrip " << tempchannel << "\t "
00091                                                            << " NconsecutiveBadStrips " << count  << "\t "
00092                                                            <<"flag " << tempflag << "\t"
00093                                                            << " packed integer " << std::hex << theBadStripRange  << std::dec
00094                                                            << std::endl;            
00095 
00096           theSiStripVector.push_back(theBadStripRange);
00097 
00098           if (infile.eof()){ // Don't forget to save the last strip before eof!!!
00099             SiStripBadStrip::Range range(theSiStripVector.begin(),theSiStripVector.end());
00100             if ( ! SiStripBadStrip_->put(tempdetid,range) )
00101               edm::LogError("SiStripBadStripFromASCIIFile")<<"[SiStripBadStripFromASCIIFile::GetNewObject] detid already exists"<<std::endl;
00102             theSiStripVector.clear();
00103           }
00104 
00105           count=1;
00106           tempchannel=channel;
00107           tempflag=flag;
00108                 
00109       }else{count++;}
00110     }
00111     
00112     if(detid!=tempdetid){
00113                                                     // 1.badstrip, nconsectrips, flag
00114           theBadStripRange = SiStripBadStrip_->encode(tempchannel-1, count, tempflag); // In the quality object, strips are counted from 0 to 767!!! Therefore "tempchannel-1"!
00115                                                                                        // In the input txt-file, they have to be from 1 to 768 instead!!!
00116           edm::LogInfo("SiStripBadStripFromASCIIFile")<< "detid " << tempdetid << " \t"
00117                                                            << " firstBadStrip " << tempchannel << "\t "
00118                                                            << " NconsecutiveBadStrips " << count  << "\t "
00119                                                            <<"flag " << tempflag << "\t"
00120                                                            << " packed integer " << std::hex << theBadStripRange  << std::dec
00121                                                            << std::endl;            
00122           
00123           theSiStripVector.push_back(theBadStripRange);
00124           
00125           // populate db  object
00126           SiStripBadStrip::Range range(theSiStripVector.begin(),theSiStripVector.end());
00127     if ( ! SiStripBadStrip_->put(tempdetid,range) )
00128       edm::LogError("SiStripBadStripFromASCIIFile")<<"[SiStripBadStripFromASCIIFile::GetNewObject] detid already exists"<<std::endl;
00129     theSiStripVector.clear();
00130     
00131     count=1;
00132     tempdetid=detid;
00133     tempchannel=channel;
00134     tempflag=flag;
00135     }
00136    }
00137  
00138   return SiStripBadStrip_;
00139 }