1 #include "otsdaq/DataManager/RawDataSaverConsumerBase.h"
2 #include "otsdaq/Macros/BinaryStringMacros.h"
3 #include "otsdaq/MessageFacility/MessageFacility.h"
15 RawDataSaverConsumerBase::RawDataSaverConsumerBase(std::string supervisorApplicationUID,
16 std::string bufferUID,
17 std::string processorUID,
19 const std::string& configurationPath)
21 ,
DataConsumer(supervisorApplicationUID, bufferUID, processorUID, HighConsumerPriority)
22 ,
Configurable(theXDAQContextConfigTree, configurationPath)
23 , filePath_(theXDAQContextConfigTree.getNode(configurationPath).getNode(
"FilePath").getValue<std::string>())
24 , fileRadix_(theXDAQContextConfigTree.getNode(configurationPath).getNode(
"RadixFileName").getValue<std::string>())
25 , maxFileSize_(theXDAQContextConfigTree.getNode(configurationPath).getNode(
"MaxFileSize").getValue<long>() * 1000000)
26 , currentSubRunNumber_(0)
34 RawDataSaverConsumerBase::~RawDataSaverConsumerBase(
void) {}
37 void RawDataSaverConsumerBase::startProcessingData(std::string runNumber)
41 currentSubRunNumber_ = 0;
44 DataConsumer::startProcessingData(runNumber);
48 void RawDataSaverConsumerBase::stopProcessingData(
void)
50 DataConsumer::stopProcessingData();
55 void RawDataSaverConsumerBase::openFile(std::string runNumber)
57 currentRunNumber_ = runNumber;
59 std::stringstream fileName;
60 fileName << filePath_ <<
"/" << fileRadix_ <<
"_Run" << runNumber;
63 fileName <<
"_" << currentSubRunNumber_;
64 fileName <<
"_Raw.dat";
65 __CFG_COUT__ <<
"Saving file: " << fileName.str() << std::endl;
66 outFile_.open(fileName.str().c_str(), std::ios::out | std::ios::binary);
67 if(!outFile_.is_open())
69 __CFG_SS__ <<
"Can't open file " << fileName.str() << std::endl;
77 void RawDataSaverConsumerBase::closeFile(
void)
79 if(outFile_.is_open())
87 void RawDataSaverConsumerBase::save(
const std::string& data)
134 long length = outFile_.tellp();
135 if(length >= maxFileSize_ / 1000)
138 ++currentSubRunNumber_;
139 openFile(currentRunNumber_);
143 writePacketHeader(data);
144 outFile_.write((
char*)&data[0], data.length());
145 writePacketFooter(data);
149 bool RawDataSaverConsumerBase::workLoopThread(toolbox::task::WorkLoop* )
154 return WorkLoop::continueWorkLoop_;
158 void RawDataSaverConsumerBase::fastRead(
void)
161 if(DataConsumer::read(dataP_, headerP_) < 0)
175 DataConsumer::setReadSubBuffer<std::string, std::map<std::string, std::string> >();
179 void RawDataSaverConsumerBase::slowRead(
void)
183 if(DataConsumer::read(data_, header_) < 0)