DataLoggerSimulator.cpp
Go to the documentation of this file.
1 /*
2  * File: DataLoggerSimulator.cpp
3  * Author: denis
4  *
5  * Created on February 15, 2012, 10:27 AM
6  */
7 
8 #ifdef NOVACMAKE
11 #else
12 #include "MockDataDAQ/DataLoggerSimulator.h"
13 #include "MockDataDAQ/Configuration.h"
14 #endif
15 #include "DAQDataFormats/RawDataBlock.h"
16 #include "DAQDataFormats/RawTrigger.h"
17 
18 
19 
20 /// Keyword in the file name for Events's file
21 #define EVENT_KEYWORD_IN_FILE_NAME "Events"
22 #define RUN_KEYWORD_IN_FILE_NAME "Run"
23 
24 namespace mcdatadaq {
25 
26 //------------------------------------------------------------------------------
28  fOutputEventFile(0),
29  fOutputRunFile(0)
30 {
31 
33 
34  /// Setup the Event Object
35  fCurrentEvent.setRunNumber (1);
36  fCurrentEvent.setSubrun (1);
37  fCurrentEvent.setEventNumber(1);
38 
39 
40  /// Open event files
41  if(!config->isProducingJustMicroSlices()){
42  const std::string final_file_name_event = config->getFullFileName(EVENT_KEYWORD_IN_FILE_NAME);
43  fOutputEventFile = fopen (final_file_name_event.c_str(),"wb");
44 
45  /// Open run file if needed
46  if(config->isProducingRunObject()){
47  const std::string final_file_name_run = config->getFullFileName(RUN_KEYWORD_IN_FILE_NAME);
48  fOutputRunFile = fopen (final_file_name_run.c_str(),"wb");
49  }// end of opening run file
50  }// end of opening event and run files
51 
52 }
53 
54 
55 //------------------------------------------------------------------------------
57 
58  std::cout<<"Destructing DataLoggerSimulator\n";
59 
60  /// Close output files
61  if(fOutputEventFile) {
63  }
64 
65  if(fOutputRunFile){
66  fCurrentRunHeader.close();
67  writeRun();
69  }
70 }
71 
72 //------------------------------------------------------------------------------
73 bool DataLoggerSimulator::produceEvent(const std::vector<daqdataformats::RawDataBlock*>& datablocks,
75 
77 
78  /// Set Trigger for the event
79  fCurrentEvent.setTrigger(trigger->getBuffer());
80 
81  /// Loop over Datablocks and add them to the event
82  for(uint32_t idatablock = 0; idatablock < datablocks.size(); idatablock++){
83 
84  daqdataformats::RawDataBlock* current_datablock = datablocks[idatablock];
85  fCurrentEvent.addDataBlock(current_datablock->getBuffer());
86  }// end of loop over datablocks
88 
89  //fCurrentEvent.print();
90 
91  /// Write out the event
92  writeEvent();
93 
94 
95  /// Add event to the run object if it is configured to do so.
96  /// Otherwise, don't bother
97  if(config->isProducingRunObject())
98  writeRun();
99 
100  return true;
101 }
102 
103 //------------------------------------------------------------------------------
106  return config->writeToFile(fOutputEventFile, fCurrentEvent);
107 }
108 
109 //------------------------------------------------------------------------------
111  fCurrentRunHeader.addRunSize(fCurrentEvent.sizeofdata());
112  fCurrentRunHeader.advanceEventNumber();
114  return config->writeToFile(fOutputRunFile, fCurrentEvent);
115 }
116 
117 //------------------------------------------------------------------------------
119 
120  fCurrentEvent.getHeader()->setDataBlockNumber(0);
121  fCurrentEvent.getHeader()->setEventSize( fCurrentEvent.getHeader()->sizeofdata()
122  +fCurrentEvent.getTrigger()->sizeofdata()
123  );
124  fCurrentEvent.getHeader()->advanceEventNumber();
125  fCurrentEvent.getHeader()->setCRCCalculationUsed(false);
126 
127  return true;
128 }
129 
130 
131 }// end of namespace
bool isProducingJustMicroSlices() const
Do we produce just microslices?
bool writeRun()
Write Run Object into output file.
bool close(const bool produce_crc=false)
Definition: RawEvent.h:63
Definition: config.py:1
Class to hold the data from the global trigger in the correct format.
Definition: RawTrigger.h:40
FILE * fOutputEventFile
File for events.
static Configuration * getInstance()
Method to obtain the class instance.
fclose(fg1)
IMPLEMENT_MAIN_STANDARD IMPLEMENT_MAIN_setBufferSource bool addDataBlock(const void *buffer)
Definition: RawEvent.h:61
#define EVENT_KEYWORD_IN_FILE_NAME
Keyword in the file name for Events&#39;s file.
bool setTrigger(const daqdataformats::RawTrigger &tr)
Definition: RawEvent.h:64
Something conflicts with RandomNumberGenerator. Keep DAQSimulator.h include below Art Framework inclu...
daqdataformats::RawRunHeader fCurrentRunHeader
Run Object.
bool produceEvent(const std::vector< daqdataformats::RawDataBlock * > &, daqdataformats::RawTrigger *)
bool writeToFile(FILE *, const daqdataformats::RawDAQData &) const
Utility method of writing DAQ data into a file.
OStream cout
Definition: OStream.cxx:6
bool isProducingRunObject() const
Do we produce Run object?
std::string getFullFileName(const std::string addition_to_file_name) const
FILE * fOutputRunFile
File for the run.
daqdataformats::RawEvent fCurrentEvent
Event Object.
#define RUN_KEYWORD_IN_FILE_NAME
bool nextEvent()
Advance to the next event - clear Event and advance it&#39;s number.
bool writeEvent()
Write Event Object into output file.
enum BeamMode string