CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends
SiStripDetVOffBuilder Class Reference

Builds the SiStripDetVOff object for transfer by O2O. More...

#include <SiStripDetVOffBuilder.h>

Classes

struct  DetIdListTimeAndStatus
 
struct  TimesAndValues
 

Public Member Functions

void BuildDetVOffObj ()
 
void discardIOVs (std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &it, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &initialIt, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > &resultVec, const bool last, const unsigned int first)
 Removes IOVs as dictated by reduction. More...
 
bool FileExists (std::string filename)
 
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > getModulesVOff ()
 
std::vector< std::vector< uint32_t > > getPayloadStats ()
 
void reduce (std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &it, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &initialIt, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > &resultVec, const bool last=false)
 Operates the reduction of the fast sequences of ramping up and down of the voltages. More...
 
void reduction (const uint32_t deltaTmin, const uint32_t maxIOVlength)
 
void setLastSiStripDetVOff (SiStripDetVOff *lastPayload, cond::Time_t lastTimeStamp)
 
 SiStripDetVOffBuilder (const edm::ParameterSet &, const edm::ActivityRegistry &)
 
 ~SiStripDetVOffBuilder ()
 

Private Types

typedef std::vector< std::pair< std::vector< uint32_t >, coral::TimeStamp > > DetIdTimeStampVector
 

Private Member Functions

void buildPSUdetIdMap (TimesAndValues &tStruct, DetIdListTimeAndStatus &dStruct)
 
std::pair< int, int > extractDetIdVector (const unsigned int i, SiStripDetVOff *modV, DetIdListTimeAndStatus &detIdStruct)
 
cond::Time_t findMostRecentTimeStamp (const std::vector< coral::TimeStamp > &coralDate)
 
int findSetting (uint32_t id, const coral::TimeStamp &changeDate, const std::vector< uint32_t > &settingID, const std::vector< coral::TimeStamp > &settingDate)
 
int findSetting (std::string dpname, const coral::TimeStamp &changeDate, const std::vector< std::string > &settingDpname, const std::vector< coral::TimeStamp > &settingDate)
 
cond::Time_t getCondTime (const coral::TimeStamp &coralTime)
 
coral::TimeStamp getCoralTime (cond::Time_t iovTime)
 
void lastValue (TimesAndValues &tStruct)
 
void lastValueFromFile (TimesAndValues &tStruct)
 
void printPar (std::stringstream &ss, const std::vector< int > &par)
 
void readLastValueFromFile (std::vector< uint32_t > &dpIDs, std::vector< float > &vmonValues, std::vector< coral::TimeStamp > &dateChange)
 
void removeDuplicates (std::vector< uint32_t > &vec)
 
void setPayloadStats (const uint32_t afterV, const uint32_t numAdded, const uint32_t numRemoved)
 
void statusChange (cond::Time_t &lastTime, TimesAndValues &tStruct)
 
std::string timeToStream (const coral::TimeStamp &coralTime, const string &comment="")
 
std::string timeToStream (const cond::Time_t &condTime, const string &comment="")
 

Private Attributes

std::string authenticationPath
 
std::unique_ptr< SiStripCoralIfacecoralInterface
 
bool debug_
 
uint32_t deltaTmin_
 
std::string detIdListFile_
 
std::string excludedDetIdListFile_
 
bool fromFile
 
double highVoltageOnThreshold_
 
std::pair< SiStripDetVOff *, cond::Time_tlastStoredCondObj
 
std::string lastValueFileName
 
uint32_t maxIOVlength_
 
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > modulesOff
 
std::string onlineDbConnectionString
 
std::vector< std::vector< uint32_t > > payloadStats
 
std::string psuDetIdMapFile_
 
std::vector< int > tDefault
 
coral::TimeStamp tmax
 
std::vector< int > tmax_par
 
coral::TimeStamp tmin
 
std::vector< int > tmin_par
 
std::vector< int > tset_par
 
coral::TimeStamp tsetmin
 
bool whichQuery
 
std::string whichTable
 

Friends

class TestSiStripDetVOffBuilder
 

Detailed Description

Builds the SiStripDetVOff object for transfer by O2O.

Author
J.Cole modified by Marco De Mattia

Definition at line 37 of file SiStripDetVOffBuilder.h.

Member Typedef Documentation

typedef std::vector<std::pair<std::vector<uint32_t>, coral::TimeStamp> > SiStripDetVOffBuilder::DetIdTimeStampVector
private

Definition at line 76 of file SiStripDetVOffBuilder.h.

Constructor & Destructor Documentation

SiStripDetVOffBuilder::~SiStripDetVOffBuilder ( )

Destructor.

Definition at line 86 of file SiStripDetVOffBuilder.cc.

86  {
87  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::" << __func__ << "]: destructing ...";
88 }
SiStripDetVOffBuilder::SiStripDetVOffBuilder ( const edm::ParameterSet pset,
const edm::ActivityRegistry  
)

Default constructor.

Definition at line 5 of file SiStripDetVOffBuilder.cc.

References authenticationPath, fromFile, lastStoredCondObj, lastValueFileName, onlineDbConnectionString, printPar(), psuDetIdMapFile_, tmax, tmax_par, tmin, tmin_par, tset_par, tsetmin, whichQuery, and whichTable.

8  whichTable(pset.getParameter<std::string>("queryType")),
9  lastValueFileName(pset.getParameter<std::string>("lastValueFile")),
10  fromFile(pset.getParameter<bool>("lastValueFromFile")),
11  psuDetIdMapFile_(pset.getParameter<std::string>("PsuDetIdMapFile")),
12  debug_(pset.getParameter<bool>("debugModeOn")),
13  tDefault(7, 0),
14  tmax_par(pset.getParameter<std::vector<int> >("Tmax")),
15  tmin_par(pset.getParameter<std::vector<int> >("Tmin")),
16  tset_par(pset.getParameter<std::vector<int> >("TSetMin")),
17  deltaTmin_(pset.getParameter<uint32_t>("DeltaTmin")),
18  maxIOVlength_(pset.getParameter<uint32_t>("MaxIOVlength")),
19  detIdListFile_(pset.getParameter<std::string>("DetIdListFile")),
20  excludedDetIdListFile_(pset.getParameter<std::string>("ExcludedDetIdListFile")),
21  highVoltageOnThreshold_(pset.getParameter<double>("HighVoltageOnThreshold")) {
22  lastStoredCondObj.first = nullptr;
23  lastStoredCondObj.second = 0;
24 
25  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::SiStripDetVOffBuilder] constructor" << endl;
26 
27  // set up vectors based on pset parameters (tDefault purely for initialization)
28 
29  whichQuery = (whichTable == "STATUSCHANGE" || (whichTable == "LASTVALUE" && !fromFile));
30 
31  //Define the query interval [Tmin, Tmax]
32  //where Tmax comes from the cfg
33  // Tmin comes from the cfg for the first o2o, after that it is extracted from Offline DB
34 
35  tmax = coral::TimeStamp(tmax_par[0], tmax_par[1], tmax_par[2], tmax_par[3], tmax_par[4], tmax_par[5], tmax_par[6]);
36 
37  if (whichQuery) {
38  // Is there a better way to do this? TODO - investigate
39  tmin = coral::TimeStamp(tmin_par[0], tmin_par[1], tmin_par[2], tmin_par[3], tmin_par[4], tmin_par[5], tmin_par[6]);
40  }
41 
42  if (whichTable == "LASTVALUE") {
43  tsetmin =
44  coral::TimeStamp(tset_par[0], tset_par[1], tset_par[2], tset_par[3], tset_par[4], tset_par[5], tset_par[6]);
45  }
46 
47  if (onlineDbConnectionString.empty()) {
48  edm::LogError("SiStripDetVOffBuilder")
49  << "[SiStripDetVOffBuilder::SiStripDetVOffBuilder] DB name has not been set properly ... Returning ...";
50  return;
51  }
52 
53  if (fromFile && whichTable == "LASTVALUE" && lastValueFileName.empty()) {
54  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::SiStripDetVOffBuilder] File expected for "
55  "lastValue table, but filename not specified ... Returning ...";
56  return;
57  }
58 
59  // write out the parameters
60  std::stringstream ss;
61  ss << "[SiStripDetVOffBuilder::SiStripDetVOffBuilder]\n"
62  << " Parameters:\n"
63  << " DB connection string: " << onlineDbConnectionString << "\n"
64  << " Authentication path: " << authenticationPath << "\n"
65  << " Table to be queried: " << whichTable << "\n"
66  << " MapFile: " << psuDetIdMapFile_ << "\n";
67 
68  if (whichQuery) {
69  ss << " Tmin: ";
70  printPar(ss, tmin_par);
71  ss << std::endl;
72  }
73  ss << " Tmax: ";
74  printPar(ss, tmax_par);
75  ss << std::endl;
76 
77  if (whichTable == "LASTVALUE") {
78  ss << " TSetMin: ";
79  printPar(ss, tset_par);
80  ss << std::endl;
81  }
82  edm::LogError("SiStripDetVOffBuilder") << ss.str();
83 }
T getParameter(std::string const &) const
void printPar(std::stringstream &ss, const std::vector< int > &par)
std::vector< int > tDefault
std::pair< SiStripDetVOff *, cond::Time_t > lastStoredCondObj
std::vector< int > tmax_par
std::vector< int > tmin_par
std::vector< int > tset_par

Member Function Documentation

void SiStripDetVOffBuilder::BuildDetVOffObj ( )

Build the SiStripDetVOff object for transfer.

Definition at line 96 of file SiStripDetVOffBuilder.cc.

References authenticationPath, SiStripPsuDetIdMap::BuildMap(), buildPSUdetIdMap(), coralInterface, gather_cfg::cout, debug_, detIdListFile_, SiStripDetVOffBuilder::DetIdListTimeAndStatus::detidV, excludedDetIdListFile_, extractDetIdVector(), plotBeamSpotDB::first, fromFile, edm::FileInPath::fullPath(), getCondTime(), SiStripDetVOff::getDetIds(), mps_fire::i, lastStoredCondObj, lastValue(), lastValueFromFile(), SiStripDetVOffBuilder::TimesAndValues::latestTime, genParticles_cff::map, modulesOff, onlineDbConnectionString, payloadStats, SiStripDetVOff::put(), matplotRender::reader, setPayloadStats(), statusChange(), tmax, whichQuery, and whichTable.

Referenced by SiStripDetVOffHandler::analyze().

96  {
97  // vectors for storing output from DB or text file
98  TimesAndValues timesAndValues;
99 
100  // Open the PVSS DB connection
102  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Query type is " << whichTable
103  << endl;
104 
105  if (whichTable == "LASTVALUE") {
106  edm::LogError("SiStripDetVOffBuilder")
107  << "[SiStripDetVOffBuilder::BuildDetVOff]: Use file? " << ((fromFile) ? "TRUE" : "FALSE");
108  }
109 
110  if (lastStoredCondObj.second > 0) {
111  edm::LogError("SiStripDetVOffBuilder")
112  << "[SiStripDetVOffBuilder::BuildDetVOff]: retrieved last time stamp from DB: " << lastStoredCondObj.second
113  << endl;
114  }
115  // access the information!
116  //We've been using the STATUSCHANGE query only in last year or so... LASTVALUE may have untested issues...
117  //In either case the idea is that the results of the query are saved into the timesAndValues struct
118  //ready to be anaylized (i.e. translated into detIDs, HV/LV statuses)
119 
120  if (whichQuery) {
121  if (whichTable == "STATUSCHANGE") {
122  statusChange(lastStoredCondObj.second, timesAndValues);
123  }
124  if (whichTable == "LASTVALUE") {
125  if (fromFile) {
126  lastValueFromFile(timesAndValues);
127  } else {
128  lastValue(timesAndValues);
129  }
130  }
131  }
132 
133  //Initialize the stuct that will be used to keep the detID-translated information
134  DetIdListTimeAndStatus dStruct;
135 
136  // build PSU - det ID map
137  //The following method actually "builds" 4 maps: LVMap, HVMap, HVUnmapped_Map, HVCrosstalking_Map.
138  //It also takes the timesAndValues from the query above and using the maps, it processes the information
139  //populating the DetIDListTimeAndStatus struct that will hold the information by detid.
140  buildPSUdetIdMap(timesAndValues, dStruct);
141 
142  // initialize variables
143  modulesOff.clear();
144  cond::Time_t saveIovTime = 0;
145 
146  // - If there is already an object stored in the database
147  // -- store it in the modulesOff vector
148  // -- set the saveIovTime as that
149  // -- set the payload stats to empty
150  // Successivamente:
151  // - loop su tutti gli elementi del detidV, che stato letto dal pvss (questi elementi sono pair<vettore di detid, time>)
152  // -- setta il tempo dell'IOV:
153  // --- LASTVALUE -> iovtime settato a latestTime
154  // --- altrimenti iovtime = tempo associato al detId vector del loop
155 
156  // check if there is already an object stored in the DB
157  // This happens only if you are using STATUSCHANGE
158  if (lastStoredCondObj.first != nullptr && lastStoredCondObj.second > 0) {
159  modulesOff.push_back(lastStoredCondObj);
160  saveIovTime = lastStoredCondObj.second;
161  setPayloadStats(0, 0, 0);
162  }
163 
164  //Master loop over all the results of the query stored in the dStruct (that contains vectors with vectors of detids, statuses, isHV flags, etc and in particular a vector of timestamps for which the info is valid... basically it is a loop over the timestamps (i.e. IOVs).
165  for (unsigned int i = 0; i < dStruct.detidV.size(); i++) {
166  // std::vector<uint32_t> detids = dStruct.detidV[i].first;
167  // removeDuplicates(detids);
168  std::vector<uint32_t>* detids = &(dStruct.detidV[i].first);
169 
170  // set the condition time for the transfer
171  cond::Time_t iovtime = 0;
172 
173  if (whichTable == "LASTVALUE") {
174  iovtime = timesAndValues.latestTime;
175  }
176 
177  else {
178  iovtime = getCondTime((dStruct.detidV[i]).second);
179  }
180 
181  // decide how to initialize modV
182  SiStripDetVOff* modV = nullptr;
183 
184  // When using STATUSCHANGE they are equal only for the first
185  // When using LASTVALUE they are equal only if the tmin was set to tsetmin
186 
187  if (iovtime != saveIovTime) { // time is different, so create new object
188 
189  // This can be only when using LASTVALUE or with a new tag
190  if (modulesOff.empty()) {
191  // create completely new object and set the initial state to Tracker all off
192  modV = new SiStripDetVOff();
193 
194  // Use the file
196  SiStripDetInfoFileReader reader(fp.fullPath());
197  const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>& detInfos = reader.getAllData();
198 
199  //FIXME:
200  //Following code is actually broken (well not until the cfg has "" for excludedDetIDListFile parameter!
201  //Fix it if felt necessary (remember that it assumes that whatever detids are excluded should NOT be in the regular map
202  //breaking our current situation with a fully mapped (LV-wise) tracker...
203  // Careful: if a module is in the exclusion list it must be ignored and the initial status is set to ON.
204  // These modules are expected to not be in the PSU-DetId map, so they will never get any status change from the query.
206  std::vector<std::pair<uint32_t, std::string> > excludedDetIdMap;
207  if (!excludedDetIdListFile_.empty()) {
208  map.BuildMap(excludedDetIdListFile_, excludedDetIdMap);
209  }
210  for (std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator it = detInfos.begin();
211  it != detInfos.end();
212  ++it) {
213  std::vector<std::pair<uint32_t, std::string> >::const_iterator exclIt = excludedDetIdMap.begin();
214  bool excluded = false;
215  for (; exclIt != excludedDetIdMap.end(); ++exclIt) {
216  if (it->first == exclIt->first) {
217  excluded = true;
218  break;
219  }
220  }
221  if (!excluded) {
222  modV->put(it->first, 1, 1);
223  }
224  }
225 
226  } else {
227  modV = new SiStripDetVOff(*(modulesOff.back().first));
228  } // start from copy of previous object
229  } else {
230  modV =
231  (modulesOff.back())
232  .first; // modify previous object (TEST THIS if possible! it's fundamental in handling changes at the edges of O2O executions and also in case of PVSS DB buffering!
233  }
234 
235  // extract the detID vector before modifying for stats calculation
236  std::vector<uint32_t> beforeV;
237  modV->getDetIds(beforeV);
238 
239  //CHECKTHIS
240  //The following method call is potentially problematic:
241  //passing modV as argument while extracting information about dStruct,
242  //modV is not currently used in the method!
243  std::pair<int, int> hvlv = extractDetIdVector(
244  i, modV, dStruct); //Returns a pair like this HV OFF->1,-1 HV ON->0,-1 LV OFF->-1,1 LV ON->-1,0
245  //Basically a LV OFF of -1 means that the information (IOV) in question is from an HV channel turning on or off and viceversa for an HVOFF of -1.
246  //This could be confusing when reading the debug output!
247 
248  for (unsigned int j = 0; j < detids->size(); j++) {
249  if (debug_)
250  cout << "at time = " << iovtime << " detid[" << j << "] = " << (*detids)[j] << " has hv = " << hvlv.first
251  << " and lv = " << hvlv.second << endl;
252  modV->put((*detids)[j], hvlv.first, hvlv.second);
253  }
254 
255  // calculate the stats for storage
256  unsigned int numAdded = 0, numRemoved = 0;
257  if (iovtime == saveIovTime) {
258  std::vector<uint32_t> oldStats = payloadStats.back();
259  numAdded = oldStats[1];
260  numRemoved = oldStats[2];
261  }
262  std::vector<uint32_t> afterV;
263  modV->getDetIds(afterV);
264 
265  if ((afterV.size() - beforeV.size()) > 0) {
266  numAdded += afterV.size() - beforeV.size();
267  } else if ((beforeV.size() - afterV.size()) > 0) {
268  numRemoved += beforeV.size() - afterV.size();
269  }
270 
271  // store the object if it's a new object
272  if (iovtime != saveIovTime) {
273  SiStripDetVOff* testV = nullptr;
274  if (!modulesOff.empty()) {
275  testV = modulesOff.back().first;
276  }
277  if (modulesOff.empty() || !(*modV == *testV)) {
278  modulesOff.push_back(std::make_pair(modV, iovtime));
279  // save the time of the object
280  saveIovTime = iovtime;
281  // save stats
282  setPayloadStats(afterV.size(), numAdded, numRemoved);
283  } else {
284  // modV will not be used anymore, DELETE it to avoid memory leak!
285  delete modV;
286  }
287  } else {
288  (payloadStats.back())[0] = afterV.size();
289  (payloadStats.back())[1] = numAdded;
290  (payloadStats.back())[2] = numRemoved;
291  }
292  }
293 
294  // compare the first element and the last from previous transfer
295  if (lastStoredCondObj.first != nullptr && lastStoredCondObj.second > 0) {
296  if (*(lastStoredCondObj.first) == *(modulesOff[0].first)) {
297  if (modulesOff.size() == 1) {
298  // if no HV/LV transition was found in this period: update the last IOV to be tmax
299  modulesOff[0].second = getCondTime(tmax);
300  } else {
301  // HV/LV transitions found: remove the first one (which came from previous transfer)
302  modulesOff.erase(modulesOff.begin());
303  payloadStats.erase(payloadStats.begin());
304  }
305  }
306  }
307 
308  if (debug_) {
309  std::cout << std::endl;
310  std::cout << "Size of modulesOff = " << modulesOff.size() << std::endl;
311  for (unsigned int i = 0; i < modulesOff.size(); i++) {
312  std::vector<uint32_t> finalids;
313  (modulesOff[i].first)->getDetIds(finalids);
314  std::cout << "Index = " << i << " Size of DetIds vector = " << finalids.size() << std::endl;
315  std::cout << "Time = " << modulesOff[i].second << std::endl;
316  for (unsigned int j = 0; j < finalids.size(); j++) {
317  std::cout << "detid = " << finalids[j] << " LV off = " << (modulesOff[i].first)->IsModuleLVOff(finalids[j])
318  << " HV off = " << (modulesOff[i].first)->IsModuleHVOff(finalids[j]) << std::endl;
319  }
320  }
321  }
322 }
std::pair< int, int > extractDetIdVector(const unsigned int i, SiStripDetVOff *modV, DetIdListTimeAndStatus &detIdStruct)
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > modulesOff
void buildPSUdetIdMap(TimesAndValues &tStruct, DetIdListTimeAndStatus &dStruct)
Extension to SiStripConfigDb to map PSU channels to DetIDs using DCU-PSU map and DCU-DetID map...
bool put(const uint32_t DetId, const int HVoff, const int LVoff)
Insert information for a single detId.
std::pair< SiStripDetVOff *, cond::Time_t > lastStoredCondObj
std::unique_ptr< SiStripCoralIface > coralInterface
unsigned long long Time_t
Definition: Time.h:16
cond::Time_t getCondTime(const coral::TimeStamp &coralTime)
void getDetIds(std::vector< uint32_t > &DetIds_) const
An interface class to the PVSS cond DB.
std::vector< std::vector< uint32_t > > payloadStats
void lastValue(TimesAndValues &tStruct)
void lastValueFromFile(TimesAndValues &tStruct)
void BuildMap(const std::string &mapFile, const bool debug)
void setPayloadStats(const uint32_t afterV, const uint32_t numAdded, const uint32_t numRemoved)
void statusChange(cond::Time_t &lastTime, TimesAndValues &tStruct)
void SiStripDetVOffBuilder::buildPSUdetIdMap ( TimesAndValues tStruct,
DetIdListTimeAndStatus dStruct 
)
private

Definition at line 762 of file SiStripDetVOffBuilder.cc.

References SiStripDetVOffBuilder::TimesAndValues::actualStatus, SiStripPsuDetIdMap::BuildMap(), SiStripDetVOffBuilder::TimesAndValues::changeDate, gather_cfg::cout, debug_, SiStripDetVOffBuilder::DetIdListTimeAndStatus::detidV, SiStripDetVOffBuilder::TimesAndValues::dpname, relativeConstraints::empty, cmsRelvalreport::exit, FileExists(), spr::find(), SiStripPsuDetIdMap::getHVCrosstalkingMap(), SiStripPsuDetIdMap::getHvDetID(), SiStripPsuDetIdMap::getHVUnmappedMap(), SiStripPsuDetIdMap::getLvDetID(), SiStripDetVOffBuilder::DetIdListTimeAndStatus::isHV, mps_splice::line, LogTrace, genParticles_cff::map, SiStripDetVOffBuilder::DetIdListTimeAndStatus::notMatched, SiStripPsuDetIdMap::printMap(), psuDetIdMapFile_, SiStripDetVOffBuilder::DetIdListTimeAndStatus::psuName, removeDuplicates(), SiStripDetVOffBuilder::DetIdListTimeAndStatus::StatusGood, AlCaHLTBitMon_QueryRunRegistry::string, protons_cff::t, and timeToStream().

Referenced by BuildDetVOffObj().

767 {
768  SiStripPsuDetIdMap map_;
769  if (psuDetIdMapFile_.empty()) {
770  std::cout << "PLEASE provide the name of a valid PSUDetIDMapFile in the cfg: currently still necessary to have a "
771  "file, soon will access the info straight from the DB!"
772  << endl;
773  //map_.BuildMap();//This method is not currently used (it would try to build a map based on a query to SiStripConfigDB, and the info there is STALE!)
774  } else {
775  map_.BuildMap(psuDetIdMapFile_, debug_); //This is the method used to build the map.
776  }
777  LogTrace("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff] PSU(Channel)-detID map(s) built";
778  //Following method to be replaced by printMaps... to print all 4 maps built!
779  map_.printMap(); //This method prints to the info.log file, notice that it is overwritten by each individual O2O job running in the same dir.
780 
781  // use map info to build input for list of objects
782  // no need to check for duplicates, as put method for SiStripDetVOff checks for you!
783 
784  //Debug variables
785  unsigned int ch0bad = 0, ch1bad = 0, ch2bad = 0, ch3bad = 0;
786  std::vector<unsigned int> numLvBad, numHvBad;
787 
788  //Create 2 extra maps that we'll use to keep track of unmapped and crosstalking detids when turning ON and OFF HV:
789  //-unmapped need to be both turned OFF when any HV goes OFF and to be turned ON when both are ON
790  //-crosstaling need to be both turned ON when any HV goes ON and to be turned OFF ONLY when BOTH are OFF.
791  std::map<std::string, bool> UnmappedState, CrosstalkingState;
792  //Get the HVUnmapped map from the map, so that we can set know which PSU are unmapped:
793  std::map<std::string, std::vector<uint32_t> > UnmappedPSUs = map_.getHVUnmappedMap();
794  //Check here if there is a file already, otherwise initialize to OFF all channels in these PSU!
795  if (FileExists("HVUnmappedChannelState.dat")) {
796  std::cout << "File HVUnmappedChannelState.dat exists!" << std::endl;
797  std::ifstream ifs("HVUnmappedChannelState.dat");
798  string line;
799  while (getline(ifs, line)) {
800  if (!line.empty()) {
801  // split the line and insert in the map
802  stringstream ss(line);
803  string PSUChannel;
804  bool HVStatus;
805  ss >> PSUChannel;
806  ss >> HVStatus;
807  //Extract the PSU from the PSUChannel (since the HVUnmapped_Map uses PSU as key
808  std::string PSU = PSUChannel.substr(0, PSUChannel.size() - 10);
809  //Look for the PSU in the unmapped map!
810  std::map<std::string, std::vector<uint32_t> >::iterator iter = UnmappedPSUs.find(PSU);
811  if (iter != UnmappedPSUs.end()) {
812  UnmappedState[PSUChannel] = HVStatus;
813  } else {
814  std::cout << "WARNING!!! There are channels in the local file with the channel status for HVUnmapped "
815  "channels, that ARE NOT CONSIDERED AS UNMAPPED in the current map!"
816  << std::endl;
817  }
818  }
819  } //End of the while loop reading and initializing UnmappedState map from file
820  //Extra check:
821  //Should check if there any HVUnmapped channels in the map that are not listed in the local file!
822  bool MissingChannels = false;
823  for (std::map<std::string, vector<uint32_t> >::iterator it = UnmappedPSUs.begin(); it != UnmappedPSUs.end(); it++) {
824  std::string chan002 = it->first + "channel002";
825  std::string chan003 = it->first + "channel003";
826  std::map<std::string, bool>::iterator iter = UnmappedState.find(chan002);
827  if (iter == UnmappedState.end()) {
828  std::cout << "ERROR! The local file with the channel status for HVUnmapped channels IS MISSING one of the "
829  "following unmapped channel voltage status information:"
830  << std::endl;
831  std::cout << chan002 << std::endl;
832  MissingChannels = true;
833  }
834  iter = UnmappedState.find(chan003);
835  if (iter == UnmappedState.end()) {
836  std::cout << "ERROR! The local file with the channel status for HVUnmapped channels IS MISSING one of the "
837  "following unmapped channel voltage status information:"
838  << std::endl;
839  std::cout << chan003 << std::endl;
840  MissingChannels = true;
841  }
842  }
843  //Now if any channel WAS missing, exit!
844  if (MissingChannels) {
845  std::cout << "!!!!\n"
846  << "Exiting now... please check the local HVUnmappedChannelState.dat and the mapfile you provided ("
847  << psuDetIdMapFile_ << ")" << std::endl;
848  exit(1);
849  }
850  } else { //If the file HVUnmappedChannelState.dat does not exist, initialize the map to all OFF.
851  //(see below for creating the file at the end of the execution with the latest state of unmapped channels.
852  for (std::map<std::string, vector<uint32_t> >::iterator it = UnmappedPSUs.begin(); it != UnmappedPSUs.end(); it++) {
853  std::string chan002 = it->first + "channel002";
854  std::string chan003 = it->first + "channel003";
855  UnmappedState[chan002] = false;
856  UnmappedState[chan003] = false;
857  }
858  }
859  //Get the HVCrosstalking map from the map, so that we can set know which PSU are crosstalking:
860  std::map<std::string, std::vector<uint32_t> > CrosstalkingPSUs = map_.getHVCrosstalkingMap();
861  //Check here if there is a file already, otherwise initialize to OFF all channels in these PSU!
862  if (FileExists("HVCrosstalkingChannelState.dat")) {
863  std::cout << "File HVCrosstalkingChannelState.dat exists!" << std::endl;
864  std::ifstream ifs("HVCrosstalkingChannelState.dat");
865  string line;
866  while (getline(ifs, line)) {
867  if (!line.empty()) {
868  // split the line and insert in the map
869  stringstream ss(line);
870  string PSUChannel;
871  bool HVStatus;
872  ss >> PSUChannel;
873  ss >> HVStatus;
874  //Extract the PSU from the PSUChannel (since the HVCrosstalking_Map uses PSU as key
875  std::string PSU = PSUChannel.substr(0, PSUChannel.size() - 10);
876  //Look for the PSU in the unmapped map!
877  std::map<std::string, std::vector<uint32_t> >::iterator iter = CrosstalkingPSUs.find(PSU);
878  if (iter != CrosstalkingPSUs.end()) {
879  CrosstalkingState[PSUChannel] = HVStatus;
880  } else {
881  std::cout << "WARNING!!! There are channels in the local file with the channel status for HVUnmapped "
882  "channels, that ARE NOT CONSIDERED AS UNMAPPED in the current map!"
883  << std::endl;
884  }
885  }
886  } //End of the while loop reading and initializing CrosstalkingState map from file
887  //Extra check:
888  //Should check if there any HVCrosstalking channels in the map that are not listed in the local file!
889  bool MissingChannels = false;
890  for (std::map<std::string, vector<uint32_t> >::iterator it = CrosstalkingPSUs.begin(); it != CrosstalkingPSUs.end();
891  it++) {
892  std::string chan002 = it->first + "channel002";
893  std::string chan003 = it->first + "channel003";
894  std::map<std::string, bool>::iterator iter = CrosstalkingState.find(chan002);
895  if (iter == CrosstalkingState.end()) {
896  std::cout << "ERROR! The local file with the channel status for HVCrosstalking channels IS MISSING one of the "
897  "following unmapped channel voltage status information:"
898  << std::endl;
899  std::cout << chan002 << std::endl;
900  MissingChannels = true;
901  }
902  iter = CrosstalkingState.find(chan003);
903  if (iter == CrosstalkingState.end()) {
904  std::cout << "ERROR! The local file with the channel status for HVCrosstalking channels IS MISSING one of the "
905  "following unmapped channel voltage status information:"
906  << std::endl;
907  std::cout << chan003 << std::endl;
908  MissingChannels = true;
909  }
910  }
911  //Now if any channel WAS missing, exit!
912  if (MissingChannels) {
913  std::cout << "!!!!\n"
914  << "Exiting now... please check the local HVCrosstalkingChannelState.dat and the mapfile you provided ("
915  << psuDetIdMapFile_ << ")" << std::endl;
916  exit(1);
917  }
918  } else { //If the file HVCrosstalkingChannelState.dat does not exist, initialize the map to all OFF.
919  //(see below for creating the file at the end of the execution with the latest state of unmapped channels.
920  for (std::map<std::string, vector<uint32_t> >::iterator it = CrosstalkingPSUs.begin(); it != CrosstalkingPSUs.end();
921  it++) {
922  std::string chan002 = it->first + "channel002";
923  std::string chan003 = it->first + "channel003";
924  CrosstalkingState[chan002] = false;
925  CrosstalkingState[chan003] = false;
926  }
927  }
928 
929  if (debug_) {
930  //print out the UnmappedState map:
931  std::cout << "Printing the UnmappedChannelState initial map:" << std::endl;
932  std::cout << "PSUChannel\t\tHVON?(true or false)" << std::endl;
933  for (std::map<std::string, bool>::iterator it = UnmappedState.begin(); it != UnmappedState.end(); it++) {
934  std::cout << it->first << "\t\t" << it->second << std::endl;
935  }
936  //print out the CrosstalkingState map:
937  std::cout << "Printing the CrosstalkingChannelState initial map:" << std::endl;
938  std::cout << "PSUChannel\t\tHVON?(true or false)" << std::endl;
939  for (std::map<std::string, bool>::iterator it = CrosstalkingState.begin(); it != CrosstalkingState.end(); it++) {
940  std::cout << it->first << "\t\t" << it->second << std::endl;
941  }
942  }
943 
944  //Loop over the psuStruct (DB query results), lopping over the PSUChannels
945  //This will probably change int he future when we will change the query itself
946  //to report directly the detIDs associated with a channel
947  //Probably we will report in the query results the detID, the changeDate
948  //and whether the channel is HV mapped, HV unmapped, HV crosstalking using a flag...
949  for (unsigned int dp = 0; dp < psuStruct.dpname.size(); dp++) {
950  //FIX ME:
951  //Check if the following if condition can EVER be true!
952  std::string PSUChannel = psuStruct.dpname[dp];
953  if (PSUChannel != "UNKNOWN") {
954  // figure out the channel and the PSU individually
956  PSUChannel.substr(PSUChannel.size() - 10); //Channel is the channel, i.e. channel000, channel001 etc
957  std::string PSU = PSUChannel.substr(0, PSUChannel.size() - 10);
958 
959  // Get the detIDs corresponding to the given PSU channel using the getDetID function of SiStripPsuDetIdMap.cc
960  //NOTA BENE
961  //Need to make sure the information is treated consistently here:
962  //The map by convention has
963  //detID-> channel002 or channel003 IF the channel is HV mapped,
964  //detID->channel000 if it is not HV mapped
965  //We want to differentiate the behavior depending on the status reported for the channel for channels that are unmapped!
966  //1-if the channel is turning OFF (!=1) then we want to report all detIDs for that channel and all detIDs that are listed as channel000 for that PSU.
967  //2-if the channel is turning ON (==1) then we want to turn on all detIDs for that channel but turn on all detIDs listed as channel000 for that PSU ONLY IF BOTH channel002 and channel003 are BOTH ON!
968  //Need to handle the case of coupled Power supplies (that only turn off when both are turned off).
969 
970  //Fixed SiStripPSUdetidMap.cc to make sure now getDetID gets the correct list of detIDs:
971  //-for channels 000/001 all the detIDs connected to the PSU
972  //-for channels 002/003 HV1/HV2 modules only (exclusively)
973  //UPDATE for HV channels:
974  //actually fixed it to report also detIDs listed as
975  //channel000 on the same supply of channel002 or channel003
976  //and the crosstalking ones (channel999) too..
977 
978  //Get the detIDs associated with the DPNAME (i.e. PSUChannel) reported by the query
979  //Declare the vector to be passed as reference parameters to the getDetID method
980  //std::vector<uint32_t> ids,unmapped_ids,crosstalking_ids;
981  std::vector<uint32_t> ids;
982  //map_.getDetID(PSUChannel, debug_, ids, unmapped_ids, crosstalking_ids);
983  //Actually the method above is a bit of an overkill, we could already use the individual methods:
984  //getLvDetID
985  //getHvDetID
986 
987  //Declaring the two vector needed for the HV case in this scope.
988  std::vector<uint32_t> unmapped_ids, crosstalking_ids;
989  bool LVCase;
990  //LV CASE
991  if (Channel == "channel000" || Channel == "channel001") {
992  LVCase = true;
993  ids = map_.getLvDetID(
994  PSU); //Since in the LV case only 1 list of detids is returned (unmapped and crosstalking are irrelevant for LV) return the vector directly
995  }
996  //HV CASE
997  else { //if (Channel=="channel002" || Channel=="channel003") {
998  LVCase = false;
999  map_.getHvDetID(PSUChannel,
1000  ids,
1001  unmapped_ids,
1002  crosstalking_ids); //In the HV case since 3 vectors are filled, use reference parameters
1003  }
1004 
1005  if (debug_) {
1006  cout << "dpname[" << dp << "] = " << PSUChannel << ", for time = " << timeToStream(psuStruct.changeDate[dp])
1007  << endl;
1008  if (!ids.empty()) {
1009  if (Channel == "channel000" || Channel == "channel001") {
1010  cout << "Corresponding to LV (PSU-)matching detids: " << endl;
1011  for (unsigned int i_detid = 0; i_detid < ids.size(); i_detid++) {
1012  cout << ids[i_detid] << std::endl;
1013  }
1014  } else {
1015  cout << "Corresponding to straight HV matching detids: " << endl;
1016  for (unsigned int i_detid = 0; i_detid < ids.size(); i_detid++) {
1017  cout << ids[i_detid] << std::endl;
1018  }
1019  }
1020  }
1021  //The unmapped_ids and crosstalking_ids are only filled for HV channels!
1022  if (!unmapped_ids.empty()) {
1023  cout << "Corresponding to HV unmapped (PSU-)matching detids: " << endl;
1024  for (unsigned int i_detid = 0; i_detid < unmapped_ids.size(); i_detid++) {
1025  cout << unmapped_ids[i_detid] << std::endl;
1026  }
1027  }
1028  if (!crosstalking_ids.empty()) {
1029  cout << "Corresponding to HV crosstalking (PSU-)matching detids: " << endl;
1030  for (unsigned int i_detid = 0; i_detid < crosstalking_ids.size(); i_detid++) {
1031  cout << crosstalking_ids[i_detid] << std::endl;
1032  }
1033  }
1034  }
1035 
1036  //NOW implement the new logic using the detids, unmapped_detids, crosstalking_detids!
1037 
1038  //First check whether the channel we're looking at is turning OFF or turning ON!
1039 
1040  //TURN OFF case:
1041  if (psuStruct.actualStatus[dp] != 1) {
1042  //Behavior is different for LV vs HV channels:
1043  //LV case:
1044  if (LVCase) {
1045  //Turn OFF all:
1046  //-positively matching
1047  //-unmapped matching
1048  //-crosstalking
1049  //for the LV case all the detids are automatically reported in the ids vector
1050  //unmapped and crosstalking are only differentiated (relevant) for HV.
1051  if (!ids.empty()) {
1052  //debug variables increment
1053  ch0bad++;
1054  ch1bad++;
1055 
1056  //Create a pair with the relevant detIDs (vector) and its timestamp
1057  //And put it in the detidV vector of the detIdStruct that will contain all the
1058  //results
1059  detIdStruct.detidV.push_back(std::make_pair(ids, psuStruct.changeDate[dp]));
1060 
1061  //Set the status to OFF
1062  detIdStruct.StatusGood.push_back(false);
1063 
1064  //debug variable population
1065  numLvBad.insert(numLvBad.end(), ids.begin(), ids.end());
1066 
1067  //Set the flag for LV/HV:
1068  detIdStruct.isHV.push_back(0); //LV
1069 
1070  //Set the PSUChannel (I guess for debug purposes?)
1071  detIdStruct.psuName.push_back(PSUChannel);
1072  }
1073  }
1074  //HV case:
1075  else { //if (!LVCase) {
1076  //Debug variables increment:
1077  if (!ids.empty() || !unmapped_ids.empty() || !crosstalking_ids.empty()) {
1078  if (Channel == "channel002") {
1079  ch2bad++;
1080  } else if (Channel == "channel003") {
1081  ch3bad++;
1082  }
1083  }
1084  //First sum the ids (positively matching detids) and the unmapped_ids (since both should be TURNED OFF):
1085  std::vector<uint32_t> OFFids;
1086  OFFids.insert(OFFids.end(), ids.begin(), ids.end()); //Add the ids (if any!)
1087  OFFids.insert(OFFids.end(), unmapped_ids.begin(), unmapped_ids.end()); //Add the unmapped_ids (if any!)
1088  //Now for the cross-talking ids this is a bit more complicated!
1089  if (!crosstalking_ids
1090  .empty()) { //This already means that the PSUChannel is one of the crosstalking ones (even if only a few modules in that PSU are showing crosstalking behavior both its channels have to be considered crosstalking of course!
1091  //Set the channel OFF in the CrosstalkingState map!
1092  CrosstalkingState[PSUChannel] = false; //Turn OFF the channel in the state map!
1093 
1094  //Need to check if both channels (HV1==channel002 or HV2==channel003) are OFF!
1095  if (!CrosstalkingState[PSUChannel.substr(0, PSUChannel.size() - 1) + "2"] &&
1096  !CrosstalkingState[PSUChannel.substr(0, PSUChannel.size() - 1) + "3"]) { //if HV1 & HV2 both OFF (false)
1097  OFFids.insert(
1098  OFFids.end(),
1099  crosstalking_ids.begin(),
1100  crosstalking_ids.end()); //Add the crosstalking_ids (if any!) since both HV1 and HV2 are OFF!
1101  if (debug_) {
1102  std::cout << "Adding the unmapped detids corresponding to (HV1/2 cross-talking) PSU "
1103  << PSUChannel.substr(0, PSUChannel.size() - 10) << " to the list of detids turning OFF"
1104  << std::endl;
1105  }
1106  }
1107  }
1108  //Handle the crosstalking channel by setting it to OFF in the CrosstalkingState map!
1109  if (!unmapped_ids
1110  .empty()) { //This already means that the PSUChannel is one of the unmapped ones (even if only a few modules in that PSU are unmapped both its channels have to be considered crosstalking of course!
1111  UnmappedState[PSUChannel] = false; //Turn OFF the channel in the state map!
1112  }
1113  if (!OFFids.empty()) {
1114  //Create a pair with the relevant detIDs (vector) and its timestamp
1115  //And put it in the detidV vector of the detIdStruct that will contain all the
1116  //results
1117 
1118  //Going OFF HV:
1119  //report not only ids, but also unmapped_ids.
1120  //have to handle crosstalking_ids here... (only OFF if they corresponding PSU HV1/HV2 is off already...
1121  //then add all three vectors to the pair below...
1122  detIdStruct.detidV.push_back(std::make_pair(OFFids, psuStruct.changeDate[dp]));
1123 
1124  //Set the status to OFF
1125  detIdStruct.StatusGood.push_back(false);
1126 
1127  //debug variable population
1128  numHvBad.insert(numHvBad.end(), ids.begin(), ids.end());
1129 
1130  //Set the flag for LV/HV:
1131  detIdStruct.isHV.push_back(1); //HV
1132 
1133  //Set the PSUChannel (I guess for debug purposes?)
1134  detIdStruct.psuName.push_back(PSUChannel);
1135  }
1136  }
1137  }
1138  //TURNING ON CASE
1139  else {
1140  //Implement the rest of the logic!
1141  //Behavior is different for LV vs HV channels:
1142  //LV case:
1143  if (LVCase) {
1144  //Turn ON all (PSU)matching detids:
1145  //for the LV case all the detids are automatically reported in the ids vector
1146  //unmapped and crosstalking are only differentiated (relevant) for HV.
1147  if (!ids.empty()) {
1148  //Create a pair with the relevant detIDs (vector) and its timestamp
1149  //And put it in the detidV vector of the detIdStruct that will contain all the
1150  //results
1151  detIdStruct.detidV.push_back(std::make_pair(ids, psuStruct.changeDate[dp]));
1152 
1153  //Set the status to ON
1154  detIdStruct.StatusGood.push_back(true);
1155 
1156  //Set the flag for LV/HV:
1157  detIdStruct.isHV.push_back(0); //LV
1158 
1159  //Set the PSUChannel (I guess for debug purposes?)
1160  detIdStruct.psuName.push_back(PSUChannel);
1161  }
1162  }
1163  //HV case:
1164  else { //if (!LVCase) {
1165  //First sum the ids (positively matching detids) and the crosstalking_ids (since all ids on a crosstalking PSU should be TURNED ON when at least one HV channel is ON):
1166  std::vector<uint32_t> ONids;
1167  ONids.insert(ONids.end(), ids.begin(), ids.end()); //Add the ids (if any!)
1168  ONids.insert(
1169  ONids.end(), crosstalking_ids.begin(), crosstalking_ids.end()); //Add the crosstalking_ids (if any!)
1170  //Now for the unmapped ids this is a bit more complicated!
1171  if (!unmapped_ids
1172  .empty()) { //This already means that the PSUChannel is one of the unmapped ones (even if only a few modules in that PSU are unmapped both its channels have to be considered unmapped of course!
1173  //Set the HV1 channel on in the UnmappedState map!
1174  UnmappedState[PSUChannel] = true; //Turn ON the channel in the state map!
1175 
1176  //Need to check if BOTH channels (HV1==channel002 or HV2==channel003) are ON!
1177  if (UnmappedState[PSUChannel.substr(0, PSUChannel.size() - 1) + "2"] &&
1178  UnmappedState[PSUChannel.substr(0, PSUChannel.size() - 1) + "3"]) { //if HV1 & HV2 are both ON (true)
1179  ONids.insert(ONids.end(),
1180  unmapped_ids.begin(),
1181  unmapped_ids.end()); //Add the unmapped_ids (if any!) since both HV1 and HV2 are ON!
1182  if (debug_) {
1183  std::cout << "Adding the detids corresponding to HV-unmapped PSU "
1184  << PSUChannel.substr(0, PSUChannel.size() - 10) << " to the list of detids turning ON"
1185  << std::endl;
1186  }
1187  }
1188  }
1189  //Handle the crosstalking channel by setting it to OFF in the CrosstalkingState map!
1190  if (!crosstalking_ids
1191  .empty()) { //This already means that the PSUChannel is one of the crosstalking ones (even if only a few modules in that PSU are showing crosstalking behavior both its channels have to be considered crosstalking of course!
1192  CrosstalkingState[PSUChannel] = true; //Turn ON the channel in the state map!
1193  }
1194  if (!ONids.empty()) {
1195  //Create a pair with the relevant detIDs (vector) and its timestamp
1196  //And put it in the detidV vector of the detIdStruct that will contain all the
1197  //results
1198 
1199  //Going OFF HV:
1200  //report not only ids, but also unmapped_ids.
1201  //have to handle crosstalking_ids here... (only OFF if they corresponding PSU HV1/HV2 is off already...
1202  //then add all three vectors to the pair below...
1203  detIdStruct.detidV.push_back(std::make_pair(ONids, psuStruct.changeDate[dp]));
1204 
1205  //Set the status to ON
1206  detIdStruct.StatusGood.push_back(true);
1207 
1208  //Set the flag for LV/HV:
1209  detIdStruct.isHV.push_back(1); //HV
1210 
1211  //Set the PSUChannel (I guess for debug purposes?)
1212  detIdStruct.psuName.push_back(PSUChannel);
1213  }
1214  }
1215  }
1216  } //End of if dpname not "UNKNOWN"
1217  else {
1218  //if (debug) {
1219  //std::cout<<"PSU Channel name WAS NOT RECOGNIZED"<<std::endl;
1220  //}
1221  detIdStruct.notMatched++;
1222  }
1223  } //End of the loop over all PSUChannels reported by the DB query.
1224  //At this point we need to (over)write the 2 files that will keep the HVUnmapped and HVCrosstalking channels status:
1225  std::ofstream ofsUnmapped("HVUnmappedChannelState.dat");
1226  for (std::map<std::string, bool>::iterator it = UnmappedState.begin(); it != UnmappedState.end(); it++) {
1227  ofsUnmapped << it->first << "\t" << it->second << std::endl;
1228  }
1229  std::ofstream ofsCrosstalking("HVCrosstalkingChannelState.dat");
1230  for (std::map<std::string, bool>::iterator it = CrosstalkingState.begin(); it != CrosstalkingState.end(); it++) {
1231  ofsCrosstalking << it->first << "\t" << it->second << std::endl;
1232  }
1233 
1234  removeDuplicates(numLvBad);
1235  removeDuplicates(numHvBad);
1236 
1237  // useful debugging stuff!
1238  if (debug_) {
1239  std::cout << "Number of channels that turned OFF in this O2O interval" << std::endl;
1240  std::cout << "Channel000 = " << ch0bad << " Channel001 = " << ch1bad << std::endl;
1241  std::cout << "Channel002 = " << ch2bad << " Channel003 = " << ch3bad << std::endl;
1242  std::cout << "Number of LV detIDs that turned OFF in this O2O interval = " << numLvBad.size() << std::endl;
1243  std::cout << "Number of HV detIDs that turned OFF in this O2O interval = " << numHvBad.size() << std::endl;
1244  }
1245 
1246  LogTrace("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::" << __func__
1247  << "]: Number of PSUs retrieved from DB with map information "
1248  << detIdStruct.detidV.size();
1249  LogTrace("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::" << __func__
1250  << "]: Number of PSUs retrieved from DB with no map information "
1251  << detIdStruct.notMatched;
1252 
1253  unsigned int dupCount = 0;
1254  for (unsigned int t = 0; t < numLvBad.size(); t++) {
1255  std::vector<unsigned int>::iterator iter = std::find(numHvBad.begin(), numHvBad.end(), numLvBad[t]);
1256  if (iter != numHvBad.end()) {
1257  dupCount++;
1258  }
1259  }
1260  if (debug_)
1261  std::cout << "Number of channels for which LV & HV turned OFF in this O2O interval = " << dupCount << std::endl;
1262 }
std::map< std::string, std::vector< uint32_t > > getHVUnmappedMap()
Extension to SiStripConfigDb to map PSU channels to DetIDs using DCU-PSU map and DCU-DetID map...
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void removeDuplicates(std::vector< uint32_t > &vec)
bool FileExists(std::string filename)
std::vector< uint32_t > getLvDetID(std::string psu)
void getHvDetID(std::string psuchannel, std::vector< uint32_t > &ids, std::vector< uint32_t > &unmapped_ids, std::vector< uint32_t > &crosstalking_ids)
#define LogTrace(id)
void BuildMap(const std::string &mapFile, const bool debug)
std::map< std::string, std::vector< uint32_t > > getHVCrosstalkingMap()
DQMChannel Channel
std::string timeToStream(const coral::TimeStamp &coralTime, const string &comment="")
void SiStripDetVOffBuilder::discardIOVs ( std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &  it,
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &  initialIt,
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > &  resultVec,
const bool  last,
const unsigned int  first 
)

Removes IOVs as dictated by reduction.

Definition at line 564 of file SiStripDetVOffBuilder.cc.

References gather_cfg::cout, and debug_.

Referenced by getPayloadStats(), and reduce().

568  {
569  if (debug_) {
570  cout << "first (1->means the sequence started at the first timestamp in the query results, 0-> that it did not)= "
571  << first << endl;
572  cout << "initial->first (initial SiStripDetVOff object of the IOV sequence)= " << initialIt->first
573  << ", second (initial timestamp of the IOV sequence) = " << initialIt->second << endl;
574  cout << "last (0->means that the sequence is not ending with the last item in the query results, 1-> that it "
575  "DOES!)= "
576  << last << endl;
577  }
578  if (last == true) {
579  resultVec.erase(initialIt + first, it + 1);
580  // Minus 2 because it will be incremented at the end of the loop becoming end()-1.
581  it = resultVec.end() - 2;
582  } else {
583  it = resultVec.erase(initialIt + first, it);
584  }
585 }
pair< int, int > SiStripDetVOffBuilder::extractDetIdVector ( const unsigned int  i,
SiStripDetVOff modV,
DetIdListTimeAndStatus detIdStruct 
)
private

Definition at line 1272 of file SiStripDetVOffBuilder.cc.

References gather_cfg::cout, debug_, mps_fire::i, SiStripDetVOffBuilder::DetIdListTimeAndStatus::isHV, psuDetIdMapFile_, SiStripDetVOffBuilder::DetIdListTimeAndStatus::psuName, SiStripDetVOffBuilder::DetIdListTimeAndStatus::StatusGood, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by BuildDetVOffObj().

1274  {
1275  // set the LV and HV off flags ready for storing
1276  int lv_off = -1, hv_off = -1;
1277  if (detIdStruct.isHV[i] == 0) {
1278  lv_off = !(detIdStruct.StatusGood[i]);
1279  }
1280  if (detIdStruct.isHV[i] == 1) {
1281  hv_off = !(detIdStruct.StatusGood[i]);
1282 
1283  // TESTING WITHOUT THE FIX
1284  // -----------------------
1285 
1286  if (psuDetIdMapFile_.empty()) {
1287  // temporary fix to handle the fact that we don't know which HV channel the detIDs are associated to
1288  if (i > 0) {
1289  std::string iChannel = detIdStruct.psuName[i].substr((detIdStruct.psuName[i].size() - 3));
1290  std::string iPsu = detIdStruct.psuName[i].substr(0, (detIdStruct.psuName[i].size() - 3));
1291  if (iChannel == "002" || iChannel == "003") {
1292  bool lastStatusOfOtherChannel = true;
1293  for (unsigned int j = 0; j < i; j++) {
1294  std::string jPsu = detIdStruct.psuName[j].substr(0, (detIdStruct.psuName[j].size() - 3));
1295  std::string jChannel = detIdStruct.psuName[j].substr((detIdStruct.psuName[j].size() - 3));
1296  if (iPsu == jPsu && iChannel != jChannel && (jChannel == "002" || jChannel == "003")) {
1297  if (debug_)
1298  cout << "psu[" << i << "] = " << detIdStruct.psuName[i]
1299  << " with status = " << detIdStruct.StatusGood[i] << " and psu[" << j
1300  << "] = " << detIdStruct.psuName[j] << " with status " << detIdStruct.StatusGood[j] << endl;
1301  lastStatusOfOtherChannel = detIdStruct.StatusGood[j];
1302  }
1303  }
1304  if (detIdStruct.StatusGood[i] != lastStatusOfOtherChannel) {
1305  if (debug_)
1306  cout << "turning off hv" << endl;
1307  hv_off = 1;
1308  }
1309  }
1310  }
1311  }
1312 
1313  // -----------------------
1314  }
1315 
1316  return make_pair(hv_off, lv_off);
1317 }
bool SiStripDetVOffBuilder::FileExists ( std::string  filename)

Definition at line 747 of file SiStripDetVOffBuilder.cc.

References tkal_create_file_lists::FileInfo, and trackingPlots::stat.

Referenced by buildPSUdetIdMap(), and getPayloadStats().

747  {
748  //Helper method to check if local files exist (needed to handle HVUnmapped, HVCrosstalking modules)
749  struct stat FileInfo;
750  bool Existence;
751  int Stat;
752  //Try to get file attributes
753  Stat = stat(FileName.c_str(), &FileInfo);
754  if (Stat == 0) {
755  Existence = true;
756  } else {
757  Existence = false;
758  }
759  return Existence;
760 }
cond::Time_t SiStripDetVOffBuilder::findMostRecentTimeStamp ( const std::vector< coral::TimeStamp > &  coralDate)
private

Definition at line 507 of file SiStripDetVOffBuilder.cc.

References gather_cfg::cout, debug_, getCondTime(), and mps_fire::i.

Referenced by lastValue(), and lastValueFromFile().

507  {
508  cond::Time_t latestDate = getCondTime(coralDate[0]);
509 
510  if (debug_) {
511  std::cout << "latestDate: condTime = " << (latestDate >> 32) << " - "
512  << (latestDate & 0xFFFFFFFF)
513  //<< " coralTime= " << coralDate[0]
514  << std::endl;
515  }
516 
517  for (unsigned int i = 1; i < coralDate.size(); i++) {
518  cond::Time_t testDate = getCondTime(coralDate[i]);
519  if (testDate > latestDate) {
520  latestDate = testDate;
521  }
522  }
523  return latestDate;
524 }
unsigned long long Time_t
Definition: Time.h:16
cond::Time_t getCondTime(const coral::TimeStamp &coralTime)
int SiStripDetVOffBuilder::findSetting ( uint32_t  id,
const coral::TimeStamp &  changeDate,
const std::vector< uint32_t > &  settingID,
const std::vector< coral::TimeStamp > &  settingDate 
)
private

Returns the PSU channel setting, based on date. Works from DP ID.

Definition at line 324 of file SiStripDetVOffBuilder.cc.

References mps_fire::i, createfilelist::int, and protons_cff::time.

Referenced by lastValue(), and lastValueFromFile().

327  {
328  int setting = -1;
329  // find out how many channel entries there are
330  std::vector<int> locations;
331  for (unsigned int i = 0; i < settingID.size(); i++) {
332  if (settingID[i] == id) {
333  locations.push_back((int)i);
334  }
335  }
336 
337  // simple cases
338  if (locations.empty()) {
339  setting = -1;
340  } else if (locations.size() == 1) {
341  setting = locations[0];
342  }
343  // more than one entry for this channel
344  // NB. entries ordered by date!
345  else {
346  for (unsigned int j = 0; j < locations.size(); j++) {
347 #ifdef USING_NEW_CORAL
348  const boost::posix_time::ptime& testSec = changeDate.time();
349  const boost::posix_time::ptime& limitSec = settingDate[(unsigned int)locations[j]].time();
350 #else
351  long testSec = changeDate.time().ns();
352  long limitSec = settingDate[(unsigned int)locations[j]].time().ns();
353 #endif
354  if (testSec >= limitSec) {
355  setting = locations[j];
356  }
357  }
358  }
359  return setting;
360 }
int SiStripDetVOffBuilder::findSetting ( std::string  dpname,
const coral::TimeStamp &  changeDate,
const std::vector< std::string > &  settingDpname,
const std::vector< coral::TimeStamp > &  settingDate 
)
private

Returns the PSU channel setting, based on date. Works from PSU channel name. Overloaded.

Definition at line 362 of file SiStripDetVOffBuilder.cc.

References mps_fire::i, createfilelist::int, and protons_cff::time.

365  {
366  int setting = -1;
367  // find out how many channel entries there are
368  std::vector<int> locations;
369  for (unsigned int i = 0; i < settingDpname.size(); i++) {
370  if (settingDpname[i] == dpname) {
371  locations.push_back((int)i);
372  }
373  }
374 
375  // simple cases
376  if (locations.empty()) {
377  setting = -1;
378  } else if (locations.size() == 1) {
379  setting = locations[0];
380  }
381  // more than one entry for this channel
382  // NB. entries ordered by date!
383  else {
384  for (unsigned int j = 0; j < locations.size(); j++) {
385 #ifdef USING_NEW_CORAL
386  const boost::posix_time::ptime& testSec = changeDate.time();
387  const boost::posix_time::ptime& limitSec = settingDate[(unsigned int)locations[j]].time();
388 #else
389  long testSec = changeDate.time().ns();
390  long limitSec = settingDate[(unsigned int)locations[j]].time().ns();
391 #endif
392  if (testSec >= limitSec) {
393  setting = locations[j];
394  }
395  }
396  }
397  return setting;
398 }
cond::Time_t SiStripDetVOffBuilder::getCondTime ( const coral::TimeStamp &  coralTime)
private

Utility code to convert a coral timestamp to the correct time format for O2O timestamp.

Definition at line 467 of file SiStripDetVOffBuilder.cc.

References cond::time::from_boost().

Referenced by BuildDetVOffObj(), findMostRecentTimeStamp(), and getCoralTime().

467  {
468  // const boost::posix_time::ptime& t = coralTime.time();
469  cond::Time_t condTime = cond::time::from_boost(coralTime.time());
470 
471  // cout << "[SiStripDetVOffBuilder::getCondTime] Converting CoralTime into CondTime: "
472  // << " coralTime = (coralTimeInNs) " << coralTime.total_nanoseconds() << " condTime " << (condTime>> 32) << " - " << (condTime & 0xFFFFFFFF) << endl;
473 
474  return condTime;
475 }
unsigned long long Time_t
Definition: Time.h:16
Time_t from_boost(boost::posix_time::ptime bt)
coral::TimeStamp SiStripDetVOffBuilder::getCoralTime ( cond::Time_t  iovTime)
private

Utility code to convert an O2O timestamp into a coral timestamp.

Definition at line 477 of file SiStripDetVOffBuilder.cc.

References gather_cfg::cout, debug_, getCondTime(), and cond::time::to_boost().

Referenced by statusChange().

477  {
478  // This method is defined in the TimeConversions header and it does the following:
479  // - takes the seconds part of the iovTime (bit-shifting of 32)
480  // - adds the nanoseconds part (first 32 bits mask)
481  // - adds the time0 that is the time from begin of times (boost::posix_time::from_time_t(0);)
482  coral::TimeStamp coralTime(cond::time::to_boost(iovTime));
483 
484  if (debug_) {
485  unsigned long long iovSec = iovTime >> 32;
486  uint32_t iovNanoSec = uint32_t(iovTime);
487  cond::Time_t testTime = getCondTime(coralTime);
488  cout << "[SiStripDetVOffBuilder::getCoralTime] Converting CondTime into CoralTime: "
489  << " condTime = " << iovSec << " - " << iovNanoSec << " getCondTime(coralTime) = " << (testTime >> 32) << " - "
490  << (testTime & 0xFFFFFFFF) << endl;
491  }
492 
493  return coralTime;
494 }
unsigned long long Time_t
Definition: Time.h:16
cond::Time_t getCondTime(const coral::TimeStamp &coralTime)
boost::posix_time::ptime to_boost(Time_t iValue)
std::vector<std::pair<SiStripDetVOff*, cond::Time_t> > SiStripDetVOffBuilder::getModulesVOff ( )
inline

Return modules Off vector of objects.

Definition at line 48 of file SiStripDetVOffBuilder.h.

References deltaTmin_, maxIOVlength_, modulesOff, and reduction().

Referenced by SiStripDetVOffHandler::analyze().

48  {
50  return modulesOff;
51  }
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > modulesOff
void reduction(const uint32_t deltaTmin, const uint32_t maxIOVlength)
std::vector<std::vector<uint32_t> > SiStripDetVOffBuilder::getPayloadStats ( )
inline

Return statistics about payloads transferred for storage in logDB.

Definition at line 53 of file SiStripDetVOffBuilder.h.

References discardIOVs(), FileExists(), corrVsCorr::filename, plotBeamSpotDB::first, plotBeamSpotDB::last, payloadStats, reduce(), reduction(), setLastSiStripDetVOff(), and AlCaHLTBitMon_QueryRunRegistry::string.

53 { return payloadStats; }
std::vector< std::vector< uint32_t > > payloadStats
void SiStripDetVOffBuilder::lastValue ( TimesAndValues tStruct)
private

Definition at line 651 of file SiStripDetVOffBuilder.cc.

References SiStripDetVOffBuilder::TimesAndValues::actualStatus, SiStripDetVOffBuilder::TimesAndValues::actualValue, SiStripDetVOffBuilder::TimesAndValues::changeDate, coralInterface, SiStripDetVOffBuilder::TimesAndValues::dpname, findMostRecentTimeStamp(), findSetting(), highVoltageOnThreshold_, SiStripDetVOffBuilder::TimesAndValues::latestTime, LogDebug, tmax, tmin, tsetmin, and whichTable.

Referenced by BuildDetVOffObj().

651  {
652  coralInterface->doQuery(whichTable, tmin, tmax, tStruct.changeDate, tStruct.actualValue, tStruct.dpname);
653 
654  tStruct.latestTime = findMostRecentTimeStamp(tStruct.changeDate);
655 
656  // preset the size of the status vector
657  tStruct.actualStatus.resize(tStruct.actualValue.size());
658 
659  // retrieve the channel settings from the PVSS DB
660  std::vector<coral::TimeStamp> settingDate;
661  std::vector<float> settingValue;
662  std::vector<std::string> settingDpname;
663  std::vector<uint32_t> settingDpid;
664  coralInterface->doSettingsQuery(tsetmin, tmax, settingDate, settingValue, settingDpname, settingDpid);
665  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Channel settings retrieved";
666  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Number of PSU channels: "
667  << settingDpname.size();
668 
669  unsigned int missing = 0;
670  std::stringstream ss;
671  for (unsigned int j = 0; j < tStruct.dpname.size(); j++) {
672  int setting = findSetting(tStruct.dpname[j], tStruct.changeDate[j], settingDpname, settingDate);
673  if (setting >= 0) {
674  if (tStruct.actualValue[j] > (highVoltageOnThreshold_ * (settingValue[setting]))) {
675  tStruct.actualStatus[j] = 1;
676  } else {
677  tStruct.actualStatus[j] = 0;
678  }
679  } else {
680  tStruct.actualStatus[j] = -1;
681  missing++;
682  ss << "Channel = " << tStruct.dpname[j] << std::endl;
683  }
684  }
685  LogDebug("SiStripDetVOffBuilder")
686  << "[SiStripDetVOffBuilder::BuildDetVOff]: Number of channels with no setting information " << missing;
687  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Number of entries in dpname vector "
688  << tStruct.dpname.size();
689 }
#define LogDebug(id)
int findSetting(uint32_t id, const coral::TimeStamp &changeDate, const std::vector< uint32_t > &settingID, const std::vector< coral::TimeStamp > &settingDate)
std::unique_ptr< SiStripCoralIface > coralInterface
cond::Time_t findMostRecentTimeStamp(const std::vector< coral::TimeStamp > &coralDate)
void SiStripDetVOffBuilder::lastValueFromFile ( TimesAndValues tStruct)
private

Definition at line 691 of file SiStripDetVOffBuilder.cc.

References SiStripDetVOffBuilder::TimesAndValues::actualStatus, SiStripDetVOffBuilder::TimesAndValues::actualValue, SiStripDetVOffBuilder::TimesAndValues::changeDate, coralInterface, SiStripDetVOffBuilder::TimesAndValues::dpid, SiStripDetVOffBuilder::TimesAndValues::dpname, findMostRecentTimeStamp(), findSetting(), highVoltageOnThreshold_, SiStripDetVOffBuilder::TimesAndValues::latestTime, LogDebug, readLastValueFromFile(), tmax, and tsetmin.

Referenced by BuildDetVOffObj().

691  {
692  readLastValueFromFile(tStruct.dpid, tStruct.actualValue, tStruct.changeDate);
693  tStruct.latestTime = findMostRecentTimeStamp(tStruct.changeDate);
694  LogDebug("SiStripDetVOffBuilder")
695  << "[SiStripDetVOffBuilder::BuildDetVOff]: File access complete \n\t Number of values read from file: "
696  << tStruct.dpid.size();
697 
698  // retrieve the channel settings from the PVSS DB
699  std::vector<coral::TimeStamp> settingDate;
700  std::vector<float> settingValue;
701  std::vector<std::string> settingDpname;
702  std::vector<uint32_t> settingDpid;
703 
704  coralInterface->doSettingsQuery(tsetmin, tmax, settingDate, settingValue, settingDpname, settingDpid);
705  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Channel settings retrieved";
706  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Number of PSU channels: "
707  << settingDpname.size();
708 
709  unsigned int missing = 0;
710  std::stringstream ss;
711  // need to get the PSU channel names from settings
712  tStruct.dpname.clear();
713  tStruct.dpname.resize(tStruct.dpid.size());
714  for (unsigned int j = 0; j < tStruct.dpid.size(); j++) {
715  int setting = findSetting(tStruct.dpid[j], tStruct.changeDate[j], settingDpid, settingDate);
716  if (setting >= 0) {
717  if (tStruct.actualValue[j] > (highVoltageOnThreshold_ * settingValue[setting])) {
718  tStruct.actualStatus[j] = 1;
719  } else {
720  tStruct.actualStatus[j] = 0;
721  }
722  tStruct.dpname[j] = settingDpname[setting];
723  } else {
724  tStruct.actualStatus[j] = -1;
725  tStruct.dpname[j] = "UNKNOWN";
726  missing++;
727  ss << "DP ID = " << tStruct.dpid[j] << std::endl;
728  }
729  }
730  LogDebug("SiStripDetVOffBuilder") << "Number of missing psu channels = " << missing << std::endl;
731  LogDebug("SiStripDetVOffBuilder") << "IDs are: = " << ss.str();
732 }
#define LogDebug(id)
int findSetting(uint32_t id, const coral::TimeStamp &changeDate, const std::vector< uint32_t > &settingID, const std::vector< coral::TimeStamp > &settingDate)
std::unique_ptr< SiStripCoralIface > coralInterface
void readLastValueFromFile(std::vector< uint32_t > &dpIDs, std::vector< float > &vmonValues, std::vector< coral::TimeStamp > &dateChange)
cond::Time_t findMostRecentTimeStamp(const std::vector< coral::TimeStamp > &coralDate)
void SiStripDetVOffBuilder::printPar ( std::stringstream &  ss,
const std::vector< int > &  par 
)
private

Definition at line 90 of file SiStripDetVOffBuilder.cc.

References heppy_batch::val.

Referenced by SiStripDetVOffBuilder().

90  {
91  for (int val : par) {
92  ss << val << " ";
93  }
94 }
void SiStripDetVOffBuilder::readLastValueFromFile ( std::vector< uint32_t > &  dpIDs,
std::vector< float > &  vmonValues,
std::vector< coral::TimeStamp > &  dateChange 
)
private

Extract the lastValue values from file rather than from the PVSS cond DB.

Definition at line 400 of file SiStripDetVOffBuilder.cc.

References indexGen::date, util.getRunInfo::day(), mps_fire::i, lastValueFileName, mps_splice::line, edm::second(), AlCaHLTBitMon_QueryRunRegistry::string, and create_public_lumi_plots::year.

Referenced by lastValueFromFile().

402  {
403  std::ifstream lastValueFile(lastValueFileName.c_str());
404  if (lastValueFile.bad()) {
405  edm::LogError("SiStripDetVOffBuilder")
406  << "[SiStripDetVOffBuilder::" << __func__ << "]: last Value file does not exist!";
407  return;
408  }
409 
410  dpIDs.clear();
411  vmonValues.clear();
412  dateChange.clear();
413  std::vector<std::string> changeDates;
414 
416  // remove the first line as it is the title line
417  // std::getline(lastValueFile,line);
418  // line.clear();
419  // now extract data
420  while (std::getline(lastValueFile, line)) {
421  std::istringstream ss(line);
422  uint32_t dpid;
423  float vmon;
424  std::string changeDate;
425  ss >> std::skipws >> dpid >> vmon >> changeDate;
426  dpIDs.push_back(dpid);
427  vmonValues.push_back(vmon);
428  changeDates.push_back(changeDate);
429  }
430  lastValueFile.close();
431 
432  // Now convert dates to coral::TimeStamp
433  for (unsigned int i = 0; i < changeDates.size(); i++) {
434  std::string part = changeDates[i].substr(0, 4);
435  int year = atoi(part.c_str());
436  part.clear();
437 
438  part = changeDates[i].substr(5, 2);
439  int month = atoi(part.c_str());
440  part.clear();
441 
442  part = changeDates[i].substr(8, 2);
443  int day = atoi(part.c_str());
444  part.clear();
445 
446  part = changeDates[i].substr(11, 2);
447  int hour = atoi(part.c_str());
448  part.clear();
449 
450  part = changeDates[i].substr(14, 2);
451  int minute = atoi(part.c_str());
452  part.clear();
453 
454  part = changeDates[i].substr(17, 2);
455  int second = atoi(part.c_str());
456  part.clear();
457 
458  coral::TimeStamp date(year, month, day, hour, minute, second, 0);
459  dateChange.push_back(date);
460  }
461 
462  if (changeDates.size() != dateChange.size()) {
463  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::" << __func__ << "]: date conversion failed!!";
464  }
465 }
U second(std::pair< T, U > const &p)
part
Definition: HCALResponse.h:20
def day(string)
Definition: getRunInfo.py:11
void SiStripDetVOffBuilder::reduce ( std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &  it,
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &  initialIt,
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > &  resultVec,
const bool  last = false 
)

Operates the reduction of the fast sequences of ramping up and down of the voltages.

Definition at line 526 of file SiStripDetVOffBuilder.cc.

References gather_cfg::cout, debug_, discardIOVs(), SoftLeptonByDistance_cfi::distance, plotBeamSpotDB::first, plotBeamSpotDB::last, and edm::second().

Referenced by getPayloadStats(), and reduction().

529  {
530  //const bool last is set to false by default in the header file...
531  int first = 0;
532  // Check if it is the first
533  if (distance(resultVec.begin(), initialIt) == 0) {
534  first = 1;
535  }
536 
537  if (debug_ && (it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() == 0) &&
538  (it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() == 0)) {
539  cout << "Same number of LV and HV at start and end of sequence: LV off = " << it->first->getLVoffCounts()
540  << " HV off = " << it->first->getHVoffCounts() << endl;
541  }
542 
543  // if it was going off
544  if ((it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() > 0) ||
545  (it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() > 0)) {
546  // Set the time of the current (last) iov as the time of the initial iov of the sequence
547  // replace the first iov with the last one
548  //Naughty use of const bool last... by default it is false (=0), and for the case of the last timestamp in the query results it is set to true(=1) in the call
549  (it + last)->second = (initialIt)->second;
550  discardIOVs(it, initialIt, resultVec, last, 0);
551  if (debug_)
552  cout << "Reducing IOV sequence (going off)" << endl;
553  }
554  // if it was going on
555  else if ((it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() <= 0) ||
556  (it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() <= 0)) {
557  // replace the last minus one iov with the first one
558  discardIOVs(it, initialIt, resultVec, last, first);
559  if (debug_)
560  cout << "Reducing IOV sequence (going on)" << endl;
561  }
562 }
void discardIOVs(std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &it, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &initialIt, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > &resultVec, const bool last, const unsigned int first)
Removes IOVs as dictated by reduction.
U second(std::pair< T, U > const &p)
void SiStripDetVOffBuilder::reduction ( const uint32_t  deltaTmin,
const uint32_t  maxIOVlength 
)

Definition at line 588 of file SiStripDetVOffBuilder.cc.

References KineDebug3::count(), modulesOff, reduce(), and edm::second().

Referenced by getModulesVOff(), and getPayloadStats().

588  {
589  int count = 0;
590  std::vector<std::pair<SiStripDetVOff*, cond::Time_t> >::iterator initialIt;
591 
592  int resultVecSize = modulesOff.size();
593  int resultsIndex = 0;
594 
595  if (resultVecSize > 1) {
596  std::vector<std::pair<SiStripDetVOff*, cond::Time_t> >::iterator it = modulesOff.begin();
597  for (; it != modulesOff.end() - 1; ++it, ++resultsIndex) {
598  unsigned long long deltaT = ((it + 1)->second - it->second) >> 32;
599  unsigned long long deltaTsequence = 0;
600  if (count > 1) {
601  deltaTsequence = ((it + 1)->second - initialIt->second) >> 32;
602  }
603  // Save the initial pair
604  if ((deltaT < deltaTmin) && ((count == 0) || (deltaTsequence < maxIOVlength))) {
605  // If we are not in a the sequence
606  if (count == 0) {
607  initialIt = it;
608  }
609  // Increase the counter in any case.
610  ++count;
611  }
612  // We do it only if the sequence is bigger than two cases
613  else if (count > 1) {
614  reduce(it, initialIt, modulesOff);
615  // reset all
616  count = 0;
617  } else {
618  // reset all
619  count = 0;
620  }
621  // Border case
622  if (resultsIndex == resultVecSize - 2 && count != 0) {
623  reduce(it, initialIt, modulesOff, true);
624  }
625  }
626  }
627 }
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > modulesOff
U second(std::pair< T, U > const &p)
void reduce(std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &it, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &initialIt, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > &resultVec, const bool last=false)
Operates the reduction of the fast sequences of ramping up and down of the voltages.
void SiStripDetVOffBuilder::removeDuplicates ( std::vector< uint32_t > &  vec)
private

Utility code to remove all the duplicates from a vector of uint32_t.

Definition at line 496 of file SiStripDetVOffBuilder.cc.

References jetUpdater_cfi::sort, and tier0::unique().

Referenced by buildPSUdetIdMap().

496  {
497  std::sort(vec.begin(), vec.end());
498  std::vector<uint32_t>::iterator it = std::unique(vec.begin(), vec.end());
499  vec.resize(it - vec.begin());
500 }
def unique(seq, keepstr=True)
Definition: tier0.py:25
void SiStripDetVOffBuilder::setLastSiStripDetVOff ( SiStripDetVOff lastPayload,
cond::Time_t  lastTimeStamp 
)

Store the last payload transferred to DB as starting point for creation of new object list. ONLY WORKS FOR STATUSCHANGE OPTION.

Definition at line 502 of file SiStripDetVOffBuilder.cc.

References lastStoredCondObj.

Referenced by SiStripDetVOffHandler::analyze(), and getPayloadStats().

502  {
503  lastStoredCondObj.first = lastPayload;
504  lastStoredCondObj.second = lastTimeStamp;
505 }
std::pair< SiStripDetVOff *, cond::Time_t > lastStoredCondObj
void SiStripDetVOffBuilder::setPayloadStats ( const uint32_t  afterV,
const uint32_t  numAdded,
const uint32_t  numRemoved 
)
private

Definition at line 1264 of file SiStripDetVOffBuilder.cc.

References payloadStats.

Referenced by BuildDetVOffObj().

1264  {
1265  std::vector<uint32_t> pStats(3, 0);
1266  pStats.push_back(afterV);
1267  pStats.push_back(numAdded);
1268  pStats.push_back(numRemoved);
1269  payloadStats.push_back(pStats);
1270 }
std::vector< std::vector< uint32_t > > payloadStats
void SiStripDetVOffBuilder::statusChange ( cond::Time_t lastTime,
TimesAndValues tStruct 
)
private

Definition at line 629 of file SiStripDetVOffBuilder.cc.

References SiStripDetVOffBuilder::TimesAndValues::actualStatus, SiStripDetVOffBuilder::TimesAndValues::actualValue, SiStripDetVOffBuilder::TimesAndValues::changeDate, coralInterface, SiStripDetVOffBuilder::TimesAndValues::dpname, getCoralTime(), tmax, tmin, heppy_batch::val, and whichTable.

Referenced by BuildDetVOffObj().

629  {
630  // Setting tmin to the last value IOV of the database tag
631  if (lastTime > 0) {
632  tmin = getCoralTime(lastTime);
633  }
634 
635  coralInterface->doQuery(whichTable, tmin, tmax, tStruct.changeDate, tStruct.actualValue, tStruct.dpname);
636  //UNIT TEST DEBUG to bypass the query wait time!!!
637  //coral::TimeStamp testtime=getCoralTime(lastTime);
638  //tStruct.changeDate.push_back(testtime);
639  //tStruct.actualValue.push_back(1.);
640  //tStruct.dpname.push_back("cms_trk_dcs_03:CAEN/CMS_TRACKER_SY1527_3/branchController00/easyCrate3/easyBoard17/channel002");
641 
642  // preset the size of the status vector
643  tStruct.actualStatus.resize(tStruct.actualValue.size());
644  tStruct.actualStatus.clear();
645 
646  for (float val : tStruct.actualValue) {
647  tStruct.actualStatus.push_back(static_cast<int>(val));
648  }
649 }
std::unique_ptr< SiStripCoralIface > coralInterface
coral::TimeStamp getCoralTime(cond::Time_t iovTime)
string SiStripDetVOffBuilder::timeToStream ( const coral::TimeStamp &  coralTime,
const string &  comment = "" 
)
private

Definition at line 740 of file SiStripDetVOffBuilder.cc.

Referenced by buildPSUdetIdMap().

740  {
741  stringstream ss;
742  ss << "Starting from IOV time in the database : year = " << coralTime.year() << ", month = " << coralTime.month()
743  << ", day = " << coralTime.day() << ", hour = " << coralTime.hour() << ", minute = " << coralTime.minute()
744  << ", second = " << coralTime.second() << ", nanosecond = " << coralTime.nanosecond() << std::endl;
745  return ss.str();
746 }
string SiStripDetVOffBuilder::timeToStream ( const cond::Time_t condTime,
const string &  comment = "" 
)
private

Definition at line 734 of file SiStripDetVOffBuilder.cc.

734  {
735  stringstream ss;
736  ss << comment << (condTime >> 32) << " - " << (condTime & 0xFFFFFFFF) << std::endl;
737  return ss.str();
738 }

Friends And Related Function Documentation

friend class TestSiStripDetVOffBuilder
friend

Definition at line 38 of file SiStripDetVOffBuilder.h.

Member Data Documentation

std::string SiStripDetVOffBuilder::authenticationPath
private

Definition at line 120 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), and SiStripDetVOffBuilder().

std::unique_ptr<SiStripCoralIface> SiStripDetVOffBuilder::coralInterface
private
bool SiStripDetVOffBuilder::debug_
private
uint32_t SiStripDetVOffBuilder::deltaTmin_
private

Definition at line 128 of file SiStripDetVOffBuilder.h.

Referenced by getModulesVOff().

std::string SiStripDetVOffBuilder::detIdListFile_
private

Definition at line 130 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj().

std::string SiStripDetVOffBuilder::excludedDetIdListFile_
private

Definition at line 131 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj().

bool SiStripDetVOffBuilder::fromFile
private

Definition at line 123 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), and SiStripDetVOffBuilder().

double SiStripDetVOffBuilder::highVoltageOnThreshold_
private

Definition at line 133 of file SiStripDetVOffBuilder.h.

Referenced by lastValue(), and lastValueFromFile().

std::pair<SiStripDetVOff*, cond::Time_t> SiStripDetVOffBuilder::lastStoredCondObj
private
std::string SiStripDetVOffBuilder::lastValueFileName
private

Definition at line 122 of file SiStripDetVOffBuilder.h.

Referenced by readLastValueFromFile(), and SiStripDetVOffBuilder().

uint32_t SiStripDetVOffBuilder::maxIOVlength_
private

Definition at line 128 of file SiStripDetVOffBuilder.h.

Referenced by getModulesVOff().

std::vector<std::pair<SiStripDetVOff*, cond::Time_t> > SiStripDetVOffBuilder::modulesOff
private

Definition at line 115 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), getModulesVOff(), and reduction().

std::string SiStripDetVOffBuilder::onlineDbConnectionString
private

Definition at line 119 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), and SiStripDetVOffBuilder().

std::vector<std::vector<uint32_t> > SiStripDetVOffBuilder::payloadStats
private

Definition at line 114 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), getPayloadStats(), and setPayloadStats().

std::string SiStripDetVOffBuilder::psuDetIdMapFile_
private
std::vector<int> SiStripDetVOffBuilder::tDefault
private

Definition at line 127 of file SiStripDetVOffBuilder.h.

coral::TimeStamp SiStripDetVOffBuilder::tmax
private
std::vector<int> SiStripDetVOffBuilder::tmax_par
private

Definition at line 127 of file SiStripDetVOffBuilder.h.

Referenced by SiStripDetVOffBuilder().

coral::TimeStamp SiStripDetVOffBuilder::tmin
private

Definition at line 126 of file SiStripDetVOffBuilder.h.

Referenced by lastValue(), SiStripDetVOffBuilder(), and statusChange().

std::vector<int> SiStripDetVOffBuilder::tmin_par
private

Definition at line 127 of file SiStripDetVOffBuilder.h.

Referenced by SiStripDetVOffBuilder().

std::vector<int> SiStripDetVOffBuilder::tset_par
private

Definition at line 127 of file SiStripDetVOffBuilder.h.

Referenced by SiStripDetVOffBuilder().

coral::TimeStamp SiStripDetVOffBuilder::tsetmin
private

Definition at line 126 of file SiStripDetVOffBuilder.h.

Referenced by lastValue(), lastValueFromFile(), and SiStripDetVOffBuilder().

bool SiStripDetVOffBuilder::whichQuery
private

Definition at line 78 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), and SiStripDetVOffBuilder().

std::string SiStripDetVOffBuilder::whichTable
private