CMS 3D CMS Logo

SiStripFedCablingManipulator.cc
Go to the documentation of this file.
5 #include <fstream>
6 #include <iostream>
7 
9  edm::LogInfo("SiStripFedCablingManipulator") << "SiStripFedCablingManipulator constructor " << std::endl;
10 }
11 
13  edm::LogInfo("SiStripFedCablingManipulator")
14  << "SiStripFedCablingManipulator::~SiStripFedCablingManipulator()" << std::endl;
15 }
16 
19  es.get<SiStripFedCablingRcd>().get(esobj);
20 
21  SiStripFedCabling* obj = nullptr;
22  manipulate(esobj.product(), obj);
23 
24  cond::Time_t Time_ = 0;
25 
26  //And now write data in DB
28  if (dbservice.isAvailable()) {
29  if (obj == nullptr) {
30  edm::LogError("SiStripFedCablingManipulator") << "null pointer obj. nothing will be written " << std::endl;
31  return;
32  }
33 
34  std::string openIovAt = iConfig_.getUntrackedParameter<std::string>("OpenIovAt", "beginOfTime");
35  if (openIovAt == "beginOfTime")
36  Time_ = dbservice->beginOfTime();
37  else if (openIovAt == "currentTime")
38  dbservice->currentTime();
39  else
40  Time_ = iConfig_.getUntrackedParameter<uint32_t>("OpenIovAtTime", 1);
41 
42  //if first time tag is populated
43  if (dbservice->isNewTagRequest("SiStripFedCablingRcd")) {
44  edm::LogInfo("SiStripFedCablingManipulator") << "first request for storing objects with Record "
45  << "SiStripFedCablingRcd"
46  << " at time " << Time_ << std::endl;
47  dbservice->createNewIOV<SiStripFedCabling>(obj, Time_, dbservice->endOfTime(), "SiStripFedCablingRcd");
48  } else {
49  edm::LogInfo("SiStripFedCablingManipulator") << "appending a new object to existing tag "
50  << "SiStripFedCablingRcd"
51  << " in since mode " << std::endl;
52  dbservice->appendSinceTime<SiStripFedCabling>(obj, Time_, "SiStripFedCablingRcd");
53  }
54  } else {
55  edm::LogError("SiStripFedCablingManipulator") << "Service is unavailable" << std::endl;
56  }
57 }
58 
61 
62  std::ifstream inputFile_;
63  inputFile_.open(fp.c_str());
64 
65  std::map<uint32_t, std::pair<uint32_t, uint32_t> > dcuDetIdMap;
66  uint32_t dcuid, Olddetid, Newdetid;
67 
68  // if(fp.c_str()==""){
69  if (fp.empty()) {
70  edm::LogInfo("SiStripFedCablingManipulator")
71  << "::manipulate : since no file is specified, the copy of the input cabling will be applied" << std::endl;
72  oobj = new SiStripFedCabling(*iobj);
73 
74  } else if (!inputFile_.is_open()) {
75  edm::LogError("SiStripFedCablingManipulator") << "::manipulate - ERROR in opening file " << fp << std::endl;
76  throw cms::Exception("CorruptedData") << "::manipulate - ERROR in opening file " << fp << std::endl;
77  } else {
78  for (;;) {
79  inputFile_ >> dcuid >> Olddetid >> Newdetid;
80 
81  if (!(inputFile_.eof() || inputFile_.fail())) {
82  if (dcuDetIdMap.find(dcuid) == dcuDetIdMap.end()) {
83  edm::LogInfo("SiStripFedCablingManipulator") << dcuid << " " << Olddetid << " " << Newdetid << std::endl;
84 
85  dcuDetIdMap[dcuid] = std::pair<uint32_t, uint32_t>(Olddetid, Newdetid);
86  } else {
87  edm::LogError("SiStripFedCablingManipulator")
88  << "::manipulate - ERROR duplicated dcuid " << dcuid << std::endl;
89  throw cms::Exception("CorruptedData")
90  << "SiStripFedCablingManipulator::manipulate - ERROR duplicated dcuid " << dcuid;
91  break;
92  }
93  } else if (inputFile_.eof()) {
94  edm::LogInfo("SiStripFedCablingManipulator") << "::manipulate - END of file reached" << std::endl;
95  break;
96  } else if (inputFile_.fail()) {
97  edm::LogError("SiStripFedCablingManipulator") << "::manipulate - ERROR while reading file" << std::endl;
98  break;
99  }
100  }
101  inputFile_.close();
102  std::map<uint32_t, std::pair<uint32_t, uint32_t> >::const_iterator it = dcuDetIdMap.begin();
103  for (; it != dcuDetIdMap.end(); ++it)
104  edm::LogInfo("SiStripFedCablingManipulator")
105  << "::manipulate - Map " << it->first << " " << it->second.first << " " << it->second.second;
106 
107  std::vector<FedChannelConnection> conns;
108 
109  auto feds = iobj->fedIds();
110  for (auto ifeds = feds.begin(); ifeds != feds.end(); ifeds++) {
111  auto conns_per_fed = iobj->fedConnections(*ifeds);
112  for (auto iconn = conns_per_fed.begin(); iconn != conns_per_fed.end(); ++iconn) {
113  std::map<uint32_t, std::pair<uint32_t, uint32_t> >::const_iterator it = dcuDetIdMap.find(iconn->dcuId());
114  if (it != dcuDetIdMap.end() && it->second.first == iconn->detId()) {
115  edm::LogInfo("SiStripFedCablingManipulator")
116  << "::manipulate - fedid " << *ifeds << " dcuid " << iconn->dcuId() << " oldDet " << iconn->detId()
117  << " newDetID " << it->second.second;
118  conns.push_back(FedChannelConnection(iconn->fecCrate(),
119  iconn->fecSlot(),
120  iconn->fecRing(),
121  iconn->ccuAddr(),
122  iconn->ccuChan(),
123  iconn->i2cAddr(0),
124  iconn->i2cAddr(1),
125  iconn->dcuId(),
126  it->second.second, //<------ New detid
127  iconn->nApvPairs(),
128  iconn->fedId(),
129  iconn->fedCh(),
130  iconn->fiberLength(),
131  iconn->dcu(),
132  iconn->pll(),
133  iconn->mux(),
134  iconn->lld()));
135  } else {
136  conns.push_back(FedChannelConnection(iconn->fecCrate(),
137  iconn->fecSlot(),
138  iconn->fecRing(),
139  iconn->ccuAddr(),
140  iconn->ccuChan(),
141  iconn->i2cAddr(0),
142  iconn->i2cAddr(1),
143  iconn->dcuId(),
144  iconn->detId(),
145  iconn->nApvPairs(),
146  iconn->fedId(),
147  iconn->fedCh(),
148  iconn->fiberLength(),
149  iconn->dcu(),
150  iconn->pll(),
151  iconn->mux(),
152  iconn->lld()));
153  }
154  }
155  }
156 
157  oobj = new SiStripFedCabling(conns);
158  }
159 }
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
l1tstage2emulator_dqm_sourceclient-live_cfg.feds
feds
Definition: l1tstage2emulator_dqm_sourceclient-live_cfg.py:153
SiStripFedCablingManipulator::endRun
void endRun(const edm::Run &run, const edm::EventSetup &es) override
Definition: SiStripFedCablingManipulator.cc:17
cond::service::PoolDBOutputService::beginOfTime
cond::Time_t beginOfTime() const
Definition: PoolDBOutputService.cc:187
SiStripFedCablingManipulator::~SiStripFedCablingManipulator
~SiStripFedCablingManipulator() override
Definition: SiStripFedCablingManipulator.cc:12
edm::Run
Definition: Run.h:45
edm::LogInfo
Definition: MessageLogger.h:254
SiStripFedCabling.h
cond::service::PoolDBOutputService::appendSinceTime
void appendSinceTime(const T *payloadObj, cond::Time_t sinceTime, const std::string &recordName)
Definition: PoolDBOutputService.h:135
personalPlayback.fp
fp
Definition: personalPlayback.py:523
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
SiStripFedCabling
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses,...
Definition: SiStripFedCabling.h:25
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
SiStripFedCablingManipulator::SiStripFedCablingManipulator
SiStripFedCablingManipulator(const edm::ParameterSet &iConfig)
Definition: SiStripFedCablingManipulator.cc:8
SiStripFedCablingRcd
Definition: SiStripCondDataRecords.h:22
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
cond::service::PoolDBOutputService::createNewIOV
void createNewIOV(const T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t, const std::string &recordName)
Definition: PoolDBOutputService.h:110
SiStripFedCablingManipulator::manipulate
void manipulate(const SiStripFedCabling *, SiStripFedCabling *&)
Definition: SiStripFedCablingManipulator.cc:59
edm::ESHandle< SiStripFedCabling >
SiStripFedCablingManipulator.h
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FedChannelConnection
Class containning control, module, detector and connection information, at the level of a FED channel...
Definition: FedChannelConnection.h:26
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
edm::Service< cond::service::PoolDBOutputService >
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
cond::service::PoolDBOutputService::endOfTime
cond::Time_t endOfTime() const
Definition: PoolDBOutputService.cc:185
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Exception
Definition: hltDiff.cc:246
EventSetup.h
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:100
SiStripFedCablingRcd.h
SiStripFedCabling::fedIds
FedsConstIterRange fedIds() const
Definition: SiStripFedCabling.h:154
SiStripFedCabling::fedConnections
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Definition: SiStripFedCabling.cc:160
cond::service::PoolDBOutputService::currentTime
cond::Time_t currentTime() const
Definition: PoolDBOutputService.cc:189
SiStripFedCablingManipulator::iConfig_
edm::ParameterSet iConfig_
Definition: SiStripFedCablingManipulator.h:29