emcOMQAFEM.C

Go to the documentation of this file.
00001 #include "emcOMAsciiT.h"
00002 #include "emcQAFEM.h"
00003 #include "emcDataManager.h"
00004 #include "EmcIndexer.h"
00005 #include "asciitimestamp.h"
00006 #include "dirfilemanip.h"
00007 #include <string>
00008 #include <vector>
00009 
00010 namespace
00011 {
00012   bool reader(emcQAFEM& qaFEM, int code)
00013   {
00014     // We read 4 status files for this FEM.
00015     // Each file containts:
00016     // PHTimeStamp begin
00017     // PHTimeStamp end
00018     // channel error warning
00019     // channel error warning
00020     // ...
00021     // where channel is between 0 and 143, error and warning are 6 bits flags
00022     // From the 4 6-bits flags, we hereby construct a 32 bits
00023     // (6x4+some reserved ones for future use) flag for each
00024     // channel. Ordering of the bytes is governed by the producers vector
00025     // below.
00026     //
00027     // NOTE: only absPosition is used here (pinNumber,post_pre and tac_pre
00028     // are dummy).
00029 
00030     int absPosition;
00031     int idummy;
00032 
00033     if ( code < 0 )
00034       {
00035         code = qaFEM.AbsolutePosition();
00036       }
00037 
00038     emcCalFEM::FEMDecode(code,absPosition,idummy,idummy,idummy);
00039 
00040     int SN;
00041     int SM144N;
00042 
00043     EmcIndexer::PXSM144_iSiSM144( absPosition, SN, SM144N );
00044 
00045     std::vector<std::string> producers;
00046     // The order of this procuders vector IS crucial
00047     // as it determines the status bit positions in the
00048     // final ERROR and WARNING arrays
00049 
00050     producers.push_back("PED");
00051     producers.push_back("HLR");
00052     producers.push_back("ToF");
00053     producers.push_back("GAINS");
00054 
00055     // Typically the file names are like
00056     // SxSMyy.FEMzzz.tac-pre.producer.QA
00057     // e.g.W1SM15.PED.QA
00058 
00059     emcDataManager* dm = emcDataManager::GetInstance();
00060 
00061     size_t i;
00062     char filename[256];
00063     INT32 ERROR[144], WARNING[144];
00064 
00065     PHTimeStamp begin;
00066     PHTimeStamp end;
00067     PHTimeStamp insert;
00068     end.setToFarFuture();
00069 
00070     for ( i = 0; i < 144; i++ )
00071       {
00072         ERROR[i] = WARNING[i] = 0;
00073       }
00074 
00075     std::string dir = expand(dm->GetSourceDir());
00076 
00077     for ( i = 0; i < producers.size(); i++ )
00078       {
00079 
00080         if ( (absPosition >= 172) &&
00081              ( producers[i] == "ToF" ||
00082                producers[i] == "GAINS") )
00083           continue;
00084 
00085         snprintf(filename, 256, "%s/QA/%sSM%02d.%s.QA",
00086                  dir.c_str(),
00087                  EmcIndexer::EmcSectorId(SN),
00088                  SM144N,
00089                  producers[i].c_str());
00090 
00091         std::ifstream fs(filename);
00092 
00093         if (!fs)
00094           {
00095             continue;
00096           }
00097 
00098         begin = getTimeStamp(fs);
00099         insert = getTimeStamp(fs);
00100 
00101         int channel;
00102         INT32 error , warning;
00103 
00104         while ( fs >> channel >> error >> warning )
00105           {
00106             assert (channel >= 0 && channel < 144);
00107             assert (error < 64);
00108             assert (warning < 64);
00109             ERROR[channel] |= (error << 6 * i);
00110             WARNING[channel] |= (warning << 6 * i);
00111           }
00112 
00113         fs.close();
00114       }
00115 
00116     for ( i = 0; i < 144; i ++ )
00117       {
00118         if ( ERROR[i] || WARNING[i] )
00119           {
00120             qaFEM.AppendOneChannel(i, ERROR[i], WARNING[i]);
00121           }
00122       }
00123 
00124     qaFEM.SetValidityPeriod(begin, end);
00125 
00126     return true;
00127   }
00128 
00129   emcOMAsciiT<emcQAFEM> gemcOMQAFEM("emcOMQA",
00130                                     "Read emcQAFEM objects",
00131                                     reader);
00132 }