Changeset 14702


Ignore:
Timestamp:
11/26/12 12:13:31 (12 years ago)
Author:
tbretz
Message:
Produce a consistent pair of night/run-number and propagate both to open a new file; check the night whenever a run number is manipulated.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/EventBuilderWrapper.h

    r14685 r14702  
    110110
    111111    string   fPath;
     112    uint64_t fNightAsInt;
    112113    uint32_t fRunNumber;
    113114
    114115protected:
    115     int64_t InitRunNumber()
    116     {
     116    bool InitRunNumber(const string &path="")
     117    {
     118        if (!path.empty())
     119        {
     120            if (!DimWriteStatistics::DoesPathExist(path, fMsg))
     121            {
     122                fMsg.Error("Data path "+path+" does not exist!");
     123                return false;
     124            }
     125
     126            fPath = path;
     127            fDimWriteStats.SetCurrentFolder(fPath);
     128
     129            fMsg.Info("Data path set to "+path+".");
     130        }
     131
     132        // Get current night
     133        const uint64_t night = Time().NightAsInt();
     134        if (night==fNightAsInt)
     135            return true;
     136
     137        // Check for run numbers
    117138        fRunNumber = 1000;
    118139
    119         // Ensure that the night doesn't change during our check
    120         const int check = Time().NightAsInt();
    121 
    122140        while (--fRunNumber>0)
    123141        {
    124             const string name = DataProcessorImp::FormFileName(fPath, fRunNumber, "");
     142            const string name = DataProcessorImp::FormFileName(fPath, night, fRunNumber, "");
    125143
    126144            if (access((name+"bin").c_str(), F_OK) == 0)
     
    130148            if (access((name+"drs.fits").c_str(), F_OK) == 0)
    131149                break;
    132 
    133         }
    134 
    135         if (check != Time().NightAsInt())
    136             return InitRunNumber();
    137 
     150        }
     151
     152        // This is now the first file which does not exist
    138153        fRunNumber++;
    139154
     155        // Check if we have exceeded the maximum
    140156        if (fRunNumber==1000)
    141157        {
    142             fMsg.Error("You have a file with run-number 1000 in "+fPath);
    143             return -1;
     158            fMsg.Error("You have a file with run-number 1000 in "+fPath+" ["+to_string(night)+"]");
     159            return false;
    144160        }
    145161
    146162        ostringstream str;
    147         str << "Set next run-number to " << fRunNumber << " determined from '" << (fPath.empty()?".":fPath) << "'";
     163        if (fNightAsInt==0)
     164            str << "First night...";
     165        else
     166            str << "Night has changd from " << fNightAsInt << "... new";
     167        str << " run-number is " << night << "-" << setfill('0') << setw(3) << fRunNumber << " [" << (fPath.empty()?".":fPath) << "]";
    148168        fMsg.Message(str);
    149169
    150         //fMsg.Info(" ==> TODO: Crosscheck with database!");
    151 
    152         return check;
    153     }
    154 
    155     int64_t InitRunNumber(const string &path)
    156     {
    157         if (!DimWriteStatistics::DoesPathExist(path, fMsg))
    158         {
    159             fMsg.Error("Data path "+path+" does not exist!");
    160             return -1;
    161         }
    162 
    163         //const fs::path fullPath = fs::system_complete(fs::path(path));
    164 
    165         fPath = path;
    166 
    167         fDimWriteStats.SetCurrentFolder(fPath);
    168 
    169         return InitRunNumber();
     170        fNightAsInt = night;
     171
     172        return true;
    170173    }
    171174
     
    255258                                                           "|numConn[int]:number of sockets successfully opened per board"),
    256259        fDimFileFormat  ("FAD_CONTROL/FILE_FORMAT",        "S:1",  ""),
    257         fDebugStream(false), fDebugRead(false), fDebugLog(false)
     260        fDebugStream(false), fDebugRead(false), fDebugLog(false), fNightAsInt(0)
    258261    {
    259262        if (This)
     
    298301            ref.second,
    299302        };
     303
     304        if (!InitRunNumber())
     305            return 0;
    300306
    301307        // FIMXE: Maybe reset an event counter so that the mcp can count events?
     
    630636        switch (fFileFormat)
    631637        {
    632         case FAD::kNone:    file = new DataDump(fPath, runid,  fMsg); break;
    633         case FAD::kDebug:   file = new DataDebug(fPath, runid, fMsg); break;
    634         case FAD::kCfitsio: file = new DataWriteFits(fPath, runid,  fMsg); break;
    635         case FAD::kFits:    file = new DataWriteFits2(fPath, runid,  fMsg); break;
    636         case FAD::kRaw:     file = new DataWriteRaw(fPath, runid,   fMsg); break;
    637         case FAD::kCalib:   file = new DataCalib(fPath, runid, fDimDrsCalibration, fDimDrsRuns, fMsg); break;
     638        case FAD::kNone:    file = new DataDump(fPath, fNightAsInt, runid,  fMsg); break;
     639        case FAD::kDebug:   file = new DataDebug(fPath, fNightAsInt, runid, fMsg); break;
     640        case FAD::kCfitsio: file = new DataWriteFits(fPath, fNightAsInt, runid,  fMsg); break;
     641        case FAD::kFits:    file = new DataWriteFits2(fPath, fNightAsInt, runid,  fMsg); break;
     642        case FAD::kRaw:     file = new DataWriteRaw(fPath, fNightAsInt, runid,   fMsg); break;
     643        case FAD::kCalib:   file = new DataCalib(fPath, fNightAsInt, runid, fDimDrsCalibration, fDimDrsRuns, fMsg); break;
    638644        }
    639645
     
    10501056    }
    10511057
    1052     void IncreaseRunNumber(uint32_t run)
    1053     {
    1054         if (run>fRunNumber)
    1055             fRunNumber = run;
     1058    bool IncreaseRunNumber(uint32_t run)
     1059    {
     1060        if (!InitRunNumber())
     1061            return false;
     1062
     1063        if (run<fRunNumber)
     1064        {
     1065            ostringstream msg;
     1066            msg <<
     1067                "Run number " << run << " smaller than next available "
     1068                "run number " << fRunNumber << " in " << fPath << " [" << fNightAsInt << "]";
     1069            fMsg.Error(msg);
     1070            return false;
     1071        }
     1072
     1073        fRunNumber = run;
     1074
     1075        return true;
    10561076    }
    10571077
Note: See TracChangeset for help on using the changeset viewer.