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 
58  std::string fp=iConfig_.getParameter<std::string>("file");
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  const std::vector<uint16_t>& feds=iobj->feds();
109  std::vector<uint16_t>::const_iterator ifeds=feds.begin();
110  for(;ifeds!=feds.end();ifeds++){
111  const std::vector<FedChannelConnection>& conns_per_fed =iobj->connections( *ifeds );
112  std::vector<FedChannelConnection>::const_iterator iconn=conns_per_fed.begin();
113  for(;iconn!=conns_per_fed.end();++iconn){
114  std::map<uint32_t, std::pair<uint32_t, uint32_t> >::const_iterator it=dcuDetIdMap.find(iconn->dcuId());
115  if(it!=dcuDetIdMap.end() && it->second.first==iconn->detId()){
116  edm::LogInfo("SiStripFedCablingManipulator")<< "::manipulate - fedid "<< *ifeds << " dcuid " << iconn->dcuId() << " oldDet " << iconn->detId() << " newDetID " << it->second.second ;
117  conns.push_back(FedChannelConnection(
118  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  )
136  );
137  }else{
138  conns.push_back(FedChannelConnection(
139  iconn->fecCrate(),
140  iconn->fecSlot(),
141  iconn->fecRing(),
142  iconn->ccuAddr(),
143  iconn->ccuChan(),
144  iconn->i2cAddr(0),
145  iconn->i2cAddr(1),
146  iconn->dcuId(),
147  iconn->detId(),
148  iconn->nApvPairs(),
149  iconn->fedId(),
150  iconn->fedCh(),
151  iconn->fiberLength(),
152  iconn->dcu(),
153  iconn->pll(),
154  iconn->mux(),
155  iconn->lld()
156  )
157  );
158  }
159  }
160  }
161 
162  oobj = new SiStripFedCabling( conns );
163 
164  }
165 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::vector< uint16_t > & feds() 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...
bool isAvailable() const
Definition: Service.h:47
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:55
T const * product() const
Definition: ESHandle.h:62
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
void endRun(const edm::Run &run, const edm::EventSetup &es)
const std::vector< FedChannelConnection > & connections(uint16_t fed_id) const
Definition: Run.h:33