#!/ldcg/bin/tclsh

##******************************************************************
##
## Name: cacheCheck
##
## This is a utility for reporting cross directory conflict
## information that would otherwise be swallowed by the
## diskcache API and arbitrated based on ::MOUNT_PT order.
##
## By default, the system declared ::MOUNT_PT value will be
## used. However, the user may specify as many directories
## as he wishes as arguments, and they will be used instead
## of the ::MOUNT_PT.
##
## It can take several minutes to run on a large directory
## hierarchy.
##
## In some cases you may need to edit this file, but it will run
## as is at all official LDAS sites.
##
## Redirect stdout to a file to catch the output... important
## progress info will be sent to stderr.
##
## All data conflicts will be preceeded with Class::Method()
## that discovers the conflict, followed by path of a currently
## examined directory, followed by pair of "IFO-TYPE-" for data
## in conflict:
##
##   {DirectoryInfo::updateFrameHash() path='CURRENT_DIR'
##   'ifo-type-'='IFO-Type-': all conflicts}
##
## "all conflicts" could be a combination of multiple exceptions
## from the list below.
##
## Here are all possible conflict messages generated by the code:
##
## 1. Under the same directory:
##
##   * Duplicate start time is detected for GPS start time=NNN.
##
##   * Time overlap is detected for frame GPS start time=NNN
##     and already existing interval (startTime,stopTime)=(YYY,XXX).
##
##   * Time overlap is detected for updated interval
##     (startTime,stopTime)=(XXX,YYY) vs. interval
##     (startTime,stopTime)=(MMM,NNN).
##
## 2. Across different directories (under the same MOUNT_PT entry
##    when running in LDAS, or the same AND different MOUNT_PT
##    entries when running in "cacheCheck"):
##
##   * Duplicate start time is detected for GPS start time=NNN:
##     data already exists under 'DIR_PATH' directory.
##
##   * Time overlap is detected for frame GPS start time=NNN
##     and already existing interval (startTime,stopTime)=(XXX,YYY)
##     under "DIR_PATH' directory.
##
## email questions and problems to: pehrens@ligo.caltech.edu
##
##******************************************************************

set auto_path "/ldas/lib $auto_path"

;## this is to fool the genericAPI into thinking it is
;## in it's expected operating environment.
set ::API diskcache

;## the necessary libs for an LDAS diskcache API, and the
;## required resource files.
source /ldas_outgoing/LDASapi.rsc
source /ldas_outgoing/diskcacheAPI/LDASdiskcache.rsc
package require genericAPI
package require diskcacheAPI


puts stderr "update filename extensions ::SCANNED_FILENAME_EXTENSIONS: $::SCANNED_FILENAME_EXTENSIONS"
updateFileExtList $::SCANNED_FILENAME_EXTENSIONS


;## we can operate on a user specified set of directories, or
;## default to the directories listed in ::MOUNT_PT.
if { [ llength $argv ] } {
   set ::MOUNT_PT [ lrange $argv 0 end ]
}

puts stderr "scanning ::MOUNT_PT: $::MOUNT_PT"

;## special ofrm og updateMountPtList especially for this
;## utility.
updateMountPtList $::MOUNT_PT 1

puts stderr "please be patient, this can take a L-O-N-G time!"

foreach mtpt $::MOUNT_PT {
   puts stderr "scanning: $mtpt"
   set junk [ getDirEnt $mtpt ]
   foreach item $junk {
      foreach sub $item {
         puts stdout $sub
      }
   }
}

exit
