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 (const TrackerTopology *trackerTopo)
 
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::auto_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 40 of file SiStripDetVOffBuilder.h.

Member Typedef Documentation

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

Definition at line 78 of file SiStripDetVOffBuilder.h.

Constructor & Destructor Documentation

SiStripDetVOffBuilder::~SiStripDetVOffBuilder ( )

Destructor.

Definition at line 81 of file SiStripDetVOffBuilder.cc.

81  {
82  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::" << __func__ << "]: destructing ...";
83 }
SiStripDetVOffBuilder::SiStripDetVOffBuilder ( const edm::ParameterSet pset,
const edm::ActivityRegistry  
)

Default constructor.

Definition at line 7 of file SiStripDetVOffBuilder.cc.

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

7  :
10  whichTable(pset.getParameter<std::string>("queryType")),
11  lastValueFileName(pset.getParameter<std::string>("lastValueFile")),
12  fromFile(pset.getParameter<bool>("lastValueFromFile")),
13  psuDetIdMapFile_(pset.getParameter<std::string>("PsuDetIdMapFile")),
14  debug_(pset.getParameter<bool>("debugModeOn")),
15  tDefault(7,0),
16  tmax_par(pset.getParameter< std::vector<int> >("Tmax")),
17  tmin_par(pset.getParameter< std::vector<int> >("Tmin")),
18  tset_par(pset.getParameter< std::vector<int> >("TSetMin")),
19  deltaTmin_(pset.getParameter<uint32_t>("DeltaTmin")),
20  maxIOVlength_(pset.getParameter<uint32_t>("MaxIOVlength")),
21  detIdListFile_(pset.getParameter< std::string >("DetIdListFile")),
22  excludedDetIdListFile_(pset.getParameter< std::string >("ExcludedDetIdListFile")),
23  highVoltageOnThreshold_(pset.getParameter<double>("HighVoltageOnThreshold"))
24 {
25  lastStoredCondObj.first = nullptr;
26  lastStoredCondObj.second = 0;
27 
28  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::SiStripDetVOffBuilder] constructor" << endl;
29 
30  // set up vectors based on pset parameters (tDefault purely for initialization)
31 
32  whichQuery=(whichTable == "STATUSCHANGE" || (whichTable == "LASTVALUE" && !fromFile));
33 
34  //Define the query interval [Tmin, Tmax]
35  //where Tmax comes from the cfg
36  // Tmin comes from the cfg for the first o2o, after that it is extracted from Offline DB
37 
38  tmax = coral::TimeStamp(tmax_par[0],tmax_par[1],tmax_par[2],tmax_par[3],tmax_par[4],tmax_par[5],tmax_par[6]);
39 
40  if (whichQuery) {
41  // Is there a better way to do this? TODO - investigate
42  tmin=coral::TimeStamp(tmin_par[0],tmin_par[1],tmin_par[2],tmin_par[3],tmin_par[4],tmin_par[5],tmin_par[6]);
43  }
44 
45  if (whichTable == "LASTVALUE") {
46  tsetmin = coral::TimeStamp(tset_par[0],tset_par[1],tset_par[2],tset_par[3],tset_par[4],tset_par[5],tset_par[6]);
47  }
48 
49  if (onlineDbConnectionString == "") {
50  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::SiStripDetVOffBuilder] DB name has not been set properly ... Returning ...";
51  return;
52  }
53 
54  if (fromFile && whichTable == "LASTVALUE" && lastValueFileName == "") {
55  edm::LogError("SiStripDetVOffBuilder") << "[SiStripDetVOffBuilder::SiStripDetVOffBuilder] File expected for 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: "; printPar(ss,tmin_par); ss << std::endl;
70  }
71  ss << " Tmax: " ; printPar(ss,tmax_par); ss << std::endl;
72 
73  if (whichTable == "LASTVALUE"){
74  ss << " TSetMin: "; printPar(ss,tset_par); ss << std::endl;
75  }
76  edm::LogError("SiStripDetVOffBuilder") << ss.str();
77 
78 }
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 ( const TrackerTopology trackerTopo)

Build the SiStripDetVOff object for transfer.

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

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

References SiStripDetVOffBuilder::TimesAndValues::actualStatus, SiStripPsuDetIdMap::BuildMap(), SiStripDetVOffBuilder::TimesAndValues::changeDate, gather_cfg::cout, debug_, SiStripDetVOffBuilder::DetIdListTimeAndStatus::detidV, reco::dp, SiStripDetVOffBuilder::TimesAndValues::dpname, cmsRelvalreport::exit, FileExists(), spr::find(), SiStripPsuDetIdMap::getHVCrosstalkingMap(), SiStripPsuDetIdMap::getHvDetID(), SiStripPsuDetIdMap::getHVUnmappedMap(), SiStripPsuDetIdMap::getLvDetID(), electrons_cff::ids, SiStripDetVOffBuilder::DetIdListTimeAndStatus::isHV, geometryCSVtoXML::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().

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

References gather_cfg::cout, and debug_.

Referenced by getPayloadStats(), and reduce().

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

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

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

Definition at line 702 of file SiStripDetVOffBuilder.cc.

References trackingPlots::stat.

Referenced by buildPSUdetIdMap(), and getPayloadStats().

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

Definition at line 466 of file SiStripDetVOffBuilder.cc.

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

Referenced by lastValue(), and lastValueFromFile().

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

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

Referenced by lastValue(), and lastValueFromFile().

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

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

336  {
337  int setting = -1;
338  // find out how many channel entries there are
339  std::vector<int> locations;
340  for (unsigned int i = 0; i < settingDpname.size(); i++) { if (settingDpname[i] == dpname) {locations.push_back((int)i);} }
341 
342  // simple cases
343  if (locations.empty()) {setting = -1;}
344  else if (locations.size() == 1) {setting = locations[0];}
345  // more than one entry for this channel
346  // NB. entries ordered by date!
347  else {
348  for (unsigned int j = 0; j < locations.size(); j++) {
349 #ifdef USING_NEW_CORAL
350  const boost::posix_time::ptime& testSec = changeDate.time();
351  const boost::posix_time::ptime& limitSec = settingDate[(unsigned int)locations[j]].time();
352 #else
353  long testSec = changeDate.time().ns();
354  long limitSec = settingDate[(unsigned int)locations[j]].time().ns();
355 #endif
356  if (testSec >= limitSec) {setting = locations[j];}
357  }
358  }
359  return setting;
360 }
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 424 of file SiStripDetVOffBuilder.cc.

References cond::time::from_boost().

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

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

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

Referenced by statusChange().

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

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

Referenced by SiStripDetVOffHandler::analyze().

52  {
54  return modulesOff;
55  }
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 57 of file SiStripDetVOffBuilder.h.

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

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

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

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

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

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

References heppy_batch::val.

Referenced by SiStripDetVOffBuilder().

85  {
86  BOOST_FOREACH(int val, par){
87  ss << val << " ";
88  }
89 }
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 362 of file SiStripDetVOffBuilder.cc.

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

Referenced by lastValueFromFile().

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

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

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

Referenced by getModulesVOff(), and getPayloadStats().

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

References tier0::unique().

Referenced by buildPSUdetIdMap().

455  {
456  std::sort(vec.begin(),vec.end());
457  std::vector<uint32_t>::iterator it = std::unique(vec.begin(),vec.end());
458  vec.resize( it - vec.begin() );
459 }
def unique(seq, keepstr=True)
Definition: tier0.py:24
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 461 of file SiStripDetVOffBuilder.cc.

References lastStoredCondObj.

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

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

References payloadStats.

Referenced by BuildDetVOffObj().

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

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

586 {
587  // Setting tmin to the last value IOV of the database tag
588  if( lastTime > 0 ) {
589  tmin = getCoralTime(lastTime);
590  }
591 
592  coralInterface->doQuery(whichTable, tmin ,tmax, tStruct.changeDate, tStruct.actualValue, tStruct.dpname);
593  //UNIT TEST DEBUG to bypass the query wait time!!!
594  //coral::TimeStamp testtime=getCoralTime(lastTime);
595  //tStruct.changeDate.push_back(testtime);
596  //tStruct.actualValue.push_back(1.);
597  //tStruct.dpname.push_back("cms_trk_dcs_03:CAEN/CMS_TRACKER_SY1527_3/branchController00/easyCrate3/easyBoard17/channel002");
598 
599  // preset the size of the status vector
600  tStruct.actualStatus.resize(tStruct.actualValue.size());
601  tStruct.actualStatus.clear();
602 
603  BOOST_FOREACH(float val, tStruct.actualValue) {
604  tStruct.actualStatus.push_back(static_cast<int>(val));
605  }
606 }
std::auto_ptr< SiStripCoralIface > coralInterface
coral::TimeStamp getCoralTime(cond::Time_t iovTime)
string SiStripDetVOffBuilder::timeToStream ( const coral::TimeStamp &  coralTime,
const string &  comment = "" 
)
private

Definition at line 690 of file SiStripDetVOffBuilder.cc.

Referenced by buildPSUdetIdMap().

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

Definition at line 683 of file SiStripDetVOffBuilder.cc.

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

Friends And Related Function Documentation

friend class TestSiStripDetVOffBuilder
friend

Definition at line 42 of file SiStripDetVOffBuilder.h.

Member Data Documentation

std::string SiStripDetVOffBuilder::authenticationPath
private

Definition at line 124 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), and SiStripDetVOffBuilder().

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

Definition at line 132 of file SiStripDetVOffBuilder.h.

Referenced by getModulesVOff().

std::string SiStripDetVOffBuilder::detIdListFile_
private

Definition at line 134 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj().

std::string SiStripDetVOffBuilder::excludedDetIdListFile_
private

Definition at line 135 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj().

bool SiStripDetVOffBuilder::fromFile
private

Definition at line 127 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), and SiStripDetVOffBuilder().

double SiStripDetVOffBuilder::highVoltageOnThreshold_
private

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

Referenced by readLastValueFromFile(), and SiStripDetVOffBuilder().

uint32_t SiStripDetVOffBuilder::maxIOVlength_
private

Definition at line 132 of file SiStripDetVOffBuilder.h.

Referenced by getModulesVOff().

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

Definition at line 119 of file SiStripDetVOffBuilder.h.

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

std::string SiStripDetVOffBuilder::onlineDbConnectionString
private

Definition at line 123 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), and SiStripDetVOffBuilder().

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

Definition at line 118 of file SiStripDetVOffBuilder.h.

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

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

Definition at line 131 of file SiStripDetVOffBuilder.h.

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

Definition at line 131 of file SiStripDetVOffBuilder.h.

Referenced by SiStripDetVOffBuilder().

coral::TimeStamp SiStripDetVOffBuilder::tmin
private

Definition at line 130 of file SiStripDetVOffBuilder.h.

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

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

Definition at line 131 of file SiStripDetVOffBuilder.h.

Referenced by SiStripDetVOffBuilder().

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

Definition at line 131 of file SiStripDetVOffBuilder.h.

Referenced by SiStripDetVOffBuilder().

coral::TimeStamp SiStripDetVOffBuilder::tsetmin
private

Definition at line 130 of file SiStripDetVOffBuilder.h.

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

bool SiStripDetVOffBuilder::whichQuery
private

Definition at line 81 of file SiStripDetVOffBuilder.h.

Referenced by BuildDetVOffObj(), and SiStripDetVOffBuilder().

std::string SiStripDetVOffBuilder::whichTable
private