CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCFileDumper.cc
Go to the documentation of this file.
1 #include <iomanip>
2 
3 #include "CSCFileDumper.h"
4 
5 //Framework stuff
9 
10 //FEDRawData
14 
16 
18 
19 #include <iostream>
20 #include <sstream>
21 #include <stdio.h>
22 
24 {
25  output = pset.getUntrackedParameter<std::string>("output");
28  events = pset.getUntrackedParameter<std::string>("events","");
29  source_ = pset.getUntrackedParameter<std::string>("source","rawDataCollector");
30 
31  if( events.length() ){
32  for(size_t pos1=0,pos2=events.find(",");;pos1=pos2+1,pos2=events.find(",",pos2+1)){
33  if( pos2!=std::string::npos ){
34  long event=0;
35  if( sscanf(events.substr(pos1,pos2-pos1).c_str(),"%ld",&event) == 1 && event>=0 )
36  eventsToDump.insert((unsigned long)event);
37  else
38  edm::LogError("CSCFileDumper")<<" cannot parse events ("<<events<<") parameter: "<<events.substr(pos1,pos2-pos1);
39  } else {
40  long event=0;
41  if( sscanf(events.substr(pos1,events.length()-pos1).c_str(),"%ld",&event) == 1 && event>=0 )
42  eventsToDump.insert((unsigned long)event);
43  else
44  edm::LogError("CSCFileDumper")<<" cannot parse events ("<<events<<") parameter: "<<events.substr(pos1,events.length()-pos1);
45  break;
46  }
47  }
48  std::ostringstream tmp;
49  for(std::set<unsigned long>::const_iterator evt=eventsToDump.begin(); evt!=eventsToDump.end(); evt++) tmp<<*evt<<" ";
50  edm::LogInfo("CSCFileDumper")<<" Following events will be dumped: "<<tmp.str();
51  } else
52  edm::LogInfo("CSCFileDumper")<<" All events will be dumped";
53 }
54 
56  std::map<int,FILE*>::const_iterator stream = dump_files.begin();
57  while( stream != dump_files.end() ){
58  fclose(stream->second);
59  stream++;
60  }
61 }
62 
64  // Get a handle to the FED data collection
66 
67  // Get a handle to the FED data collection
68  e.getByLabel(source_, rawdata);
69 
70  for(int id=fedID_first; id<=fedID_last; ++id){ //for each of our DCCs
71  std::map<int,FILE*>::const_iterator stream = dump_files.find(id);
72  if( stream == dump_files.end() ){
73  std::ostringstream name;
74  name<<output<<"_"<<id<<std::ends;
75  FILE *file;
76  if( (file = fopen(name.str().c_str(),"wt"))==NULL ){
77  edm::LogError("CSCFileDumper")<<"Cannot open the file: "<<name.str();
78  continue;
79  } else
80  dump_files[id] = file;
81  stream = dump_files.find(id);
82  }
83 
85  const FEDRawData& fedData = rawdata->FEDData(id);
86  unsigned short int length = fedData.size();
87 
88  if( length && ( eventsToDump.empty() || eventsToDump.find( (unsigned long)e.id().event() )!=eventsToDump.end() ) ){
89  //std::cout<<"Event found for fed id:"<<id<<std::endl;
90  // Event buffer
91  size_t size=length/2;
92  const unsigned short *buf = (unsigned short *)fedData.data();
93  fwrite(buf,2,size,stream->second);
94  }
95  }
96 }
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
std::string events
Definition: CSCFileDumper.h:19
void analyze(const edm::Event &e, const edm::EventSetup &c)
#define NULL
Definition: scimark2.h:8
CSCFileDumper(const edm::ParameterSet &pset)
std::string output
Definition: CSCFileDumper.h:19
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
std::set< unsigned long > eventsToDump
Definition: CSCFileDumper.h:16
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
std::string source_
Definition: CSCFileDumper.h:29
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
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
dictionary rawdata
Definition: lumiPlot.py:393
tuple size
Write out results.
std::map< int, FILE * > dump_files
Definition: CSCFileDumper.h:15
virtual ~CSCFileDumper(void)