CMS 3D CMS Logo

SiPixelFEDChannelContainerWriteFromASCII.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondFormats/SiPixelObjects
4 // Class: SiPixelFEDChannelContainerTestWriter
5 //
9 //
10 // Original Author: Marco Musich
11 // Created: Wed, 27 Nov 2018 12:04:36 GMT
12 //
13 //
14 
15 // system include files
16 #include <memory>
17 #include <fstream>
18 
19 // user include files
34 
35 //
36 // class declaration
37 //
38 
40 public:
43 
44  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
45 
46 private:
47  void analyze(const edm::Event&, const edm::EventSetup&) override;
48  void endJob() override;
49 
50  // ----------member data ---------------------------
53  const bool printdebug_;
54  const bool addDefault_;
56 };
57 
58 //
59 // constructors and destructor
60 //
62  : m_record(iConfig.getParameter<std::string>("record")),
63  m_SnapshotInputs(iConfig.getParameter<std::string>("snapshots")),
64  printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)),
65  addDefault_(iConfig.getUntrackedParameter<bool>("addDefault", false)) {
66  //now do what ever initialization is needed
68 }
69 
71 
72 //
73 // member functions
74 //
75 
76 // ------------ method called for each event ------------
78  using namespace edm;
79 
80  std::ifstream mysnapshots(m_SnapshotInputs);
82 
83  std::string scenario = "";
84  unsigned int thedetid(0);
85 
87 
88  if (mysnapshots.is_open()) {
89  while (getline(mysnapshots, line)) {
90  if (printdebug_) {
91  edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII") << line << std::endl;
92  }
93  std::istringstream iss(line);
94  unsigned int run, ls, detid, fed, link, roc_first, roc_last;
95  iss >> run >> ls >> detid >> fed >> link >> roc_first >> roc_last;
96 
97  PixelFEDChannel theBadChannel{fed, link, roc_first, roc_last};
98 
99  auto newscenario = std::to_string(run) + "_" + std::to_string(ls);
100  if (newscenario != scenario) {
101  edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII") << "================================" << std::endl;
102  edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII")
103  << "found a new scenario: " << newscenario << std::endl;
104  if (!scenario.empty()) {
105  edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII")
106  << "size of the fed channel vector: " << theBadFEDChannels.size() << std::endl;
107  edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII")
108  << "================================" << std::endl;
109  myQualities->setScenario(scenario, theBadFEDChannels);
110  theBadFEDChannels.clear();
111  }
112  scenario = newscenario;
113  }
114 
115  if (detid != thedetid) {
116  if (printdebug_) {
117  edm::LogVerbatim("SiPixelFEDChannelContainerWriteFromASCII") << "found a new detid!" << detid << std::endl;
118  }
119  thedetid = detid;
120  }
121  theBadFEDChannels[thedetid].push_back(theBadChannel);
122  }
123  }
124 
125  myQualities->setScenario(scenario, theBadFEDChannels);
126 
127  if (printdebug_) {
128  edm::LogInfo("SiPixelFEDChannelContainerWriteFromASCII") << "Content of SiPixelFEDChannelContainer " << std::endl;
129 
130  // use buil-in method in the CondFormat
132  }
133 }
134 
135 // ------------ method called once each job just after ending the event loop ------------
137  // adds an empty payload with name "default" => no channels are masked
138  if (addDefault_) {
140  myQualities->setScenario("default", theBadFEDChannels);
141  }
142 
143  edm::LogInfo("SiPixelFEDChannelContainerWriteFromASCII")
144  << "Size of SiPixelFEDChannelContainer object " << myQualities->size() << std::endl
145  << std::endl;
146 
147  // Form the data here
149  if (poolDbService.isAvailable()) {
150  cond::Time_t valid_time = poolDbService->currentTime();
151  // this writes the payload to begin in current run defined in cfg
152  poolDbService->writeOneIOV(*myQualities, valid_time, m_record);
153  }
154 }
155 
156 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
159  desc.setComment("Writes payloads of type SiPixelFEDChannelContainer from input ASCII files");
160  desc.addUntracked<bool>("printDebug", true);
161  desc.addUntracked<bool>("addDefault", true);
162  desc.add<std::string>("snapshots", "");
163  desc.add<std::string>("record", "SiPixelStatusScenariosRcd");
164  descriptions.add("SiPixelFEDChannelContainerWriteFromASCII", desc);
165 }
166 
167 //define this as a plug-in
Log< level::Info, true > LogVerbatim
scenario
Definition: constants.h:173
void analyze(const edm::Event &, const edm::EventSetup &) override
static std::string to_string(const XMLCh *ch)
int iEvent
Definition: GenABIO.cc:224
unsigned long long Time_t
Definition: Time.h:14
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Info, false > LogInfo
def ls(path, rec=False)
Definition: eostools.py:349
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void setScenario(const std::string &theScenarioId, const SiPixelFEDChannelCollection &theBadFEDChannels)
HLT enums.
bool isAvailable() const
Definition: Service.h:40
std::map< DetId, std::vector< PixelFEDChannel > > SiPixelFEDChannelCollection