ascii_dump.cc

Go to the documentation of this file.
00001 
00006 #include "Reader.hh"
00007 #include "ConfigHandler.hh"
00008 #include "CommandSwitchFunctions.hh"
00009 #include "EventHandler.hh"
00010 #include "AsciiWriter.hh"
00011 #include "ConvertData.hh"
00012 
00013 #include <cstdlib>
00014 #include <string>
00015 
00016 
00017 void SetOutputFile(AsciiWriter* writer, const char* inputfile){
00018   if( writer->GetFilename() == writer->GetDefaultFilename() ){
00019      //set the filename to be the input filename + .txt
00020     std::string fname(inputfile);
00021     //remove a possible trailing slash in case of a directory argument
00022     while(fname.length()>0 && fname[fname.length()-1] =='/' ){
00023       fname.resize(fname.length()-1);
00024     }
00025     //remove leading directories
00026     while(fname.find('/') != std::string::npos){
00027       fname = fname.substr(fname.find('/')+1);
00028     }
00029     //remove filename suffix
00030     fname = fname.substr(0, fname.find('.'));
00031     //append the root filename
00032     fname.append(".txt");
00033     //make sure we haven't made an empty string here!
00034     if(fname!=".txt")
00035       writer->SetFilename(fname);
00036   }
00037 }
00038 
00039 int ProcessOneFile(const char* filename, int max_event=-1, int min_event=0)
00040 {
00041   Message(INFO)<<"\n***************************************\n"
00042                <<"  Processing File "<<filename
00043                <<"\n***************************************\n";
00044   EventHandler* modules = EventHandler::GetInstance();
00045   Reader reader(filename);
00046   
00047   if(modules->Initialize()){
00048     Message(ERROR)<<"Unable to initialize all modules.\n";
00049     return 1;
00050   }
00051   
00052   //read through the file and process all events
00053   time_t start_time = time(0);
00054   int evtnum = min_event;
00055   while(reader.IsOk() && !reader.eof()){
00056     if(max_event > 0 && evtnum >= max_event) 
00057       break;
00058     Message(DEBUG)<<"*************Event "<<evtnum<<"**************\n";
00059     if(evtnum%5000 == 0)
00060       Message(INFO)<<"Processing event "<<evtnum<<std::endl;
00061     
00062     RawEventPtr raw = reader.GetEventWithIndex(evtnum++);
00063     if(!raw){
00064       Message(ERROR)<<"Problem encountered reading event "<<evtnum<<std::endl;
00065     }
00066     modules->Process(raw);
00067     
00068   }
00069   //finish up
00070   modules->Finalize();
00071   Message(INFO)<<"Processed "<<evtnum - min_event<<" events in "
00072                <<time(0) - start_time<<" seconds. \n";
00073   return 0;
00074 }
00075 
00076 int main(int argc, char** argv)
00077 {
00078   int max_event=-1, min_event = 0;
00079   ConfigHandler* config = ConfigHandler::GetInstance();
00080   config->SetProgramUsageString("ascii_dum [<options>] <rawdata> [<rawdata2>...]");
00081   config->AddCommandSwitch(' ',"max","last event to process",
00082                            CommandSwitch::DefaultRead<int>(max_event),
00083                            "event");
00084   config->AddCommandSwitch(' ',"min","first event to process",
00085                            CommandSwitch::DefaultRead<int>(min_event),
00086                            "event");
00087   
00088   EventHandler* modules = EventHandler::GetInstance();
00089   //modules->AddCommonModules();
00090   modules->AddModule<ConvertData>();
00091   AsciiWriter* writer = modules->AddModule<AsciiWriter>();
00092   
00093   if(config->ProcessCommandLine(argc, argv))
00094     return -1;
00095 
00096   if(argc < 2){
00097     Message(ERROR)<<"Incorrect number of arguments: "<<argc<<std::endl;
00098     config->PrintSwitches(true);
00099   }
00100   
00101   for(int i = 1; i<argc; i++){
00102     if(i > 1)
00103       writer->SetFilename(writer->GetDefaultFilename());
00104     SetOutputFile(writer, argv[i] );
00105     if(ProcessOneFile(argv[i], max_event, min_event)){
00106       Message(ERROR)<<"Error processing file "<<argv[i]<<"; aborting.\n";
00107       return 1;
00108     }
00109   }
00110   return 0;
00111 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 20 Jun 2014 for daqman by  doxygen 1.6.1