CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripBadStripFromASCIIFile.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <cstdio>
4 #include <string>
5 
6 
7 // user include files
8 
9 
11 
20 
21 
22 #include "CLHEP/Random/RandFlat.h"
23 #include "CLHEP/Random/RandGauss.h"
24 
25 
26 
28 
29 
30 
31 using namespace std;
32 
35  printdebug_(iConfig.getUntrackedParameter<bool>("printDebug",false))
36 {
37  fp_ = iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripQuality/data/DefectsFromConstructionDB.dat"));
38  }
39 
40 
42 
43  SiStripBadStrip* SiStripBadStrip_ = new SiStripBadStrip();
44 
45  // open file and fill DB
46  ifstream infile((fp_.fullPath()).c_str());
47  if(!infile){std::cout << "Problem while trying to open File: " << (fp_.fullPath()).c_str() << std::endl;}
48 
49 
50  //variables needed for reading file and filling of SiStripBadStripObject
51  uint32_t detid;
52  short flag;
53  short channel;
54 
55  bool firstrun=true;
56  short tempchannel=0;
57  int count =0;
58  std::vector<unsigned int> theSiStripVector;
59  short tempflag=0;
60  uint32_t tempdetid=0;
61 
62 
63  while(!infile.eof()){
64 
65  // get data from file:
66  //infile >> detid >> channel >> flag;
67 
68  //if no flag is available, use the following:
69  infile >> detid >> channel;
70  flag = 1;
71 
72  unsigned int theBadStripRange=0;
73 
74  // first loop ?
75  if(firstrun) {
76  tempdetid=detid;
77  tempchannel=channel;
78  tempflag=flag;
79  count =0;
80  firstrun=false;
81  }
82 
83 
84  if(detid==tempdetid){
85  if (channel!=tempchannel+count || flag != tempflag){
86  // 1.badstrip, nconsectrips, flag
87  theBadStripRange = SiStripBadStrip_->encode(tempchannel-1, count, tempflag); // In the quality object, strips are counted from 0 to 767!!! Therefore "tempchannel-1"!
88  // In the input txt-file, they have to be from 1 to 768 instead!!!
89  edm::LogInfo("SiStripBadStripFromASCIIFile")<< "detid " << tempdetid << " \t"
90  << " firstBadStrip " << tempchannel << "\t "
91  << " NconsecutiveBadStrips " << count << "\t "
92  <<"flag " << tempflag << "\t"
93  << " packed integer " << std::hex << theBadStripRange << std::dec
94  << std::endl;
95 
96  theSiStripVector.push_back(theBadStripRange);
97 
98  if (infile.eof()){ // Don't forget to save the last strip before eof!!!
99  SiStripBadStrip::Range range(theSiStripVector.begin(),theSiStripVector.end());
100  if ( ! SiStripBadStrip_->put(tempdetid,range) )
101  edm::LogError("SiStripBadStripFromASCIIFile")<<"[SiStripBadStripFromASCIIFile::GetNewObject] detid already exists"<<std::endl;
102  theSiStripVector.clear();
103  }
104 
105  count=1;
106  tempchannel=channel;
107  tempflag=flag;
108 
109  }else{count++;}
110  }
111 
112  if(detid!=tempdetid){
113  // 1.badstrip, nconsectrips, flag
114  theBadStripRange = SiStripBadStrip_->encode(tempchannel-1, count, tempflag); // In the quality object, strips are counted from 0 to 767!!! Therefore "tempchannel-1"!
115  // In the input txt-file, they have to be from 1 to 768 instead!!!
116  edm::LogInfo("SiStripBadStripFromASCIIFile")<< "detid " << tempdetid << " \t"
117  << " firstBadStrip " << tempchannel << "\t "
118  << " NconsecutiveBadStrips " << count << "\t "
119  <<"flag " << tempflag << "\t"
120  << " packed integer " << std::hex << theBadStripRange << std::dec
121  << std::endl;
122 
123  theSiStripVector.push_back(theBadStripRange);
124 
125  // populate db object
126  SiStripBadStrip::Range range(theSiStripVector.begin(),theSiStripVector.end());
127  if ( ! SiStripBadStrip_->put(tempdetid,range) )
128  edm::LogError("SiStripBadStripFromASCIIFile")<<"[SiStripBadStripFromASCIIFile::GetNewObject] detid already exists"<<std::endl;
129  theSiStripVector.clear();
130 
131  count=1;
132  tempdetid=detid;
133  tempchannel=channel;
134  tempflag=flag;
135  }
136  }
137 
138  return SiStripBadStrip_;
139 }
T getUntrackedParameter(std::string const &, T const &) const
SiStripBadStripFromASCIIFile(const edm::ParameterSet &iConfig)
virtual SiStripBadStrip * getNewObject()
std::pair< ContainerIterator, ContainerIterator > Range
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false
std::string fullPath() const
Definition: FileInPath.cc:165
bool put(const uint32_t &detID, const InputVector &vect)
unsigned int encode(const unsigned short &first, const unsigned short &NconsecutiveBadStrips, const unsigned short &flag=0)