10 static size_t locEVIONumOutputThreads = 0;
11 return locEVIONumOutputThreads;
17 static map<string, HDEVIOWriter*> locEVIOOutputters;
18 return locEVIOOutputters;
24 static map<string, DEVIOBufferWriter*> locEVIOBufferWriters;
25 return locEVIOBufferWriters;
31 static map<string, pthread_t> locEVIOOutputThreads;
32 return locEVIOOutputThreads;
46 gPARMS->SetDefaultParameter(
"EVIOOUT:COMPACT" ,
COMPACT,
"Drop words where we can to reduce output file size. This shouldn't loose any vital information, but can be turned off to help with debugging.");
47 gPARMS->SetDefaultParameter(
"EVIOOUT:PREFER_EMULATED" ,
PREFER_EMULATED,
"If true, then sample data will not be written to output, but emulated hits will. Otherwise, do exactly the opposite.");
48 gPARMS->SetDefaultParameter(
"EVIOOUT:DEBUG_FILES" ,
DEBUG_FILES,
"Write input and output debug files in addition to the standard output.");
54 locEventLoop->GetSingle(
ttab);
57 japp->WriteLock(
"EVIOWriter");
61 japp->Unlock(
"EVIOWriter");
66 jerr <<
"Unable to open \"hdevio_debug_input.evio\"!" << endl;
70 jout <<
"Opened \"hdevio_debug_input.evio\" for debug output" << endl;
75 jerr <<
"Unable to open \"hdevio_debug_output_preswap.evio\"!" << endl;
79 jout <<
"Opened \"hdevio_debug_output_preswap.evio\" for debug output" << endl;
92 jerr <<
"Tried to set values in DEventWriterEVIO::SetDetectorsToWriteOut() but translation table not loaded!" << endl;
97 japp->WriteLock(
"EVIOWriter");
99 japp->Unlock(
"EVIOWriter");
103 japp->Unlock(
"EVIOWriter");
107 set<uint32_t> rocs_to_write_out;
110 if(detector_list ==
"") {
111 japp->WriteLock(
"EVIOWriter");
113 japp->Unlock(
"EVIOWriter");
118 map<string, DTranslationTable::Detector_t> name_to_id;
124 std::istringstream ss(detector_list);
126 while(std::getline(ss, token,
',')) {
135 rocids.insert(rocids1.begin(), rocids1.end());
136 rocids.insert(rocids2.begin(), rocids2.end());
142 rocids.insert(rocids1.begin(), rocids1.end());
146 rocs_to_write_out.insert( rocids.begin(), rocids.end() );
150 japp->WriteLock(
"EVIOWriter");
152 japp->Unlock(
"EVIOWriter");
158 vector<const JObject *> locObjectsToSaveNull;
159 return Write_EVIOEvent(locEventLoop, locOutputFileNameSubString, locObjectsToSaveNull);
164 vector<const JObject *> &locObjectsToSave)
const
166 JEvent& locEvent = locEventLoop->GetJEvent();
169 JEventSource* locEventSource = locEvent.GetJEventSource();
170 if(locEventSource == NULL)
178 JEvent &jevent = locEventLoop->GetJEvent();
179 JEventSource *jes = jevent.GetJEventSource();
182 static bool warned =
false;
183 if(!warned) jerr <<
"Event source not a JEventSource_EVIO type!" << endl;
193 string locOutputFileName =
Get_OutputFileName(locEventLoop, locOutputFileNameSubString);
194 japp->WriteLock(
"EVIOWriter");
208 if(locObjectsToSave.size() == 0)
219 japp->Unlock(
"EVIOWriter");
226 vector<uint32_t> *locOutputBufferVec =
new vector<uint32_t>();
227 locOutputBufferVec->reserve(locOutputBufferSize);
229 double locOutputBufferWords = locOutputBufferSize/4;
234 for(uint32_t i=0; i<locOutputBufferWords; i++) {
237 locOutputBufferVec->push_back(locOutputBuffer[i]);
242 return Write_EVIOBuffer(locEventLoop, locOutputBufferVec, locOutputFileNameSubString);
250 JEvent& locEvent = locEventLoop->GetJEvent();
253 JEventSource* locEventSource = locEvent.GetJEventSource();
254 if(locEventSource == NULL)
258 if(locEvioSource == NULL) {
259 jerr <<
"WARNING!!! You MUST use this only with EVIO formatted data!!!" << endl;
263 string locOutputFileName =
Get_OutputFileName(locEventLoop, locOutputFileNameSubString);
264 japp->WriteLock(
"EVIOWriter");
270 jerr <<
"Unable to open EVIO file \""<< locOutputFileName <<
"\" for writing!" << endl;
272 japp->Unlock(
"EVIOWriter");
282 japp->Unlock(
"EVIOWriter");
295 JEvent& locEvent = locEventLoop->GetJEvent();
296 JEventSource* locEventSource = locEvent.GetJEventSource();
297 if(locEventSource == NULL)
298 return "no_name.evio";
301 string locSourceFileName = locEventSource->GetSourceName();
302 size_t locSlashIndex = locSourceFileName.find_last_of(
"/");
303 string locSourceFileName_Pathless = (locSlashIndex != string::npos) ? locSourceFileName.substr(locSlashIndex + 1) : locSourceFileName;
306 size_t locDotIndex = locSourceFileName_Pathless.find_last_of(
".");
307 if(locDotIndex != string::npos)
309 string locSuffix = locSourceFileName_Pathless.substr(locDotIndex + 1);
310 if((locSuffix ==
"root") || (locSuffix ==
"evio") || (locSuffix ==
"hddm"))
311 locSourceFileName_Pathless = locSourceFileName_Pathless.substr(0, locDotIndex);
314 return (locSourceFileName_Pathless +
string(
".") + locOutputFileNameSubString +
string(
".evio"));
326 pthread_t locEVIOout_thr;
328 bool success = (result == 0);
332 jerr <<
"Unable to open EVIO file: error code = " << result << endl;
335 jout <<
"Output EVIO file " << locOutputFileName <<
" created." << endl;
346 japp->WriteLock(
"EVIOWriter");
351 japp->Unlock(
"EVIOWriter");
359 string locOutputFileName = locIterator->first;
364 locEVIOOutputter->
Quit();
367 int result = pthread_join(locEVIOOutputThread, &retval);
369 jerr <<
"Problem closing EVIO file: error code = " << result << endl;
370 delete locEVIOOutputter;
371 std::cout <<
"Closed EVIO file " << locOutputFileName << std::endl;
376 japp->Unlock(
"EVIOWriter");
void * HDEVIOOutputThread(void *evioout)
void GetEVIOBuffer(jana::JEvent &jevent, uint32_t *&buff, uint32_t &size) const
std::ofstream * ofs_debug_input
static map< DTranslationTable::Detector_t, set< uint32_t > > & Get_ROCID_By_System(void)
map< string, pthread_t > & Get_EVIOOutputThreads(void) const
size_t & Get_NumEVIOOutputThreads(void) const
map< string, DEVIOBufferWriter * > & Get_EVIOBufferWriters(void) const
void AddBufferToOutput(vector< uint32_t > *buff)
DEventWriterEVIO(JEventLoop *locEventLoop)
vector< uint32_t > * GetBufferFromPool(void)
string Get_OutputFileName(JEventLoop *locEventLoop, string locOutputFileNameSubString) const
bool Write_EVIOBuffer(JEventLoop *locEventLoop, vector< uint32_t > *locOutputBuffer, string locOutputFileNameSubString) const
void SetDetectorsToWriteOut(string detector_list, string locOutputFileNameSubString) const
bool Write_EVIOEvent(JEventLoop *locEventLoop, string locOutputFileNameSubString) const
std::ofstream * ofs_debug_output
const DTranslationTable * ttab
void WriteEventToBuffer(JEventLoop *loop, vector< uint32_t > &buff, vector< const JObject * > objects_to_save) const
map< string, HDEVIOWriter * > & Get_EVIOOutputters(void) const
bool Open_OutputFile(JEventLoop *locEventLoop, string locOutputFileName) const
The JEventSource_EVIO class implements a JEventSource capable of reading in EVIO data from raw data f...
static string DetectorName(Detector_t type)