CMS 3D CMS Logo

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