ATLAS Offline Software
v5_DataWriter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <time.h>
6 #include <sstream>
7 #include <stdlib.h>
8 #include "v5_Guid.h"
9 #include "ers/ers.h"
10 
11 #include <boost/shared_ptr.hpp>
12 
14 #include "EventStorage/DataWriterCallBack.h"
15 #include "EventStorage/FileNameCallback.h"
16 #include "EventStorage/RawFileName.h"
17 #include "EventStorage/EventStorageIssues.h"
18 #include "EventStorage/SimpleFileName.h"
19 #include "v5_DataBuffer.h"
20 
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <unistd.h>
24 #include <stdio.h>
25 
26 using namespace std;
27 using namespace offline_EventStorage_v5;
28 using EventStorage::DataWriterCallBack;
29 using EventStorage::DWError;
30 using EventStorage::FileNameCallback;
31 using EventStorage::SimpleFileName;
32 
33 // constructors
34 DataWriter::
35 DataWriter(const string& writingPath,
36  boost::shared_ptr<FileNameCallback> theFNCB,
37  const run_parameters_record& rPar,
38  const std::string& project,
39  const std::string& streamType,
40  const std::string& streamName,
41  const std::string& stream,
42  const unsigned int lumiBlockNumber,
43  const std::string& applicationName,
44  const std::vector<std::string>& fmdStrings,
46  const unsigned int compLevel)
47 {
48  initDW(writingPath, theFNCB, rPar, project, streamType, streamName, stream, lumiBlockNumber, applicationName, fmdStrings, compression, compLevel);
49 
50 }
51 
52 DataWriter::
53 DataWriter(const string& writingPath,
54  const string& fileNameCore,
55  const run_parameters_record& rPar,
56  const freeMetaDataStrings& fmdStrings,
57  const unsigned int startIndex,
59  const unsigned int compLevel)
60 {
61  boost::shared_ptr<daq::RawFileName>
62  fileName(new daq::RawFileName(fileNameCore));
63 
64  if ( fileName->hasValidCore() ) {
65  m_project = fileName->project();
66  m_streamType = fileName->streamType();
67  m_streamName = fileName->streamName();
68  m_stream = fileName->stream();
69  m_lumiBlockNumber = fileName->lumiBlockNumber();
70  m_applicationName = fileName->applicationName();
71  } else {
72  std::stringstream mystream;
73  mystream << "FileName " << fileName->fileName()
74  << " has failed interpretation."
75  << " The file header will have no values for "
76  << " project, stream, lumiBlock and appName";
77  ERS_DEBUG(1,mystream.str());
78  // EventStorage::RawFileNameIssue myissue(ERS_HERE, mystream.str().c_str() );
79  // ers::warning(myissue);
80  m_project = "";
81  m_streamType = "";
82  m_streamName = "";
83  m_stream = "";
84  m_lumiBlockNumber = 0;
85  m_applicationName = "";
86  }
87 
88  fileName->setFileSequenceNumber(startIndex);
89 
90  initDW(writingPath, fileName, rPar, m_project, m_streamType, m_streamName,
91  m_stream, m_lumiBlockNumber, m_applicationName,
92  fmdStrings, compression,compLevel);
93 
94 }
95 
96 
97 DataWriter::
98 DataWriter(const string& writingPath,
99  const string& fileNameCore,
100  const run_parameters_record& rPar,
101  const std::string& project,
102  const std::string& streamType,
103  const std::string& streamName,
104  const std::string& stream,
105  const unsigned int lumiBlockNumber,
106  const std::string& applicationName,
107  const std::vector<std::string>& fmdStrings,
109  const unsigned int compLevel)
110 {
111  boost::shared_ptr<FileNameCallback> fileName(new SimpleFileName(fileNameCore));
112  initDW(writingPath, fileName, rPar, project, streamType, streamName, stream, lumiBlockNumber, applicationName, fmdStrings, compression, compLevel);
113 
114 }
115 
116 // destructor
117 DataWriter::~DataWriter()
118 {
119  ERS_DEBUG(1,"DataWriter::~DataWriter() called.");
120 
121  m_file_end_record.status = 1; // This identifies the end of the sequence.
122  if(m_cFileOpen) closeFile();
123 
124  delete m_compressed;
125 
126  ERS_DEBUG(1,"DataWriter::~DataWriter() finished.");
127 }
128 
129 
130 void DataWriter::
131 initDW(const string& writingPath,
132  boost::shared_ptr<FileNameCallback> theFNCB,
133  const run_parameters_record& rPar,
134  const std::string& project,
135  const std::string& streamType,
136  const std::string& streamName,
137  const std::string& stream,
138  const unsigned int lumiBlockNumber,
139  const std::string& applicationName,
140  const std::vector<std::string>& fmdStrings,
142  const unsigned int compLevel)
143 {
144  m_project = project;
145  m_streamType = streamType;
146  m_streamName = streamName;
147  m_stream = stream;
148  m_lumiBlockNumber = lumiBlockNumber;
149  m_applicationName = applicationName;
150 
151  m_filenamecallback = theFNCB;
152 
153  reset_record(&m_file_start_record,&file_start_pattern);
154  reset_record(&m_internal_run_parameters_record,&run_parameters_pattern);
155  reset_record(&m_file_end_record,&file_end_pattern);
156  m_cFileMB = 0.0;
157  m_runMB = 0.0;
158  m_latestPosition = -1;
159 
160  m_writePath = writingPath;
161  m_nextWritePath = "";
162  //m_fileNameCore = fileNameCore;
163 
164  m_file_name_strings.appName = m_applicationName;
165  // m_file_name_strings.appName = getAppName(fileNameCore);
166  m_file_name_strings.fileNameCore = m_filenamecallback->getCoreName();
167 
168  setRunParamsRecord(rPar);
169 
170  m_file_start_record.sizeLimit_MB = 0;
171  m_file_start_record.sizeLimit_dataBlocks = 0;
172  date_timeAsInt(m_file_start_record.date,m_file_start_record.time);
173 
174  m_cFileOpen=false;
175  m_openFailed = false;
176 
177  m_callBack = NULL;
178 
179  m_fmdStrings = fmdStrings;
180 
181  m_compression = compression;
182  m_complevel = compLevel;
183  m_compressed = new DataBuffer();
184 
185  // add stream, project, compression, lumiBlock
186  // (if they are valid) to meta-data:
187  m_fmdStrings.push_back("Stream=" + m_stream );
188  m_fmdStrings.push_back("Project=" + m_project );
189  std::ostringstream o;
190  o << m_lumiBlockNumber;
191  m_fmdStrings.push_back("LumiBlock=" + o.str());
192 
193  if(m_compression != offline_EventStorage_v5::NONE){
194  m_fmdStrings.push_back(offline_EventStorage_v5::compressiontag +
195  "=" + offline_EventStorage_v5::type_to_string(m_compression));
196  }
197 
198  m_check = ::adler32(0L, Z_NULL, 0);
199 
200  m_guid = "";
201  m_next_guid = "";
202  this->spaceForGuid();
203  this->openNextFile();
204 
205 }
206 
207 
208 // */
209 
210 
211 //date and time utility
212 void DataWriter::date_timeAsInt(uint32_t &getDate, uint32_t &getTime) const
213 {
214  long a_time;
215  time(&a_time);
216 
217  struct tm t;
218  localtime_r( &a_time, &t);
219 
220  getDate= 1000000*t.tm_mday+
221  10000*(1+t.tm_mon)+
222  1900+t.tm_year;
223 
224  getTime= 10000*t.tm_hour+
225  100*t.tm_min+
226  t.tm_sec ;
227 }
228 
229 
230 bool DataWriter::good() const
231 {
232 
233  if(m_openFailed) return false;
234 
235  if(m_cFileOpen)
236  {
237  return m_cFile.good();
238  }
239  else
240  {
241  return true;
242  }
243 
244 }
245 
246 
247 // configuration
248 DWError DataWriter::setMaxFileMB(const unsigned int& maxFileMB)
249 {
250  m_file_start_record.sizeLimit_MB = maxFileMB;
251  return EventStorage::DWOK;
252 }
253 
254 DWError DataWriter::setMaxFileNE(const unsigned int& maxFileNE)
255 {
256  m_file_start_record.sizeLimit_dataBlocks = maxFileNE;
257  return EventStorage::DWOK;
258 }
259 
260 void DataWriter::setRunParamsRecord(const run_parameters_record& rPar)
261 {
262  // accept the params, whatever they are
263  // run number is in this record (and only there)
264  m_internal_run_parameters_record.marker = rPar.marker;
265  m_internal_run_parameters_record.record_size = rPar.record_size;
266  m_internal_run_parameters_record.run_number = rPar.run_number;
267  m_internal_run_parameters_record.max_events = rPar.max_events;
268  m_internal_run_parameters_record.rec_enable = rPar.rec_enable;
269  m_internal_run_parameters_record.trigger_type = rPar.trigger_type;
270  m_internal_run_parameters_record.detector_mask_1of2 = rPar.detector_mask & 0xFFFFFFFF;
271  m_internal_run_parameters_record.detector_mask_2of2 = (rPar.detector_mask>> 32);
272  m_internal_run_parameters_record.beam_type = rPar.beam_type;
273  m_internal_run_parameters_record.beam_energy = rPar.beam_energy;
274 }
275 
276 // output of data
277 DWError DataWriter::putData(const unsigned int& dataSize, const void *event)
278 {
279 
280  uint32_t todisk;
282  iov.iov_base = event;
283  iov.iov_len = dataSize;
284  return this->putData(1, &iov, todisk);
285 }
286 
287 // output of scattered data using iovec
288 DWError DataWriter::putData(const unsigned int& entries, const struct iovec * my_iovec)
289 {
290  uint32_t todisk;
291  return this->putData(entries, my_iovec, todisk);
292 }
293 
294 DWError DataWriter::putData(const unsigned int& dataSize, const void *event, uint32_t& sizeToDisk){
295 
297  iov.iov_base = event;
298  iov.iov_len = dataSize;
299  return this->putData(1, &iov, sizeToDisk);
300 }
301 
302 DWError DataWriter::putData(const unsigned int& entries, const iovec_const * my_iovec, uint32_t& sizeToDisk){
303  return this->putData_implementation(entries, my_iovec, sizeToDisk);
304 }
305 
306 
307 DWError DataWriter::putPrecompressedData(const unsigned int& dataSize,
308  const void *event){
309 
311  iov.iov_base = event;
312  iov.iov_len = dataSize;
313  return this->putPrecompressedData(1, &iov);
314 }
315 
316 
317 DWError DataWriter::putPrecompressedData(const unsigned int& entries,
318  const iovec_const* my_iovec){
319 
320  uint32_t todisk;
321  return this->putData_implementation(entries, my_iovec, todisk, true);
322 }
323 
324 
325 DWError DataWriter::putData_implementation(const unsigned int& entries, const iovec_const * my_iovec, uint32_t& sizeToDisk, bool precompressed){
326 
327  ERS_DEBUG(3,"DataWriter::putData called for an iovec.");
328  if(!m_cFileOpen) openNextFile();
329 
330  if(!m_cFileOpen) return EventStorage::DWNOOK;
331 
332  if(!m_cFile.good()) return EventStorage::DWNOOK;
333 
334  // calculate events size
335  unsigned int dataSize = 0;
336  for(unsigned int i = 0; i<entries; i++) {
337  dataSize += my_iovec[i].iov_len;
338  }
339 
340 
341 
342  sizeToDisk = dataSize;
343 
344 
345  // apply limits
346  if(m_file_start_record.sizeLimit_MB>0) {
347  double eventMB=static_cast<double>(dataSize)/(1024*1024);
348  double dataMB=m_cFileMB+eventMB;
349  if(static_cast<unsigned int>(dataMB+0.5) >
350  m_file_start_record.sizeLimit_MB) {
351  ERS_DEBUG(3,"Approaching file size limit in MB.");
352  nextFile();
353  }
354  }
355 
356  if((m_file_start_record.sizeLimit_dataBlocks>0) &&
357  (m_file_end_record.events_in_file >= m_file_start_record.sizeLimit_dataBlocks)){
358  ERS_DEBUG(3,"Approaching file size limit in number of events.");
359  nextFile();
360  }
361 
362  //Here we should compress, so that we have the effective size
363  //for the event record
364  if(m_compression == ZLIB && !precompressed){
365  try{
366  offline_EventStorage_v5::zlibcompress(*m_compressed, sizeToDisk,
367  entries, my_iovec, dataSize, m_complevel);
368  }catch(offline_EventStorage_v5::CompressionIssue& ex){
369  EventStorage::WritingIssue ci(ERS_HERE, "Data compression failed.", ex);
370  ers::error(ci);
371  return EventStorage::DWNOOK;
372  }
373  }
374 
375  // prepare the event record
377  dsR.data_block_number = m_file_end_record.events_in_run + 1;
378  dsR.data_block_size = sizeToDisk;
379 
380  // remember the position
381  m_latestPosition = m_cFile.tellg();
382 
383  // write the event record followed by event data
384  file_record(&dsR,&data_separator_pattern);
385 
386 
387  if(m_compression != ZLIB || precompressed){
388  for (unsigned int i =0; i<entries; i++){
389  m_cFile.write(static_cast<const char*>(my_iovec[i].iov_base),
390  my_iovec[i].iov_len);
391 
392  m_check = ::adler32(m_check,
393  static_cast<const Bytef *>(my_iovec[i].iov_base),
394  my_iovec[i].iov_len);
395  }
396  }else{
397  m_cFile.write(static_cast<const char *>(m_compressed->handle()), sizeToDisk);
398  m_check = ::adler32(m_check,
399  static_cast<const Bytef *>(m_compressed->handle()),
400  sizeToDisk);
401  }
402 
403  // update statistics
404  m_cFileMB += static_cast<double>(sizeToDisk)/(1024*1024);
405  m_runMB += static_cast<double>(sizeToDisk)/(1024*1024);
406  m_file_end_record.events_in_file++;
407  m_file_end_record.events_in_run++;
408 
409  ERS_DEBUG(3,"Event "<< m_file_end_record.events_in_run<<" is written at offset "<<m_latestPosition);
410 
411  if(!m_cFile.good()) return EventStorage::DWNOOK;
412 
413  return EventStorage::DWOK;
414 }
415 
416 
417 int64_t DataWriter::getPosition() const
418 {
419  return m_latestPosition;
420 }
421 
422 // statistics
423 unsigned int DataWriter::eventsInFile() const
424 {
425  return m_file_end_record.events_in_file;
426 }
427 
428 unsigned int DataWriter::eventsInFileSequence() const
429 {
430  return m_file_end_record.events_in_run;
431 }
432 
433 unsigned int DataWriter::dataMB_InFile() const
434 {
435  return static_cast<unsigned int>(m_cFileMB+0.5);
436 }
437 
438 unsigned int DataWriter::dataMB_InFileSequence() const
439 {
440  return static_cast<unsigned int>(m_runMB+0.5);
441 }
442 
443 // closes the current file
444 DWError DataWriter::closeFile()
445 {
446  ERS_DEBUG(3,"DataWriter::closeFile() called.");
447 
448  // do statistics
449  m_file_end_record.data_in_file = static_cast<unsigned int>(m_cFileMB+0.5);
450  m_file_end_record.data_in_run = static_cast<unsigned int>(m_runMB+0.5);
451 
452  date_timeAsInt(m_file_end_record.date,m_file_end_record.time);
453 
454  // write eof record
455  file_record(&m_file_end_record,&file_end_pattern);
456 
457  m_cFile.close();
458  std::ostringstream oss;
459  oss.width(8);
460  oss.fill('0');
461  oss << std::hex << std::uppercase <<m_check;
462  std::string checksum = oss.str();
463  m_check = ::adler32(0L, Z_NULL, 0);
464 
465  // rename the file
466  ERS_DEBUG(3,"Rename file " << nameFile(UNFINISHED) << endl
467  << "to " << nameFile(FINISHED));
468  if (::rename(nameFile(UNFINISHED).c_str(), nameFile(FINISHED).c_str()) == -1) {
469 
470  EventStorage::WritingIssue ci(ERS_HERE, "Rename failed.");
471  ers::error(ci);
472  return EventStorage::DWNOOK;
473  }
474 
475  // check if the file is there
476  if(fileExists(nameFile(FINISHED)) && m_cFileOpen)
477  {
478  ERS_DEBUG(2,"Finished file "<<nameFile(FINISHED));
479  if(m_callBack != NULL) {
480  ERS_DEBUG(3,"Execute callback from DataWriter.");
481  m_callBack->FileWasClosed(
482  m_filenamecallback->getCurrentFileName(),
484  m_streamType,
485  m_streamName,
486  m_applicationName,
487  m_guid,
488  checksum,
489  m_file_end_record.events_in_file,
490  m_internal_run_parameters_record.run_number,
491  m_file_start_record.file_number,
492  m_lumiBlockNumber,
494  );
495  }
496 
497  // now we can substitute new directory, if specified
498  if(m_nextWritePath != "") {
499  m_writePath=m_nextWritePath;
500  m_nextWritePath="";
501  ERS_DEBUG(3,"New writing path became effective. The path is "
502  <<m_writePath);
503  }
504  m_cFileOpen = false;
505 
506  try{
507  m_filenamecallback->advance();
508  }catch(EventStorage::ES_SingleFile &e){
509  //If opennext file is called, it
510  // will fail there
511  }
512  return EventStorage::DWOK;
513  }
514  return EventStorage::DWNOOK;
515 }
516 
517 // closes the current file and opens another one
518 DWError DataWriter::nextFile()
519 {
520  ERS_DEBUG(2,"DataWriter::nextFile() called.");
521 
522  DWError we=closeFile();
523 
524 /* if (m_freename)
525  {
526  EventStorage::ES_SingleFile ci(ERS_HERE, "DataWriter called with freename = 1. DataWriter wants to go to next file, but cannot, since indexing is forbidden. Either deactive freename (so files can be indexed, or increase the file size limit (or turn it off)");
527  throw ci;
528  }*/
529 
530  openNextFile();
531  if(m_openFailed) we=EventStorage::DWNOOK;
532  return we;
533 }
534 
535 bool DataWriter::fileExists(const string& name) const
536 {
537  ifstream test(name.c_str(),ios::binary | ios::in);
538  bool isThere = test.good();
539  test.close();
540 
541  return isThere;
542 }
543 
544 void DataWriter::openNextFile()
545 {
546  m_cFileMB=0.0;
547  m_file_end_record.events_in_file=0;
548 
549  try{
550  m_file_start_record.file_number = m_filenamecallback->getIndex();
551  }catch(EventStorage::ES_SingleFile &e){
552  m_file_start_record.file_number++;
553  }
554  date_timeAsInt(m_file_start_record.date,m_file_start_record.time);
555 
556  ERS_DEBUG(2,"Trying to open file "<<nameFile(UNFINISHED));
557 
560  {
561 
563  string err = "found an existing file with name " + nameFile(UNFINISHED);
564  EventStorage::WritingIssue ci(ERS_HERE, err.c_str());
565  ers::warning(ci);
566 
567  } else {
568 
569  string err = "found an existing file with name " + nameFile(FINISHED);
570  EventStorage::WritingIssue ci(ERS_HERE, err.c_str());
571  ers::warning(ci);
572  }
573  m_filenamecallback->fileAlreadyExists();
574 
575  m_file_start_record.file_number = m_filenamecallback->getIndex();
576 
577  ostringstream oss;
578  oss << "increase file number to ";
579  oss << m_file_start_record.file_number;
580  EventStorage::WritingIssue ci(ERS_HERE, oss.str().c_str());
581  ers::warning(ci);
582  }
583  ERS_DEBUG(2,"OK to write file with number "<<m_file_start_record.file_number);
584 
585  ERS_DEBUG(2,"Opening file: " << nameFile(UNFINISHED));
586 
587  m_cFile.clear();
588  m_cFile.open(nameFile(UNFINISHED).c_str(),
589  ios::out | ios::app | ios::binary);
590 
591  m_check = ::adler32(0L, Z_NULL, 0);
592 
593  file_record(&m_file_start_record,&file_start_pattern);
594  file_record(m_file_name_strings);
595 
596  this->replaceGuid();
597 
598  ERS_DEBUG(3,"Writing "<<m_fmdStrings.size()<<" metadata strings.");
599  if(m_fmdStrings.size()>0) file_record(m_fmdStrings);
600  file_record(&m_internal_run_parameters_record,&run_parameters_pattern);
601  ERS_DEBUG(3,"Status of the file. good() returns "<<m_cFile.good());
602  m_cFileOpen = m_cFile.good();
603  m_openFailed = !m_cFile.good();
604 
605  if((m_callBack != NULL) && m_cFileOpen) {
606  ERS_DEBUG(3,"Execute callback from DataWriter.");
607  m_callBack->FileWasOpened(
608  m_filenamecallback->getCurrentFileName(),
610  m_streamType,
611  m_streamName,
612  m_applicationName,
613  m_guid,
614  m_internal_run_parameters_record.run_number,
615  m_file_start_record.file_number,
616  m_lumiBlockNumber
617  );
618  }
619 }
620 
621 string DataWriter::nameFile(const FileStatus& fs) const
622 {
623  ostringstream n;
624  n << m_writePath << "/";
625  n << m_filenamecallback->getCurrentFileName((FINISHED == fs)?false:true);
626  string name = n.str();
627  return name;
628 }
629 
630 void DataWriter::cd(const string& writingPath) {
631  m_nextWritePath = writingPath;
632  ERS_DEBUG(3,"Directory changed to "<<m_nextWritePath
633  <<" (effective for hext file).");
634 }
635 
636 bool DataWriter::inTransition() const {
637 
638  bool inT=false;
639  if((m_nextWritePath != "") &&
640  (m_nextWritePath != m_writePath)) inT=true;
641  return inT;
642 
643 }
644 
645 void DataWriter::file_record(void *ri, const void *pi) {
646 
647  uint32_t *record = reinterpret_cast<uint32_t *>(ri);
648  const uint32_t *pattern = reinterpret_cast<const uint32_t *>(pi);
649  int size=pattern[1];
650 
651  for(int i=0; i<size; i++) {
652  if(pattern[i] != 0) {
653  m_cFile.write((char *)(pattern+i),sizeof(uint32_t));
654  m_check = ::adler32(m_check,(const Bytef*)(pattern+i),sizeof(uint32_t));
655  } else {
656  m_cFile.write((char *)(record+i),sizeof(uint32_t));
657  m_check = ::adler32(m_check,(const Bytef*)(record+i),sizeof(uint32_t));
658  }
659  }
660 }
661 
662 
663 void DataWriter::file_record(const offline_EventStorage_v5::file_name_strings& nst) {
664 
665  const char *cName = nst.appName.c_str();
666  const char *cTag = nst.fileNameCore.c_str();
667 
668  uint32_t sizeName = nst.appName.size();
669  uint32_t sizeTag = nst.fileNameCore.size();
670 
671  m_cFile.write((char *)(&offline_EventStorage_v5::file_name_strings_marker),sizeof(uint32_t));
672  m_check = ::adler32(m_check,(const Bytef*)
674  sizeof(uint32_t));
675 
676  m_cFile.write((char *)(&sizeName),sizeof(uint32_t));
677  m_check = ::adler32(m_check,(const Bytef*)
678  (&sizeName),
679  sizeof(uint32_t));
680  m_cFile.write(cName,sizeName);
681  m_check = ::adler32(m_check,(const Bytef*)
682  (cName),
683  sizeName);
684 
685  char ns = sizeName % 4;
686  if(ns){
687  m_cFile.write(" ",4-ns);
688  m_check = ::adler32(m_check,(const Bytef*)" ",4-ns);
689  }
690 
691  m_cFile.write((char *)(&sizeTag),sizeof(uint32_t));
692  m_check = ::adler32(m_check,(const Bytef*)(&sizeTag),sizeof(uint32_t));
693  m_cFile.write(cTag,sizeTag);
694  m_check = ::adler32(m_check,(const Bytef*)cTag,sizeTag);
695 
696  ns = sizeTag % 4;
697  if(ns){
698  m_cFile.write(" ",4-ns);
699  m_check = ::adler32(m_check,(const Bytef*)" ",4-ns);
700  }
701 
702 }
703 
704 void DataWriter::file_record(const offline_EventStorage_v5::freeMetaDataStrings& fmdStrings)
705 {
706  ERS_DEBUG(2,"Writing the metadata strings.");
707 
708  m_cFile.write((char *)(&offline_EventStorage_v5::free_strings_marker),sizeof(uint32_t));
709  m_check = ::adler32(m_check, (const Bytef*)
711  sizeof(uint32_t));
712 
713  uint32_t nstrings = fmdStrings.size();
714  m_cFile.write((char *)(&nstrings),sizeof(uint32_t));
715  m_check = ::adler32(m_check, (const Bytef*)
716  (&nstrings),
717  sizeof(uint32_t));
718 
719  vector<string>::const_iterator it;
720  for(it=fmdStrings.begin(); it!=fmdStrings.end(); ++it) {
721 
722  const char *cst = it->c_str();
723  uint32_t slen = it->size();
724 
725  m_cFile.write((char *)(&slen),sizeof(uint32_t));
726  m_check = ::adler32(m_check,(const Bytef*)(&slen),sizeof(uint32_t));
727  m_cFile.write(cst,slen);
728  m_check = ::adler32(m_check,(const Bytef*)cst,slen);
729  char ns = slen % 4;
730  if(ns){
731  m_cFile.write(" ",4-ns);
732  m_check = ::adler32(m_check,(const Bytef*)" ",4-ns);
733  }
734  }
735 }
736 
737 void DataWriter::registerCallBack(DataWriterCallBack *pUserCBclass) {
738  m_callBack = pUserCBclass;
739  if(m_callBack != NULL) {
740  m_callBack->FileWasOpened(
741  m_filenamecallback->getCurrentFileName(),
743  m_streamType,
744  m_streamName,
745  m_applicationName,
746  m_guid,
747  m_internal_run_parameters_record.run_number,
748  m_file_start_record.file_number,
749  m_lumiBlockNumber
750  );
751  }
752 }
753 
754 void DataWriter::spaceForGuid() {
755  string e("");
756  m_fmdStrings.insert(m_fmdStrings.begin(),e);
757 }
758 
759 void DataWriter::replaceGuid() {
760  using namespace std;
761 
762  if (m_next_guid == ""){
764  m_guid = g.toString();
765  }else{
766  m_guid = m_next_guid;
767  m_next_guid = "";
768  }
769 
770  string e1="GUID=" + m_guid;
771  m_fmdStrings[0]=e1;
772 }
773 
774 void DataWriter::setGuid(const std::string& Guid){
775  m_next_guid = Guid;
776 }
777 
778 
779 uint64_t DataWriter::getFileSize(const std::string& fileNameCore) const
780 {
781  struct stat64 tmp;
782  if (::stat64(fileNameCore.c_str(), &tmp) == -1) {
783  EventStorage::WritingIssue ci(ERS_HERE, "stat64 failed.");
784  ers::error(ci);
785  return 0;
786  }
787 
788  return tmp.st_size;
789 }
790 
791 
792 offline_EventStorage_v5::CompressionType DataWriter::getCompression() const
793 {
794  return m_compression;
795 }
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
offline_EventStorage_v5::file_name_strings::fileNameCore
std::string fileNameCore
Definition: v5_EventStorageRecords.h:57
v5_Guid.h
dqt_zlumi_alleff_HIST.iov
iov
Definition: dqt_zlumi_alleff_HIST.py:119
offline_EventStorage_v5::FINISHED
@ FINISHED
Definition: v5_DataWriter.h:42
offline_EventStorage_v5::free_strings_marker
const uint32_t free_strings_marker
Definition: v5_EventStorageRecords.h:96
offline_EventStorage_v5::freeMetaDataStrings
std::vector< std::string > freeMetaDataStrings
Definition: v5_EventStorageRecords.h:60
offline_EventStorage_v5::run_parameters_record::max_events
uint32_t max_events
Definition: v5_EventStorageRecords.h:66
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
egammaEnergyPositionAllSamples::e1
double e1(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 1st sampling
offline_EventStorage_v5::FileStatus
FileStatus
Definition: v5_DataWriter.h:42
offline_EventStorage_v5::file_start_pattern
const file_start_record file_start_pattern
Definition: v5_EventStorageRecords.h:98
extractSporadic.nameFile
string nameFile
Definition: extractSporadic.py:84
skel.it
it
Definition: skel.GENtoEVGEN.py:423
offline_EventStorage_v5::run_parameters_record::run_number
uint32_t run_number
Definition: v5_EventStorageRecords.h:65
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
offline_EventStorage_v5::iovec_const
Definition: v5_EventStorageRecords.h:36
v5_DataBuffer.h
offline_EventStorage_v5::run_parameters_record::rec_enable
uint32_t rec_enable
Definition: v5_EventStorageRecords.h:67
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:144
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
offline_poolCopy_v5::Guid
Definition: v5_Guid.h:33
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
python.copyTCTOutput.getFileSize
def getFileSize(pfn)
Definition: copyTCTOutput.py:14
pi
#define pi
Definition: TileMuonFitter.cxx:65
offline_EventStorage_v5::run_parameters_record::marker
uint32_t marker
Definition: v5_EventStorageRecords.h:63
Pmt::getPosition
Eigen::Vector3d getPosition(const xAOD::TrackParticle &trk)
Definition: PoorMansIpAugmenterAlg.cxx:43
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
pool::Guid
::Guid Guid
Definition: T_AthenaPoolCustCnv.h:19
offline_EventStorage_v5::file_name_strings_marker
const uint32_t file_name_strings_marker
Definition: v5_EventStorageRecords.h:95
offline_EventStorage_v5::file_name_strings
Definition: v5_EventStorageRecords.h:55
offline_EventStorage_v5::run_parameters_record::beam_energy
uint32_t beam_energy
Definition: v5_EventStorageRecords.h:71
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
offline_EventStorage_v5::run_parameters_pattern
const internal_run_parameters_record run_parameters_pattern
Definition: v5_EventStorageRecords.h:134
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
lumiFormat.i
int i
Definition: lumiFormat.py:92
offline_EventStorage_v5::DataBuffer
Definition: v5_DataBuffer.h:16
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
beamspotman.n
n
Definition: beamspotman.py:731
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
offline_EventStorage_v5::file_end_pattern
const file_end_record file_end_pattern
Definition: v5_EventStorageRecords.h:167
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
offline_EventStorage_v5::file_name_strings::appName
std::string appName
Definition: v5_EventStorageRecords.h:56
offline_EventStorage_v5::UNFINISHED
@ UNFINISHED
Definition: v5_DataWriter.h:42
offline_EventStorage_v5::ZLIB
@ ZLIB
Definition: v5_EventStorageRecords.h:41
offline_EventStorage_v5
Definition: ByteStreamDataWriterV5.h:15
offline_EventStorage_v5::run_parameters_record::record_size
uint32_t record_size
Definition: v5_EventStorageRecords.h:64
offline_EventStorage_v5::data_separator_record
Definition: v5_EventStorageRecords.h:74
offline_EventStorage_v5::run_parameters_record::beam_type
uint32_t beam_type
Definition: v5_EventStorageRecords.h:70
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
offline_EventStorage_v5::run_parameters_record::detector_mask
uint64_t detector_mask
Definition: v5_EventStorageRecords.h:69
PayloadHelpers::dataSize
size_t dataSize(TDA::PayloadIterator start)
Size in bytes of the buffer that is needed to decode next fragment data content.
Definition: TriggerEDMDeserialiserAlg.cxx:188
offline_EventStorage_v5::iovec_const::iov_len
size_t iov_len
Definition: v5_EventStorageRecords.h:38
project
T_ResultType project(ParameterMapping::type< N > parameter_map, const T_Matrix &matrix)
Definition: MeasurementSelector.h:142
offline_EventStorage_v5::data_separator_pattern
const data_separator_record data_separator_pattern
Definition: v5_EventStorageRecords.h:160
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
RunTileMonitoring.streamType
streamType
Definition: RunTileMonitoring.py:158
ReadBchFromCool.good
good
Definition: ReadBchFromCool.py:433
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
offline_EventStorage_v5::CompressionType
CompressionType
Definition: v5_EventStorageRecords.h:41
Guid
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition: Guid.h:20
offline_EventStorage_v5::data_separator_record::data_block_size
uint32_t data_block_size
Definition: v5_EventStorageRecords.h:78
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
offline_EventStorage_v5::run_parameters_record::trigger_type
uint32_t trigger_type
Definition: v5_EventStorageRecords.h:68
Herwig7_QED_EvtGen_ll.fs
dictionary fs
Definition: Herwig7_QED_EvtGen_ll.py:17
entries
double entries
Definition: listroot.cxx:49
offline_EventStorage_v5::run_parameters_record
Definition: v5_EventStorageRecords.h:62
calibdata.cd
cd
Definition: calibdata.py:51
python.SystemOfUnits.ns
int ns
Definition: SystemOfUnits.py:130
offline_EventStorage_v5::NONE
@ NONE
Definition: v5_EventStorageRecords.h:41
get_generator_info.error
error
Definition: get_generator_info.py:40
offline_EventStorage_v5::reset_record
void reset_record(void *ri, const void *pi)
Definition: v5_EventStorageRecords.cxx:56
offline_EventStorage_v5::data_separator_record::data_block_number
uint32_t data_block_number
Definition: v5_EventStorageRecords.h:77
v5_DataWriter.h
python.BeamSpotUpdate.compression
compression
Definition: BeamSpotUpdate.py:188
fileExists
bool fileExists(const std::string &filename)
Definition: main_comphistfiles.cxx:57