test
CMS 3D CMS Logo

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