lootSpillFiles.h File Reference

Go to the source code of this file.

Functions

void lootSpillFiles (const char *path, const char *logfile)
void lootSpillFile (const char *filename)
void createSpillTables ()

Function Documentation

void createSpillTables (  ) 

Definition at line 18 of file lootSpillFiles.cxx.

References DbiCascader::CreateStatement(), DbiStatement::ExecuteUpdate(), DbiTableProxyRegistry::GetCascader(), and DbiTableProxyRegistry::Instance().

Referenced by main().

00019 {
00020   int  dbNo = 0; // or whatever cascade entry you need
00021   DbiStatement* s = DbiTableProxyRegistry::Instance()
00022     .GetCascader()
00023     .CreateStatement(dbNo);
00024 
00025   s->ExecuteUpdate("create table if not exists SPILLTIMENDVLD ("
00026                    " SEQNO         int not null primary key auto_increment,"
00027                    " TIMESTART     datetime not null,"
00028                    " TIMEEND       datetime not null,"
00029                    " DETECTORMASK  tinyint,"
00030                    " SIMMASK       tinyint,"
00031                    " TASK          int,"
00032                    " AGGREGATENO   int,"
00033                    " CREATIONDATE  datetime not null,"
00034                    " INSERTDATE    datetime not null )");
00035 
00036   s->ExecuteUpdate("create table if not exists SPILLTIMEND ("
00037                    " SEQNO integer,"
00038                    " SECOND integer,"
00039                    " NANOSEC integer, "
00040                    " index (SEQNO))");
00041 
00042   delete s;  //Drop statement to release connection.
00043   s = 0;
00044 }

void lootSpillFile ( const char *  filename  ) 

Definition at line 95 of file lootSpillFiles.cxx.

References VldTimeStamp::AsString(), VldRange::AsString(), DbiWriter< T >::Close(), Form(), gSystem(), SimFlag::kData, Detector::kNear, SpillTimeND::kTask_TimeGoblin, and TimeIsValid().

Referenced by lootSpillFiles().

00096 {
00097   char filename[1000];
00098   strcpy(filename,infile);
00099 
00100   bool gzipped = false;
00101   TString tfile(infile);
00102   if(tfile.EndsWith(".gz")) {
00103     gzipped = true;
00104     gSystem->Exec(Form("gunzip %s -c > /tmp/temp_spilldata.dat",infile));
00105     sprintf(filename,"/tmp/temp_spilldata.dat");
00106   }
00107 
00108   ifstream file(filename);
00109   if(!file.good()){
00110     cout << "Problem reading file " << filename << endl;
00111     return;
00112   }
00113 
00114   int stampsec;
00115   int stampnsec;
00116   int type;
00117   int spill;
00118 
00119   // Get first guess at start/end times:
00120   int timeStart = 2000000000;
00121   int timeEnd   = -100000000;
00122 
00123   // Build a vector of the data:
00124   vector<VldTimeStamp> data;
00125   //VldTimeStamp data[100000];
00126   UInt_t ndata = 0;
00127 
00128   char cline[1000];
00129   //string constants. From TimeGoblin/SpillHandler.cxx
00130   string Start("Start:");
00131   string Stop("Stop:");
00132 
00133   while((!file.eof())&&(file.good())) {
00134     file.getline(cline,1000,'\n');
00135     
00136     string line(cline);
00137 
00138     if(line.size()<=0) continue;
00139     
00140     if(line[0]=='#') {
00141       // It's a comment line.
00142       string::size_type pos;    
00143 
00144       pos = line.find(Start);
00145       if(pos!=string::npos) {
00146         // Found start line.
00147         if(sscanf(cline+pos+Start.size(),"%d",&stampsec)>0) {
00148           if(stampsec<timeStart) timeStart=stampsec;      
00149           if(stampsec>timeEnd  ) timeEnd=stampsec;        
00150           cout << "Start: " << stampsec << endl;
00151         } else {
00152           cout << "Couldn't interpret Start: line" << endl;
00153         }
00154       }
00155 
00156       pos = line.find(Stop);
00157       if(pos!=string::npos) {
00158         // Found start line.
00159         if(sscanf(cline+pos+Stop.size(),"%d",&stampsec)>0) {
00160           if(stampsec<timeStart) timeStart=stampsec;      
00161           if(stampsec>timeEnd  ) timeEnd=stampsec;        
00162           cout << "Stop: " << stampsec << endl;
00163         } else {
00164           cout << "Couldn't interpret Stop: line" << endl;
00165         }
00166       }
00167       
00168     } else {
00169       // ordinary line.
00170       int res = sscanf(cline,"%d %d %d %d",&stampsec,&stampnsec,&type,&spill);
00171       if(res==4) {
00172         //if(type==3)  // only genuine stamps now are written.
00173           
00174         if(TimeIsValid(stampsec,timeStart)) {
00175           if((stampsec+1) > timeEnd  ) timeEnd = stampsec+1;
00176           if((stampsec  ) < timeStart) timeStart = stampsec;
00177           
00178           VldTimeStamp stamp(stampsec,stampnsec);
00179           //cout  << stampsec << "\t" << stampnsec << "\t" << stamp.AsString() << endl;
00180           
00181           //data[ndata] = stamp;
00182           data.push_back(stamp);      
00183           ndata++;
00184         } else {
00185           cout << "Invalid timestamp: " << cline << endl;
00186         }       
00187       } else {
00188         cout << "Bad line: " << cline << endl;
00189       }
00190     }
00191   }
00192   
00193   //if(ndata>0) // Write the DB table even if no rows!
00194   {
00195 
00196   VldTimeStamp vldStart(timeStart,0);
00197   VldTimeStamp vldEnd(timeEnd,0);
00198 
00199   cout << "Time start: " << timeStart << "\t" << vldStart.AsString() << endl;
00200   cout << "Time end: "   << timeEnd   << "\t" << vldEnd.AsString() << endl;  
00201 
00202   VldTimeStamp vldCreate = vldStart;
00203   
00204   VldRange range( (int)Detector::kNear,
00205                   (int)SimFlag::kData,
00206                   vldStart,
00207                   vldEnd,
00208                   Form("Timestamps looted from TimeGoblin file %s by script $ Id: $",infile)
00209                   );
00210 
00211   cout << "Starting write: " << range.AsString() << endl;
00212 
00213   DbiWriter<SpillTimeND> writer (range,
00214                                  -1, //Aggregate
00215                                  SpillTimeND::kTask_TimeGoblin,  //task
00216                                  vldCreate, // Creation date
00217                                  0,   // db no
00218                                  Form("Timestamps looted from TimeGoblin spilltime.dat file %s by script $ Id: $",infile)
00219                                  );
00220 
00221   for(UInt_t i = 0; i<ndata; i++) {
00222     SpillTimeND datum(data[i]);
00223     writer << datum;
00224   }
00225 
00226   writer.Close();
00227   }
00228 
00229 
00230   if(gzipped) gSystem->Exec("rm /tmp/temp_spilldata.dat");
00231 }

void lootSpillFiles ( const char *  path,
const char *  logfile 
)

Definition at line 47 of file lootSpillFiles.cxx.

References gSystem(), and lootSpillFile().

Referenced by main().

00048 {
00049   // Loot the given directory for goblin files.
00050   void* dir = gSystem->OpenDirectory(path);
00051   while(1) {
00052     const char* entry = gSystem->GetDirEntry(dir);
00053     if(!entry) break;
00054     TString entrystr(entry);
00055     if((entrystr.Contains("spilltime") && entrystr.Contains(".dat"))) {
00056       cout << "Looking at " << entry << endl;
00057       char filename[1000];
00058       sprintf(filename,"%s/%s",path,entry);
00059       bool good = true;
00060       
00061       {
00062         ifstream lootfile(logfile);
00063         if(!lootfile.good()) cout << "Can't find logfile " << logfile << endl;
00064         char line[1000];
00065         while((!lootfile.eof())&&(lootfile.good())) {
00066           lootfile.getline(line,1000,'\n');
00067           if(strcmp(line,filename)==0) good=false;
00068         }
00069         lootfile.close();
00070       }      
00071 
00072       if(good) {
00073         lootSpillFile(filename);
00074 
00075         // Log that this file is processed.
00076         ofstream lootfile(logfile,ios_base::out|ios_base::ate|ios_base::app);
00077         lootfile << filename << endl;
00078         lootfile.close();
00079         
00080       } else
00081         cout << "Already processed file " << filename << endl;
00082     }
00083   }
00084 }


Generated on 2 Nov 2017 for loon by  doxygen 1.6.1