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->createOneIOV<SiStripFedCabling>(*obj, Time_, "SiStripFedCablingRcd");
45  } else {
46  edm::LogInfo("SiStripFedCablingManipulator") << "appending a new object to existing tag "
47  << "SiStripFedCablingRcd"
48  << " in since mode " << std::endl;
49  dbservice->appendOneIOV<SiStripFedCabling>(*obj, 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 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
Log< level::Error, false > LogError
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
T getUntrackedParameter(std::string const &, T const &) const
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
unsigned long long Time_t
Definition: Time.h:14
bool isNewTagRequest(const std::string &recordName)
Class containning control, module, detector and connection information, at the level of a FED channel...
std::unique_ptr< SiStripFedCabling > manipulate(const SiStripFedCabling &)
Transition
Definition: Transition.h:12
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd > fedCablingToken_
SiStripFedCablingManipulator(const edm::ParameterSet &iConfig)
Log< level::Info, false > LogInfo
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
HLT enums.
bool isAvailable() const
Definition: Service.h:40
void endRun(const edm::Run &run, const edm::EventSetup &es) override
FedsConstIterRange fedIds() const
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Definition: Run.h:45