test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripSpyIdentifyRuns.cc
Go to the documentation of this file.
1 // Original Author: Anne-Marie Magnan
2 // Created: 2010/02/25
3 //
4 
5 #include <sstream>
6 #include <fstream>
7 #include <iostream>
8 #include <memory>
9 #include <list>
10 #include <algorithm>
11 #include <cassert>
12 
13 
25 
30 
32 
33 //
34 // Class declaration
35 //
36 namespace sistrip {
37 
39  {
40  public:
41 
44 
45  private:
46 
47  virtual void beginJob() override;
48  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
49  virtual void endJob() override;
50 
51  void writeRunInFile(const unsigned int aRunNumber);
52 
53  //name of the output file containing the run numbers
54  //of spy runs
56  std::ofstream outFile_;
57 
58  //tag of spydata source collection
61  uint32_t prevRun_;
62 
63  };
64 }//namespace
65 
66 using edm::LogError;
67 using edm::LogWarning;
68 using edm::LogInfo;
69 //
70 // Constructors and destructor
71 //
72 namespace sistrip {
73 
75  : fileName_(iConfig.getParameter<std::string>("OutputTextFile")),
76  srcTag_(iConfig.getParameter<edm::InputTag>("InputProductLabel")),
77  prevRun_(0)
78  {
79  srcToken_ = consumes<FEDRawDataCollection>(srcTag_);
80  }
81 
82 
84 
85  }
86 
88  {
89  outFile_.open(fileName_.c_str(),std::ios::out);
90  if (!outFile_.is_open()) {
91  edm::LogError("SiStripSpyIdentifyRuns") << " -- Cannot open file : " << fileName_ << " for writting."
92  << std::endl;
93  edm::LogInfo("SiStripSpyIdentifyRuns") << " *** SPY RUNS *** "<< std::endl;
94 
95  }
96  else {
97  outFile_ << " *** SPY RUNS *** " << std::endl;
98  }
99  }
100 
102  {
103 
104  //static bool lFirstEvent = true;
105  //if (!lFirstEvent) return;
106  uint32_t lRunNum = aEvt.id().run();
107  if (lRunNum == prevRun_) return;
108 
110  aEvt.getByToken( srcToken_, lHandle );
111  const FEDRawDataCollection& buffers = *lHandle;
112 
113  for (unsigned int iFed(FEDNumbering::MINSiStripFEDID);
115  iFed++)
116  {
117 
118  //retrieve FED raw data for given FED
119  const FEDRawData& input = buffers.FEDData( static_cast<int>(iFed) );
120  //check on FEDRawData pointer and size
121  if ( !input.data() ||!input.size() ) continue;
122 
123  //construct FEDBuffer
124  std::auto_ptr<sistrip::FEDSpyBuffer> buffer;
125  try {
126  buffer.reset(new sistrip::FEDSpyBuffer(input.data(),input.size()));
127  } catch (const cms::Exception& e) {
128  edm::LogWarning("SiStripSpyIdentifyRuns")
129  << "Exception caught when creating FEDSpyBuffer object for FED " << iFed << ": " << e.what();
130  //if (!(buffer->readoutMode() == READOUT_MODE_SPY)) break;
131  std::string lErrStr = e.what();
132  if (lErrStr.find("Buffer is not from spy channel")!=lErrStr.npos) break;
133  else {
134  writeRunInFile(lRunNum);
135  break;
136  }
137  } // end of buffer reset try.
138  edm::LogWarning("SiStripSpyIdentifyRuns")
139  << " -- this is a spy file, run " << lRunNum << std::endl;
140  writeRunInFile(lRunNum);
141  break;
142  }
143  //lFirstEvent = false;
144  prevRun_ = lRunNum;
145 
146  }
147 
148  void SpyIdentifyRunsModule::writeRunInFile(const unsigned int aRunNumber){
149  if (!outFile_.is_open()) {
150  edm::LogInfo("SiStripSpyIdentifyRuns") << aRunNumber
151  << std::endl;
152  }
153  else {
154  outFile_ << aRunNumber << std::endl;
155  }
156  }
157 
159 
160  //save global run number in text file in local directory
161  //output loginfo with number of errors
162  //or throw exception ?
163  if (outFile_.is_open()) outFile_.close();
164 
165  }
166 
167 
168 }//namespace
169 
RunNumber_t run() const
Definition: EventID.h:42
virtual char const * what() const
Definition: Exception.cc:141
edm::EDGetTokenT< FEDRawDataCollection > srcToken_
void writeRunInFile(const unsigned int aRunNumber)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
static std::string const input
Definition: EdmProvDump.cc:44
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
tuple out
Definition: dbtoconf.py:99
Constants and enumerated types for FED/FEC systems.
sistrip::SpyIdentifyRunsModule SiStripSpyIdentifyRuns
edm::EventID id() const
Definition: EventBase.h:56
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
SpyIdentifyRunsModule(const edm::ParameterSet &)