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 39 of file SiStripDetVOffBuilder.h.

Member Typedef Documentation

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

Definition at line 77 of file SiStripDetVOffBuilder.h.

Constructor & Destructor Documentation

SiStripDetVOffBuilder::~SiStripDetVOffBuilder ( )

Destructor.

Definition at line 79 of file SiStripDetVOffBuilder.cc.

79  {
80  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::" << __func__ << "]: destructing ...";
81 }
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.

5  :
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 {
23  lastStoredCondObj.first = nullptr;
24  lastStoredCondObj.second = 0;
25 
26  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::SiStripDetVOffBuilder] constructor" << endl;
27 
28  // set up vectors based on pset parameters (tDefault purely for initialization)
29 
30  whichQuery=(whichTable == "STATUSCHANGE" || (whichTable == "LASTVALUE" && !fromFile));
31 
32  //Define the query interval [Tmin, Tmax]
33  //where Tmax comes from the cfg
34  // Tmin comes from the cfg for the first o2o, after that it is extracted from Offline DB
35 
36  tmax = coral::TimeStamp(tmax_par[0],tmax_par[1],tmax_par[2],tmax_par[3],tmax_par[4],tmax_par[5],tmax_par[6]);
37 
38  if (whichQuery) {
39  // Is there a better way to do this? TODO - investigate
40  tmin=coral::TimeStamp(tmin_par[0],tmin_par[1],tmin_par[2],tmin_par[3],tmin_par[4],tmin_par[5],tmin_par[6]);
41  }
42 
43  if (whichTable == "LASTVALUE") {
44  tsetmin = 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") << "[SiStripDetVOffBuilder::SiStripDetVOffBuilder] DB name has not been set properly ... Returning ...";
49  return;
50  }
51 
52  if (fromFile && whichTable == "LASTVALUE" && lastValueFileName.empty()) {
53  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::SiStripDetVOffBuilder] File expected for lastValue table, but filename not specified ... Returning ...";
54  return;
55  }
56 
57  // write out the parameters
58  std::stringstream ss;
59  ss << "[SiStripDetVOffBuilder::SiStripDetVOffBuilder]\n"
60  << " Parameters:\n"
61  << " DB connection string: " << onlineDbConnectionString << "\n"
62  << " Authentication path: " << authenticationPath << "\n"
63  << " Table to be queried: " << whichTable << "\n"
64  << " MapFile: " << psuDetIdMapFile_ << "\n";
65 
66  if (whichQuery){
67  ss << " Tmin: "; printPar(ss,tmin_par); ss << std::endl;
68  }
69  ss << " Tmax: " ; printPar(ss,tmax_par); ss << std::endl;
70 
71  if (whichTable == "LASTVALUE"){
72  ss << " TSetMin: "; printPar(ss,tset_par); ss << std::endl;
73  }
74  edm::LogError("SiStripDetVOffBuilder") << ss.str();
75 
76 }
T getParameter(std::string const &) const
void printPar(std::stringstream &ss, const std::vector< int > &par)
std::vector< int > tDefault
std::vector< int > tmax_par
std::vector< int > tmin_par
std::pair< SiStripDetVOff *, cond::Time_t > lastStoredCondObj
std::vector< int > tset_par

Member Function Documentation

void SiStripDetVOffBuilder::BuildDetVOffObj ( )

Build the SiStripDetVOff object for transfer.

Definition at line 89 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().

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

Definition at line 716 of file SiStripDetVOffBuilder.cc.

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

Referenced by BuildDetVOffObj().

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

References gather_cfg::cout, and debug_.

Referenced by getPayloadStats(), and reduce().

522 {
523  if( debug_ ) {
524  cout << "first (1->means the sequence started at the first timestamp in the query results, 0-> that it did not)= " << first << endl;
525  cout << "initial->first (initial SiStripDetVOff object of the IOV sequence)= " << initialIt->first << ", second (initial timestamp of the IOV sequence) = " << initialIt->second << endl;
526  cout << "last (0->means that the sequence is not ending with the last item in the query results, 1-> that it DOES!)= " << last << endl;
527  }
528  if( last == true ) {
529  resultVec.erase(initialIt+first, it+1);
530  // Minus 2 because it will be incremented at the end of the loop becoming end()-1.
531  it = resultVec.end()-2;
532  }
533  else {
534  it = resultVec.erase(initialIt+first, it);
535  }
536 }
pair< int, int > SiStripDetVOffBuilder::extractDetIdVector ( const unsigned int  i,
SiStripDetVOff modV,
DetIdListTimeAndStatus detIdStruct 
)
private

Definition at line 1188 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().

1189 {
1190  // set the LV and HV off flags ready for storing
1191  int lv_off = -1, hv_off = -1;
1192  if (detIdStruct.isHV[i] == 0) {lv_off = !(detIdStruct.StatusGood[i]);}
1193  if (detIdStruct.isHV[i] == 1) {
1194  hv_off = !(detIdStruct.StatusGood[i]);
1195 
1196  // TESTING WITHOUT THE FIX
1197  // -----------------------
1198 
1199  if( psuDetIdMapFile_.empty() ) {
1200  // temporary fix to handle the fact that we don't know which HV channel the detIDs are associated to
1201  if (i > 0) {
1202  std::string iChannel = detIdStruct.psuName[i].substr( (detIdStruct.psuName[i].size()-3) );
1203  std::string iPsu = detIdStruct.psuName[i].substr(0, (detIdStruct.psuName[i].size()-3) );
1204  if (iChannel == "002" || iChannel == "003") {
1205  bool lastStatusOfOtherChannel = true;
1206  for (unsigned int j = 0; j < i; j++) {
1207  std::string jPsu = detIdStruct.psuName[j].substr(0, (detIdStruct.psuName[j].size()-3) );
1208  std::string jChannel = detIdStruct.psuName[j].substr( (detIdStruct.psuName[j].size()-3) );
1209  if (iPsu == jPsu && iChannel != jChannel && (jChannel == "002" || jChannel == "003")) {
1210  if( debug_ ) cout << "psu["<<i<<"] = " << detIdStruct.psuName[i] << " with status = " << detIdStruct.StatusGood[i] << " and psu["<<j<<"] = " << detIdStruct.psuName[j] << " with status " << detIdStruct.StatusGood[j] << endl;
1211  lastStatusOfOtherChannel = detIdStruct.StatusGood[j];
1212  }
1213  }
1214  if (detIdStruct.StatusGood[i] != lastStatusOfOtherChannel) {
1215  if( debug_ ) cout << "turning off hv" << endl;
1216  hv_off = 1;
1217  }
1218  }
1219  }
1220  }
1221 
1222  // -----------------------
1223 
1224  }
1225 
1226  return make_pair(hv_off, lv_off);
1227 }
bool SiStripDetVOffBuilder::FileExists ( std::string  filename)

Definition at line 700 of file SiStripDetVOffBuilder.cc.

References trackingPlots::stat.

Referenced by buildPSUdetIdMap(), and getPayloadStats().

700  {
701  //Helper method to check if local files exist (needed to handle HVUnmapped, HVCrosstalking modules)
702  struct stat FileInfo;
703  bool Existence;
704  int Stat;
705  //Try to get file attributes
706  Stat=stat(FileName.c_str(),&FileInfo);
707  if (Stat==0) {
708  Existence=true;
709  }
710  else {
711  Existence=false;
712  }
713  return Existence;
714 }
cond::Time_t SiStripDetVOffBuilder::findMostRecentTimeStamp ( const std::vector< coral::TimeStamp > &  coralDate)
private

Definition at line 464 of file SiStripDetVOffBuilder.cc.

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

Referenced by lastValue(), and lastValueFromFile().

464  {
465  cond::Time_t latestDate = getCondTime(coralDate[0]);
466 
467  if( debug_ ) {
468  std::cout << "latestDate: condTime = "
469  << (latestDate>>32)
470  << " - "
471  << (latestDate&0xFFFFFFFF)
472  //<< " coralTime= " << coralDate[0]
473  << std::endl;
474  }
475 
476  for (unsigned int i = 1; i < coralDate.size(); i++) {
477  cond::Time_t testDate = getCondTime(coralDate[i]);
478  if (testDate > latestDate) {
479  latestDate = testDate;
480  }
481  }
482  return latestDate;
483 }
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 308 of file SiStripDetVOffBuilder.cc.

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

Referenced by lastValue(), and lastValueFromFile().

308  {
309  int setting = -1;
310  // find out how many channel entries there are
311  std::vector<int> locations;
312  for (unsigned int i = 0; i < settingID.size(); i++) { if (settingID[i] == id) {locations.push_back((int)i);} }
313 
314  // simple cases
315  if (locations.empty()) {setting = -1;}
316  else if (locations.size() == 1) {setting = locations[0];}
317  // more than one entry for this channel
318  // NB. entries ordered by date!
319  else {
320  for (unsigned int j = 0; j < locations.size(); j++) {
321 #ifdef USING_NEW_CORAL
322  const boost::posix_time::ptime& testSec = changeDate.time();
323  const boost::posix_time::ptime& limitSec = settingDate[(unsigned int)locations[j]].time();
324 #else
325  long testSec = changeDate.time().ns();
326  long limitSec = settingDate[(unsigned int)locations[j]].time().ns();
327 #endif
328  if (testSec >= limitSec) {setting = locations[j];}
329  }
330  }
331  return setting;
332 }
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 334 of file SiStripDetVOffBuilder.cc.

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

334  {
335  int setting = -1;
336  // find out how many channel entries there are
337  std::vector<int> locations;
338  for (unsigned int i = 0; i < settingDpname.size(); i++) { if (settingDpname[i] == dpname) {locations.push_back((int)i);} }
339 
340  // simple cases
341  if (locations.empty()) {setting = -1;}
342  else if (locations.size() == 1) {setting = locations[0];}
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) {setting = locations[j];}
355  }
356  }
357  return setting;
358 }
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 422 of file SiStripDetVOffBuilder.cc.

References cond::time::from_boost().

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

422  {
423 
424  // const boost::posix_time::ptime& t = coralTime.time();
425  cond::Time_t condTime = cond::time::from_boost(coralTime.time());
426 
427  // cout << "[SiStripDetVOffBuilder::getCondTime] Converting CoralTime into CondTime: "
428  // << " coralTime = (coralTimeInNs) " << coralTime.total_nanoseconds() << " condTime " << (condTime>> 32) << " - " << (condTime & 0xFFFFFFFF) << endl;
429 
430  return condTime;
431 }
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 433 of file SiStripDetVOffBuilder.cc.

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

Referenced by statusChange().

434 {
435  // This method is defined in the TimeConversions header and it does the following:
436  // - takes the seconds part of the iovTime (bit-shifting of 32)
437  // - adds the nanoseconds part (first 32 bits mask)
438  // - adds the time0 that is the time from begin of times (boost::posix_time::from_time_t(0);)
439  coral::TimeStamp coralTime(cond::time::to_boost(iovTime));
440 
441  if( debug_ ) {
442  unsigned long long iovSec = iovTime >> 32;
443  uint32_t iovNanoSec = uint32_t(iovTime);
444  cond::Time_t testTime=getCondTime(coralTime);
445  cout << "[SiStripDetVOffBuilder::getCoralTime] Converting CondTime into CoralTime: "
446  << " condTime = " << iovSec << " - " << iovNanoSec
447  << " getCondTime(coralTime) = " << (testTime>>32) << " - " << (testTime&0xFFFFFFFF) << endl;
448  }
449 
450  return coralTime;
451 }
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 51 of file SiStripDetVOffBuilder.h.

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

Referenced by SiStripDetVOffHandler::analyze().

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

Return statistics about payloads transferred for storage in logDB.

Definition at line 56 of file SiStripDetVOffBuilder.h.

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

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

Definition at line 606 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().

607 {
608  coralInterface->doQuery(whichTable, tmin ,tmax, tStruct.changeDate, tStruct.actualValue, tStruct.dpname);
609 
610  tStruct.latestTime = findMostRecentTimeStamp( tStruct.changeDate );
611 
612  // preset the size of the status vector
613  tStruct.actualStatus.resize(tStruct.actualValue.size());
614 
615  // retrieve the channel settings from the PVSS DB
616  std::vector<coral::TimeStamp> settingDate;
617  std::vector<float> settingValue;
618  std::vector<std::string> settingDpname;
619  std::vector<uint32_t> settingDpid;
620  coralInterface->doSettingsQuery(tsetmin,tmax,settingDate,settingValue,settingDpname,settingDpid);
621  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Channel settings retrieved";
622  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Number of PSU channels: " << settingDpname.size();
623 
624  unsigned int missing = 0;
625  std::stringstream ss;
626  for (unsigned int j = 0; j < tStruct.dpname.size(); j++) {
627  int setting = findSetting(tStruct.dpname[j],tStruct.changeDate[j],settingDpname,settingDate);
628  if (setting >= 0) {
629  if (tStruct.actualValue[j] > (highVoltageOnThreshold_*(settingValue[setting]))) {tStruct.actualStatus[j] = 1;}
630  else {tStruct.actualStatus[j] = 0;}
631  } else {
632  tStruct.actualStatus[j] = -1;
633  missing++;
634  ss << "Channel = " << tStruct.dpname[j] << std::endl;
635  }
636  }
637  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Number of channels with no setting information " << missing;
638  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Number of entries in dpname vector " << tStruct.dpname.size();
639 }
#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 641 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().

642 {
643  readLastValueFromFile(tStruct.dpid,tStruct.actualValue,tStruct.changeDate);
644  tStruct.latestTime = findMostRecentTimeStamp( tStruct.changeDate );
645  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: File access complete \n\t Number of values read from file: " << tStruct.dpid.size();
646 
647  // retrieve the channel settings from the PVSS DB
648  std::vector<coral::TimeStamp> settingDate;
649  std::vector<float> settingValue;
650  std::vector<std::string> settingDpname;
651  std::vector<uint32_t> settingDpid;
652 
653  coralInterface->doSettingsQuery(tsetmin,tmax,settingDate,settingValue,settingDpname,settingDpid);
654  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Channel settings retrieved";
655  LogDebug("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::BuildDetVOff]: Number of PSU channels: " << settingDpname.size();
656 
657  unsigned int missing = 0;
658  std::stringstream ss;
659  // need to get the PSU channel names from settings
660  tStruct.dpname.clear();
661  tStruct.dpname.resize(tStruct. dpid.size());
662  for (unsigned int j = 0; j < tStruct.dpid.size(); j++) {
663  int setting = findSetting(tStruct.dpid[j],tStruct.changeDate[j],settingDpid,settingDate);
664  if (setting >= 0) {
665  if (tStruct.actualValue[j] > (highVoltageOnThreshold_*settingValue[setting])) {tStruct.actualStatus[j] = 1;}
666  else {
667  tStruct.actualStatus[j] = 0;
668  }
669  tStruct.dpname[j] = settingDpname[setting];
670  } else {
671  tStruct.actualStatus[j] = -1;
672  tStruct.dpname[j] = "UNKNOWN";
673  missing++;
674  ss << "DP ID = " << tStruct.dpid[j] << std::endl;
675  }
676  }
677  LogDebug("SiStripDetVOffBuilder") << "Number of missing psu channels = " << missing << std::endl;
678  LogDebug("SiStripDetVOffBuilder") << "IDs are: = " << ss.str();
679 }
#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 83 of file SiStripDetVOffBuilder.cc.

References heppy_batch::val.

Referenced by SiStripDetVOffBuilder().

83  {
84  for(int val : par){
85  ss << val << " ";
86  }
87 }
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 360 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().

360  {
361  std::ifstream lastValueFile(lastValueFileName.c_str());
362  if (lastValueFile.bad()) {
363  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::" << __func__ << "]: last Value file does not exist!";
364  return;
365  }
366 
367  dpIDs.clear();
368  vmonValues.clear();
369  dateChange.clear();
370  std::vector<std::string> changeDates;
371 
373  // remove the first line as it is the title line
374  // std::getline(lastValueFile,line);
375  // line.clear();
376  // now extract data
377  while( std::getline(lastValueFile,line) ) {
378  std::istringstream ss(line);
379  uint32_t dpid;
380  float vmon;
381  std::string changeDate;
382  ss >> std::skipws >> dpid >> vmon >> changeDate;
383  dpIDs.push_back(dpid);
384  vmonValues.push_back(vmon);
385  changeDates.push_back(changeDate);
386  }
387  lastValueFile.close();
388 
389  // Now convert dates to coral::TimeStamp
390  for (unsigned int i = 0; i < changeDates.size(); i++) {
391  std::string part = changeDates[i].substr(0,4);
392  int year = atoi(part.c_str());
393  part.clear();
394 
395  part = changeDates[i].substr(5,2);
396  int month = atoi(part.c_str());
397  part.clear();
398 
399  part = changeDates[i].substr(8,2);
400  int day = atoi(part.c_str());
401  part.clear();
402 
403  part = changeDates[i].substr(11,2);
404  int hour = atoi(part.c_str());
405  part.clear();
406 
407  part = changeDates[i].substr(14,2);
408  int minute = atoi(part.c_str());
409  part.clear();
410 
411  part = changeDates[i].substr(17,2);
412  int second = atoi(part.c_str());
413  part.clear();
414 
415  coral::TimeStamp date(year,month,day,hour,minute,second,0);
416  dateChange.push_back(date);
417  }
418 
419  if (changeDates.size() != dateChange.size()) {edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::" << __func__ << "]: date conversion failed!!";}
420 }
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 485 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().

489 {
490  //const bool last is set to false by default in the header file...
491  int first = 0;
492  // Check if it is the first
493  if( distance(resultVec.begin(), initialIt) == 0 ) {
494  first = 1;
495  }
496 
497  if( debug_ && ( it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() == 0 ) && ( it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() == 0 ) ) {
498  cout << "Same number of LV and HV at start and end of sequence: LV off = " << it->first->getLVoffCounts() << " HV off = " << it->first->getHVoffCounts() << endl;
499  }
500 
501  // if it was going off
502  if( ( it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() > 0 ) || ( it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() > 0 ) ) {
503  // Set the time of the current (last) iov as the time of the initial iov of the sequence
504  // replace the first iov with the last one
505  //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
506  (it+last)->second = (initialIt)->second;
507  discardIOVs(it, initialIt, resultVec, last, 0);
508  if( debug_ ) cout << "Reducing IOV sequence (going off)" << endl;
509  }
510  // if it was going on
511  else if( ( it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() <= 0 ) || ( it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() <= 0 ) ) {
512  // replace the last minus one iov with the first one
513  discardIOVs(it, initialIt, resultVec, last, first);
514  if( debug_ ) cout << "Reducing IOV sequence (going on)" << endl;
515  }
516 }
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 539 of file SiStripDetVOffBuilder.cc.

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

Referenced by getModulesVOff(), and getPayloadStats().

540 {
541 
542  int count = 0;
543  std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator initialIt;
544 
545  int resultVecSize = modulesOff.size();
546  int resultsIndex = 0;
547 
548  if( resultVecSize > 1 ) {
549  std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator it = modulesOff.begin();
550  for( ; it != modulesOff.end()-1; ++it, ++resultsIndex ) {
551  unsigned long long deltaT = ((it+1)->second - it->second) >> 32;
552  unsigned long long deltaTsequence = 0;
553  if( count > 1 ) {
554  deltaTsequence = ((it+1)->second - initialIt->second) >> 32;
555  }
556  // Save the initial pair
557  if( (deltaT < deltaTmin) && ( (count == 0) || ( deltaTsequence < maxIOVlength ) ) ) {
558  // If we are not in a the sequence
559  if( count == 0 ) {
560  initialIt = it;
561  }
562  // Increase the counter in any case.
563  ++count;
564  }
565  // We do it only if the sequence is bigger than two cases
566  else if( count > 1 ) {
567  reduce(it, initialIt, modulesOff);
568  // reset all
569  count = 0;
570  }
571  else {
572  // reset all
573  count = 0;
574  }
575  // Border case
576  if( resultsIndex == resultVecSize-2 && count != 0 ) {
577  reduce(it, initialIt, modulesOff, true);
578  }
579  }
580  }
581 }
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.
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > modulesOff
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 453 of file SiStripDetVOffBuilder.cc.

References tier0::unique().

Referenced by buildPSUdetIdMap().

453  {
454  std::sort(vec.begin(),vec.end());
455  std::vector<uint32_t>::iterator it = std::unique(vec.begin(),vec.end());
456  vec.resize( it - vec.begin() );
457 }
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 459 of file SiStripDetVOffBuilder.cc.

References lastStoredCondObj.

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

459  {
460  lastStoredCondObj.first = lastPayload;
461  lastStoredCondObj.second = lastTimeStamp;
462 }
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 1179 of file SiStripDetVOffBuilder.cc.

References payloadStats.

Referenced by BuildDetVOffObj().

1180 {
1181  std::vector<uint32_t> pStats(3,0);
1182  pStats.push_back(afterV);
1183  pStats.push_back(numAdded);
1184  pStats.push_back(numRemoved);
1185  payloadStats.push_back(pStats);
1186 }
std::vector< std::vector< uint32_t > > payloadStats
void SiStripDetVOffBuilder::statusChange ( cond::Time_t lastTime,
TimesAndValues tStruct 
)
private

Definition at line 583 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().

584 {
585  // Setting tmin to the last value IOV of the database tag
586  if( lastTime > 0 ) {
587  tmin = getCoralTime(lastTime);
588  }
589 
590  coralInterface->doQuery(whichTable, tmin ,tmax, tStruct.changeDate, tStruct.actualValue, tStruct.dpname);
591  //UNIT TEST DEBUG to bypass the query wait time!!!
592  //coral::TimeStamp testtime=getCoralTime(lastTime);
593  //tStruct.changeDate.push_back(testtime);
594  //tStruct.actualValue.push_back(1.);
595  //tStruct.dpname.push_back("cms_trk_dcs_03:CAEN/CMS_TRACKER_SY1527_3/branchController00/easyCrate3/easyBoard17/channel002");
596 
597  // preset the size of the status vector
598  tStruct.actualStatus.resize(tStruct.actualValue.size());
599  tStruct.actualStatus.clear();
600 
601  for(float val : tStruct.actualValue) {
602  tStruct.actualStatus.push_back(static_cast<int>(val));
603  }
604 }
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 688 of file SiStripDetVOffBuilder.cc.

Referenced by buildPSUdetIdMap().

689 {
690  stringstream ss;
691  ss << "Starting from IOV time in the database : year = " << coralTime.year()
692  << ", month = " << coralTime.month()
693  << ", day = " << coralTime.day()
694  << ", hour = " << coralTime.hour()
695  << ", minute = " << coralTime.minute()
696  << ", second = " << coralTime.second()
697  << ", nanosecond = " << coralTime.nanosecond() << std::endl;
698  return ss.str();
699 }
string SiStripDetVOffBuilder::timeToStream ( const cond::Time_t condTime,
const string &  comment = "" 
)
private

Definition at line 681 of file SiStripDetVOffBuilder.cc.

682 {
683  stringstream ss;
684  ss << comment << (condTime>> 32) << " - " << (condTime & 0xFFFFFFFF) << std::endl;
685  return ss.str();
686 }

Friends And Related Function Documentation

friend class TestSiStripDetVOffBuilder
friend

Definition at line 41 of file SiStripDetVOffBuilder.h.

Member Data Documentation

std::string SiStripDetVOffBuilder::authenticationPath
private

Definition at line 123 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 131 of file SiStripDetVOffBuilder.h.

Referenced by getModulesVOff().

std::string SiStripDetVOffBuilder::detIdListFile_
private

Definition at line 133 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj().

std::string SiStripDetVOffBuilder::excludedDetIdListFile_
private

Definition at line 134 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj().

bool SiStripDetVOffBuilder::fromFile
private

Definition at line 126 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), and SiStripDetVOffBuilder().

double SiStripDetVOffBuilder::highVoltageOnThreshold_
private

Definition at line 136 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 125 of file SiStripDetVOffBuilder.h.

Referenced by readLastValueFromFile(), and SiStripDetVOffBuilder().

uint32_t SiStripDetVOffBuilder::maxIOVlength_
private

Definition at line 131 of file SiStripDetVOffBuilder.h.

Referenced by getModulesVOff().

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

Definition at line 118 of file SiStripDetVOffBuilder.h.

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

std::string SiStripDetVOffBuilder::onlineDbConnectionString
private

Definition at line 122 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), and SiStripDetVOffBuilder().

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

Definition at line 117 of file SiStripDetVOffBuilder.h.

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

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

Definition at line 130 of file SiStripDetVOffBuilder.h.

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

Definition at line 130 of file SiStripDetVOffBuilder.h.

Referenced by SiStripDetVOffBuilder().

coral::TimeStamp SiStripDetVOffBuilder::tmin
private

Definition at line 129 of file SiStripDetVOffBuilder.h.

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

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

Definition at line 130 of file SiStripDetVOffBuilder.h.

Referenced by SiStripDetVOffBuilder().

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

Definition at line 130 of file SiStripDetVOffBuilder.h.

Referenced by SiStripDetVOffBuilder().

coral::TimeStamp SiStripDetVOffBuilder::tsetmin
private

Definition at line 129 of file SiStripDetVOffBuilder.h.

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

bool SiStripDetVOffBuilder::whichQuery
private

Definition at line 80 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), and SiStripDetVOffBuilder().

std::string SiStripDetVOffBuilder::whichTable
private