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 // $Id: SiStripSpyIdentifyRuns.cc,v 1.2 2010/04/26 15:00:55 amagnan Exp $
4 //
5 
6 #include <sstream>
7 #include <fstream>
8 #include <iostream>
9 #include <memory>
10 #include <list>
11 #include <algorithm>
12 #include <cassert>
13 
24 
29 
31 
32 //
33 // Class declaration
34 //
35 namespace sistrip {
36 
38  {
39  public:
40 
43 
44  private:
45 
46  virtual void beginJob();
47  virtual void analyze(const edm::Event&, const edm::EventSetup&);
48  virtual void endJob();
49 
50  void writeRunInFile(const unsigned int aRunNumber);
51 
52  //name of the output file containing the run numbers
53  //of spy runs
54  std::string fileName_;
55  std::ofstream outFile_;
56 
57  //tag of spydata source collection
59 
60  uint32_t prevRun_;
61 
62  };
63 }//namespace
64 
65 using edm::LogError;
66 using edm::LogWarning;
67 using edm::LogInfo;
68 //
69 // Constructors and destructor
70 //
71 namespace sistrip {
72 
74  : fileName_(iConfig.getParameter<std::string>("OutputTextFile")),
75  srcTag_(iConfig.getParameter<edm::InputTag>("InputProductLabel")),
76  prevRun_(0)
77  {
78 
79  }
80 
81 
83 
84  }
85 
87  {
88  outFile_.open(fileName_.c_str(),std::ios::out);
89  if (!outFile_.is_open()) {
90  edm::LogError("SiStripSpyIdentifyRuns") << " -- Cannot open file : " << fileName_ << " for writting."
91  << std::endl;
92  edm::LogInfo("SiStripSpyIdentifyRuns") << " *** SPY RUNS *** "<< std::endl;
93 
94  }
95  else {
96  outFile_ << " *** SPY RUNS *** " << std::endl;
97  }
98  }
99 
101  {
102 
103  //static bool lFirstEvent = true;
104  //if (!lFirstEvent) return;
105  uint32_t lRunNum = aEvt.id().run();
106  if (lRunNum == prevRun_) return;
107 
109  aEvt.getByLabel( srcTag_, lHandle );
110  const FEDRawDataCollection& buffers = *lHandle;
111 
112  for (unsigned int iFed(FEDNumbering::MINSiStripFEDID);
114  iFed++)
115  {
116 
117  //retrieve FED raw data for given FED
118  const FEDRawData& input = buffers.FEDData( static_cast<int>(iFed) );
119  //check on FEDRawData pointer and size
120  if ( !input.data() ||!input.size() ) continue;
121 
122  //construct FEDBuffer
123  std::auto_ptr<sistrip::FEDSpyBuffer> buffer;
124  try {
125  buffer.reset(new sistrip::FEDSpyBuffer(input.data(),input.size()));
126  } catch (const cms::Exception& e) {
127  edm::LogWarning("SiStripSpyIdentifyRuns")
128  << "Exception caught when creating FEDSpyBuffer object for FED " << iFed << ": " << e.what();
129  //if (!(buffer->readoutMode() == READOUT_MODE_SPY)) break;
130  std::string lErrStr = e.what();
131  if (lErrStr.find("Buffer is not from spy channel")!=lErrStr.npos) break;
132  else {
133  writeRunInFile(lRunNum);
134  break;
135  }
136  } // end of buffer reset try.
137  edm::LogWarning("SiStripSpyIdentifyRuns")
138  << " -- this is a spy file, run " << lRunNum << std::endl;
139  writeRunInFile(lRunNum);
140  break;
141  }
142  //lFirstEvent = false;
143  prevRun_ = lRunNum;
144 
145  }
146 
147  void SpyIdentifyRunsModule::writeRunInFile(const unsigned int aRunNumber){
148  if (!outFile_.is_open()) {
149  edm::LogInfo("SiStripSpyIdentifyRuns") << aRunNumber
150  << std::endl;
151  }
152  else {
153  outFile_ << aRunNumber << std::endl;
154  }
155  }
156 
158 
159  //save global run number in text file in local directory
160  //output loginfo with number of errors
161  //or throw exception ?
162  if (outFile_.is_open()) outFile_.close();
163 
164  }
165 
166 
167 }//namespace
168 
RunNumber_t run() const
Definition: EventID.h:42
virtual char const * what() const
Definition: Exception.cc:141
void writeRunInFile(const unsigned int aRunNumber)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
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:29
SpyIdentifyRunsModule(const edm::ParameterSet &)