Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

io::ReadWriteModule Class Reference

Basic interface to event data file input and output. More...

#include <ReadWriteModule.h>

List of all members.

Public Member Functions

 ReadWriteModule ()
virtual ~ReadWriteModule ()
int AddFile (const char *file_regexp)
int RemoveFile (const char *file_regexp)
int GoToFile (const char *file)
int AdvanceFile (int n=1)
int RewindFile (int n=1)
virtual int GoTo (int run, int event)
virtual int Advance (int n=1)
virtual int Rewind (int n=1)
virtual int Reload ()
void AdoptInputFilter (io::Filter *f)
void AdoptOutputFilter (io::Filter *f)
void SetOutputFileName (const char *n)
void Report () const
const char * CurrentFile () const
const char * FileName (int i) const
int RunNumber () const
int EventNumber () const
bool ReadOK ()
edm::EventHandleGetEvent ()
int WriteEvent ()
void Close ()
void SetOutSizeLimit (int mbLimit)

Protected Member Functions

void SetReadOK (bool ok=true)
void SetEventHandle (io::EventHandle *handle)

Private Member Functions

virtual void UpdateEventNumbers ()
virtual int SetupInputFile ()
int SetupOutputFile ()
bool CheckInFilters (edm::EventHandle &evt)
bool CheckOutFilters (edm::EventHandle &evt)

Private Attributes

int fRunNumber
 Run number for current event.
int fEventNumber
 Event number for current event.
bool fReadOK
 Next read should be OK?
int fFileIndex
 Current place in the file list.
TFile * fInFile
 Current file pointer.
io::EventHandlefEvtHandle
 The event handle.
bool fOwnHandle
 Is the EvtHandle owned by us?
std::vector< std::string > fFileList
 List of files attached.
TFile * fOutFile
 Output data file.
int fNwrite
 Number of events written.
int fFlushFreq
 Flush output every n events.
Long64_t fOutSizeLimit
 [bytes] Split output after this limit
std::vector< io::Filter * > fInFilterList
 Owned list of input filters.
std::vector< io::Filter * > fOutFilterList
 Owned list of output filters.


Detailed Description

Basic interface to event data file input and output.

Definition at line 27 of file ReadWriteModule.h.


Constructor & Destructor Documentation

ReadWriteModule::ReadWriteModule  ) 
 

Definition at line 19 of file ReadWriteModule.cxx.

00019                                  :
00020   fRunNumber   (  0     ),
00021   fEventNumber (  0     ),
00022   fReadOK      (  false ), 
00023   fFileIndex   ( -1     ), 
00024   fInFile      (  0     ), 
00025   fEvtHandle   (  0     ), 
00026   fOwnHandle   (  true  ),
00027   fOutFile     (  0     ),
00028   fNwrite      (  0     ),
00029   fFlushFreq   (  100   ),
00030   fOutSizeLimit(  0     )
00031 { 
00032   // fEvtHandle pointer is set to 0 so that classes which inherit can
00033   // change the pointer in their constructor before the handle is ever
00034   // accessed by IO module
00035 }

ReadWriteModule::~ReadWriteModule  )  [virtual]
 

Close all files and clean up

Definition at line 41 of file ReadWriteModule.cxx.

References fInFile, fInFilterList, fOutFile, fOutFilterList, and fOwnHandle.

00042 { 
00043   if (fInFile) {
00044     fInFile->Close();
00045     delete fInFile;
00046     fInFile = 0;
00047   }
00048   if (fOutFile) {
00049     fOutFile->Write();
00050     fOutFile->Close();
00051     delete fOutFile;
00052     fOutFile = 0;
00053   }
00054   if (fOwnHandle && fEvtHandle) {
00055     delete fEvtHandle;
00056   }
00057   std::vector<Filter*>::iterator itr;
00058   std::vector<Filter*>::iterator itrEnd (fInFilterList.end());
00059   itr    = fInFilterList.begin();
00060   itrEnd = fInFilterList.end();
00061   for (; itr!=itrEnd; ++itr) if (*itr) delete (*itr);
00062   itr    = fOutFilterList.begin();
00063   itrEnd = fOutFilterList.end();
00064   for (; itr!=itrEnd; ++itr) if (*itr) delete (*itr);
00065 }


Member Function Documentation

int ReadWriteModule::AddFile const char *  file_regexp  ) 
 

Add files that match the regular expression

Todo:
: The method for finding files which match the regular expression is rather primitive

Definition at line 74 of file ReadWriteModule.cxx.

References edm::EventHandle::Clear(), fEvtHandle, fFileIndex, fFileList, fReadOK, and SetupInputFile().

Referenced by evdb::IoModule::AddFile(), main(), and jobc::CmdLine::SetupIoModule().

00075 {
00076   int nfiles = 0;
00077 
00078   // If nobody created event handle, we should do it now
00079   if (!fEvtHandle) fEvtHandle = new EventHandle;
00080 
00081   // Handle several of the special file types here, defaulting in the
00082   // end to looking for files in the local directory structure
00083   if(strstr(file_regexp,"dcache:dcap")!=0){
00084     std::string f(file_regexp);
00085     fFileList.push_back(f);
00086     ++nfiles;
00087   }
00088   else if (strstr(file_regexp, "root://") != 0) {
00089     std::string f(file_regexp);
00090     fFileList.push_back(f);
00091     ++nfiles;
00092   }
00093   else if (strncmp(file_regexp, "/dev/null",9)==0) {
00094     std::string f(file_regexp);
00095     fFileList.push_back(f);
00096     ++nfiles;
00097   }
00098   else {
00099     // Cheap way to get list of files matching the expression (assumes
00100     // some flavor of unix
00101     char tmp_name[128] = {"/tmp/IOMOD.XXXXXX"};
00102     mkstemp(tmp_name);
00103     std::string cmd;
00104     cmd  = "(ls ";
00105     cmd += file_regexp;
00106     cmd += " > ";
00107     cmd += tmp_name;
00108     cmd += ") >& /dev/null";
00109     system(cmd.c_str());
00110     
00111     // Open the temp file and get the list of files which matched
00112     static const int s = 256;
00113     char             buff[s];
00114     FILE*            fp     = fopen(tmp_name,"r");
00115     std::string      file;
00116     while ( fgets(buff,s-1,fp) != NULL ) {
00117       int len = strlen(buff);
00118       while (buff[len]==' ' || buff[len]=='\n' || buff[len]=='\0') --len;
00119       buff[len+1]='\0';
00120       file = buff;
00121       fFileList.push_back(file);
00122       ++nfiles;
00123     }
00124     if (nfiles==0) {
00125       std::cerr << "No input files match '" 
00126                 << file_regexp 
00127                 << "'" << std::endl;
00128     }
00129     fclose(fp);
00130     // Remove the temporary file
00131     unlink(tmp_name);
00132   }
00133 
00134   // Setup the first file in the list
00135   if (fFileIndex<0 && fFileList.size()>0) {
00136     fFileIndex = 0;
00137     fEvtHandle->Clear();
00138     if (this->SetupInputFile()) {
00139       fReadOK = true;
00140     }
00141     else {
00142       fReadOK = false;
00143     }
00144   }
00145   return nfiles;
00146 }

void ReadWriteModule::AdoptInputFilter io::Filter f  ) 
 

Definition at line 562 of file ReadWriteModule.cxx.

References fInFilterList.

Referenced by jobc::CmdLine::SetupIoModule().

00562                                                 { 
00563   fInFilterList.push_back(f); 
00564 }

void ReadWriteModule::AdoptOutputFilter io::Filter f  ) 
 

Definition at line 570 of file ReadWriteModule.cxx.

References fOutFilterList.

00570                                                  {
00571   fOutFilterList.push_back(f);
00572 }

int ReadWriteModule::Advance int  n = 1  )  [virtual]
 

Advance n events in the stream

Parameters:
n : Number of events to skip ahead
Returns:
Number of events actually skipped

Definition at line 287 of file ReadWriteModule.cxx.

References io::EventHandle::Advance(), AdvanceFile(), CheckInFilters(), fEvtHandle, fReadOK, and UpdateEventNumbers().

Referenced by evdb::IoModule::Advance(), GoTo(), main(), jobc::Job::Run(), and jobc::CmdLine::SetupIoModule().

00288 { 
00289   assert(fEvtHandle);
00290 
00291   int ndone = 0;
00292   while (ndone < n) {
00293     // Try to advance far enough in the current file to match the request
00294     int ntry = n-ndone;
00295     int ndid;
00296     ndid = fEvtHandle->Advance(ntry);
00297     ndone += ndid;
00298     // If the current file doesn't have enough events to fill the
00299     // request, go to the next file
00300     if (ndid<ntry) {
00301       int advance = this->AdvanceFile();
00302       // If there is no next file, stop and return the number of records
00303       // actually advanced
00304       if (advance<1) {
00305         fReadOK = false;
00306         return ndone;
00307       }
00308       ++ndone; // count the file boundary as one advance
00309     }
00310   }
00311   // Check if the current event passed filters, if not, advance one
00312   if (this->CheckInFilters(*fEvtHandle) == false) {
00313     ndone += this->Advance(1);
00314   }
00315   this->UpdateEventNumbers();
00316   return ndone;
00317 }

int ReadWriteModule::AdvanceFile int  n = 1  ) 
 

Advance n positions in the file list

Parameters:
n : Number of files to skip. Counts the current file.
Returns:
Number of files actually skipped.

Definition at line 187 of file ReadWriteModule.cxx.

References fFileIndex, fFileList, fReadOK, and SetupInputFile().

Referenced by Advance(), and evdb::IoModule::AdvanceFile().

00188 { 
00189   if (n<=0) return 0;
00190   
00191   int indexMax  = fFileList.size()-1;
00192   int indexSave = fFileIndex;
00193 
00194   fFileIndex += n;
00195   if (fFileIndex > indexMax) {
00196     fFileIndex = indexMax+1;
00197     fReadOK    = false;
00198     return 0;
00199   }
00200 
00201   // Do something to open new file...
00202   this->SetupInputFile();
00203 
00204   return (fFileIndex-indexSave);
00205 }

bool ReadWriteModule::CheckInFilters edm::EventHandle evd  )  [private]
 

Check if this event passes all the input filters attached to this module. Events which fail will be skipped.

Parameters:
evd : The event to check against all filters.

Definition at line 581 of file ReadWriteModule.cxx.

References fInFilterList.

Referenced by Advance(), and Rewind().

00582 {
00583   std::vector<Filter*>::iterator itr    (fInFilterList.begin());
00584   std::vector<Filter*>::iterator itrEnd (fInFilterList.end());
00585   for (; itr!=itrEnd; ++itr) {
00586     bool ret = (**itr)(evd);
00587     if (ret==false) return false; // Failed filter
00588   }
00589   return true; // Passed all filters
00590 }

bool ReadWriteModule::CheckOutFilters edm::EventHandle evd  )  [private]
 

Check if this event passes all the output filter attached to this module. Events which failed will not be written.

Parameters:
evd : Handle to the event to examine

Definition at line 599 of file ReadWriteModule.cxx.

References fOutFilterList.

00600 {
00601   std::vector<Filter*>::iterator itr    (fOutFilterList.begin());
00602   std::vector<Filter*>::iterator itrEnd (fOutFilterList.end());
00603   for (; itr!=itrEnd; ++itr) {
00604     bool ret = (**itr)(evd);
00605     if (ret==false) return false; // Failed filter
00606   }
00607   return true; // Passed all filters
00608 }

void ReadWriteModule::Close  ) 
 

Close the output file attached to this module

Definition at line 627 of file ReadWriteModule.cxx.

References io::EventHandle::Close(), fNwrite, fOutFile, and io::EventHandle::Write().

Referenced by evdb::AutoAdvance::HandleTimer(), and main().

00628 {
00629   if (fOutFile) {
00630     std::cout << "Wrote " << fNwrite << " events. Closing file."
00631               << std::endl;
00632     fOutFile->Write();
00633     fOutFile->Close();
00634     delete fOutFile;
00635     fOutFile = 0;
00636   }
00637 }

const char * ReadWriteModule::CurrentFile  )  const
 

Return the name of the currently open input file

Parameters:
The name of the currently open input file

Definition at line 413 of file ReadWriteModule.cxx.

References fFileIndex, and fFileList.

Referenced by evdb::IoModule::CurrentFile(), main(), and jobc::Job::Run().

00414 {
00415   if (fFileList.size()>0) {
00416     if (fFileIndex>=0 && fFileIndex<(int)fFileList.size()) {
00417       return fFileList[fFileIndex].c_str();
00418     }
00419   }
00420   return "";
00421 }

int io::ReadWriteModule::EventNumber  )  const [inline]
 

Definition at line 53 of file ReadWriteModule.h.

Referenced by jobc::Job::Run().

00053 { return fEventNumber; }

const char * ReadWriteModule::FileName int  i  )  const
 

Return the name of the ith file in the input list

Parameters:
i : Index (starts from 0)
Returns:
: File name. 0 if there is no file at the position i

Definition at line 430 of file ReadWriteModule.cxx.

References fFileList.

Referenced by evdb::IoModule::FileName().

00431 {
00432   if (i>=0 && i<(int)fFileList.size()) return fFileList[i].c_str();
00433   return 0;
00434 }

edm::EventHandle & ReadWriteModule::GetEvent  ) 
 

Return the event handle connected to the input stream

Returns:
The event handle connected to the input stream

Definition at line 442 of file ReadWriteModule.cxx.

References fEvtHandle.

Referenced by evdb::IoModule::GetEvent(), main(), jobc::Job::Run(), and UpdateEventNumbers().

00443 {
00444   if (!fEvtHandle) fEvtHandle = new EventHandle;
00445   return *fEvtHandle; 
00446 }

int ReadWriteModule::GoTo int  run,
int  event
[virtual]
 

Skip exactly to a particular run and event number.

Returns:
1 if run/event are found, 0 if failed.
If we fail to find the event, the position in the stream is left where the search terminated.

Definition at line 243 of file ReadWriteModule.cxx.

References Advance(), fEventNumber, fRunNumber, Rewind(), and UpdateEventNumbers().

Referenced by evdb::IoModule::GoTo(), main(), and jobc::CmdLine::SetupIoModule().

00244 { 
00245   // Get an initial guess at how many events to skip
00246   this->UpdateEventNumbers();
00247   int nSkipEvent = abs(event - fEventNumber); 
00248   if (run != fRunNumber) nSkipEvent += 1000;
00249   
00250   // This assumes that the files are sorted in run/event order
00251   for (;;) {
00252     // Check if we're done
00253     if (fRunNumber == run && fEventNumber == event) return 1;
00254     
00255     // Advance/Rewind in the data stream
00256     while (run<fRunNumber || event<fEventNumber) { 
00257       int nrew = this->Rewind(nSkipEvent);
00258       this->UpdateEventNumbers();
00259       if (nrew == 0) break;
00260     }
00261     while (run>fRunNumber || event>fEventNumber) {
00262       int nadv = this->Advance(nSkipEvent);
00263       this->UpdateEventNumbers();
00264       if (nadv == 0) break;
00265     }
00266 
00267     // Check if we've found the right event
00268     if (fRunNumber == run && fEventNumber == event) return 1;
00269 
00270     // If we were stepping one-by-one and couldn't find the event,
00271     // stop searching
00272     if (nSkipEvent <= 1) return 0;
00273 
00274     // Reduce step size for next search
00275     nSkipEvent = nSkipEvent/2;
00276   }
00277   return 0;
00278 }

int ReadWriteModule::GoToFile const char *  file  ) 
 

Move the input stream to the start of a named file

Parameters:
file : name of file to skip to
Returns:
1 on success, 0 on failure

Definition at line 166 of file ReadWriteModule.cxx.

References fFileIndex, fFileList, and SetupInputFile().

Referenced by evdb::IoModule::GoToFile().

00167 { 
00168   unsigned int i;
00169   for (i=0; i<fFileList.size(); ++i) {
00170     if (fFileList[i] == file) {
00171       fFileIndex = i;
00172       this->SetupInputFile();
00173       return 1;
00174     }
00175   }
00176   // File not in list
00177   return 0;
00178 }

bool ReadWriteModule::ReadOK  ) 
 

Definition at line 500 of file ReadWriteModule.cxx.

Referenced by main(), and jobc::Job::Run().

00500 { return fReadOK; }

int ReadWriteModule::Reload  )  [virtual]
 

Mark the event handle as unfilled so that requests for data members have to go back to the event file

Returns:
1 on success (
Todo:
success is the only possibility...)

Definition at line 358 of file ReadWriteModule.cxx.

References edm::EventHandle::ClearLoadFlags(), and fEvtHandle.

Referenced by evdb::IoModule::Reload().

00359 { 
00360   fEvtHandle->ClearLoadFlags();
00361   return 1;
00362 }

int ReadWriteModule::RemoveFile const char *  file_regexp  ) 
 

Remove files from the input list

Parameters:
file_regexp : Files to remove from a list
Todo:
Not implemented

Definition at line 155 of file ReadWriteModule.cxx.

Referenced by evdb::IoModule::RemoveFile().

00155                                                            {
00156   return 0; 
00157 }

void ReadWriteModule::Report  )  const
 

Print some summary information about the status of the input module

Definition at line 395 of file ReadWriteModule.cxx.

References fEvtHandle, fFileList, and io::EventHandle::Index().

Referenced by evdb::IoModule::AddFile(), and jobc::Job::Run().

00396 {
00397   std::cout << "Files in list:" << std::endl;
00398   for (int i=0; i<(int)fFileList.size(); ++i) {
00399     if (i==fFileIndex) std::cout << ">";
00400     else               std::cout << " ";
00401     std::cout << "[" << i << "] " << fFileList[i];
00402     if (i==fFileIndex) std::cout << " (i="<<fEvtHandle->Index()<<")";
00403     std::cout << std::endl;
00404   }
00405 }

int ReadWriteModule::Rewind int  n = 1  )  [virtual]
 

Go back n positions in the event stream

Parameters:
n : Skip backwards n events in the stream
Returns:
Number of events actually skipped

Definition at line 326 of file ReadWriteModule.cxx.

References CheckInFilters(), fEvtHandle, io::EventHandle::Rewind(), and RewindFile().

Referenced by GoTo(), and evdb::IoModule::Rewind().

00327 {
00328   int ndone = 0;
00329   while (ndone < n) {
00330     // Try to rewind far enough in the current file to finish
00331     int ntry = n-ndone;
00332     int ndid = fEvtHandle->Rewind(ntry);
00333     ndone += ndid;
00334     // Not enough events in current file, go to previous file and 
00335     if (ndid<ntry) {
00336       int rewind = this->RewindFile();
00337       if (rewind<1) {
00338         std::cout << "Reached start of event stream.\n";
00339         return ndone;
00340       }
00341       ++ndone; // count the file boundary as one rewind
00342     }
00343   }
00344   // Check if the current event passed filters, if not, rewind one
00345   if (this->CheckInFilters(*fEvtHandle) == false) {
00346     ndone += this->Rewind(1);
00347   }
00348   return ndone;
00349 }

int ReadWriteModule::RewindFile int  n = 1  ) 
 

Rewind n positions in the file list

Parameters:
n : Number of position to go back
Returns:
Number of positions actually skipped

Definition at line 214 of file ReadWriteModule.cxx.

References fFileIndex, fReadOK, and SetupInputFile().

Referenced by evdb::AutoAdvance::HandleTimer(), Rewind(), and evdb::IoModule::RewindFile().

00215 {
00216   if (n<=0) return 0;
00217   
00218   int indexMin  = 0;
00219   int indexSave = fFileIndex;
00220 
00221   fFileIndex -= n;
00222   if (fFileIndex < indexMin) {
00223     fFileIndex = 0;
00224     fReadOK    = false;
00225     return 0;
00226   }
00227 
00228   // Do something to open new file...
00229   this->SetupInputFile();
00230 
00231   return (indexSave-fFileIndex);
00232 }

int io::ReadWriteModule::RunNumber  )  const [inline]
 

Definition at line 52 of file ReadWriteModule.h.

Referenced by jobc::Job::Run(), and jobc::CmdLine::SetupIoModule().

00052 { return fRunNumber;   }

void ReadWriteModule::SetEventHandle io::EventHandle handle  )  [protected]
 

Establish the connection between this module and an event handle.

Parameters:
handle : The event handle where event data ends up in memory

Definition at line 616 of file ReadWriteModule.cxx.

References fEvtHandle, and fOwnHandle.

00617 {
00618   assert(!fEvtHandle);
00619   fEvtHandle = handle;
00620   fOwnHandle = false;
00621 }

void ReadWriteModule::SetOutputFileName const char *  n  ) 
 

Set the output file name and set it up

Parameters:
n : Name of the output file

Todo:
No provisions made for appending to files etc. etc. Only "RECREATE" supported

Definition at line 373 of file ReadWriteModule.cxx.

References io::EventHandle::Close(), fEvtHandle, fOutFile, io::EventHandle::SetupOutputFile(), and io::EventHandle::Write().

Referenced by main(), evdb::IoModule::SetOutputFileName(), jobc::CmdLine::SetupIoModule(), and WriteEvent().

00374 {
00375   std::string fname(n);
00376   if (!fEvtHandle) fEvtHandle = new EventHandle;
00377   if (fOutFile && (fname==fOutFile->GetName())) return;
00378 
00379   if (fOutFile) { 
00380     fEvtHandle->Close();
00381     fOutFile->Flush(); 
00382     fOutFile->Write(); 
00383     delete fOutFile; 
00384     fOutFile = 0;
00385   }
00386 
00387   fOutFile = new TFile(fname.c_str(),"RECREATE","Event Data File",1);
00388   fEvtHandle->SetupOutputFile(fOutFile);
00389 }

void ReadWriteModule::SetOutSizeLimit int  mbLimit  ) 
 

Set the output file buffer size

Parameters:
mbLimit : Size in Mb

Definition at line 645 of file ReadWriteModule.cxx.

References fOutSizeLimit.

Referenced by jobc::CmdLine::SetupIoModule().

00646 {
00647   fOutSizeLimit = mbLimit; fOutSizeLimit *= 1000000;
00648 }

void io::ReadWriteModule::SetReadOK bool  ok = true  )  [inline, protected]
 

Definition at line 69 of file ReadWriteModule.h.

00069 { fReadOK = ok; }

int ReadWriteModule::SetupInputFile  )  [private, virtual]
 

Definition at line 504 of file ReadWriteModule.cxx.

References io::EventHandle::Close(), fEvtHandle, fFileIndex, fFileList, fInFile, fReadOK, io::EventHandle::SetupInputFile(), and UpdateEventNumbers().

Referenced by AddFile(), AdvanceFile(), GoToFile(), and RewindFile().

00505 {
00506 //======================================================================
00507 // Setup a new file
00508 //======================================================================
00509   if (fFileIndex<0 || fFileIndex>=(int)fFileList.size()) {
00510     fReadOK = false;
00511     return 0;
00512   }
00513   
00514   // Check if the filename has changed
00515   if (fInFile && fInFile->GetName()!=fFileList[fFileIndex]) {
00516     fInFile->Flush();
00517     fInFile->Close();
00518     delete fInFile;
00519     fInFile = 0;
00520     fReadOK = false;
00521   }
00522   
00523   // Check for special case where we've been asked to supply a stream
00524   // of empty events
00525   if (strncmp(fFileList[fFileIndex].c_str(),"/dev/null",9)==0) {
00526     fEvtHandle = new EmptyEventHandle(fFileList[fFileIndex].c_str());
00527     this->UpdateEventNumbers();
00528     fReadOK = true;
00529     return 1;
00530   }
00531 
00532   //....................................................................  
00533   // From here on out, handle the normal case of an input
00534   // FMWK-formatted file
00535   
00536   // Open the new file
00537   fInFile = TFile::Open(fFileList[fFileIndex].c_str());
00538   if (fInFile==0) {
00539     std::cout << "Failed to open file '" 
00540               << fFileList[fFileIndex] << "' for read.\n";
00541     // std::cout<<"Is it a dcache file? "<<endl;
00542     // if(strstr(fFileList[fFileIndex].c_str(),"dcache:dcap")!=0){
00543     // fInFile = TFile::Open(fFileList[fFileIndex].c_str())
00544     fReadOK = false;
00545     return 0;
00546   }
00547 
00548   // Sync. the event handle to the new file
00549   if (fEvtHandle->SetupInputFile(fInFile)) {
00550     this->UpdateEventNumbers();
00551     fReadOK = true;
00552     return 1;
00553   }
00554   
00555   // Error conditions fall through to here
00556   fReadOK = false;
00557   return 0;
00558 }

int io::ReadWriteModule::SetupOutputFile  )  [private]
 

void ReadWriteModule::UpdateEventNumbers  )  [private, virtual]
 

Update the run and event numbers used for tracking our position in the event stream

Definition at line 453 of file ReadWriteModule.cxx.

References edm::EventHeader::Event(), fEventNumber, fRunNumber, GetEvent(), edm::EventHandle::Header(), and edm::EventHeader::Run().

Referenced by Advance(), GoTo(), and SetupInputFile().

00454 {
00455   edm::EventHandle& ev = this->GetEvent();
00456   edm::EventHeader& eh = ev.Header();
00457   fRunNumber           = eh.Run();
00458   fEventNumber         = eh.Event();
00459 }

int ReadWriteModule::WriteEvent  ) 
 

Write event on the output file stream

Todo:
There should be some options for clearing temporary folders prior to writing out

Definition at line 468 of file ReadWriteModule.cxx.

References fEventNumber, fEvtHandle, fFlushFreq, fNwrite, fOutFile, fOutSizeLimit, SetOutputFileName(), and io::EventHandle::Write().

Referenced by main(), jobc::Job::Run(), and evdb::IoModule::WriteEvent().

00469 {
00470   if (fOutFile==0) {
00471     std::cout << "ReadWriteModule: No output file set." << std::endl;
00472     return 0;
00473   }
00474   int aok = fEvtHandle->Write();
00475   if (aok) {
00476     ++fNwrite;
00477     if (fNwrite%fFlushFreq == 0) { fOutFile->Flush(); }
00478   }
00479   if ((fOutSizeLimit > 0) &&
00480       (fOutSizeLimit < fOutFile->GetSize())) {
00481     // We should start writing to a new file
00482     std::string fname = fOutFile->GetName();
00483 
00484     std::string::size_type pos = fname.find("_Evt");
00485     if (pos == std::string::npos) {
00486       pos = fname.find(".root");
00487     }
00488     fname = fname.substr(0, pos);
00489     char evtStr[256];
00490     sprintf(evtStr, "_Evt%06d.root", fEventNumber);
00491     fname += evtStr;
00492     std::cout << "Starting new file: " << fname << std::endl;
00493     SetOutputFileName(fname.c_str());
00494   }
00495   return aok;
00496 }


Member Data Documentation

int io::ReadWriteModule::fEventNumber [private]
 

Event number for current event.

Definition at line 75 of file ReadWriteModule.h.

Referenced by GoTo(), UpdateEventNumbers(), and WriteEvent().

io::EventHandle* io::ReadWriteModule::fEvtHandle [private]
 

The event handle.

Definition at line 79 of file ReadWriteModule.h.

Referenced by AddFile(), Advance(), GetEvent(), Reload(), Report(), Rewind(), SetEventHandle(), SetOutputFileName(), SetupInputFile(), and WriteEvent().

int io::ReadWriteModule::fFileIndex [private]
 

Current place in the file list.

Definition at line 77 of file ReadWriteModule.h.

Referenced by AddFile(), AdvanceFile(), CurrentFile(), GoToFile(), RewindFile(), and SetupInputFile().

std::vector<std::string> io::ReadWriteModule::fFileList [private]
 

List of files attached.

Definition at line 81 of file ReadWriteModule.h.

Referenced by AddFile(), AdvanceFile(), CurrentFile(), FileName(), GoToFile(), Report(), and SetupInputFile().

int io::ReadWriteModule::fFlushFreq [private]
 

Flush output every n events.

Definition at line 86 of file ReadWriteModule.h.

Referenced by WriteEvent().

TFile* io::ReadWriteModule::fInFile [private]
 

Current file pointer.

Definition at line 78 of file ReadWriteModule.h.

Referenced by SetupInputFile(), and ~ReadWriteModule().

std::vector<io::Filter*> io::ReadWriteModule::fInFilterList [private]
 

Owned list of input filters.

Definition at line 90 of file ReadWriteModule.h.

Referenced by AdoptInputFilter(), CheckInFilters(), and ~ReadWriteModule().

int io::ReadWriteModule::fNwrite [private]
 

Number of events written.

Definition at line 85 of file ReadWriteModule.h.

Referenced by Close(), and WriteEvent().

TFile* io::ReadWriteModule::fOutFile [private]
 

Output data file.

Definition at line 84 of file ReadWriteModule.h.

Referenced by Close(), SetOutputFileName(), WriteEvent(), and ~ReadWriteModule().

std::vector<io::Filter*> io::ReadWriteModule::fOutFilterList [private]
 

Owned list of output filters.

Definition at line 91 of file ReadWriteModule.h.

Referenced by AdoptOutputFilter(), CheckOutFilters(), and ~ReadWriteModule().

Long64_t io::ReadWriteModule::fOutSizeLimit [private]
 

[bytes] Split output after this limit

Definition at line 87 of file ReadWriteModule.h.

Referenced by SetOutSizeLimit(), and WriteEvent().

bool io::ReadWriteModule::fOwnHandle [private]
 

Is the EvtHandle owned by us?

Definition at line 80 of file ReadWriteModule.h.

Referenced by SetEventHandle(), and ~ReadWriteModule().

bool io::ReadWriteModule::fReadOK [private]
 

Next read should be OK?

Definition at line 76 of file ReadWriteModule.h.

Referenced by AddFile(), Advance(), AdvanceFile(), RewindFile(), and SetupInputFile().

int io::ReadWriteModule::fRunNumber [private]
 

Run number for current event.

Definition at line 74 of file ReadWriteModule.h.

Referenced by GoTo(), and UpdateEventNumbers().


The documentation for this class was generated from the following files:
Generated on Sun Nov 22 04:45:31 2009 for NOvA Offline by  doxygen 1.3.9.1